about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-02-09 00:19:45 +0000
committerbors <bors@rust-lang.org>2016-02-09 00:19:45 +0000
commit75271d8f1ad12ff8b9e97c4df1c94e7b3911e485 (patch)
treec144309dadd1a873e76d15faf036591b2cfe05f4 /src
parentf8fa6140fa6a85ea21ef4d2d56764862f7b3728b (diff)
parenta1ffe6b6bbfec7374f91dbbfb2e51a3fa5fadb1e (diff)
downloadrust-75271d8f1ad12ff8b9e97c4df1c94e7b3911e485.tar.gz
rust-75271d8f1ad12ff8b9e97c4df1c94e7b3911e485.zip
Auto merge of #31278 - alexcrichton:print-cfg, r=brson
This commit is an implementation of the new compiler flags required by [RFC
1361][rfc]. This specifically adds a new `cfg` option to the `--print` flag to
the compiler. This new directive will print the defined `#[cfg]` directives by
the compiler for the target in question.

[rfc]: https://github.com/rust-lang/rfcs/blob/master/text/1361-cargo-cfg-dependencies
Diffstat (limited to 'src')
-rw-r--r--src/librustc/session/config.rs2
-rw-r--r--src/librustc_driver/lib.rs19
-rw-r--r--src/test/run-make/print-cfg/Makefile15
3 files changed, 36 insertions, 0 deletions
diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs
index 68949863bfc..f6079217829 100644
--- a/src/librustc/session/config.rs
+++ b/src/librustc/session/config.rs
@@ -163,6 +163,7 @@ pub enum PrintRequest {
     FileNames,
     Sysroot,
     CrateName,
+    Cfg,
 }
 
 pub enum Input {
@@ -1105,6 +1106,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
             "crate-name" => PrintRequest::CrateName,
             "file-names" => PrintRequest::FileNames,
             "sysroot" => PrintRequest::Sysroot,
+            "cfg" => PrintRequest::Cfg,
             req => {
                 early_error(error_format, &format!("unknown print request `{}`", req))
             }
diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs
index 70bd938321a..67a9f032a71 100644
--- a/src/librustc_driver/lib.rs
+++ b/src/librustc_driver/lib.rs
@@ -518,6 +518,25 @@ impl RustcDefaultCalls {
                                       .to_string_lossy());
                     }
                 }
+                PrintRequest::Cfg => {
+                    for cfg in config::build_configuration(sess) {
+                        match cfg.node {
+                            ast::MetaWord(ref word) => println!("{}", word),
+                            ast::MetaNameValue(ref name, ref value) => {
+                                println!("{}=\"{}\"", name, match value.node {
+                                    ast::LitStr(ref s, _) => s,
+                                    _ => continue,
+                                });
+                            }
+                            // Right now there are not and should not be any
+                            // MetaList items in the configuration returned by
+                            // `build_configuration`.
+                            ast::MetaList(..) => {
+                                panic!("MetaList encountered in default cfg")
+                            }
+                        }
+                    }
+                }
             }
         }
         return Compilation::Stop;
diff --git a/src/test/run-make/print-cfg/Makefile b/src/test/run-make/print-cfg/Makefile
new file mode 100644
index 00000000000..c74233d495b
--- /dev/null
+++ b/src/test/run-make/print-cfg/Makefile
@@ -0,0 +1,15 @@
+-include ../tools.mk
+
+all: default
+	$(RUSTC) --target x86_64-pc-windows-gnu --print cfg | grep windows
+	$(RUSTC) --target x86_64-pc-windows-gnu --print cfg | grep x86_64
+	$(RUSTC) --target i686-pc-windows-msvc --print cfg | grep msvc
+	$(RUSTC) --target i686-apple-darwin --print cfg | grep macos
+
+ifdef IS_WINDOWS
+default:
+	$(RUSTC) --print cfg | grep windows
+else
+default:
+	$(RUSTC) --print cfg | grep unix
+endif