From 89c7554d4a9f9b4c83a91b43575db9aa5d3964a4 Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Fri, 20 Jul 2018 06:03:04 +0200 Subject: 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 --- build_extra/rust/get_rust_ldflags.py | 40 ++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'build_extra/rust/get_rust_ldflags.py') 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 -- cgit v1.2.3