Skip to content

Commit d32ff14

Browse files
committed
Add replace-version-placeholder tool
This tool is to be ran at specific points in the release process to replace the version place holder made by stabilizations with the version number.
1 parent a2e2d76 commit d32ff14

File tree

8 files changed

+116
-1
lines changed

8 files changed

+116
-1
lines changed

Cargo.lock

+8
Original file line numberDiff line numberDiff line change
@@ -3293,6 +3293,14 @@ dependencies = [
32933293
"winapi",
32943294
]
32953295

3296+
[[package]]
3297+
name = "replace-version-placeholder"
3298+
version = "0.1.0"
3299+
dependencies = [
3300+
"tidy",
3301+
"walkdir",
3302+
]
3303+
32963304
[[package]]
32973305
name = "rls"
32983306
version = "1.41.0"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ members = [
3535
"src/tools/jsondocck",
3636
"src/tools/html-checker",
3737
"src/tools/bump-stage0",
38+
"src/tools/replace-version-placeholder",
3839
"src/tools/lld-wrapper",
3940
]
4041

src/bootstrap/builder.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ impl<'a> Builder<'a> {
647647
test::CrateRustdocJsonTypes,
648648
test::Linkcheck,
649649
test::TierCheck,
650+
test::ReplacePlaceholderTest,
650651
test::Cargotest,
651652
test::Cargo,
652653
test::Rls,
@@ -746,7 +747,12 @@ impl<'a> Builder<'a> {
746747
install::Src,
747748
install::Rustc
748749
),
749-
Kind::Run => describe!(run::ExpandYamlAnchors, run::BuildManifest, run::BumpStage0),
750+
Kind::Run => describe!(
751+
run::ExpandYamlAnchors,
752+
run::BuildManifest,
753+
run::BumpStage0,
754+
run::ReplaceVersionPlaceholder,
755+
),
750756
// These commands either don't use paths, or they're special-cased in Build::build()
751757
Kind::Clean | Kind::Format | Kind::Setup => vec![],
752758
}

src/bootstrap/run.rs

+22
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,25 @@ impl Step for BumpStage0 {
103103
builder.run(&mut cmd);
104104
}
105105
}
106+
107+
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
108+
pub struct ReplaceVersionPlaceholder;
109+
110+
impl Step for ReplaceVersionPlaceholder {
111+
type Output = ();
112+
const ONLY_HOSTS: bool = true;
113+
114+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
115+
run.path("src/tools/replace-version-placeholder")
116+
}
117+
118+
fn make_run(run: RunConfig<'_>) {
119+
run.builder.ensure(ReplaceVersionPlaceholder);
120+
}
121+
122+
fn run(self, builder: &Builder<'_>) -> Self::Output {
123+
let mut cmd = builder.tool_cmd(Tool::ReplaceVersionPlaceholder);
124+
cmd.arg(&builder.src);
125+
builder.run(&mut cmd);
126+
}
127+
}

src/bootstrap/test.rs

+37
Original file line numberDiff line numberDiff line change
@@ -2527,6 +2527,43 @@ impl Step for TierCheck {
25272527
}
25282528
}
25292529

2530+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
2531+
pub struct ReplacePlaceholderTest;
2532+
2533+
impl Step for ReplacePlaceholderTest {
2534+
type Output = ();
2535+
const ONLY_HOSTS: bool = true;
2536+
const DEFAULT: bool = true;
2537+
2538+
/// Ensure the version placeholder replacement tool builds
2539+
fn run(self, builder: &Builder<'_>) {
2540+
builder.info("build check for version replacement placeholder");
2541+
2542+
// Test the version placeholder replacement tool itself.
2543+
let bootstrap_host = builder.config.build;
2544+
let compiler = builder.compiler(0, bootstrap_host);
2545+
let cargo = tool::prepare_tool_cargo(
2546+
builder,
2547+
compiler,
2548+
Mode::ToolBootstrap,
2549+
bootstrap_host,
2550+
"test",
2551+
"src/tools/replace-version-placeholder",
2552+
SourceType::InTree,
2553+
&[],
2554+
);
2555+
try_run(builder, &mut cargo.into());
2556+
}
2557+
2558+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
2559+
run.path("src/tools/replace-version-placeholder")
2560+
}
2561+
2562+
fn make_run(run: RunConfig<'_>) {
2563+
run.builder.ensure(Self);
2564+
}
2565+
}
2566+
25302567
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
25312568
pub struct LintDocs {
25322569
pub compiler: Compiler,

src/bootstrap/tool.rs

+1
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ bootstrap_tool!(
378378
JsonDocCk, "src/tools/jsondocck", "jsondocck";
379379
HtmlChecker, "src/tools/html-checker", "html-checker";
380380
BumpStage0, "src/tools/bump-stage0", "bump-stage0";
381+
ReplaceVersionPlaceholder, "src/tools/replace-version-placeholder", "replace-version-placeholder";
381382
);
382383

383384
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "replace-version-placeholder"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]
9+
tidy = { path = "../tidy" }
10+
walkdir = "2"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::path::PathBuf;
2+
use tidy::{t, walk};
3+
4+
pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION";
5+
6+
fn main() {
7+
let root_path: PathBuf = std::env::args_os().nth(1).expect("need path to root of repo").into();
8+
let version_path = root_path.join("src").join("version");
9+
let version_str = t!(std::fs::read_to_string(&version_path), version_path);
10+
let version_str = version_str.trim();
11+
walk::walk(
12+
&root_path,
13+
&mut |path| {
14+
walk::filter_dirs(path)
15+
// We exempt these as they require the placeholder
16+
// for their operation
17+
|| path.ends_with("compiler/rustc_passes/src/lib_features.rs")
18+
|| path.ends_with("src/tools/tidy/src/features/version.rs")
19+
|| path.ends_with("src/tools/replace-version-placeholder")
20+
},
21+
&mut |entry, contents| {
22+
if !contents.contains(VERSION_PLACEHOLDER) {
23+
return;
24+
}
25+
let new_contents = contents.replace(VERSION_PLACEHOLDER, version_str);
26+
let path = entry.path();
27+
t!(std::fs::write(&path, new_contents), path);
28+
},
29+
);
30+
}

0 commit comments

Comments
 (0)