summaryrefslogtreecommitdiff
path: root/build_extra/rust/run.py
diff options
context:
space:
mode:
authorGoffert van Gool <ruphin@ruphin.net>2018-12-13 22:16:58 +0100
committerRyan Dahl <ry@tinyclouds.org>2018-12-13 16:16:58 -0500
commit40d6daf8240f9dc090c23f975488c424b88f120f (patch)
tree5b502de7a3d286861fb826f4242004a2e8218b25 /build_extra/rust/run.py
parent07369a6270473a2e4eb74d0c1936284d3b9558f3 (diff)
Read version from Cargo.toml (#1267)
Diffstat (limited to 'build_extra/rust/run.py')
-rw-r--r--build_extra/rust/run.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/build_extra/rust/run.py b/build_extra/rust/run.py
index 3a86c423c..dc89c09a1 100644
--- a/build_extra/rust/run.py
+++ b/build_extra/rust/run.py
@@ -1,13 +1,24 @@
#!/usr/bin/env python
-# This file just executes its arguments, except that also adds GN_OUT_DIR to the
-# environ. This is for compatibility with cargo.
+# 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.
import subprocess
import sys
import os
+import re
# 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.
os.environ["GN_OUT_DIR"] = os.path.abspath(".")
assert os.path.isdir(os.environ["GN_OUT_DIR"])
-sys.exit(subprocess.call(sys.argv[1:]))
+# 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:
+ os.environ["CARGO_PKG_VERSION"] = match.group(1)
+ del args[i]
+ break
+
+sys.exit(subprocess.call(args))