chromium/chrome/updater/win/installer/BUILD.gn

# Copyright 2019 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/python.gni")
import("//build/timestamp.gni")
import("//chrome/process_version_rc_template.gni")
import("//chrome/updater/branding.gni")
import("//testing/test.gni")

source_set("msi_custom_action_sources") {
  sources = [
    "msi_custom_action.cc",
    "msi_custom_action.h",
  ]

  deps = [
    "//base",
    "//chrome/updater:public_sources",
    "//chrome/updater:tagging",
    "//third_party/abseil-cpp:absl",
  ]

  libs = [ "msi.lib" ]
}

shared_library("msi_custom_action") {
  sources = [ "msi_custom_action.def" ]

  deps = [
    ":msi_custom_action_sources",
    ":version",
  ]

  configs += [ "//build/config/win:windowed" ]
}

source_set("lib") {
  visibility = [
    ":lib_with_resources",
    "//chrome/updater:updater_test_sources",
    "//chrome/updater/test/test_installer:test_meta_installer",
  ]
  sources = [
    "configuration.cc",
    "configuration.h",
    "exit_code.h",
    "installer.cc",
    "installer.h",
    "installer_constants.cc",
    "installer_constants.h",
    "installer_resource.h",
    "pe_resource.cc",
    "pe_resource.h",
    "string.cc",
    "string.h",
  ]

  public_deps = [ "//base" ]

  deps = [
    "//chrome/installer/util:constants",
    "//chrome/installer/util:metainstaller_utils",
    "//chrome/updater:base",
    "//chrome/updater:branding_header",
    "//chrome/updater:tagging",
    "//third_party/abseil-cpp:absl",
  ]
}

source_set("lib_with_resources") {
  visibility = [ ":*" ]
  sources = [ "installer.rc" ]
  public_deps = [ ":lib" ]
}

# `process_version_rc_template` invokes `process_version` with the default
# template rc file which is at //chrome/app/chrome_version.rc.version.
process_version_rc_template("version") {
  _internal_name = "$updater_metainstaller_name" + "($current_cpu)"
  if (is_debug) {
    _internal_name += " (debug)"
  }
  extra_args = [
    "-e",
    "PRODUCT_FULLNAME=\"$updater_metainstaller_name\"",
    "-e",
    "INTERNAL_NAME=\"$_internal_name\"",
    "-e",
    "ORIGINAL_FILENAME=\"UpdaterSetup.exe\"",
    "-e",
    "PRODUCT_SHORTNAME=\"$updater_product_full_name\"",
  ]
  output = "$root_out_dir/installer_version.rc"
}

# This target creats a list of runtime dependencies for the component
# builds. This list is parsed by the |create_installer_archive| script, the
# DLL paths extracted out from the list, and included in the archive.
updater_runtime_deps = "$target_gen_dir/updater.runtime_deps"
group("updater_runtime_deps") {
  write_runtime_deps = updater_runtime_deps
  data_deps = [ "//chrome/updater/win:updater" ]
}

updater_test_runtime_deps = "$target_gen_dir/updater_test.runtime_deps"
group("updater_test_runtime_deps") {
  write_runtime_deps = updater_test_runtime_deps
  data_deps = [ "//chrome/updater/win:updater_test" ]
}

template("generate_installer") {
  output_dir = invoker.out_dir
  packed_files_rc_file = "$target_gen_dir/$target_name/packed_files.rc"
  archive_name = target_name + "_archive"
  staging_dir = "$target_gen_dir/$target_name"

  action(archive_name) {
    script = "create_installer_archive.py"

    release_file = invoker.release_file

    inputs = [ release_file ]

    outputs = [
      "$output_dir/updater.packed.7z",
      packed_files_rc_file,
    ]

    args = [
      "--build_dir",
      rebase_path(root_out_dir, root_build_dir),
      "--staging_dir",
      rebase_path(staging_dir, root_build_dir),
      "--input_file",
      rebase_path(release_file, root_build_dir),
      "--resource_file_path",
      rebase_path(packed_files_rc_file, root_build_dir),
      "--output_dir",
      rebase_path(output_dir, root_build_dir),
      "--setup_runtime_deps",
      rebase_path(invoker.runtime_deps, root_build_dir),
      "--output_name=updater",
      "--timestamp",
      build_timestamp,

      # Optional argument for verbose archiving output.
      #"--verbose",
    ]

    deps = invoker.archive_deps

    if (is_component_build) {
      args += [ "--component_build=1" ]
    }
  }

  executable(target_name) {
    output_name = invoker.output_name

    sources = [
      "installer_main.cc",
      packed_files_rc_file,
    ]

    configs += [ "//build/config/win:windowed" ]

    libs = [ "setupapi.lib" ]

    deps = [
             ":$archive_name",
             ":lib_with_resources",
             ":version",
             "//build/win:default_exe_manifest",
             "//chrome/updater:base",
             "//chrome/updater:branding_header",
             "//third_party/abseil-cpp:absl",
           ] + invoker.deps
  }
}

generate_installer("installer") {
  out_dir = root_out_dir
  output_name = "UpdaterSetup"
  archive_deps = [
    ":updater_runtime_deps",
    "//chrome/updater/win:updater",
  ]
  deps = [ "//chrome/updater:constants_prod" ]
  release_file = "updater.release"
  runtime_deps = updater_runtime_deps
}

generate_installer("installer_test") {
  out_dir = root_out_dir + "/update_test_contents"
  output_name = "UpdaterSetup_test"
  archive_deps = [
    ":updater_test_runtime_deps",
    "//chrome/updater/win:updater_test",
  ]
  deps = [ "//chrome/updater:constants_test" ]
  release_file = "updater_test.release"
  runtime_deps = updater_test_runtime_deps
}