Read version from Cargo.toml (#1267)

This commit is contained in:
Goffert van Gool 2018-12-13 22:16:58 +01:00 committed by Ryan Dahl
parent 07369a6270
commit 40d6daf824
6 changed files with 57 additions and 5 deletions

View file

@ -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))