From b6bb2978e18475cb8833a76094ee8320f74ec032 Mon Sep 17 00:00:00 2001 From: Zachary Anderson Date: Wed, 19 Apr 2017 09:00:12 -0700 Subject: [PATCH] [Fuchsia] Build only the parts of the SDK that are needed In particular, dart2js, dartdoc, and ddc aren't used. R=johnmccutchan@google.com, pylaligand@google.com Review-Url: https://codereview.chromium.org/2826793002 . --- BUILD.gn | 74 +------- sdk/BUILD.gn | 345 +++++++++++++++++++++++++++++++++++ tools/copy_tree.py | 56 ++++++ tools/create_sdk.py | 40 +--- tools/write_revision_file.py | 34 ++++ tools/write_version_file.py | 32 ++++ 6 files changed, 471 insertions(+), 110 deletions(-) create mode 100644 sdk/BUILD.gn create mode 100755 tools/copy_tree.py create mode 100755 tools/write_revision_file.py create mode 100755 tools/write_version_file.py diff --git a/BUILD.gn b/BUILD.gn index a0094562e53..f37232f4b79 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -67,80 +67,10 @@ group("runtime_precompiled") { ] } -action("create_sdk") { +group("create_sdk") { deps = [ - "runtime/bin:dart", - "utils/analysis_server", - "utils/compiler:dart2js", - "utils/compiler:utils_wrapper", - "utils/dartanalyzer:generate_dartanalyzer_snapshot", - "utils/dartanalyzer:generate_summary_spec", - "utils/dartanalyzer:generate_summary_strong", - "utils/dartdevc", - "utils/dartdoc", - "utils/dartfmt", - "utils/pub", + "sdk:create_sdk", ] - - sdk_lib_files = exec_script("tools/list_dart_files.py", - [ - "absolute", - rebase_path("sdk/lib"), - ], - "list lines") - - preamble_files = - exec_script("tools/list_files.py", - [ - "absolute", - "", - rebase_path("sdk/lib/_internal/js_runtime/lib/preambles"), - ], - "list lines") - - sdk_bin_files = exec_script("tools/list_files.py", - [ - "absolute", - "", - rebase_path("sdk/bin"), - ], - "list lines") - - inputs = sdk_lib_files + preamble_files + sdk_bin_files + [ - "sdk/lib/dart_client.platform", - "sdk/lib/dart_server.platform", - "sdk/lib/dart_shared.platform", - "$root_gen_dir/dart2js.dart.snapshot", - "$root_gen_dir/utils_wrapper.dart.snapshot", - "$root_gen_dir/pub.dart.snapshot", - "$root_gen_dir/dartanalyzer.dart.snapshot", - "$root_gen_dir/dartdevc.dart.snapshot", - "$root_gen_dir/dartfmt.dart.snapshot", - "$root_gen_dir/analysis_server.dart.snapshot", - "$root_gen_dir/dartdoc.dart.snapshot", - "$root_gen_dir/spec.sum", - "$root_gen_dir/strong.sum", - "tools/VERSION", - ] - - outputs = [ - "$root_out_dir/dart-sdk/README", - ] - - script = "tools/create_sdk.py" - args = [ - "--sdk_output_dir", - rebase_path("$root_out_dir/dart-sdk"), - "--snapshot_location", - rebase_path("$root_gen_dir"), - ] - if (defined(is_fuchsia) && is_fuchsia_host) { - args += [ "--copy_libs" ] - } - if (defined(is_fuchsia) && (is_fuchsia || is_fuchsia_host)) { - # The binaries are already stripped. - args += [ "--disable_stripping" ] - } } group("dart2js") { diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn new file mode 100644 index 00000000000..8ac005149e4 --- /dev/null +++ b/sdk/BUILD.gn @@ -0,0 +1,345 @@ +# Copyright (c) 2017, 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. + +# The SDK for Fuchsia does not include: +# dart2js +# dartdoc +# ddc +# and libraries that are browser-specific, since these are not used and require +# significant time to build. +# TODO(zra): Assemble the SDK completely with GN, and remove create_sdk.py. +if (defined(is_fuchsia) && (is_fuchsia || is_fuchsia_host)) { + +template("copy_tree") { + assert(defined(invoker.source), "copy_tree must define 'source'") + assert(defined(invoker.dest), "copy_tree must define 'dest'") + source = invoker.source + dest = invoker.dest + action(target_name) { + deps = [] + if (defined(invoker.deps)) { + deps += invoker.deps + } + input_files = exec_script("../tools/list_files.py", + [ + "absolute", + "", + rebase_path(source), + ], + "list lines") + inputs = input_files + relative_files = rebase_path(input_files, rebase_path(source)) + + output_files = [] + foreach(input, relative_files) { + output_files += ["$dest/$input"] + } + + outputs = output_files + script = "../tools/copy_tree.py" + args = [ + "--from", + rebase_path(source), + "--to", + rebase_path(dest), + ] + if (defined(invoker.exclude)) { + args += [ + "--exclude", + invoker.exclude, + ] + } + } +} + +copy("copy_dart") { + deps = [ "../runtime/bin:dart" ] + dart_out = get_label_info("../runtime/bin:dart", "root_out_dir") + dart_name = get_label_info("../runtime/bin:dart", "name") + sources = [ "$dart_out/$dart_name" ] + outputs = [ "$root_out_dir/dart-sdk/bin/dart" ] +} + +copy("copy_dylibs") { + deps = [ + "//third_party/boringssl:crypto", + "//third_party/boringssl:ssl", + ] + crypto_out = get_label_info("//third_party/boringssl:crypto", "root_out_dir") + crypto_name = get_label_info("//third_party/boringssl:crypto", "name") + ssl_out = get_label_info("//third_party/boringssl:ssl", "root_out_dir") + ssl_name = get_label_info("//third_party/boringssl:ssl", "name") + sources = [ + "$crypto_out/lib${crypto_name}.so", + "$ssl_out/lib${ssl_name}.so" + ] + outputs = [ "$root_out_dir/dart-sdk/bin/{{source_file_part}}" ] +} + +template("copy_sdk_script") { + assert(defined(invoker.name), "copy_sdk_script must define 'name'") + name = invoker.name + copy(target_name) { + sources = [ "bin/${name}_sdk" ] + outputs = [ "$root_out_dir/dart-sdk/bin/${name}"] + } +} + +_sdk_scripts = [ + "dartanalyzer", + "dartfmt", + "pub", +] + +foreach(sdk_script, _sdk_scripts) { + copy_sdk_script("copy_${sdk_script}_script") { + name = sdk_script + } +} + +group("copy_scripts") { + deps = [ + ":copy_dartanalyzer_script", + ":copy_dartfmt_script", + ":copy_pub_script", + ] +} + +_snapshots = [ + ["analysis_server", "../utils/analysis_server"], + ["dartanalyzer", "../utils/dartanalyzer:generate_dartanalyzer_snapshot"], + ["dartfmt", "../utils/dartfmt"], + ["pub", "../utils/pub"], +] + +foreach(snapshot, _snapshots) { + copy("copy_${snapshot[0]}_snapshot") { + deps = [ + snapshot[1], + ] + sources = [ "$root_gen_dir/${snapshot[0]}.dart.snapshot" ] + outputs = [ "$root_out_dir/dart-sdk/bin/snapshots/{{source_file_part}}" ] + } +} + +group("copy_snapshots") { + deps = [ + ":copy_analysis_server_snapshot", + ":copy_dartanalyzer_snapshot", + ":copy_dartfmt_snapshot", + ":copy_pub_snapshot", + ] +} + +copy("copy_analysis_summaries") { + deps = [ + ":copy_libraries", + "../utils/dartanalyzer:generate_summary_spec", + "../utils/dartanalyzer:generate_summary_strong", + ] + sources = [ + "$root_gen_dir/spec.sum", + "$root_gen_dir/strong.sum", + ] + outputs = [ "$root_out_dir/dart-sdk/lib/_internal/{{source_file_part}}" ] +} + +copy("copy_headers") { + sources = [ + "../runtime/include/dart_api.h", + "../runtime/include/dart_mirrors_api.h", + "../runtime/include/dart_native_api.h", + "../runtime/include/dart_tools_api.h", + ] + outputs = [ "$root_out_dir/dart-sdk/include/{{source_file_part}}" ] +} + +copy("copy_platform_files") { + sources = [ + "lib/dart_client.platform", + "lib/dart_server.platform", + "lib/dart_shared.platform", + ] + outputs = [ "$root_out_dir/dart-sdk/lib/{{source_file_part}}" ] +} + +copy_tree("copy_pub_assets") { + deps = [ ":copy_libraries" ] + source = "../third_party/pkg/pub/lib/src/asset" + dest = "$root_out_dir/dart-sdk/lib/_internal/pub/asset" +} + +_libraries = [ + "_internal", + "async", + "collection", + "convert", + "core", + "developer", + "internal", + "io", + "isolate", + "math", + "mirrors", + "profiler", + "typed_data", +] + +foreach(library, _libraries) { + copy_tree("copy_${library}_library") { + source = "lib/$library" + dest = "$root_out_dir/dart-sdk/lib/$library" + exclude = "*.svn,doc,*.py,*.gypi,*.sh,.gitignore" + } +} + +group("copy_libraries") { + deps = [ + ":copy__internal_library", + ":copy_async_library", + ":copy_collection_library", + ":copy_convert_library", + ":copy_core_library", + ":copy_developer_library", + ":copy_internal_library", + ":copy_io_library", + ":copy_isolate_library", + ":copy_math_library", + ":copy_mirrors_library", + ":copy_profiler_library", + ":copy_typed_data_library", + ] +} + +action("write_version_file") { + output = "$root_out_dir/dart-sdk/version" + outputs = [ output ] + script = "../tools/write_version_file.py" + args = [ + "--output", + rebase_path(output), + ] +} + +action("write_revision_file") { + output = "$root_out_dir/dart-sdk/revision" + outputs = [ output ] + script = "../tools/write_revision_file.py" + args = [ + "--output", + rebase_path(output) + ] +} + +copy("copy_readme") { + sources = [ "../README.dart-sdk" ] + outputs = [ "$root_out_dir/dart-sdk/README" ] +} + + +copy("copy_license") { + sources = [ "../LICENSE" ] + outputs = [ "$root_out_dir/dart-sdk/LICENSE" ] +} + + +copy("copy_api_readme") { + sources = [ "api_readme.md" ] + outputs = [ "$root_out_dir/dart-sdk/lib/api_readme.md" ] +} + + +group("create_sdk") { + deps = [ + ":copy_analysis_summaries", + ":copy_api_readme", + ":copy_dart", + ":copy_headers", + ":copy_libraries", + ":copy_license", + ":copy_platform_files", + ":copy_pub_assets", + ":copy_readme", + ":copy_scripts", + ":copy_snapshots", + ":write_revision_file", + ":write_version_file", + ] + if (is_fuchsia_host && is_linux) { + deps += [ ":copy_dylibs" ] + } +} + +} else { + +action("create_sdk") { + deps = [ + "../runtime/bin:dart", + "../utils/analysis_server", + "../utils/compiler:dart2js", + "../utils/compiler:utils_wrapper", + "../utils/dartanalyzer:generate_dartanalyzer_snapshot", + "../utils/dartanalyzer:generate_summary_spec", + "../utils/dartanalyzer:generate_summary_strong", + "../utils/dartdevc", + "../utils/dartdoc", + "../utils/dartfmt", + "../utils/pub", + ] + + sdk_lib_files = exec_script("../tools/list_dart_files.py", + [ + "absolute", + rebase_path("lib"), + ], + "list lines") + + preamble_files = + exec_script("../tools/list_files.py", + [ + "absolute", + "", + rebase_path("lib/_internal/js_runtime/lib/preambles"), + ], + "list lines") + + sdk_bin_files = exec_script("../tools/list_files.py", + [ + "absolute", + "", + rebase_path("bin"), + ], + "list lines") + + inputs = sdk_lib_files + preamble_files + sdk_bin_files + [ + "lib/dart_client.platform", + "lib/dart_server.platform", + "lib/dart_shared.platform", + "$root_gen_dir/dart2js.dart.snapshot", + "$root_gen_dir/utils_wrapper.dart.snapshot", + "$root_gen_dir/pub.dart.snapshot", + "$root_gen_dir/dartanalyzer.dart.snapshot", + "$root_gen_dir/dartdevc.dart.snapshot", + "$root_gen_dir/dartfmt.dart.snapshot", + "$root_gen_dir/analysis_server.dart.snapshot", + "$root_gen_dir/dartdoc.dart.snapshot", + "$root_gen_dir/spec.sum", + "$root_gen_dir/strong.sum", + "../tools/VERSION", + ] + + outputs = [ + "$root_out_dir/dart-sdk/README", + ] + + script = "../tools/create_sdk.py" + args = [ + "--sdk_output_dir", + rebase_path("$root_out_dir/dart-sdk"), + "--snapshot_location", + rebase_path("$root_gen_dir"), + ] +} + +} diff --git a/tools/copy_tree.py b/tools/copy_tree.py new file mode 100755 index 00000000000..da1cb6c8aa9 --- /dev/null +++ b/tools/copy_tree.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python +# Copyright (c) 2017, 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. + +import argparse +import os +import re +import shutil +import sys + +def ParseArgs(args): + args = args[1:] + parser = argparse.ArgumentParser( + description='A script to copy a file tree somewhere') + + parser.add_argument('--exclude_patterns', '-e', + type=str, + help='Patterns to exclude [passed to shutil.copytree]') + parser.add_argument('--from', '-f', + dest="copy_from", + type=str, + required=True, + help='Source tree root') + parser.add_argument('--to', '-t', + type=str, + required=True, + help='Destination') + + return parser.parse_args(args) + + +def ValidateArgs(args): + if not os.path.isdir(args.copy_from): + print "--from argument must refer to a directory" + return False + return True + + +def Main(argv): + args = ParseArgs(argv) + if not ValidateArgs(args): + return -1 + if os.path.exists(args.to): + shutil.rmtree(args.to) + if args.exclude_patterns == None: + shutil.copytree(args.copy_from, args.to) + else: + patterns = args.exclude_patterns.split(',') + shutil.copytree(args.copy_from, args.to, + ignore=shutil.ignore_patterns(tuple(patterns))) + return 0 + + +if __name__ == '__main__': + sys.exit(Main(sys.argv)) diff --git a/tools/create_sdk.py b/tools/create_sdk.py index 0260693f6ee..b93d0e4278c 100755 --- a/tools/create_sdk.py +++ b/tools/create_sdk.py @@ -94,28 +94,9 @@ def GetOptions(): help='Where to output the sdk') options.add_option("--snapshot_location", help='Location of the snapshots.') - options.add_option("--copy_libs", - action="store_true", default=False, - help='Copy dynamically linked libraries to the SDK bin directory.') - options.add_option("--disable_stripping", - action="store_true", default=False, - help='Do not try to strip binaries. Use when they are already stripped') return options.parse_args() -def ReplaceInFiles(paths, subs): - """Reads a series of files, applies a series of substitutions to each, and - saves them back out. subs should by a list of (pattern, replace) tuples.""" - for path in paths: - contents = open(path).read() - for pattern, replace in subs: - contents = re.sub(pattern, replace, contents) - - dest = open(path, 'w') - dest.write(contents) - dest.close() - - def Copy(src, dest): copyfile(src, dest) copymode(src, dest) @@ -138,20 +119,6 @@ def CopyShellScript(src_file, dest_dir): Copy(src, dest) -def CopyLibs(out_dir, bin_dir): - for library in ['libcrypto', 'libssl']: - ext = '.so' - if HOST_OS == 'macos': - ext = '.dylib' - elif HOST_OS == 'win32': - ext = '.dll' - src = os.path.join(out_dir, library + ext) - dst = os.path.join(bin_dir, library + ext) - if os.path.isfile(src): - copyfile(src, dst) - copymode(src, dst) - - def CopyDartScripts(home, sdk_root): for executable in ['dart2js_sdk', 'dartanalyzer_sdk', 'dartfmt_sdk', 'pub_sdk', 'dartdoc', 'dartdevc_sdk']: @@ -243,9 +210,9 @@ def Main(): copyfile(dart_src_binary, dart_dest_binary) copymode(dart_src_binary, dart_dest_binary) # Strip the binaries on platforms where that is supported. - if HOST_OS == 'linux' and not options.disable_stripping: + if HOST_OS == 'linux': subprocess.call(['strip', dart_dest_binary]) - elif HOST_OS == 'macos' and not options.disable_stripping: + elif HOST_OS == 'macos': subprocess.call(['strip', '-x', dart_dest_binary]) # @@ -336,9 +303,6 @@ def Main(): CopyAnalysisSummaries(SNAPSHOT, LIB) CopyDevCompilerSdk(HOME, LIB) - if options.copy_libs: - CopyLibs(build_dir, BIN) - # Write the 'version' file version = utils.GetVersion() versionFile = open(os.path.join(SDK_tmp, 'version'), 'w') diff --git a/tools/write_revision_file.py b/tools/write_revision_file.py new file mode 100755 index 00000000000..698f82ac8c9 --- /dev/null +++ b/tools/write_revision_file.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# Copyright (c) 2017, 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. + +import argparse +import os +import sys +import utils + +def ParseArgs(args): + args = args[1:] + parser = argparse.ArgumentParser( + description='A script to write the version string to a file') + + parser.add_argument('--output', '-o', + type=str, + required=True, + help='File to write') + + return parser.parse_args(args) + + +def Main(argv): + args = ParseArgs(argv) + revision = utils.GetGitRevision() + if revision is not None: + with open(args.output, 'w') as f: + f.write('%s\n' % revision) + return 0 + + +if __name__ == '__main__': + sys.exit(Main(sys.argv)) diff --git a/tools/write_version_file.py b/tools/write_version_file.py new file mode 100755 index 00000000000..f655845fe4c --- /dev/null +++ b/tools/write_version_file.py @@ -0,0 +1,32 @@ +#!/usr/bin/env python +# Copyright (c) 2017, 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. + +import argparse +import os +import sys +import utils + +def ParseArgs(args): + args = args[1:] + parser = argparse.ArgumentParser( + description='A script to write the version string to a file') + + parser.add_argument('--output', '-o', + type=str, + required=True, + help='File to write') + + return parser.parse_args(args) + + +def Main(argv): + args = ParseArgs(argv) + version = utils.GetVersion() + with open(args.output, 'w') as versionFile: + versionFile.write(version + '\n') + return 0 + +if __name__ == '__main__': + sys.exit(Main(sys.argv))