use rustc_span::edition::{Edition, DEFAULT_EDITION, EDITION_NAME_LIST, LATEST_STABLE_EDITION};
use rustc_span::source_map::{FileName, FilePathMapping};
use rustc_span::symbol::{sym, Symbol};
+use rustc_span::RealFileName;
use rustc_span::SourceFileHashAlgorithm;
use rustc_errors::emitter::HumanReadableErrorType;
json_artifact_notifications: false,
json_unused_externs: false,
pretty: None,
+ working_dir: RealFileName::LocalPath(std::env::current_dir().unwrap()),
}
}
}
),
opt::flag_s("", "test", "Build a test harness"),
opt::opt_s("", "target", "Target triple for which the code is compiled", "TARGET"),
- opt::multi_s("W", "warn", "Set lint warnings", "OPT"),
- opt::multi_s("A", "allow", "Set lint allowed", "OPT"),
- opt::multi_s("D", "deny", "Set lint denied", "OPT"),
- opt::multi_s("F", "forbid", "Set lint forbidden", "OPT"),
+ opt::multi_s("A", "allow", "Set lint allowed", "LINT"),
+ opt::multi_s("W", "warn", "Set lint warnings", "LINT"),
+ opt::multi_s("", "force-warn", "Set lint force-warn", "LINT"),
+ opt::multi_s("D", "deny", "Set lint denied", "LINT"),
+ opt::multi_s("F", "forbid", "Set lint forbidden", "LINT"),
opt::multi_s(
"",
"cap-lints",
level",
"LEVEL",
),
- opt::multi_s(
- "",
- "force-warn",
- "Specifiy lints that should warn even if \
- they are allowed somewhere else",
- "LINT",
- ),
opt::multi_s("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
opt::flag_s("V", "version", "Print version info and exit"),
opt::flag_s("v", "verbose", "Use verbose output"),
never = never colorize output",
"auto|always|never",
),
- opt::opt(
- "",
- "pretty",
- "Pretty-print the input instead of compiling;
- valid types are: `normal` (un-annotated source),
- `expanded` (crates expanded), or
- `expanded,identified` (fully parenthesized, AST nodes with IDs).",
- "TYPE",
- ),
opt::multi_s(
"",
"remap-path-prefix",
pub fn get_cmd_lint_options(
matches: &getopts::Matches,
error_format: ErrorOutputType,
- debugging_opts: &DebuggingOptions,
) -> (Vec<(String, lint::Level)>, bool, Option<lint::Level>) {
let mut lint_opts_with_position = vec![];
let mut describe_lints = false;
- if !debugging_opts.unstable_options && matches.opt_present("force-warn") {
- early_error(
- error_format,
- "the `-Z unstable-options` flag must also be passed to enable \
- the flag `--force-warn=lints`",
- );
- }
-
for level in [lint::Allow, lint::Warn, lint::ForceWarn, lint::Deny, lint::Forbid] {
for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
if lint_name == "help" {
}
}
-fn parse_native_lib_kind(kind: &str, error_format: ErrorOutputType) -> NativeLibKind {
- match kind {
+fn parse_native_lib_kind(
+ matches: &getopts::Matches,
+ kind: &str,
+ error_format: ErrorOutputType,
+) -> (NativeLibKind, Option<bool>) {
+ let is_nightly = nightly_options::match_is_nightly_build(matches);
+ let enable_unstable = nightly_options::is_unstable_enabled(matches);
+
+ let (kind, modifiers) = match kind.split_once(':') {
+ None => (kind, None),
+ Some((kind, modifiers)) => (kind, Some(modifiers)),
+ };
+
+ let kind = match kind {
"dylib" => NativeLibKind::Dylib { as_needed: None },
"framework" => NativeLibKind::Framework { as_needed: None },
"static" => NativeLibKind::Static { bundle: None, whole_archive: None },
"library kind `static-nobundle` has been superseded by specifying \
`-bundle` on library kind `static`. Try `static:-bundle`",
);
+ if modifiers.is_some() {
+ early_error(
+ error_format,
+ "linking modifier can't be used with library kind `static-nobundle`",
+ )
+ }
+ if !is_nightly {
+ early_error(
+ error_format,
+ "library kind `static-nobundle` are currently unstable and only accepted on \
+ the nightly compiler",
+ );
+ }
NativeLibKind::Static { bundle: Some(false), whole_archive: None }
}
s => early_error(
error_format,
&format!("unknown library kind `{}`, expected one of dylib, framework, or static", s),
),
+ };
+ match modifiers {
+ None => (kind, None),
+ Some(modifiers) => {
+ if !is_nightly {
+ early_error(
+ error_format,
+ "linking modifiers are currently unstable and only accepted on \
+ the nightly compiler",
+ );
+ }
+ if !enable_unstable {
+ early_error(
+ error_format,
+ "linking modifiers are currently unstable, \
+ the `-Z unstable-options` flag must also be passed to use it",
+ )
+ }
+ parse_native_lib_modifiers(kind, modifiers, error_format)
+ }
}
}
fn parse_native_lib_modifiers(
- is_nightly: bool,
mut kind: NativeLibKind,
modifiers: &str,
error_format: ErrorOutputType,
),
};
- if !is_nightly {
- early_error(
- error_format,
- "linking modifiers are currently unstable and only accepted on \
- the nightly compiler",
- );
- }
-
match (modifier, &mut kind) {
("bundle", NativeLibKind::Static { bundle, .. }) => {
*bundle = Some(value);
}
fn parse_libs(matches: &getopts::Matches, error_format: ErrorOutputType) -> Vec<NativeLib> {
- let is_nightly = nightly_options::match_is_nightly_build(matches);
matches
.opt_strs("l")
.into_iter()
let (name, kind, verbatim) = match s.split_once('=') {
None => (s, NativeLibKind::Unspecified, None),
Some((kind, name)) => {
- let (kind, verbatim) = match kind.split_once(':') {
- None => (parse_native_lib_kind(kind, error_format), None),
- Some((kind, modifiers)) => {
- let kind = parse_native_lib_kind(kind, error_format);
- parse_native_lib_modifiers(is_nightly, kind, modifiers, error_format)
- }
- };
+ let (kind, verbatim) = parse_native_lib_kind(matches, kind, error_format);
(name.to_string(), kind, verbatim)
}
};
)
});
- let locparts: Vec<_> = loc.split(":").collect();
+ let locparts: Vec<_> = loc.split(':').collect();
let spec = match &locparts[..] {
["raw", ..] => {
// Don't want `:` split string
.unwrap_or_else(|e| early_error(error_format, &e[..]));
let mut debugging_opts = DebuggingOptions::build(matches, error_format);
- let (lint_opts, describe_lints, lint_cap) =
- get_cmd_lint_options(matches, error_format, &debugging_opts);
+ let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format);
check_debug_option_stability(&debugging_opts, error_format, json_rendered);
let remap_path_prefix = parse_remap_path_prefix(matches, error_format);
- let pretty = parse_pretty(matches, &debugging_opts, error_format);
+ let pretty = parse_pretty(&debugging_opts, error_format);
if !debugging_opts.unstable_options
&& !target_triple.triple().contains("apple")
if candidate.join("library/std/src/lib.rs").is_file() { Some(candidate) } else { None }
};
+ let working_dir = std::env::current_dir().unwrap_or_else(|e| {
+ early_error(error_format, &format!("Current directory is invalid: {}", e));
+ });
+
+ let (path, remapped) =
+ FilePathMapping::new(remap_path_prefix.clone()).map_prefix(working_dir.clone());
+ let working_dir = if remapped {
+ RealFileName::Remapped { local_path: Some(working_dir), virtual_name: path }
+ } else {
+ RealFileName::LocalPath(path)
+ };
+
Options {
crate_types,
optimize: opt_level,
json_artifact_notifications,
json_unused_externs,
pretty,
- }
-}
-
-fn parse_pretty(
- matches: &getopts::Matches,
- debugging_opts: &DebuggingOptions,
- efmt: ErrorOutputType,
-) -> Option<PpMode> {
- fn parse_pretty_inner(efmt: ErrorOutputType, name: &str, extended: bool) -> PpMode {
- use PpMode::*;
- let first = match (name, extended) {
- ("normal", _) => Source(PpSourceMode::Normal),
- ("identified", _) => Source(PpSourceMode::Identified),
- ("everybody_loops", true) => Source(PpSourceMode::EveryBodyLoops),
- ("expanded", _) => Source(PpSourceMode::Expanded),
- ("expanded,identified", _) => Source(PpSourceMode::ExpandedIdentified),
- ("expanded,hygiene", _) => Source(PpSourceMode::ExpandedHygiene),
- ("ast-tree", true) => AstTree(PpAstTreeMode::Normal),
- ("ast-tree,expanded", true) => AstTree(PpAstTreeMode::Expanded),
- ("hir", true) => Hir(PpHirMode::Normal),
- ("hir,identified", true) => Hir(PpHirMode::Identified),
- ("hir,typed", true) => Hir(PpHirMode::Typed),
- ("hir-tree", true) => HirTree,
- ("thir-tree", true) => ThirTree,
- ("mir", true) => Mir,
- ("mir-cfg", true) => MirCFG,
- _ => {
- if extended {
- early_error(
- efmt,
- &format!(
- "argument to `unpretty` must be one of `normal`, \
- `expanded`, `identified`, `expanded,identified`, \
- `expanded,hygiene`, `everybody_loops`, \
- `ast-tree`, `ast-tree,expanded`, `hir`, `hir,identified`, \
- `hir,typed`, `hir-tree`, `mir` or `mir-cfg`; got {}",
- name
- ),
- );
- } else {
- early_error(
- efmt,
- &format!(
- "argument to `pretty` must be one of `normal`, \
- `expanded`, `identified`, or `expanded,identified`; got {}",
- name
- ),
- );
- }
- }
- };
- tracing::debug!("got unpretty option: {:?}", first);
- first
- }
-
- if debugging_opts.unstable_options {
- if let Some(a) = matches.opt_default("pretty", "normal") {
- // stable pretty-print variants only
- return Some(parse_pretty_inner(efmt, &a, false));
- }
- }
-
- debugging_opts.unpretty.as_ref().map(|a| {
- // extended with unstable pretty-print variants
- parse_pretty_inner(efmt, &a, true)
- })
+ working_dir,
+ }
+}
+
+fn parse_pretty(debugging_opts: &DebuggingOptions, efmt: ErrorOutputType) -> Option<PpMode> {
+ use PpMode::*;
+
+ let first = match debugging_opts.unpretty.as_deref()? {
+ "normal" => Source(PpSourceMode::Normal),
+ "identified" => Source(PpSourceMode::Identified),
+ "everybody_loops" => Source(PpSourceMode::EveryBodyLoops),
+ "expanded" => Source(PpSourceMode::Expanded),
+ "expanded,identified" => Source(PpSourceMode::ExpandedIdentified),
+ "expanded,hygiene" => Source(PpSourceMode::ExpandedHygiene),
+ "ast-tree" => AstTree(PpAstTreeMode::Normal),
+ "ast-tree,expanded" => AstTree(PpAstTreeMode::Expanded),
+ "hir" => Hir(PpHirMode::Normal),
+ "hir,identified" => Hir(PpHirMode::Identified),
+ "hir,typed" => Hir(PpHirMode::Typed),
+ "hir-tree" => HirTree,
+ "thir-tree" => ThirTree,
+ "mir" => Mir,
+ "mir-cfg" => MirCFG,
+ name => early_error(
+ efmt,
+ &format!(
+ "argument to `unpretty` must be one of `normal`, \
+ `expanded`, `identified`, `expanded,identified`, \
+ `expanded,hygiene`, `everybody_loops`, \
+ `ast-tree`, `ast-tree,expanded`, `hir`, `hir,identified`, \
+ `hir,typed`, `hir-tree`, `mir` or `mir-cfg`; got {}",
+ name
+ ),
+ ),
+ };
+ tracing::debug!("got unpretty option: {:?}", first);
+ Some(first)
}
pub fn make_crate_type_option() -> RustcOptGroup {
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum PpSourceMode {
- /// `--pretty=normal`
+ /// `-Zunpretty=normal`
Normal,
/// `-Zunpretty=everybody_loops`
EveryBodyLoops,
- /// `--pretty=expanded`
+ /// `-Zunpretty=expanded`
Expanded,
- /// `--pretty=identified`
+ /// `-Zunpretty=identified`
Identified,
- /// `--pretty=expanded,identified`
+ /// `-Zunpretty=expanded,identified`
ExpandedIdentified,
- /// `--pretty=expanded,hygiene`
+ /// `-Zunpretty=expanded,hygiene`
ExpandedHygiene,
}
#[derive(Copy, Clone, PartialEq, Debug)]
pub enum PpMode {
/// Options that print the source code, i.e.
- /// `--pretty` and `-Zunpretty=everybody_loops`
+ /// `-Zunpretty=normal` and `-Zunpretty=everybody_loops`
Source(PpSourceMode),
AstTree(PpAstTreeMode),
/// Options that print the HIR, i.e. `-Zunpretty=hir`
use crate::utils::{NativeLib, NativeLibKind};
use rustc_feature::UnstableFeatures;
use rustc_span::edition::Edition;
+ use rustc_span::RealFileName;
use rustc_target::spec::{CodeModel, MergeFunctions, PanicStrategy, RelocModel};
use rustc_target::spec::{RelroLevel, SanitizerSet, SplitDebuginfo, TargetTriple, TlsModel};
use std::collections::hash_map::DefaultHasher;
TrimmedDefPaths,
Option<LdImpl>,
OutputType,
+ RealFileName,
);
impl<T1, T2> DepTrackingHash for (T1, T2)