summaryrefslogtreecommitdiff
path: root/build_extra/rust/get_rust_ldflags.py
diff options
context:
space:
mode:
authorBert Belder <bertbelder@gmail.com>2018-07-20 06:03:04 +0200
committerBert Belder <bertbelder@gmail.com>2018-07-20 19:17:31 +0200
commit89c7554d4a9f9b4c83a91b43575db9aa5d3964a4 (patch)
treebcd78bd93f6edcf0017d588326539495e1aff9b6 /build_extra/rust/get_rust_ldflags.py
parent21c4b8a42de0cdc32a1e93dfb175a0cd5588d8e7 (diff)
Suppress misleading rustc warning when running gn gen
rustc prints the warning: `-C save-temps` might not produce all requested temporary products when incremental compilation is enabled. However, incremental compilation isn't even enabled. A look at the Rust source code confirms that this warning is indeed printed unconditionally when the `-C save-temps` flag is specified: https://github.com/rust-lang/rust/blob/5f2b325f64ed6caa7179f3e04913db437656ec7e/src/librustc/session/config.rs#L1015-L1018
Diffstat (limited to 'build_extra/rust/get_rust_ldflags.py')
-rwxr-xr-xbuild_extra/rust/get_rust_ldflags.py40
1 files changed, 36 insertions, 4 deletions
diff --git a/build_extra/rust/get_rust_ldflags.py b/build_extra/rust/get_rust_ldflags.py
index f45b3ff07..b20b66143 100755
--- a/build_extra/rust/get_rust_ldflags.py
+++ b/build_extra/rust/get_rust_ldflags.py
@@ -29,6 +29,7 @@
import sys
import os
from os import path
+import re
import subprocess
import tempfile
@@ -77,10 +78,41 @@ def main():
rustc_env["ARGSFILE_PATH"] = argsfile_path
try:
- # Spawn rustc, and make it use this very script as its "linker".
- rustc_args = ["-Clinker=" + rustc_linker, "-Csave-temps"
- ] + sys.argv[1:]
- subprocess.check_call(["rustc"] + rustc_args, env=rustc_env)
+ # Build the rustc command line.
+ # * `-Clinker=` tells rustc to use our fake linker.
+ # * `-Csave-temps` prevents rustc from deleting object files after
+ # linking. We need to preserve the file `xx.crate.allocator.rcgu.o`.
+ rustc_cmd = [
+ "rustc",
+ "-Clinker=" + rustc_linker,
+ "-Csave-temps",
+ ] + sys.argv[1:]
+
+ # Spawn the rust compiler.
+ rustc_proc = subprocess.Popen(
+ rustc_cmd,
+ env=rustc_env,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+
+ # Forward rustc's output to stderr.
+ for line in rustc_proc.stdout:
+ # Suppress the warning:
+ # `-C save-temps` might not produce all requested temporary
+ # products when incremental compilation is enabled.
+ # It's pointless, because incremental compilation is disabled.
+ if re.match(r"^warning:.*save-temps.*incremental compilation",
+ line):
+ continue
+ # Also, do not write completely blank lines to stderr.
+ if line.strip() == "":
+ continue
+ sys.stderr.write(line)
+
+ # The rustc process should return zero. If not, raise an exception.
+ rustc_retcode = rustc_proc.wait()
+ if rustc_retcode != 0:
+ raise subprocess.CalledProcessError(rustc_retcode, rustc_cmd)
# Read captured linker arguments from argsfile.
argsfile_size = os.fstat(argsfile_fd).st_size