summaryrefslogtreecommitdiff
path: root/build_extra/rust/run.py
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2019-08-28 22:19:07 -0700
committerBert Belder <bertbelder@gmail.com>2019-08-29 10:45:00 -0700
commit89794d5d347d1358ec32ed42e1f0faa6e0ac6abe (patch)
treeb93bd2b981486f13e56349eb619252dc23bcfb9c /build_extra/rust/run.py
parent590463bd4a8d71330ab808774b63dd6b366bba1f (diff)
build: make it possible to pass arbitrary env vars to rustc
Diffstat (limited to 'build_extra/rust/run.py')
-rw-r--r--build_extra/rust/run.py39
1 files changed, 18 insertions, 21 deletions
diff --git a/build_extra/rust/run.py b/build_extra/rust/run.py
index 36d1ab83a..7c6bea08a 100644
--- a/build_extra/rust/run.py
+++ b/build_extra/rust/run.py
@@ -1,13 +1,15 @@
#!/usr/bin/env python
# Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
-# 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.
+
+# This file just executes its arguments, except that it allows overriding
+# environment variables using command-line arguments.
+
import subprocess
import sys
import os
import re
-args = sys.argv[1:]
+args = []
env = os.environ.copy()
if sys.platform == 'win32':
@@ -27,24 +29,19 @@ if sys.platform == 'win32':
env["GN_OUT_DIR"] = os.path.abspath(".")
assert os.path.isdir(env["GN_OUT_DIR"])
-# Some crates (e.g. 'typenum') generate source files and place them in the
-# directory indicated by the 'OUT_DIR' environment variable, which is normally
-# set by Cargo. We pre-generate these files and store them in the source repo.
-# Therefore, set 'OUT_DIR' so these crates can find their generated sources.
-for i, arg in enumerate(args):
- match = re.search('--generated-source-dir=(.*)', arg)
- if match:
- env["OUT_DIR"] = os.path.abspath(match.group(1))
- del args[i]
- break
-
-# Set the CARGO_PKG_VERSION env variable if provided as an argument
-# When building with Cargo this variable is set automatically
-for i, arg in enumerate(args):
- match = re.search('--cargo-pkg-version="?([^"]*)"?', arg)
+# Environment variables can be specified on the command line using
+# '--env=variable=value' flags. These flags are not passed through to rustc.
+# This is useful to set env vars that are normally automatically set by Cargo,
+# e.g. CARGO_PKG_NAME, CARGO_PKG_VERSION, OUT_DIR, etc.
+for arg in sys.argv[1:]:
+ match = re.search('--env=([^=]+)=(.*)', arg)
if match:
- env["CARGO_PKG_VERSION"] = match.group(1)
- del args[i]
- break
+ key, value = match.groups()
+ if key == "OUT_DIR":
+ # OUT_DIR needs to contain an absolute path.
+ value = os.path.abspath(value)
+ env[key] = value
+ else:
+ args.append(arg)
sys.exit(subprocess.call(args, env=env))