Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions src/tools/compiletest/src/directives/auxiliary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ use crate::directives::DirectiveLine;
/// The value of an `aux-crate` directive.
#[derive(Clone, Debug, Default)]
pub struct AuxCrate {
/// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude`.
pub extern_opts: Option<String>,
/// With `aux-crate: foo=bar.rs` this will be `foo`.
/// With `aux-crate: noprelude:foo=bar.rs` this will be `noprelude:foo`.
/// With `aux-crate: noprelude:foo=bar.rs` this will be `foo`.
pub name: String,
/// With `aux-crate: foo=bar.rs` this will be `bar.rs`.
pub path: String,
}

/// The value of a `proc-macro` directive.
#[derive(Clone, Debug, Default)]
pub(crate) struct ProcMacro {
/// With `proc-macro: bar.rs` this will be `bar.rs`.
pub path: String,
/// With `proc-macro: noprelude:bar.rs` this will be `noprelude`.
pub extern_opts: Option<String>,
}

/// Properties parsed from `aux-*` test directives.
#[derive(Clone, Debug, Default)]
pub(crate) struct AuxProps {
Expand All @@ -29,7 +40,7 @@ pub(crate) struct AuxProps {
/// to build and pass with the `--extern` flag.
pub(crate) crates: Vec<AuxCrate>,
/// Same as `builds`, but for proc-macros.
pub(crate) proc_macros: Vec<String>,
pub(crate) proc_macros: Vec<ProcMacro>,
/// Similar to `builds`, but also uses the resulting dylib as a
/// `-Zcodegen-backend` when compiling the test file.
pub(crate) codegen_backend: Option<String>,
Expand All @@ -45,7 +56,7 @@ impl AuxProps {
.chain(builds.iter().map(String::as_str))
.chain(bins.iter().map(String::as_str))
.chain(crates.iter().map(|c| c.path.as_str()))
.chain(proc_macros.iter().map(String::as_str))
.chain(proc_macros.iter().map(|p| p.path.as_str()))
.chain(codegen_backend.iter().map(String::as_str))
}
}
Expand All @@ -66,17 +77,31 @@ pub(super) fn parse_and_update_aux(
config.push_name_value_directive(ln, AUX_BUILD, &mut aux.builds, |r| r.trim().to_string());
config.push_name_value_directive(ln, AUX_BIN, &mut aux.bins, |r| r.trim().to_string());
config.push_name_value_directive(ln, AUX_CRATE, &mut aux.crates, parse_aux_crate);
config
.push_name_value_directive(ln, PROC_MACRO, &mut aux.proc_macros, |r| r.trim().to_string());
config.push_name_value_directive(ln, PROC_MACRO, &mut aux.proc_macros, parse_proc_macro);

if let Some(r) = config.parse_name_value_directive(ln, AUX_CODEGEN_BACKEND) {
aux.codegen_backend = Some(r.trim().to_owned());
}
}

fn parse_aux_crate(r: String) -> AuxCrate {
let mut parts = r.trim().splitn(2, '=');
AuxCrate {
name: parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string(),
path: parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string(),
}
let opts_and_name = parts.next().expect("missing aux-crate name (e.g. log=log.rs)").to_string();
let path = parts.next().expect("missing aux-crate value (e.g. log=log.rs)").to_string();
let (opts, name) = match opts_and_name.split_once(':') {
None => (None, opts_and_name),
Some((opts, name)) => (Some(opts.to_string()), name.to_string()),
};
AuxCrate { extern_opts: opts, name, path }
}

fn parse_proc_macro(r: String) -> ProcMacro {
let r = r.trim();

let (opts, path): (Option<String>, String) = match r.split_once(':') {
None => (None, r.to_string()),
Some((opts, name)) => (Some(opts.to_string()), name.to_string()),
};

ProcMacro { path: path.to_string(), extern_opts: opts }
}
37 changes: 25 additions & 12 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,23 +1277,36 @@ impl<'test> TestCx<'test> {
.replace('-', "_")
};

let add_extern =
|rustc: &mut Command, aux_name: &str, aux_path: &str, aux_type: AuxType| {
let lib_name = get_lib_name(&path_to_crate_name(aux_path), aux_type);
if let Some(lib_name) = lib_name {
rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir, lib_name));
}
};
let add_extern = |rustc: &mut Command,
extern_opts: Option<&str>,
aux_name: &str,
aux_path: &str,
aux_type: AuxType| {
let lib_name = get_lib_name(&path_to_crate_name(aux_path), aux_type);
if let Some(lib_name) = lib_name {
let opts_and_name = match extern_opts {
Some(opts) => format!("{opts}:{aux_name}"),
None => aux_name.to_string(),
};
rustc.arg("--extern").arg(format!("{opts_and_name}={aux_dir}/{lib_name}"));
}
};

for AuxCrate { name, path } in &self.props.aux.crates {
for AuxCrate { extern_opts, name, path } in &self.props.aux.crates {
let aux_type = self.build_auxiliary(&path, &aux_dir, None);
add_extern(rustc, name, path, aux_type);
add_extern(rustc, extern_opts.as_deref(), name, path, aux_type);
}

for proc_macro in &self.props.aux.proc_macros {
self.build_auxiliary(proc_macro, &aux_dir, Some(AuxType::ProcMacro));
let crate_name = path_to_crate_name(proc_macro);
add_extern(rustc, &crate_name, proc_macro, AuxType::ProcMacro);
self.build_auxiliary(&proc_macro.path, &aux_dir, Some(AuxType::ProcMacro));
let crate_name = path_to_crate_name(&proc_macro.path);
add_extern(
rustc,
proc_macro.extern_opts.as_deref(),
&crate_name,
&proc_macro.path,
AuxType::ProcMacro,
);
}

// Build any `//@ aux-codegen-backend`, and pass the resulting library
Expand Down
5 changes: 0 additions & 5 deletions tests/ui/privacy/pub-priv-dep/auxiliary/pm.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
//@ force-host
//@ no-prefer-dynamic

#![crate_type = "proc-macro"]

extern crate proc_macro;
use proc_macro::TokenStream;

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/privacy/pub-priv-dep/pub-priv1.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ aux-crate:priv:priv_dep=priv_dep.rs
//@ aux-build:pub_dep.rs
//@ aux-crate:priv:pm=pm.rs
//@ proc-macro:priv:pm.rs
//@ compile-flags: -Zunstable-options

// Basic behavior check of exported_private_dependencies from either a public
Expand Down
Loading