Skip to content

Commit

Permalink
Add tools/build.py (denoland#398)
Browse files Browse the repository at this point in the history
To allow better tab completion for ./tools/build.py
mv build_third_party.py sync_third_party.py
  • Loading branch information
ry committed Jul 24, 2018
1 parent 0213053 commit 0875411
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 31 deletions.
17 changes: 5 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,24 @@ install:
- export PATH=$PATH:$DEPOT_TOOLS_PATH
# Sync dependencies.
# TODO(ry) These sync steps are very terrible and only here temporarily.
# A single deno_deps git submodule should be created which contains V8,
# node_modules, depot_tools, rustc, and other deps.
# Building Deno *should not* depend on yarn, gclient, rustup, cargo, nor any
# internet connection.
# rustc should be added to deno_third_party. Ultimately Deno *should not*
# depend on yarn, gclient, rustup, cargo, nor any internet connection.
- curl -sSf https://sh.rustup.rs | sh -s -- -y
- export PATH=$HOME/.cargo/bin:$PATH
- rustc --version
# TODO(ry) Do not depend on run_hooks because it calls
# //third_party/depot_tools/download_from_google_storage.py
# Use git lfs and combine run_hooks with build_third_party?
# Use git lfs and combine run_hooks with sync_third_party?
- ./tools/run_hooks.py
# ccache needs the custom LLVM to be in PATH and other variables.
- export PATH=`pwd`/third_party/llvm-build/Release+Asserts/bin:$PATH
- export CCACHE_CPP2=yes
- export CCACHE_SLOPPINESS=time_macros
# In case gn gen args change, delete args.gn to avoid using cached values.
- rm -f $BUILD_PATH/args.gn
- ccache -s
# is_debug, use_allocator, and ccache are used to speed travis.
# use_custom_libcxx=false and use_sysroot=false seem to be required to build on
# Ubuntu 14.04
- gn gen $BUILD_PATH --args='is_debug=false use_allocator="none" cc_wrapper="ccache" use_custom_libcxx=false use_sysroot=false'
- gn args $BUILD_PATH --list
- ccache -s
# Travis hangs without -j2 argument to ninja.
- ninja -j2 -C $BUILD_PATH :all
- ./tools/build.py --build_path=$BUILD_PATH --args='is_debug=false use_allocator="none" use_custom_libcxx=false use_sysroot=false'
script:
- ./tools/lint.py
- ./tools/test.py $BUILD_PATH
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Dummy package info required by `cargo fetch`
# Called from tools/build_third_party.py
# Called from tools/sync_third_party.py
# Should not be called with `cargo build`
[package]
name = "deno"
Expand All @@ -8,4 +8,4 @@ version = "0.0.0"
[dependencies]
url = "1.7.1"
libc = "0.2.42"
log = "0.4.3"
log = "0.4.3"
25 changes: 16 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,25 @@ To build:
cd deno
./tools/run_hooks.py

# Configure
./third_party/depot_tools/gn gen out/default
./third_party/depot_tools/gn gen out/release --args='cc_wrapper="ccache" is_official_build=true'
./third_party/depot_tools/gn gen out/debug --args='cc_wrapper="ccache" is_debug=true '

# Build
./third_party/depot_tools/ninja -C out/default/ deno
./tools/build.py

# Run
./out/debug/deno tests/002_hello.ts

Other useful commands:

./third_party/depot_tools/gn args out/default/ --list
./third_party/depot_tools/gn args out/default/
./third_party/depot_tools/gn desc out/default/ :deno
# Call ninja manually.
./third_party/depot_tools/ninja -C out/debug :all
# Build a release binary.
./tools/build.py --mode=release :deno
# List executable targets.
./third_party/depot_tools/gn ls out/debug //:* --as=output --type=executable
# List build configuation.
./third_party/depot_tools/gn args out/debug/ --list
# Edit build configuration.
./third_party/depot_tools/gn args out/debug/
# Describe a target.
./third_party/depot_tools/gn desc out/debug/ :deno
./third_party/depot_tools/gn help

69 changes: 69 additions & 0 deletions tools/build.py
Original file line number Diff line number Diff line change
@@ -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])
16 changes: 8 additions & 8 deletions tools/run_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
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':
Expand All @@ -25,5 +25,5 @@ def download(fn):
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'])
File renamed without changes.

0 comments on commit 0875411

Please sign in to comment.