Check for profiler support via a flag, instead of an environment var

This commit is contained in:
Zalathar 2023-10-28 09:26:39 +11:00
parent f688dd684f
commit f9df1ad4f2
5 changed files with 27 additions and 2 deletions

View File

@ -1976,7 +1976,7 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the
}
if builder.config.profiler_enabled(target) {
cmd.env("RUSTC_PROFILER_SUPPORT", "1");
cmd.arg("--profiler-support");
}
cmd.env("RUST_TEST_TMPDIR", builder.tempdir());

View File

@ -387,6 +387,10 @@ pub struct Config {
// Needed both to construct build_helper::git::GitConfig
pub git_repository: String,
pub nightly_branch: String,
/// True if the profiler runtime is enabled for this target.
/// Used by the "needs-profiler-support" header in test files.
pub profiler_support: bool,
}
impl Config {

View File

@ -238,7 +238,7 @@ impl CachedNeedsConditions {
sanitizer_memtag: sanitizers.contains(&Sanitizer::Memtag),
sanitizer_shadow_call_stack: sanitizers.contains(&Sanitizer::ShadowCallStack),
sanitizer_safestack: sanitizers.contains(&Sanitizer::Safestack),
profiler_support: std::env::var_os("RUSTC_PROFILER_SUPPORT").is_some(),
profiler_support: config.profiler_support,
xray: config.target_cfg().xray,
// For tests using the `needs-rust-lld` directive (e.g. for `-Clink-self-contained=+linker`),

View File

@ -62,6 +62,7 @@ struct ConfigBuilder {
llvm_version: Option<String>,
git_hash: bool,
system_llvm: bool,
profiler_support: bool,
}
impl ConfigBuilder {
@ -100,6 +101,11 @@ impl ConfigBuilder {
self
}
fn profiler_support(&mut self, s: bool) -> &mut Self {
self.profiler_support = s;
self
}
fn build(&mut self) -> Config {
let args = &[
"compiletest",
@ -142,6 +148,9 @@ impl ConfigBuilder {
if self.system_llvm {
args.push("--system-llvm".to_owned());
}
if self.profiler_support {
args.push("--profiler-support".to_owned());
}
args.push("--rustc-path".to_string());
// This is a subtle/fragile thing. On rust-lang CI, there is no global
@ -340,6 +349,15 @@ fn sanitizers() {
assert!(check_ignore(&config, "// needs-sanitizer-thread"));
}
#[test]
fn profiler_support() {
let config: Config = cfg().profiler_support(false).build();
assert!(check_ignore(&config, "// needs-profiler-support"));
let config: Config = cfg().profiler_support(true).build();
assert!(!check_ignore(&config, "// needs-profiler-support"));
}
#[test]
fn asm_support() {
let asms = [

View File

@ -142,6 +142,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
.optflag("", "force-rerun", "rerun tests even if the inputs are unchanged")
.optflag("", "only-modified", "only run tests that result been modified")
.optflag("", "nocapture", "")
.optflag("", "profiler-support", "is the profiler runtime enabled for this target")
.optflag("h", "help", "show this message")
.reqopt("", "channel", "current Rust channel", "CHANNEL")
.optflag("", "git-hash", "run tests which rely on commit version being compiled into the binaries")
@ -315,6 +316,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
git_repository: matches.opt_str("git-repository").unwrap(),
nightly_branch: matches.opt_str("nightly-branch").unwrap(),
profiler_support: matches.opt_present("profiler-support"),
}
}