chromium/chrome/installer/util/BUILD.gn

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

import("//base/win/embedded_i18n/generate_embedded_i18n.gni")
import("//build/config/chrome_build.gni")

import("//testing/test.gni")

if (is_win) {
  source_set("metainstaller_utils") {
    sources = [
      "delete_after_reboot_helper.cc",
      "delete_after_reboot_helper.h",
      "lzma_util.cc",
      "lzma_util.h",
      "self_cleaning_temp_dir.cc",
      "self_cleaning_temp_dir.h",
    ]
    deps = [ "//third_party/lzma_sdk/google:seven_zip_reader" ]
    public_deps = [
      "//base",
      "//third_party/abseil-cpp:absl",
    ]
  }

  source_set("work_item") {
    sources = [
      "callback_work_item.cc",
      "callback_work_item.h",
      "conditional_work_item_list.cc",
      "conditional_work_item_list.h",
      "copy_tree_work_item.cc",
      "copy_tree_work_item.h",
      "create_dir_work_item.cc",
      "create_dir_work_item.h",
      "create_reg_key_work_item.cc",
      "create_reg_key_work_item.h",
      "delete_reg_key_work_item.cc",
      "delete_reg_key_work_item.h",
      "delete_reg_value_work_item.cc",
      "delete_reg_value_work_item.h",
      "delete_tree_work_item.cc",
      "delete_tree_work_item.h",
      "duplicate_tree_detector.cc",
      "duplicate_tree_detector.h",
      "install_service_work_item.cc",
      "install_service_work_item.h",
      "install_service_work_item_impl.cc",
      "install_service_work_item_impl.h",
      "move_tree_work_item.cc",
      "move_tree_work_item.h",
      "registry_key_backup.cc",
      "registry_key_backup.h",
      "registry_util.cc",
      "registry_util.h",
      "set_reg_value_work_item.cc",
      "set_reg_value_work_item.h",
      "work_item.cc",
      "work_item.h",
      "work_item_list.cc",
      "work_item_list.h",
    ]
    public_deps = [ "//base" ]
  }
}

# This file deliberately has no default "util" target so dependants have to
# specify with the ":with_no_strings" or ":with_rc_strings" variants. Random
# code that ends up getting linked into chrome proper should depend on the
# ":with_no_strings" variant. Other standalone apps will need to decide if they
# need the resource strings or not.
#
# chrome/installer/util has generated strings on Windows. These appear as
# Windows resources and are fairly large (~200KB). They are generated by the
# ":generate_strings" target and compiled by the ":strings" target.
#
# Some code, like the Windows chrome.exe (the small bootstrap binary, not
# all of chrome.dll) code uses installer_util functions without calling any
# functions that use the strings. And historically in the GYP build the strings
# resource had to be manually linked, so the strings never ended up being in
# chrome.exe and everything was fine.
#
# Other code, like chrome.dll links to installer util, and hooks up a
# TranslationDelegate which overrides the strings retrieved from the resources
# with grit pak strings.
#
# In both of these cases, link to the ":with_no_strings" variant. However, this
# is obviously a fragile and confusing situation. In the "I don't use strings at
# all case", there is no definition of what works and doesn't work, and this may
# also change over time. As an example at the time of this writing, chrome.exe
# calls GoogleUpdateSettings::UpdateDidRunState. This function doesn't use any
# strings, but other functions in InstallUtil do use localized strings.
#
# Ideally, this should be cleaved in two parts: the main "installer util" and
# some kind of mini installer util that just contains the functions needed by
# chrome.exe and any other clients that don't need the strings. It's likely
# we would still need the variant with no strings for when chrome.dll replaces
# all strings with its own versions.
static_library("with_no_strings") {
  public_deps = [ ":constants" ]

  deps = [
    "//base",
    "//chrome:strings",
    "//chrome/common:constants",
    "//components/variations",
    "//third_party/abseil-cpp:absl",
  ]

  # The constants target checks the Chrome distribution from this target. Both
  # targets have to be linked together in practice.
  allow_circular_includes_from = [ "//chrome/common:constants" ]

  if (is_win) {
    sources = [
      "additional_parameters.cc",
      "additional_parameters.h",
      "advanced_firewall_manager_win.cc",
      "advanced_firewall_manager_win.h",
      "app_command.cc",
      "app_command.h",
      "app_commands.cc",
      "app_commands.h",
      "auto_launch_util.cc",
      "auto_launch_util.h",
      "beacons.cc",
      "beacons.h",
      "delete_old_versions.cc",
      "delete_old_versions.h",
      "firewall_manager_win.cc",
      "firewall_manager_win.h",
      "google_update_settings.cc",
      "google_update_settings.h",
      "google_update_util.cc",
      "google_update_util.h",
      "helper.cc",
      "helper.h",
      "html_dialog.h",
      "html_dialog_impl.cc",
      "initial_preferences.cc",
      "initial_preferences.h",
      "install_util.cc",
      "install_util.h",
      "installation_state.cc",
      "installation_state.h",
      "l10n_string_util.cc",
      "l10n_string_util.h",
      "logging_installer.cc",
      "logging_installer.h",
      "per_install_values.cc",
      "per_install_values.h",
      "registry_entry.cc",
      "registry_entry.h",
      "scoped_token_privilege.cc",
      "scoped_token_privilege.h",
      "shell_util.cc",
      "shell_util.h",
      "taskbar_util.cc",
      "taskbar_util.h",
    ]

    public_deps += [
      ":did_run_support",
      ":metainstaller_utils",
      ":work_item",

      # Need to depend on the generated strings target since files here
      # depend on the generated header, but only depend on the ":strings"
      # target (which actually compiles and causes the generated code to be
      # linked) from the ":util" target.
      ":generate_strings",
    ]

    deps += [
      "//base:i18n",
      "//base/win:pe_image",
      "//build:branding_buildflags",
      "//chrome/install_static:install_static_util",
      "//components/app_launch_prefetch",
      "//components/base32",
      "//components/metrics:client_info",
      "//components/version_info:channel",
      "//crypto",
      "//rlz/buildflags",
      "//third_party/icu",
    ]

    libs = [
      "urlmon.lib",
      "wtsapi32.lib",
    ]

    configs += [ "//build/config:precompiled_headers" ]
  } else {
    sources = [
      "initial_preferences.cc",
      "initial_preferences.h",
    ]
  }
}

