Auto merge of #118368 - GuillaumeGomez:env-flag, r=Nilstrieb · rust-lang/rust@d86d65b (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

`}

`

`@@ -1813,6 +1814,7 @@ pub fn rustc_optgroups() -> Vec {

`

1813

1814

`"Remap source names in all output (compiler messages and output files)",

`

1814

1815

`"FROM=TO",

`

1815

1816

`),

`

``

1817

`+

opt::multi("", "env", "Inject an environment variable", "VAR=VALUE"),

`

1816

1818

`]);

`

1817

1819

` opts

`

1818

1820

`}

`

`@@ -2592,6 +2594,23 @@ fn parse_remap_path_prefix(

`

2592

2594

` mapping

`

2593

2595

`}

`

2594

2596

``

``

2597

`+

fn parse_logical_env(

`

``

2598

`+

handler: &mut EarlyErrorHandler,

`

``

2599

`+

matches: &getopts::Matches,

`

``

2600

`+

) -> FxIndexMap<String, String> {

`

``

2601

`+

let mut vars = FxIndexMap::default();

`

``

2602

+

``

2603

`+

for arg in matches.opt_strs("env") {

`

``

2604

`+

if let Some((name, val)) = arg.split_once('=') {

`

``

2605

`+

vars.insert(name.to_string(), val.to_string());

`

``

2606

`+

} else {

`

``

2607

`` +

handler.early_error(format!("--env: specify value for variable {arg}"));

``

``

2608

`+

}

`

``

2609

`+

}

`

``

2610

+

``

2611

`+

vars

`

``

2612

`+

}

`

``

2613

+

2595

2614

`// JUSTIFICATION: before wrapper fn is available

`

2596

2615

`#[allow(rustc::bad_opt_access)]

`

2597

2616

`pub fn build_session_options(

`

`@@ -2830,6 +2849,8 @@ pub fn build_session_options(

`

2830

2849

`` handler.early_error("can't dump dependency graph without -Z query-dep-graph");

``

2831

2850

`}

`

2832

2851

``

``

2852

`+

let logical_env = parse_logical_env(handler, matches);

`

``

2853

+

2833

2854

`` // Try to find a directory containing the Rust src, for more details see

``

2834

2855

`` // the doc comment on the real_rust_source_base_dir field.

``

2835

2856

`let tmp_buf;

`

`@@ -2910,6 +2931,7 @@ pub fn build_session_options(

`

2910

2931

` pretty,

`

2911

2932

` working_dir,

`

2912

2933

` color,

`

``

2934

`+

logical_env,

`

2913

2935

`}

`

2914

2936

`}

`

2915

2937

``

`@@ -3184,6 +3206,7 @@ pub(crate) mod dep_tracking {

`

3184

3206

`};

`

3185

3207

`use crate::lint;

`

3186

3208

`use crate::utils::NativeLib;

`

``

3209

`+

use rustc_data_structures::fx::FxIndexMap;

`

3187

3210

`use rustc_data_structures::stable_hasher::Hash64;

`

3188

3211

`use rustc_errors::LanguageIdentifier;

`

3189

3212

`use rustc_feature::UnstableFeatures;

`

`@@ -3342,6 +3365,21 @@ pub(crate) mod dep_tracking {

`

3342

3365

`}

`

3343

3366

`}

`

3344

3367

``

``

3368

`+

impl<T: DepTrackingHash, V: DepTrackingHash> DepTrackingHash for FxIndexMap<T, V> {

`

``

3369

`+

fn hash(

`

``

3370

`+

&self,

`

``

3371

`+

hasher: &mut DefaultHasher,

`

``

3372

`+

error_format: ErrorOutputType,

`

``

3373

`+

for_crate_hash: bool,

`

``

3374

`+

) {

`

``

3375

`+

Hash::hash(&self.len(), hasher);

`

``

3376

`+

for (key, value) in self.iter() {

`

``

3377

`+

DepTrackingHash::hash(key, hasher, error_format, for_crate_hash);

`

``

3378

`+

DepTrackingHash::hash(value, hasher, error_format, for_crate_hash);

`

``

3379

`+

}

`

``

3380

`+

}

`

``

3381

`+

}

`

``

3382

+

3345

3383

`impl DepTrackingHash for OutputTypes {

`

3346

3384

`fn hash(

`

3347

3385

`&self,

`