Store individual output file name with every PrintRequest
This commit is contained in:
parent
11dcd1d3d7
commit
c0dc0c6875
6 changed files with 61 additions and 56 deletions
|
@ -40,7 +40,7 @@ use rustc_metadata::EncodedMetadata;
|
|||
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::{OptLevel, OutputFilenames, PrintRequest};
|
||||
use rustc_session::config::{OptLevel, OutputFilenames, PrintKind, PrintRequest};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::Symbol;
|
||||
|
||||
|
@ -262,9 +262,9 @@ impl CodegenBackend for LlvmCodegenBackend {
|
|||
|tcx, ()| llvm_util::global_llvm_features(tcx.sess, true)
|
||||
}
|
||||
|
||||
fn print(&self, req: PrintRequest, sess: &Session) {
|
||||
match req {
|
||||
PrintRequest::RelocationModels => {
|
||||
fn print(&self, req: &PrintRequest, sess: &Session) {
|
||||
match req.kind {
|
||||
PrintKind::RelocationModels => {
|
||||
println!("Available relocation models:");
|
||||
for name in &[
|
||||
"static",
|
||||
|
@ -280,21 +280,21 @@ impl CodegenBackend for LlvmCodegenBackend {
|
|||
}
|
||||
println!();
|
||||
}
|
||||
PrintRequest::CodeModels => {
|
||||
PrintKind::CodeModels => {
|
||||
println!("Available code models:");
|
||||
for name in &["tiny", "small", "kernel", "medium", "large"] {
|
||||
println!(" {}", name);
|
||||
}
|
||||
println!();
|
||||
}
|
||||
PrintRequest::TlsModels => {
|
||||
PrintKind::TlsModels => {
|
||||
println!("Available TLS models:");
|
||||
for name in &["global-dynamic", "local-dynamic", "initial-exec", "local-exec"] {
|
||||
println!(" {}", name);
|
||||
}
|
||||
println!();
|
||||
}
|
||||
PrintRequest::StackProtectorStrategies => {
|
||||
PrintKind::StackProtectorStrategies => {
|
||||
println!(
|
||||
r#"Available stack protector strategies:
|
||||
all
|
||||
|
@ -319,7 +319,7 @@ impl CodegenBackend for LlvmCodegenBackend {
|
|||
"#
|
||||
);
|
||||
}
|
||||
req => llvm_util::print(req, sess),
|
||||
_other => llvm_util::print(req, sess),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
|||
use rustc_data_structures::small_c_str::SmallCStr;
|
||||
use rustc_fs_util::path_to_c_string;
|
||||
use rustc_middle::bug;
|
||||
use rustc_session::config::PrintRequest;
|
||||
use rustc_session::config::{PrintKind, PrintRequest};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_target::spec::{MergeFunctions, PanicStrategy};
|
||||
|
@ -400,11 +400,11 @@ fn print_target_features(sess: &Session, tm: &llvm::TargetMachine) {
|
|||
println!("and may be renamed or removed in a future version of LLVM or rustc.\n");
|
||||
}
|
||||
|
||||
pub(crate) fn print(req: PrintRequest, sess: &Session) {
|
||||
pub(crate) fn print(req: &PrintRequest, sess: &Session) {
|
||||
require_inited();
|
||||
let tm = create_informational_target_machine(sess);
|
||||
match req {
|
||||
PrintRequest::TargetCPUs => {
|
||||
match req.kind {
|
||||
PrintKind::TargetCPUs => {
|
||||
// SAFETY generate a C compatible string from a byte slice to pass
|
||||
// the target CPU name into LLVM, the lifetime of the reference is
|
||||
// at least as long as the C function
|
||||
|
@ -412,7 +412,7 @@ pub(crate) fn print(req: PrintRequest, sess: &Session) {
|
|||
.unwrap_or_else(|e| bug!("failed to convert to cstring: {}", e));
|
||||
unsafe { llvm::LLVMRustPrintTargetCPUs(tm, cpu_cstring.as_ptr()) };
|
||||
}
|
||||
PrintRequest::TargetFeatures => print_target_features(sess, tm),
|
||||
PrintKind::TargetFeatures => print_target_features(sess, tm),
|
||||
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ use rustc_middle::middle::debugger_visualizer::DebuggerVisualizerFile;
|
|||
use rustc_middle::middle::dependency_format::Linkage;
|
||||
use rustc_middle::middle::exported_symbols::SymbolExportKind;
|
||||
use rustc_session::config::{self, CFGuard, CrateType, DebugInfo, Strip};
|
||||
use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, SplitDwarfKind};
|
||||
use rustc_session::config::{OutputFilenames, OutputType, PrintKind, SplitDwarfKind};
|
||||
use rustc_session::cstore::DllImport;
|
||||
use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename};
|
||||
use rustc_session::search_paths::PathKind;
|
||||
|
@ -596,7 +596,7 @@ fn link_staticlib<'a>(
|
|||
|
||||
all_native_libs.extend_from_slice(&codegen_results.crate_info.used_libraries);
|
||||
|
||||
if sess.opts.prints.contains(&PrintRequest::NativeStaticLibs) {
|
||||
if sess.opts.prints.iter().any(|print| print.kind == PrintKind::NativeStaticLibs) {
|
||||
print_native_static_libs(sess, &all_native_libs, &all_rust_dylibs);
|
||||
}
|
||||
|
||||
|
@ -744,7 +744,7 @@ fn link_natively<'a>(
|
|||
cmd.env_remove(k.as_ref());
|
||||
}
|
||||
|
||||
if sess.opts.prints.contains(&PrintRequest::LinkArgs) {
|
||||
if sess.opts.prints.iter().any(|print| print.kind == PrintKind::LinkArgs) {
|
||||
println!("{:?}", &cmd);
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ pub trait CodegenBackend {
|
|||
fn locale_resource(&self) -> &'static str;
|
||||
|
||||
fn init(&self, _sess: &Session) {}
|
||||
fn print(&self, _req: PrintRequest, _sess: &Session) {}
|
||||
fn print(&self, _req: &PrintRequest, _sess: &Session) {}
|
||||
fn target_features(&self, _sess: &Session, _allow_unstable: bool) -> Vec<Symbol> {
|
||||
vec![]
|
||||
}
|
||||
|
|
|
@ -35,9 +35,7 @@ use rustc_interface::{interface, Queries};
|
|||
use rustc_lint::LintStore;
|
||||
use rustc_metadata::locator;
|
||||
use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS};
|
||||
use rustc_session::config::{
|
||||
ErrorOutputType, Input, OutFileName, OutputType, PrintRequest, TrimmedDefPaths,
|
||||
};
|
||||
use rustc_session::config::{ErrorOutputType, Input, OutFileName, OutputType, TrimmedDefPaths};
|
||||
use rustc_session::cstore::MetadataLoader;
|
||||
use rustc_session::getopts::{self, Matches};
|
||||
use rustc_session::lint::{Lint, LintId};
|
||||
|
@ -714,10 +712,10 @@ fn print_crate_info(
|
|||
sess: &Session,
|
||||
parse_attrs: bool,
|
||||
) -> Compilation {
|
||||
use rustc_session::config::PrintRequest::*;
|
||||
use rustc_session::config::PrintKind::*;
|
||||
// NativeStaticLibs and LinkArgs are special - printed during linking
|
||||
// (empty iterator returns true)
|
||||
if sess.opts.prints.iter().all(|&p| p == NativeStaticLibs || p == LinkArgs) {
|
||||
if sess.opts.prints.iter().all(|p| p.kind == NativeStaticLibs || p.kind == LinkArgs) {
|
||||
return Compilation::Continue;
|
||||
}
|
||||
|
||||
|
@ -734,7 +732,7 @@ fn print_crate_info(
|
|||
None
|
||||
};
|
||||
for req in &sess.opts.prints {
|
||||
match *req {
|
||||
match req.kind {
|
||||
TargetList => {
|
||||
let mut targets = rustc_target::spec::TARGETS.to_vec();
|
||||
targets.sort_unstable();
|
||||
|
@ -761,7 +759,7 @@ fn print_crate_info(
|
|||
};
|
||||
let t_outputs = rustc_interface::util::build_output_filenames(attrs, sess);
|
||||
let id = rustc_session::output::find_crate_name(sess, attrs);
|
||||
if *req == PrintRequest::CrateName {
|
||||
if req.kind == CrateName {
|
||||
safe_println!("{id}");
|
||||
continue;
|
||||
}
|
||||
|
@ -817,7 +815,7 @@ fn print_crate_info(
|
|||
| TargetCPUs
|
||||
| StackProtectorStrategies
|
||||
| TargetFeatures => {
|
||||
codegen_backend.print(*req, sess);
|
||||
codegen_backend.print(req, sess);
|
||||
}
|
||||
// Any output here interferes with Cargo's parsing of other printed output
|
||||
NativeStaticLibs => {}
|
||||
|
|
|
@ -710,8 +710,14 @@ impl ExternEntry {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Debug)]
|
||||
pub struct PrintRequest {
|
||||
pub kind: PrintKind,
|
||||
pub out: OutFileName,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum PrintRequest {
|
||||
pub enum PrintKind {
|
||||
FileNames,
|
||||
Sysroot,
|
||||
TargetLibdir,
|
||||
|
@ -2091,41 +2097,41 @@ fn collect_print_requests(
|
|||
) -> Vec<PrintRequest> {
|
||||
let mut prints = Vec::<PrintRequest>::new();
|
||||
if cg.target_cpu.as_ref().is_some_and(|s| s == "help") {
|
||||
prints.push(PrintRequest::TargetCPUs);
|
||||
prints.push(PrintRequest { kind: PrintKind::TargetCPUs, out: OutFileName::Stdout });
|
||||
cg.target_cpu = None;
|
||||
};
|
||||
if cg.target_feature == "help" {
|
||||
prints.push(PrintRequest::TargetFeatures);
|
||||
prints.push(PrintRequest { kind: PrintKind::TargetFeatures, out: OutFileName::Stdout });
|
||||
cg.target_feature = String::new();
|
||||
}
|
||||
|
||||
const PRINT_REQUESTS: &[(&str, PrintRequest)] = &[
|
||||
("crate-name", PrintRequest::CrateName),
|
||||
("file-names", PrintRequest::FileNames),
|
||||
("sysroot", PrintRequest::Sysroot),
|
||||
("target-libdir", PrintRequest::TargetLibdir),
|
||||
("cfg", PrintRequest::Cfg),
|
||||
("calling-conventions", PrintRequest::CallingConventions),
|
||||
("target-list", PrintRequest::TargetList),
|
||||
("target-cpus", PrintRequest::TargetCPUs),
|
||||
("target-features", PrintRequest::TargetFeatures),
|
||||
("relocation-models", PrintRequest::RelocationModels),
|
||||
("code-models", PrintRequest::CodeModels),
|
||||
("tls-models", PrintRequest::TlsModels),
|
||||
("native-static-libs", PrintRequest::NativeStaticLibs),
|
||||
("stack-protector-strategies", PrintRequest::StackProtectorStrategies),
|
||||
("target-spec-json", PrintRequest::TargetSpec),
|
||||
("all-target-specs-json", PrintRequest::AllTargetSpecs),
|
||||
("link-args", PrintRequest::LinkArgs),
|
||||
("split-debuginfo", PrintRequest::SplitDebuginfo),
|
||||
("deployment-target", PrintRequest::DeploymentTarget),
|
||||
const PRINT_KINDS: &[(&str, PrintKind)] = &[
|
||||
("crate-name", PrintKind::CrateName),
|
||||
("file-names", PrintKind::FileNames),
|
||||
("sysroot", PrintKind::Sysroot),
|
||||
("target-libdir", PrintKind::TargetLibdir),
|
||||
("cfg", PrintKind::Cfg),
|
||||
("calling-conventions", PrintKind::CallingConventions),
|
||||
("target-list", PrintKind::TargetList),
|
||||
("target-cpus", PrintKind::TargetCPUs),
|
||||
("target-features", PrintKind::TargetFeatures),
|
||||
("relocation-models", PrintKind::RelocationModels),
|
||||
("code-models", PrintKind::CodeModels),
|
||||
("tls-models", PrintKind::TlsModels),
|
||||
("native-static-libs", PrintKind::NativeStaticLibs),
|
||||
("stack-protector-strategies", PrintKind::StackProtectorStrategies),
|
||||
("target-spec-json", PrintKind::TargetSpec),
|
||||
("all-target-specs-json", PrintKind::AllTargetSpecs),
|
||||
("link-args", PrintKind::LinkArgs),
|
||||
("split-debuginfo", PrintKind::SplitDebuginfo),
|
||||
("deployment-target", PrintKind::DeploymentTarget),
|
||||
];
|
||||
|
||||
prints.extend(matches.opt_strs("print").into_iter().map(|req| {
|
||||
match PRINT_REQUESTS.iter().find(|&&(name, _)| name == req) {
|
||||
Some((_, PrintRequest::TargetSpec)) => {
|
||||
let kind = match PRINT_KINDS.iter().find(|&&(name, _)| name == req) {
|
||||
Some((_, PrintKind::TargetSpec)) => {
|
||||
if unstable_opts.unstable_options {
|
||||
PrintRequest::TargetSpec
|
||||
PrintKind::TargetSpec
|
||||
} else {
|
||||
handler.early_error(
|
||||
"the `-Z unstable-options` flag must also be passed to \
|
||||
|
@ -2133,9 +2139,9 @@ fn collect_print_requests(
|
|||
);
|
||||
}
|
||||
}
|
||||
Some((_, PrintRequest::AllTargetSpecs)) => {
|
||||
Some((_, PrintKind::AllTargetSpecs)) => {
|
||||
if unstable_opts.unstable_options {
|
||||
PrintRequest::AllTargetSpecs
|
||||
PrintKind::AllTargetSpecs
|
||||
} else {
|
||||
handler.early_error(
|
||||
"the `-Z unstable-options` flag must also be passed to \
|
||||
|
@ -2143,16 +2149,17 @@ fn collect_print_requests(
|
|||
);
|
||||
}
|
||||
}
|
||||
Some(&(_, print_request)) => print_request,
|
||||
Some(&(_, print_kind)) => print_kind,
|
||||
None => {
|
||||
let prints =
|
||||
PRINT_REQUESTS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
|
||||
PRINT_KINDS.iter().map(|(name, _)| format!("`{name}`")).collect::<Vec<_>>();
|
||||
let prints = prints.join(", ");
|
||||
handler.early_error(format!(
|
||||
"unknown print request `{req}`. Valid print requests are: {prints}"
|
||||
));
|
||||
}
|
||||
}
|
||||
};
|
||||
PrintRequest { kind, out: OutFileName::Stdout }
|
||||
}));
|
||||
|
||||
prints
|
||||
|
|
Loading…
Add table
Reference in a new issue