From 0875411267d62a0fdcaf762657f19082b440fe36 Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Tue, 24 Jul 2018 13:42:23 -0400 Subject: Add tools/build.py (#398) To allow better tab completion for ./tools/build.py mv build_third_party.py sync_third_party.py --- tools/build.py | 69 ++++++++++++++++++++++++++++++++++++++++++++++ tools/build_third_party.py | 35 ----------------------- tools/run_hooks.py | 16 +++++------ tools/sync_third_party.py | 35 +++++++++++++++++++++++ 4 files changed, 112 insertions(+), 43 deletions(-) create mode 100755 tools/build.py delete mode 100755 tools/build_third_party.py create mode 100755 tools/sync_third_party.py (limited to 'tools') diff --git a/tools/build.py b/tools/build.py new file mode 100755 index 000000000..fb061eae3 --- /dev/null +++ b/tools/build.py @@ -0,0 +1,69 @@ +#!/usr/bin/env python +# Copyright 2018 the Deno authors. All rights reserved. MIT license. +import argparse +import os +import sys +from os.path import join +from util import run +import distutils.spawn + +parser = argparse.ArgumentParser(description='') +parser.add_argument( + '--build_path', default='', help='Directory to build into.') +parser.add_argument( + '--args', default='', help='Specifies build arguments overrides.') +parser.add_argument( + '--mode', default='debug', help='Build configuration: debug, release.') +options, targets = parser.parse_known_args() + +root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +third_party_path = join(root_path, "third_party") +depot_tools_path = join(third_party_path, "depot_tools") +gn_path = join(depot_tools_path, "gn") +ninja_path = join(depot_tools_path, "ninja") + +# Add third_party/depot_tools to PATH because some google tools (e.g. +# tool_wrapper, download_from_google_storage) use some google specific python +# wrapper. +os.environ["PATH"] = depot_tools_path + os.pathsep + os.environ["PATH"] + +os.chdir(root_path) + +if options.build_path: + build_path = options.build_path +else: + build_path = join(root_path, "out", options.mode) + +gn_args = [] +if options.args: + gn_args += options.args.split() + +if options.mode == "release": + gn_args += ["is_official_build=true"] +elif options.mode == "debug": + pass +else: + print "Bad mode {}. Use 'release' or 'debug' (default)" % options.mode + sys.exit(1) + +# Check if ccache is in the path, and if so we cc_wrapper. +ccache_path = distutils.spawn.find_executable("ccache") +if ccache_path: + gn_args += [r'cc_wrapper="%s"' % ccache_path] + +# mkdir $build_path. We do this so we can write args.gn before running gn gen. +if not os.path.isdir(build_path): + os.makedirs(build_path) + +# Rather than using gn gen --args we manually write the args.gn override file. +# This is to avoid quoting/escaping complications when passing overrides as +# command-line arguments. +args_filename = join(build_path, "args.gn") +if not os.path.exists(args_filename) or options.args: + with open(args_filename, "w+") as f: + f.write("\n".join(gn_args) + "\n") + +run([gn_path, "gen", build_path]) + +target = " ".join(targets) if targets else ":all" +run([ninja_path, "-C", build_path, target]) diff --git a/tools/build_third_party.py b/tools/build_third_party.py deleted file mode 100755 index f32d669b2..000000000 --- a/tools/build_third_party.py +++ /dev/null @@ -1,35 +0,0 @@ -#!/usr/bin/env python -# Only run this script if you are changing Deno's dependencies. - -import os -from os.path import join -from util import run, remove_and_symlink - -root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) -third_party_path = join(root_path, "third_party") - -try: - os.makedirs(third_party_path) -except: - pass -os.chdir(third_party_path) - -# Run yarn to install JavaScript dependencies. -remove_and_symlink("../package.json", "package.json") -remove_and_symlink("../yarn.lock", "yarn.lock") -run(["yarn"]) -# Run cargo to install Rust dependencies. -run(["cargo", "fetch", "--manifest-path=" + root_path + "/Cargo.toml"], - envs={'CARGO_HOME': third_party_path + '/rust_crates'}) -# Run gclient to install other dependencies. -run(["gclient", "sync", "--reset", "--shallow", "--no-history", "--nohooks"], - envs={'GCLIENT_FILE': root_path + "/gclient_config.py"}) -# TODO(ry) Is it possible to remove these symlinks? -remove_and_symlink("v8/third_party/googletest", "googletest", True) -remove_and_symlink("v8/third_party/jinja2", "jinja2", True) -remove_and_symlink("v8/third_party/llvm-build", "llvm-build", True) -remove_and_symlink("v8/third_party/markupsafe", "markupsafe", True) - -# To update the deno_third_party git repo after running this, try the following: -# cd third_party -# find . -type f | grep -v "\.git" | xargs -I% git add -f --no-warn-embedded-repo "%" diff --git a/tools/run_hooks.py b/tools/run_hooks.py index 2ec671186..58178a69c 100755 --- a/tools/run_hooks.py +++ b/tools/run_hooks.py @@ -9,14 +9,14 @@ depot_tools_path = os.path.join(third_party_path, "depot_tools") os.chdir(root_path) -def download(fn): +def download(filename): run([ + "python", os.path.join(depot_tools_path + '/download_from_google_storage.py'), - '--no_resume', '--platform=' + sys.platform, '--no_auth', '--bucket', - 'chromium-gn', '-s', - os.path.join(root_path, fn) - ], - quiet=True) + '--platform=' + sys.platform, '--no_auth', '--bucket=chromium-gn', + '--sha1_file', + os.path.join(root_path, filename) + ]) if sys.platform == 'win32': @@ -25,5 +25,5 @@ elif sys.platform == 'darwin': download("third_party/v8/buildtools/mac/gn.sha1") elif sys.platform.startswith('linux'): download("third_party/v8/buildtools/linux64/gn.sha1") -run(['python', 'third_party/v8/tools/clang/scripts/update.py', '--if-needed'], - quiet=True) + +run(['python', 'third_party/v8/tools/clang/scripts/update.py', '--if-needed']) diff --git a/tools/sync_third_party.py b/tools/sync_third_party.py new file mode 100755 index 000000000..f32d669b2 --- /dev/null +++ b/tools/sync_third_party.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python +# Only run this script if you are changing Deno's dependencies. + +import os +from os.path import join +from util import run, remove_and_symlink + +root_path = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) +third_party_path = join(root_path, "third_party") + +try: + os.makedirs(third_party_path) +except: + pass +os.chdir(third_party_path) + +# Run yarn to install JavaScript dependencies. +remove_and_symlink("../package.json", "package.json") +remove_and_symlink("../yarn.lock", "yarn.lock") +run(["yarn"]) +# Run cargo to install Rust dependencies. +run(["cargo", "fetch", "--manifest-path=" + root_path + "/Cargo.toml"], + envs={'CARGO_HOME': third_party_path + '/rust_crates'}) +# Run gclient to install other dependencies. +run(["gclient", "sync", "--reset", "--shallow", "--no-history", "--nohooks"], + envs={'GCLIENT_FILE': root_path + "/gclient_config.py"}) +# TODO(ry) Is it possible to remove these symlinks? +remove_and_symlink("v8/third_party/googletest", "googletest", True) +remove_and_symlink("v8/third_party/jinja2", "jinja2", True) +remove_and_symlink("v8/third_party/llvm-build", "llvm-build", True) +remove_and_symlink("v8/third_party/markupsafe", "markupsafe", True) + +# To update the deno_third_party git repo after running this, try the following: +# cd third_party +# find . -type f | grep -v "\.git" | xargs -I% git add -f --no-warn-embedded-repo "%" -- cgit v1.2.3