Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: Implement a new --print cfg flag #31278

Merged
merged 1 commit into from
Feb 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ pub enum PrintRequest {
FileNames,
Sysroot,
CrateName,
Cfg,
}

pub enum Input {
Expand Down Expand Up @@ -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))
}
Expand Down
19 changes: 19 additions & 0 deletions src/librustc_driver/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/test/run-make/print-cfg/Makefile
Original file line number Diff line number Diff line change
@@ -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