Implement --env
compiler flag · rust-lang/rust@486e55e (original) (raw)
`@@ -8,7 +8,7 @@ use crate::search_paths::SearchPath;
`
8
8
`use crate::utils::{CanonicalizedPath, NativeLib, NativeLibKind};
`
9
9
`use crate::{lint, HashStableContext};
`
10
10
`use crate::{EarlyErrorHandler, Session};
`
11
``
`-
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet};
`
``
11
`+
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
`
12
12
`use rustc_data_structures::stable_hasher::{StableOrd, ToStableHashKey};
`
13
13
`use rustc_errors::emitter::HumanReadableErrorType;
`
14
14
`use rustc_errors::{ColorConfig, DiagnosticArgValue, HandlerFlags, IntoDiagnosticArg};
`
`@@ -1114,6 +1114,7 @@ impl Default for Options {
`
1114
1114
`pretty: None,
`
1115
1115
`working_dir: RealFileName::LocalPath(std::env::current_dir().unwrap()),
`
1116
1116
`color: ColorConfig::Auto,
`
``
1117
`+
logical_env: FxIndexMap::default(),
`
1117
1118
`}
`
1118
1119
`}
`
1119
1120
`}
`
`@@ -1810,6 +1811,7 @@ pub fn rustc_optgroups() -> Vec {
`
1810
1811
`"Remap source names in all output (compiler messages and output files)",
`
1811
1812
`"FROM=TO",
`
1812
1813
`),
`
``
1814
`+
opt::multi("", "env", "Inject an environment variable", "VAR=VALUE"),
`
1813
1815
`]);
`
1814
1816
` opts
`
1815
1817
`}
`
`@@ -2589,6 +2591,23 @@ fn parse_remap_path_prefix(
`
2589
2591
` mapping
`
2590
2592
`}
`
2591
2593
``
``
2594
`+
fn parse_logical_env(
`
``
2595
`+
handler: &mut EarlyErrorHandler,
`
``
2596
`+
matches: &getopts::Matches,
`
``
2597
`+
) -> FxIndexMap<String, String> {
`
``
2598
`+
let mut vars = FxIndexMap::default();
`
``
2599
+
``
2600
`+
for arg in matches.opt_strs("env") {
`
``
2601
`+
if let Some((name, val)) = arg.split_once('=') {
`
``
2602
`+
vars.insert(name.to_string(), val.to_string());
`
``
2603
`+
} else {
`
``
2604
`` +
handler.early_error(format!("--env
: specify value for variable {arg}
"));
``
``
2605
`+
}
`
``
2606
`+
}
`
``
2607
+
``
2608
`+
vars
`
``
2609
`+
}
`
``
2610
+
2592
2611
`// JUSTIFICATION: before wrapper fn is available
`
2593
2612
`#[allow(rustc::bad_opt_access)]
`
2594
2613
`pub fn build_session_options(
`
`@@ -2827,6 +2846,8 @@ pub fn build_session_options(
`
2827
2846
`` handler.early_error("can't dump dependency graph without -Z query-dep-graph
");
``
2828
2847
`}
`
2829
2848
``
``
2849
`+
let logical_env = parse_logical_env(handler, matches);
`
``
2850
+
2830
2851
`` // Try to find a directory containing the Rust src
, for more details see
``
2831
2852
`` // the doc comment on the real_rust_source_base_dir
field.
``
2832
2853
`let tmp_buf;
`
`@@ -2907,6 +2928,7 @@ pub fn build_session_options(
`
2907
2928
` pretty,
`
2908
2929
` working_dir,
`
2909
2930
` color,
`
``
2931
`+
logical_env,
`
2910
2932
`}
`
2911
2933
`}
`
2912
2934
``
`@@ -3181,6 +3203,7 @@ pub(crate) mod dep_tracking {
`
3181
3203
`};
`
3182
3204
`use crate::lint;
`
3183
3205
`use crate::utils::NativeLib;
`
``
3206
`+
use rustc_data_structures::fx::FxIndexMap;
`
3184
3207
`use rustc_data_structures::stable_hasher::Hash64;
`
3185
3208
`use rustc_errors::LanguageIdentifier;
`
3186
3209
`use rustc_feature::UnstableFeatures;
`
`@@ -3339,6 +3362,21 @@ pub(crate) mod dep_tracking {
`
3339
3362
`}
`
3340
3363
`}
`
3341
3364
``
``
3365
`+
impl<T: DepTrackingHash, V: DepTrackingHash> DepTrackingHash for FxIndexMap<T, V> {
`
``
3366
`+
fn hash(
`
``
3367
`+
&self,
`
``
3368
`+
hasher: &mut DefaultHasher,
`
``
3369
`+
error_format: ErrorOutputType,
`
``
3370
`+
for_crate_hash: bool,
`
``
3371
`+
) {
`
``
3372
`+
Hash::hash(&self.len(), hasher);
`
``
3373
`+
for (key, value) in self.iter() {
`
``
3374
`+
DepTrackingHash::hash(key, hasher, error_format, for_crate_hash);
`
``
3375
`+
DepTrackingHash::hash(value, hasher, error_format, for_crate_hash);
`
``
3376
`+
}
`
``
3377
`+
}
`
``
3378
`+
}
`
``
3379
+
3342
3380
`impl DepTrackingHash for OutputTypes {
`
3343
3381
`fn hash(
`
3344
3382
`&self,
`