tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

generate_runner_scripts.gni (8916B)


      1 # Copyright 2018 The Chromium Authors
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 import("//chromium/build/config/fuchsia/config.gni")
      6 import("//chromium/build/config/fuchsia/fuchsia_package_metadata.gni")
      7 import("//chromium/build/config/gclient_args.gni")
      8 import("//chromium/build/config/sysroot.gni")
      9 import("//chromium/build/util/generate_wrapper.gni")
     10 
     11 assert(is_fuchsia)
     12 
     13 declare_args() {
     14   # Sets the Fuchsia Amber repository which will be used by default by the
     15   # generated installation scripts. If not specified, then no default directory
     16   # will be used.
     17   default_fuchsia_out_dir = ""
     18 
     19   # Sets the Fuchsia device node name which will be used by default by the
     20   # generated runner scripts. If not specficed, then no default node name will
     21   # be used.
     22   default_fuchsia_device_node_name = ""
     23 
     24   # CPU architecture of the host used to run the tests.
     25   test_host_cpu = host_cpu
     26 
     27   # Sets whether emulators need to be included in the test isolates
     28   test_isolate_uses_emulator = true
     29 
     30   # A list of additional Fuchsia boot images to include in the test isolates.
     31   fuchsia_additional_boot_images = []
     32 
     33   # This variable controls the browser included in the Telemetry based test
     34   # targets.
     35   fuchsia_browser_type = "web_engine_shell"
     36 }
     37 
     38 # Generates a wrapper script under root_build_dir/bin that performs an
     39 # operation, such as deployment or execution, using a package and its
     40 # dependencies.
     41 #
     42 # Parameters:
     43 #   output_name_format: The format string for the generated script's filename.
     44 #                       The placeholder string %package% will be substituted
     45 #                       with |package| (or |package_name|, if set).
     46 #                       Examples: "run_%package%", "install_%package%"
     47 #   package: The package() target to run.
     48 #   package_name: Specifies the name of the generated package, if its
     49 #       filename is different than the |package| target name. This value must
     50 #       match package_name in the |package| target.
     51 #   package_deps: An array of [package, package_name] array pairs
     52 #       which specify additional dependency packages to be installed
     53 #       prior to execution.
     54 #   executable: The underlying script to be called by the script.
     55 #   executable_args: The list of arguments to pass to |executable|.
     56 #                    Runtime commandline arguments can be passed to
     57 #                    |executable| using the placeholder %args%.
     58 #
     59 #                    In addition, the script is passed the following
     60 #                    executable_args:
     61 #                      --package - the path to a .FAR package to install.
     62 #                      --package_name - the name of the package to use as an
     63 #                                       entry point.
     64 #   include_fuchsia_out_dir: If true, adds |default_fuchsia_out_dir|
     65 #                            to executable_args (when set in GN args).
     66 template("fuchsia_run_script_with_packages") {
     67   if (defined(invoker.package_name)) {
     68     _pkg_shortname = invoker.package_name
     69   } else {
     70     _pkg_shortname = get_label_info(invoker.package, "name")
     71   }
     72 
     73   _generated_script_path =
     74       "$root_build_dir/bin/" +
     75       string_replace(invoker.output_name_format, "%package%", _pkg_shortname)
     76 
     77   generate_wrapper(target_name) {
     78     forward_variables_from(invoker,
     79                            TESTONLY_AND_VISIBILITY + [
     80                                  "executable",
     81                                  "executable_args",
     82                                  "data",
     83                                  "include_fuchsia_out_dir",
     84                                  "target",
     85                                ])
     86 
     87     wrapper_script = _generated_script_path
     88     deps = [ invoker.package ]
     89 
     90     if (!defined(data_deps)) {
     91       data_deps = []
     92     }
     93     data_deps += [ "//chromium/build/config/fuchsia:deployment_resources" ]
     94 
     95     _combined_package_list = [ invoker.package ]
     96 
     97     if (defined(invoker.package_deps)) {
     98       foreach(package_dep, invoker.package_deps) {
     99         _combined_package_list += [ package_dep[0] ]
    100       }
    101     }
    102     foreach(package_dep, _combined_package_list) {
    103       data_deps += [
    104         package_dep,
    105         package_dep + "__archive-manifest",
    106         package_dep + "__archive-metadata",
    107       ]
    108     }
    109 
    110     if (defined(invoker.data_deps)) {
    111       data_deps += invoker.data_deps
    112     }
    113 
    114     # Compute the list of full paths to package files, including dependencies.
    115     if (defined(invoker.package_deps)) {
    116       foreach(package_dep, invoker.package_deps) {
    117         package_dep_target = package_dep[0]
    118         deps += [ package_dep_target ]
    119         data_deps += [ package_dep_target ]
    120       }
    121     }
    122 
    123     # Include package information inside the wrapper script.
    124     if (!defined(executable_args)) {
    125       executable_args = []
    126     }
    127 
    128     if (defined(include_fuchsia_out_dir) && include_fuchsia_out_dir &&
    129         default_fuchsia_out_dir != "") {
    130       executable_args += [
    131         "--fuchsia-out-dir",
    132         default_fuchsia_out_dir,
    133       ]
    134     }
    135   }
    136 
    137   # Create a wrapper script rather than using a group() in order to ensure
    138   # "ninja $target_name" always works.
    139   if (defined(invoker.executable_wrapper)) {
    140     generate_wrapper(invoker.executable_wrapper) {
    141       forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
    142       executable = _generated_script_path
    143       wrapper_script = "$root_build_dir/${invoker.executable_wrapper}"
    144       deps = [
    145         ":${invoker._install_target}",
    146         ":${invoker._run_target}",
    147       ]
    148     }
    149   }
    150 }
    151 
    152 # Generates a script which deploys a package to the TUF repo of a Fuchsia
    153 # build output directory.
    154 template("fuchsia_package_installer") {
    155   if (defined(invoker.package_name)) {
    156     pkg_shortname = invoker.package_name
    157   } else {
    158     pkg_shortname = get_label_info(invoker.package, "name")
    159   }
    160   fuchsia_package_metadata(pkg_shortname) {
    161     forward_variables_from(invoker,
    162                            TESTONLY_AND_VISIBILITY + [
    163                                  "package",
    164                                  "package_deps",
    165                                ])
    166   }
    167   fuchsia_run_script_with_packages(target_name) {
    168     forward_variables_from(invoker,
    169                            "*",
    170                            TESTONLY_AND_VISIBILITY + [ "executable_args" ])
    171     forward_variables_from(invoker, TESTONLY_AND_VISIBILITY)
    172     executable = rebase_path("//chromium/build/fuchsia/test/deploy_to_fuchsia.py")
    173     executable_args = [
    174       "--out-dir",
    175       "@WrappedPath(.)",
    176       pkg_shortname,
    177     ]
    178     output_name_format = "deploy_%package%"
    179     include_fuchsia_out_dir = true
    180   }
    181 }
    182 
    183 # Generates scripts for installing and running test packages.
    184 # See fuchsia_run_script_with_packages() for the full list of parameters.
    185 template("fuchsia_test_runner") {
    186   _run_target = "${target_name}__runner"
    187   _install_target = "${target_name}__installer"
    188 
    189   fuchsia_run_script_with_packages(_run_target) {
    190     forward_variables_from(invoker,
    191                            TESTONLY_AND_VISIBILITY + [
    192                                  "data",
    193                                  "data_deps",
    194                                  "package",
    195                                  "package_name",
    196                                  "package_deps",
    197                                ])
    198 
    199     _test_runner_py = "//chromium/build/fuchsia/test/run_test.py"
    200 
    201     executable = rebase_path(_test_runner_py)
    202 
    203     if (defined(invoker.is_test_exe) && invoker.is_test_exe) {
    204       data += [ "//.vpython3" ]
    205     }
    206     output_name_format = "run_%package%"
    207     executable_wrapper = invoker.target_name
    208 
    209     # Populate the arguments used by the test runner, defined at build-time.
    210     executable_args = [
    211       "--out-dir",
    212       "@WrappedPath(.)",
    213     ]
    214 
    215     executable_args += [ package_name ]
    216 
    217     if (defined(invoker.use_test_server) && invoker.use_test_server) {
    218       executable_args += [ "--enable-test-server" ]
    219     }
    220 
    221     if (default_fuchsia_device_node_name != "") {
    222       executable_args += [
    223         "--target-id",
    224         default_fuchsia_device_node_name,
    225       ]
    226     }
    227 
    228     # Declare the files that are needed for test execution on LUCI swarming
    229     # test clients, both directly (via data) or indirectly (via data_deps).
    230     if (!defined(data)) {
    231       data = []
    232     }
    233     data += [
    234       _test_runner_py,
    235       "$root_gen_dir/package_metadata/${invoker.package_name}.meta",
    236     ]
    237 
    238     # TODO(crbug.com/40200403): Remove this once all out-of-tree references
    239     # to "package_name_override" are migrated to "package_name".
    240     if (defined(invoker.package_name_override)) {
    241       package_name = invoker.package_name_override
    242     }
    243   }
    244   fuchsia_package_installer(_install_target) {
    245     forward_variables_from(invoker,
    246                            TESTONLY_AND_VISIBILITY + [
    247                                  "package",
    248                                  "package_name",
    249                                  "package_deps",
    250                                ])
    251   }
    252 }