# Use this version of installer_util to link to the generated strings in .rc
# format.
group("with_rc_strings") {
  public_deps = [ ":with_no_strings" ]
  if (is_win) {
    public_deps += [ ":strings" ]
  }
}

generate_embedded_i18n("generate_strings") {
  visibility = [
    ":strings",
    ":with_no_strings",
  ]
  extractor_datafile =
      "//chrome/installer/util/prebuild/create_installer_string_rc.py"

  grdfile_folder = "//chrome/app/"
  grdfile_name = "${branding_path_product}_strings"
  xtb_relative_path = "resources"
  grd_files_info = [ [
        grdfile_folder,
        grdfile_name,
        xtb_relative_path,
        default_embedded_i18_locales,
      ] ]

  output_file_name_base = "installer_util_strings"

  branding = branding_path_product
}

# Compile the generated .rc file.
source_set("strings") {
  sources = get_target_outputs(":generate_strings")
  public_deps = [ ":generate_strings" ]
}

source_set("constants") {
  public = [ "initial_preferences_constants.h" ]

  sources = [ "initial_preferences_constants.cc" ]

  if (is_win) {
    public += [
      "google_update_constants.h",
      "util_constants.h",
    ]

    sources += [
      "google_update_constants.cc",
      "util_constants.cc",
    ]

    public_deps = [ "//base" ]
  }
}

if (is_win) {
  source_set("did_run_support") {
    public = [ "update_did_run_state.h" ]

    sources = [ "update_did_run_state.cc" ]

    deps = [
      ":constants",
      "//base",
      "//chrome/install_static:install_static_util",
    ]
  }

  source_set("test_support") {
    testonly = true
    sources = [
      "fake_installation_state.h",
      "fake_product_state.h",
    ]
    deps = [
      ":with_no_strings",
      "//base",
    ]
  }

  # This source set contains tests that must run serially. These are linked into
  # setup_unittests, which does so.
  source_set("serial_unittests") {
    testonly = true
    sources = [
      "install_service_work_item_unittest.cc",
      "per_install_values_unittest.cc",
    ]
    deps = [
      ":with_no_strings",
      "//base",
      "//chrome/install_static:install_static_util",
      "//chrome/install_static/test:test_support",
      "//testing/gtest",
    ]
  }

  test("installer_util_unittests") {
    sources = [
      "additional_parameters_unittest.cc",
      "advanced_firewall_manager_win_unittest.cc",
      "beacons_unittest.cc",
      "callback_work_item_unittest.cc",
      "conditional_work_item_list_unittest.cc",
      "copy_tree_work_item_unittest.cc",
      "create_dir_work_item_unittest.cc",
      "create_reg_key_work_item_unittest.cc",
      "delete_after_reboot_helper_unittest.cc",
      "delete_old_versions_unittest.cc",
      "delete_reg_key_work_item_unittest.cc",
      "delete_reg_value_work_item_unittest.cc",
      "delete_tree_work_item_unittest.cc",
      "duplicate_tree_detector_unittest.cc",
      "google_update_settings_unittest.cc",
      "helper_unittest.cc",
      "initial_preferences_unittest.cc",
      "install_util_unittest.cc",
      "installation_state_unittest.cc",
      "l10n_string_util_unittest.cc",
      "logging_installer_unittest.cc",
      "lzma_util_unittest.cc",
      "move_tree_work_item_unittest.cc",
      "product_state_unittest.cc",
      "product_unittest.cc",
      "registry_key_backup_unittest.cc",
      "registry_test_data.cc",
      "registry_test_data.h",
      "registry_util_unittest.cc",
      "run_all_unittests.cc",
      "scoped_token_privilege_unittest.cc",
      "self_cleaning_temp_dir_unittest.cc",
      "set_reg_value_work_item_unittest.cc",
      "shell_util_unittest.cc",
      "work_item_list_unittest.cc",
      "work_item_mocks.cc",
      "work_item_mocks.h",
      "work_item_unittest.cc",
    ]

    deps = [
      ":test_support",
      ":with_rc_strings",
      "//base",
      "//base/test:test_support",
      "//build:branding_buildflags",
      "//chrome:other_version",
      "//chrome/common:constants",
      "//chrome/install_static:install_static_util",
      "//chrome/install_static/test:test_support",
      "//chrome/installer/test:alternate_version_generator_lib",
      "//components/variations",
      "//components/version_info:channel",
      "//rlz/buildflags",
      "//testing/gmock",
      "//testing/gtest",
    ]

    data = [
      "//chrome/test/data/extensions/",
      "//chrome/test/data/installer/",
    ]
  }
}  # is_win