| # Copyright 2018 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| import("//build/dart/dart_library.gni") |
| import("//build/dart/toolchain.gni") |
| |
| _compiler_label = "//topaz/runtime/dart:kernel_compiler($host_toolchain)" |
| _compiler_path = get_label_info(_compiler_label, "root_out_dir") + "/dart-tools/kernel_compiler" |
| |
| # Generates dill files for a Dart application |
| # |
| # Parameters |
| # |
| # platform_deps (required) |
| # Dependent targets that populate `platform_path` with the platform dill |
| # files. |
| # |
| # platform_path (required) |
| # Path to the build output directory containing the platform dill files. |
| # |
| # platform_name (required) |
| # The name of the platform, either "flutter_runner" or "dart_runner". |
| # |
| # main_dart (required) |
| # Path to Dart source file containing main(). |
| # |
| # package_name (optional) |
| # The name of the dart package. If not provided it will be inferred from the |
| # target name. |
| # |
| # sources (optional) |
| # A list of the application's Dart source files. |
| # |
| # manifest (optional) |
| # Path to an output manifest file containing the list of partial dill files. |
| # |
| # args (optional) |
| # A list of additional arguments to the compiler.dart program in this |
| # directory that generates the kernel files. |
| # |
| # gen_bytecode (optional) |
| # Whether the kernel compiler should generate bytecode. Defaults to false. |
| # |
| # Forwarded to dart_library: |
| # deps, disable_analysis, non_dart_deps, source_dir. |
| template("dart_kernel") { |
| assert(defined(invoker.platform_deps), "dart_kernel() requires platform_deps") |
| assert(defined(invoker.platform_path), "dart_kernel() requires platform_path") |
| assert(defined(invoker.platform_name), "dart_kernel() requires platform_name") |
| assert(defined(invoker.main_dart), "dart_kernel() requires main_dart") |
| |
| dart_library_target_name = "${target_name}_dart_library" |
| dart_library(dart_library_target_name) { |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "package_root", |
| "disable_analysis", |
| "non_dart_deps", |
| "source_dir", |
| ]) |
| |
| if (defined(invoker.package_name)) { |
| package_name = invoker.package_name |
| } else { |
| infer_package_name = true |
| } |
| |
| sources = [] |
| if (defined(invoker.sources)) { |
| sources += invoker.sources |
| } |
| extra_sources = [ |
| invoker.main_dart, |
| ] |
| } |
| |
| # TODO(tvolkert): Name this ${target_name} |
| action("${target_name}_kernel") { |
| pool = "//build/dart:dart_pool($dart_toolchain)" |
| forward_variables_from(invoker, ["testonly", "visibility"]) |
| |
| kernel_path = "$target_gen_dir/${target_name}.dil" |
| |
| depfile = "${kernel_path}.d" |
| deps = invoker.platform_deps + [ |
| ":$dart_library_target_name", |
| _compiler_label, |
| ] |
| outputs = [ |
| kernel_path, |
| ] |
| if (defined(invoker.manifest)) { |
| outputs += [ |
| # Explicit output when using --manifest. |
| invoker.manifest, |
| # Implicit output when using --manifest; see createManifest in compiler.dart. |
| invoker.manifest + ".dilplist", |
| ] |
| } |
| |
| dart_target_gen_dir = |
| get_label_info(":bogus($dart_toolchain)", "target_gen_dir") |
| rebased_packages_path = |
| rebase_path("$dart_target_gen_dir/$dart_library_target_name.packages", "//") |
| |
| multi_root_scheme = "fuchsia-source" |
| |
| script = _compiler_path |
| args = invoker.args + [ |
| "--target", |
| invoker.platform_name, |
| "--platform", |
| rebase_path("${invoker.platform_path}/platform_strong.dill"), |
| "--filesystem-scheme", |
| multi_root_scheme, |
| "--filesystem-root", |
| rebase_path("//"), |
| "--packages", |
| "$multi_root_scheme:///$rebased_packages_path", |
| "--depfile", |
| rebase_path(depfile, root_build_dir), |
| "--output", |
| rebase_path(kernel_path, root_build_dir), |
| "--no-link-platform", |
| ] |
| if (defined(invoker.manifest)) { |
| args += [ |
| "--split-output-by-packages", |
| "--manifest", |
| rebase_path(invoker.manifest), |
| ] |
| } |
| if (is_debug) { |
| args += [ "--embed-sources" ] |
| } else { |
| args += [ "--no-embed-sources" ] |
| } |
| |
| if (defined(invoker.gen_bytecode) && invoker.gen_bytecode) { |
| # TODO(zra): Drop ASTs when bytecode works without ASTs. |
| args += [ "--gen-bytecode" ] |
| } |
| |
| rebased_main_dart = rebase_path(invoker.main_dart, "//") |
| args += [ "$multi_root_scheme:///$rebased_main_dart" ] |
| } |
| } |