2018-10-31 03:32:42 -04:00
|
|
|
#!/usr/bin/env python
|
2019-01-21 14:03:30 -05:00
|
|
|
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-12-13 16:16:58 -05:00
|
|
|
# This file just executes its arguments, except that also adds GN_OUT_DIR and
|
|
|
|
# CARGO_PKG_VERSION to the environ. This is for compatibility with cargo.
|
2018-10-31 03:32:42 -04:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import os
|
2018-12-13 16:16:58 -05:00
|
|
|
import re
|
2018-10-31 03:32:42 -04:00
|
|
|
|
2019-07-07 16:39:56 -04:00
|
|
|
env = os.environ.copy()
|
|
|
|
|
2019-05-14 17:30:56 -04:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
# On Windows, when gn is setting up the build toolchain, it produces a set
|
|
|
|
# of environment variables that are required to invoke the right build
|
|
|
|
# toolchain. We need to load those environment variables here too in order
|
|
|
|
# for rustc to be able to successfully invoke the linker tool.
|
|
|
|
# The file is in 'windows environment block' format, which contains
|
|
|
|
# multiple 'key=value' pairs, separated by '\0' bytes, and terminated by
|
|
|
|
# two '\0' bytes at the end.
|
2019-07-07 16:39:56 -04:00
|
|
|
gn_env_pairs = open("environment.x64").read()[:-2].split('\0')
|
|
|
|
gn_env = dict([pair.split('=', 1) for pair in gn_env_pairs])
|
|
|
|
env.update(gn_env)
|
2019-05-14 17:30:56 -04:00
|
|
|
|
2018-11-01 01:06:55 -04:00
|
|
|
# This is for src/msg.rs to know where to find msg_generated.rs.
|
|
|
|
# When building with Cargo this variable is set by build.rs.
|
2019-05-14 17:30:56 -04:00
|
|
|
env["GN_OUT_DIR"] = os.path.abspath(".")
|
|
|
|
assert os.path.isdir(env["GN_OUT_DIR"])
|
2018-10-31 14:11:10 -04:00
|
|
|
|
2018-12-13 16:16:58 -05:00
|
|
|
# Set the CARGO_PKG_VERSION env variable if provided as an argument
|
|
|
|
# When building with Cargo this variable is set automatically
|
|
|
|
args = sys.argv[1:]
|
|
|
|
for i, arg in enumerate(args):
|
|
|
|
match = re.search('--cargo-pkg-version="?([^"]*)"?', arg)
|
|
|
|
if match:
|
2019-05-14 17:30:56 -04:00
|
|
|
env["CARGO_PKG_VERSION"] = match.group(1)
|
2018-12-13 16:16:58 -05:00
|
|
|
del args[i]
|
|
|
|
break
|
|
|
|
|
2019-05-14 17:30:56 -04:00
|
|
|
sys.exit(subprocess.call(args, env=env))
|