[build] Copy Observatory assets with GN rather than observatory_tool.py

Change-Id: Ib6faf31fffaa49dadbf47056cbce353348b7680c
Reviewed-on: https://dart-review.googlesource.com/64241
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
This commit is contained in:
Zach Anderson 2018-07-10 19:08:47 +00:00 committed by commit-bot@chromium.org
parent e26d3d5f9f
commit 576f01045a
4 changed files with 128 additions and 86 deletions

View file

@ -2,7 +2,7 @@
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
_dart_root = rebase_path("..")
_dart_root = rebase_path("../..")
# copy_tree() copies a directory tree rooted at `source` to `dest`, which should
# be somewhere under $root_out_dir.

View file

@ -2,10 +2,13 @@
# 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_dart2js_action("build_observatory") {
visibility = [ ":copy_main_dart_js" ]
script = "web/main.dart"
# dart2js produces a .deps file, but it is not in a format that is understood
@ -38,32 +41,139 @@ prebuilt_dart2js_action("build_observatory") {
]
}
# TODO(zra): Investigate using GN's copy() with set_sources_assignment_filter
# instead of using a python script.
action("deploy_observatory") {
# 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",
"*.map",
"*.precompiled.js",
"*.scriptUrls",
"*_buildLogs*",
"*~",
"CustomElements.*",
"HTMLImports.*",
"MutationObserver.*",
"ShadowDOM.*",
"bower.json",
"dart_support.*",
"interop_support.*",
"package.json",
"unittest*",
"webcomponents-lite.js",
"webcomponents.*",
]
# The ignore_patterns entry in the scopes accepted by copy_trees() 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_specs = []
copy_tree_specs += [
{
target = "copy_web_package"
visibility = [ ":deploy_observatory" ]
source = "web"
dest = "$target_out_dir/observatory/deployed/web"
ignore_patterns = observatory_ignore_string
},
]
copy_tree_specs += [
{
target = "copy_observatory_package"
visibility = [ ":deploy_observatory" ]
source = "lib"
dest = "$target_out_dir/observatory/deployed/web/packages/observatory"
ignore_patterns = observatory_ignore_string
},
]
# All the contents of third_party/observatory_pub_packages should be
# accounted for here. Uncommented entries are those packages that have
# files that pass the observatory_ignore_patterns filters.
observatory_pub_packages = [
"browser",
"charted",
"intl",
# Dependent packages that have no files that pass the above filter.
# "collection",
# "logging",
# "matcher",
# "meta",
# "observable",
# "path",
# "quiver",
# "stack_trace",
# "usage",
# Only needed for testing.
# "unittest",
]
foreach(package, observatory_pub_packages) {
copy_tree_specs += [
{
target = "copy_${package}_package"
visibility = [ ":deploy_observatory" ]
source =
"../../third_party/observatory_pub_packages/packages/$package/lib"
dest = "$target_out_dir/observatory/deployed/web/packages/$package"
ignore_patterns = observatory_ignore_string
},
]
}
# This is not a rule, rather, it generates rules with names of the form:
# "copy_$package_package" for the packages in observatory_pub_packages.
copy_trees("copy_observatory_packages") {
sources = copy_tree_specs
}
copy("copy_main_dart_js") {
visibility = [ ":deploy_observatory" ]
deps = [
":build_observatory",
]
script = "../../tools/observatory_tool.py"
inputs = [
sources = [
"$target_gen_dir/observatory/web/main.dart.js",
]
args = [
rebase_path("$target_out_dir/observatory/deployed"),
rebase_path("web"),
rebase_path("lib"),
rebase_path("$target_gen_dir/observatory/web/main.dart.js"),
rebase_path("../../third_party/observatory_pub_packages/packages"),
]
outputs = [
"$target_out_dir/observatory/deployed/web/main.dart.js",
]
}
group("deploy_observatory") {
deps = [
":copy_browser_package",
":copy_charted_package",
":copy_intl_package",
":copy_main_dart_js",
":copy_observatory_package",
":copy_web_package",
]
}
template("observatory_archive") {
enable_compression = false
if (defined(invoker.compress) && invoker.compress) {
@ -74,10 +184,6 @@ template("observatory_archive") {
":deploy_observatory",
]
inputs = [
"$target_out_dir/observatory/deployed/web/main.dart.js",
]
output_name = target_name
output = "$target_gen_dir/${output_name}.tar"

View file

@ -13,7 +13,7 @@
# or ":copy_libraries" may delete/overwrite your addition, and the build will
# fail.
import("copy_tree.gni")
import("../build/dart/copy_tree.gni")
declare_args() {
# Build a SDK with less stuff. It excludes dart2js, ddc, and web libraries.

View file

@ -1,64 +0,0 @@
#!/usr/bin/env python
# Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
"""Helper for building and deploying Observatory"""
import os
import shutil
import sys
IGNORE_PATTERNS = shutil.ignore_patterns(
'$sdk',
'*.concat.js',
'*.dart',
'*.log',
'*.map',
'*.precompiled.js',
'*.scriptUrls',
'*_buildLogs*',
'*~',
'CustomElements.*',
'HTMLImports.*',
'MutationObserver.*',
'ShadowDOM.*',
'bower.json',
'dart_support.*',
'interop_support.*',
'package.json',
'unittest*',
'webcomponents-lite.js',
'webcomponents.*')
# - Copy over the filtered web directory
# - Merge in the .js file
# - Copy over the filtered dependency lib directories
# - Copy over the filtered observatory package
def Deploy(output_dir, web_dir, observatory_lib, js_file, pub_packages_dir):
shutil.rmtree(output_dir)
os.makedirs(output_dir)
output_web_dir = os.path.join(output_dir, 'web')
shutil.copytree(web_dir, output_web_dir, ignore=IGNORE_PATTERNS)
os.utime(os.path.join(output_web_dir, 'index.html'), None)
shutil.copy(js_file, output_web_dir)
packages_dir = os.path.join(output_web_dir, 'packages')
os.makedirs(packages_dir)
for subdir in os.listdir(pub_packages_dir):
libdir = os.path.join(pub_packages_dir, subdir, 'lib')
if os.path.isdir(libdir):
shutil.copytree(libdir, os.path.join(packages_dir, subdir),
ignore=IGNORE_PATTERNS)
shutil.copytree(observatory_lib, os.path.join(packages_dir, 'observatory'),
ignore=IGNORE_PATTERNS)
def Main():
args = sys.argv[1:]
return Deploy(args[0], args[1], args[2], args[3], args[4])
if __name__ == '__main__':
sys.exit(Main());