Skip to content

Commit 8d3e25a

Browse files
committed
compiletest: Make aux-crate directive explicitly handle --extern modifiers
To make it clearer what happens. In other words, do not silently keep modifiers as part of `AuxCrate::name`.
1 parent 9aaa581 commit 8d3e25a

2 files changed

Lines changed: 41 additions & 16 deletions

File tree

src/tools/compiletest/src/directives/auxiliary.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ use std::iter;
66
use super::directives::{AUX_BIN, AUX_BUILD, AUX_CODEGEN_BACKEND, AUX_CRATE, PROC_MACRO};
77
use crate::common::Config;
88
use crate::directives::DirectiveLine;
9+
use crate::util::static_regex;
910

1011
/// The value of an `aux-crate` directive.
1112
#[derive(Clone, Debug, Default)]
1213
pub struct AuxCrate {
14+
/// Contains `--extern` modifiers, if any. See the tracking issue for more
15+
/// info: https://github.com/rust-lang/rust/issues/98405
16+
/// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude`.
17+
pub extern_modifiers: Option<String>,
1318
/// With `aux-crate: foo=bar.rs` this will be `foo`.
14-
/// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude:foo`.
19+
/// With `aux-crate: noprelude:foo=bar.rs` this will be `foo`.
1520
pub name: String,
1621
/// With `aux-crate: foo=bar.rs` this will be `bar.rs`.
1722
pub path: String,
@@ -74,9 +79,16 @@ pub(super) fn parse_and_update_aux(
7479
}
7580

7681
fn parse_aux_crate(r: String) -> AuxCrate {
77-
let mut parts = r.trim().splitn(2, '=');
78-
AuxCrate {
79-
name: parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(),
80-
path: parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(),
81-
}
82+
// Matches:
83+
// name=path
84+
// modifiers:name=path
85+
let caps = static_regex!(r"^(?:(?P<modifiers>[^=]*?):)?(?P<name>[^=]*)=(?P<path>.*)$")
86+
.captures(r.trim())
87+
.unwrap_or_else(|| panic!("missing aux-crate value (e.g. log=log.rs)"));
88+
89+
let modifiers = caps.name("modifiers").map(|m| m.as_str().to_string());
90+
let name = caps.name("name").map(|m| m.as_str().to_string()).unwrap_or_default();
91+
let path = caps.name("path").map(|m| m.as_str().to_string()).unwrap_or_default();
92+
93+
AuxCrate { extern_modifiers: modifiers, name, path }
8294
}

src/tools/compiletest/src/runtest.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,23 +1277,36 @@ impl<'test> TestCx<'test> {
12771277
.replace('-', "_")
12781278
};
12791279

1280-
let add_extern =
1281-
|rustc: &mut Command, aux_name: &str, aux_path: &str, aux_type: AuxType| {
1282-
let lib_name = get_lib_name(&path_to_crate_name(aux_path), aux_type);
1283-
if let Some(lib_name) = lib_name {
1284-
rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir, lib_name));
1285-
}
1286-
};
1280+
let add_extern = |rustc: &mut Command,
1281+
extern_modifiers: Option<&str>,
1282+
aux_name: &str,
1283+
aux_path: &str,
1284+
aux_type: AuxType| {
1285+
let lib_name = get_lib_name(&path_to_crate_name(aux_path), aux_type);
1286+
if let Some(lib_name) = lib_name {
1287+
let modifiers_and_name = match extern_modifiers {
1288+
Some(modifiers) => format!("{modifiers}:{aux_name}"),
1289+
None => aux_name.to_string(),
1290+
};
1291+
rustc.arg("--extern").arg(format!("{modifiers_and_name}={aux_dir}/{lib_name}"));
1292+
}
1293+
};
12871294

1288-
for AuxCrate { name, path } in &self.props.aux.crates {
1295+
for AuxCrate { extern_modifiers, name, path } in &self.props.aux.crates {
12891296
let aux_type = self.build_auxiliary(&path, &aux_dir, None);
1290-
add_extern(rustc, name, path, aux_type);
1297+
add_extern(rustc, extern_modifiers.as_deref(), name, path, aux_type);
12911298
}
12921299

12931300
for proc_macro in &self.props.aux.proc_macros {
12941301
self.build_auxiliary(proc_macro, &aux_dir, Some(AuxType::ProcMacro));
12951302
let crate_name = path_to_crate_name(proc_macro);
1296-
add_extern(rustc, &crate_name, proc_macro, AuxType::ProcMacro);
1303+
add_extern(
1304+
rustc,
1305+
None, // `extern_modifiers`
1306+
&crate_name,
1307+
proc_macro,
1308+
AuxType::ProcMacro,
1309+
);
12971310
}
12981311

12991312
// Build any `//@ aux-codegen-backend`, and pass the resulting library

0 commit comments

Comments
 (0)