| # Copyright 2015 The Chromium 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/copy_tree.gni") | 
 | import("../../build/dart/dart_action.gni") | 
 | import("observatory_sources.gni") | 
 |  | 
 | prebuilt_dart_action("build_observatory") { | 
 |   visibility = [ ":copy_main_dart_js" ] | 
 |  | 
 |   # dart2js produces a .deps file, but it is not in a format that is understood | 
 |   # by ninja, so we explicitly list all the sources here. | 
 |   inputs = [ "../../.dart_tool/package_config.json" ] + observatory_sources | 
 |  | 
 |   output = "$target_gen_dir/observatory/web/main.dart.js" | 
 |   outputs = [ output ] | 
 |   if (is_debug) { | 
 |     outputs += [ "$target_gen_dir/observatory/web/main.dart.js.map" ] | 
 |   } | 
 |  | 
 |   args = [ | 
 |     "compile", | 
 |     "js", | 
 |     "-o", | 
 |     rebase_path(output, root_build_dir), | 
 |     "--packages=" + | 
 |         rebase_path("../../.dart_tool/package_config.json", root_build_dir), | 
 |     rebase_path("web/main.dart", root_build_dir), | 
 |   ] | 
 |   if (is_debug) { | 
 |     args += [ "--enable-asserts" ] | 
 |   } else { | 
 |     args += [ "--minify" ] | 
 |   } | 
 | } | 
 |  | 
 | # The rules here down to "deploy_observatory" copy files into place such that | 
 | # they can be packaged into a tar file. These rules do the following copies: | 
 | # | 
 | # web/* -> | 
 | #     $target_out_dir/observatory/deployed/web | 
 | # $target_gen_dir/observatory/web/main.dart.js -> | 
 | #     $target_out_dir/observatory/deployed/web/main.dart.js | 
 | # ../../third_party/observatory_pub_packages/packages/$PACKAGE/lib/* -> | 
 | #     $target_out_dir/observatory/deployed/web/packages/$PACKAGE | 
 | # lib/* -> | 
 | #     $target_out_dir/observatory/deployed/web/packages/observatory | 
 | # | 
 | # Files matching "observatory_ignore_patterns" are excluded. | 
 |  | 
 | # Files matching these patterns are filtered out of the Observatory assets. | 
 | observatory_ignore_patterns = [ | 
 |   # "\$sdk", this is the first element concatenated into the string below. | 
 |   "*.concat.js", | 
 |   "*.dart", | 
 |   "*.log", | 
 |   "*.precompiled.js", | 
 |   "*.scriptUrls", | 
 |   "*_buildLogs*", | 
 |   "*~", | 
 |   "CustomElements.*", | 
 |   "HTMLImports.*", | 
 |   "MutationObserver.*", | 
 |   "ShadowDOM.*", | 
 |   "bower.json", | 
 |   "dart_support.*", | 
 |   "interop_support.*", | 
 |   "package.json", | 
 |   "unittest*", | 
 | ] | 
 |  | 
 | if (!is_debug) { | 
 |   observatory_ignore_patterns += [ "*.map" ] | 
 | } | 
 |  | 
 | # The ignore_patterns entry in the scopes accepted by copy_tree() is a | 
 | # string of comma delimited patterns. | 
 | observatory_ignore_string = "\$sdk" | 
 | foreach(pattern, observatory_ignore_patterns) { | 
 |   observatory_ignore_string = "$observatory_ignore_string,$pattern" | 
 | } | 
 |  | 
 | copy_tree("copy_web_package") { | 
 |   visibility = [ | 
 |     ":copy_observatory_package", | 
 |     ":deploy_observatory", | 
 |   ] | 
 |   source = "web" | 
 |   dest = "$target_out_dir/observatory/deployed/web" | 
 |   exclude = observatory_ignore_string | 
 | } | 
 |  | 
 | copy_tree("copy_observatory_package") { | 
 |   visibility = [ | 
 |     ":copy_main_dart_js", | 
 |     ":deploy_observatory", | 
 |   ] | 
 |   source = "lib" | 
 |   dest = "$target_out_dir/observatory/deployed/web/packages/observatory" | 
 |   exclude = observatory_ignore_string | 
 |  | 
 |   # This deps prevents this copy and copy_web_package from racing on the | 
 |   # creation of the "web" directory. | 
 |   deps = [ ":copy_web_package" ] | 
 | } | 
 |  | 
 | copy("copy_main_dart_js") { | 
 |   visibility = [ ":deploy_observatory" ] | 
 |   deps = [ | 
 |     ":build_observatory", | 
 |  | 
 |     # This deps prevents this copy from racing with the above copy actions on | 
 |     # the creation of the "web" directory. | 
 |     ":copy_observatory_package", | 
 |   ] | 
 |   sources = [ "$target_gen_dir/observatory/web/main.dart.js" ] | 
 |   if (is_debug) { | 
 |     sources += [ "$target_gen_dir/observatory/web/main.dart.js.map" ] | 
 |   } | 
 |   outputs = [ "$target_out_dir/observatory/deployed/web/{{source_file_part}}" ] | 
 | } | 
 |  | 
 | group("deploy_observatory") { | 
 |   deps = [ | 
 |     ":copy_main_dart_js", | 
 |     ":copy_observatory_package", | 
 |     ":copy_web_package", | 
 |   ] | 
 | } | 
 |  | 
 | template("observatory_archive") { | 
 |   enable_compression = false | 
 |   if (defined(invoker.compress) && invoker.compress) { | 
 |     enable_compression = true | 
 |   } | 
 |   action(target_name) { | 
 |     deps = [ ":deploy_observatory" ] | 
 |  | 
 |     output_name = target_name | 
 |  | 
 |     output = "$target_gen_dir/${output_name}.tar" | 
 |     outputs = [ output ] | 
 |  | 
 |     script = "../tools/create_archive.py" | 
 |     args = [ | 
 |       "--tar_output", | 
 |       rebase_path(output, root_build_dir), | 
 |       "--client_root", | 
 |       rebase_path("$target_out_dir/observatory/deployed/web/", root_build_dir), | 
 |     ] | 
 |     if (enable_compression) { | 
 |       args += [ "--compress" ] | 
 |     } | 
 |   } | 
 | } | 
 |  | 
 | observatory_archive("compressed_observatory_archive") { | 
 |   compress = true | 
 | } | 
 |  | 
 | copy("copy_compressed_observatory_archive") { | 
 |   archive_target = ":compressed_observatory_archive" | 
 |   deps = [ archive_target ] | 
 |   archive_dir = get_label_info(archive_target, "target_gen_dir") | 
 |   archive_name = get_label_info(archive_target, "name") | 
 |   archive_file = "${archive_dir}/${archive_name}.tar" | 
 |   sources = [ archive_file ] | 
 |   outputs = [ "$root_out_dir/${archive_name}.tar" ] | 
 | } | 
 |  | 
 | observatory_archive("observatory_archive") { | 
 |   compress = false | 
 | } | 
 |  | 
 | copy("copy_observatory_archive") { | 
 |   archive_target = ":observatory_archive" | 
 |   deps = [ archive_target ] | 
 |   archive_dir = get_label_info(archive_target, "target_gen_dir") | 
 |   archive_name = get_label_info(archive_target, "name") | 
 |   archive_file = "${archive_dir}/${archive_name}.tar" | 
 |   sources = [ archive_file ] | 
 |   outputs = [ "$root_out_dir/${archive_name}.tar" ] | 
 | } | 
 |  | 
 | # Generates a .cc file containing the bytes of the observatory archive in a C | 
 | # array. | 
 | # | 
 | # Parameters: | 
 | #  inner_namespace (required): | 
 | #    The inner C++ namespace that the C array lives in. | 
 | # | 
 | #  outer_namespace (required): | 
 | #    The outer C++ namespace that the C array lives in. | 
 | # | 
 | #  archive_file (required): | 
 | #    The path to the observatory archive. | 
 | # | 
 | template("observatory_archive_source") { | 
 |   assert(defined(invoker.inner_namespace), | 
 |          "Need inner_namespace in $target_name") | 
 |   assert(defined(invoker.outer_namespace), | 
 |          "Need outer_namespace in $target_name") | 
 |   assert(defined(invoker.archive_file), "Need archive_file in $target_name") | 
 |  | 
 |   action(target_name) { | 
 |     forward_variables_from(invoker, [ "deps" ]) | 
 |  | 
 |     inputs = [ invoker.archive_file ] | 
 |  | 
 |     output = "$target_gen_dir/${target_name}.cc" | 
 |     outputs = [ output ] | 
 |  | 
 |     script = "../tools/create_archive.py" | 
 |     args = [ | 
 |       "--tar_input", | 
 |       rebase_path(invoker.archive_file, root_build_dir), | 
 |       "--output", | 
 |       rebase_path(output, root_build_dir), | 
 |       "--outer_namespace", | 
 |       invoker.outer_namespace, | 
 |       "--inner_namespace", | 
 |       invoker.inner_namespace, | 
 |       "--name", | 
 |       "observatory_assets_archive", | 
 |     ] | 
 |   } | 
 | } | 
 |  | 
 | observatory_archive_source("embedded_archive_observatory") { | 
 |   outer_namespace = "dart" | 
 |   inner_namespace = "observatory" | 
 |  | 
 |   # TODO(zra): In a Fuchsia build, use a prebuilt Observatory archive. | 
 |   archive_target = ":observatory_archive" | 
 |   deps = [ archive_target ] | 
 |   archive_dir = get_label_info(archive_target, "target_gen_dir") | 
 |   archive_name = get_label_info(archive_target, "name") | 
 |   archive_file = "${archive_dir}/${archive_name}.tar" | 
 | } | 
 |  | 
 | source_set("embedded_observatory_archive") { | 
 |   deps = [ ":embedded_archive_observatory" ] | 
 |  | 
 |   sources = [ rebase_path("$target_gen_dir/embedded_archive_observatory.cc") ] | 
 | } | 
 |  | 
 | observatory_archive_source("standalone_archive_observatory") { | 
 |   outer_namespace = "dart" | 
 |   inner_namespace = "bin" | 
 |  | 
 |   # TODO(zra): In a Fuchsia build, use a prebuilt Observatory archive. | 
 |   archive_target = ":compressed_observatory_archive" | 
 |   deps = [ archive_target ] | 
 |   archive_dir = get_label_info(archive_target, "target_gen_dir") | 
 |   archive_name = get_label_info(archive_target, "name") | 
 |   archive_file = "${archive_dir}/${archive_name}.tar" | 
 | } | 
 |  | 
 | source_set("standalone_observatory_archive") { | 
 |   deps = [ ":standalone_archive_observatory" ] | 
 |  | 
 |   sources = [ rebase_path("$target_gen_dir/standalone_archive_observatory.cc") ] | 
 | } |