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.
This commit is contained in:
parent
a2e2d76768
commit
d32ff14b86
@ -3293,6 +3293,14 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "replace-version-placeholder"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"tidy",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rls"
|
||||
version = "1.41.0"
|
||||
|
@ -35,6 +35,7 @@ members = [
|
||||
"src/tools/jsondocck",
|
||||
"src/tools/html-checker",
|
||||
"src/tools/bump-stage0",
|
||||
"src/tools/replace-version-placeholder",
|
||||
"src/tools/lld-wrapper",
|
||||
]
|
||||
|
||||
|
@ -647,6 +647,7 @@ macro_rules! describe {
|
||||
test::CrateRustdocJsonTypes,
|
||||
test::Linkcheck,
|
||||
test::TierCheck,
|
||||
test::ReplacePlaceholderTest,
|
||||
test::Cargotest,
|
||||
test::Cargo,
|
||||
test::Rls,
|
||||
@ -746,7 +747,12 @@ macro_rules! describe {
|
||||
install::Src,
|
||||
install::Rustc
|
||||
),
|
||||
Kind::Run => describe!(run::ExpandYamlAnchors, run::BuildManifest, run::BumpStage0),
|
||||
Kind::Run => describe!(
|
||||
run::ExpandYamlAnchors,
|
||||
run::BuildManifest,
|
||||
run::BumpStage0,
|
||||
run::ReplaceVersionPlaceholder,
|
||||
),
|
||||
// These commands either don't use paths, or they're special-cased in Build::build()
|
||||
Kind::Clean | Kind::Format | Kind::Setup => vec![],
|
||||
}
|
||||
|
@ -103,3 +103,25 @@ fn run(self, builder: &Builder<'_>) -> Self::Output {
|
||||
builder.run(&mut cmd);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialOrd, Ord, Copy, Clone, Hash, PartialEq, Eq)]
|
||||
pub struct ReplaceVersionPlaceholder;
|
||||
|
||||
impl Step for ReplaceVersionPlaceholder {
|
||||
type Output = ();
|
||||
const ONLY_HOSTS: bool = true;
|
||||
|
||||
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
||||
run.path("src/tools/replace-version-placeholder")
|
||||
}
|
||||
|
||||
fn make_run(run: RunConfig<'_>) {
|
||||
run.builder.ensure(ReplaceVersionPlaceholder);
|
||||
}
|
||||
|
||||
fn run(self, builder: &Builder<'_>) -> Self::Output {
|
||||
let mut cmd = builder.tool_cmd(Tool::ReplaceVersionPlaceholder);
|
||||
cmd.arg(&builder.src);
|
||||
builder.run(&mut cmd);
|
||||
}
|
||||
}
|
||||
|
@ -2527,6 +2527,43 @@ fn run(self, builder: &Builder<'_>) {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct ReplacePlaceholderTest;
|
||||
|
||||
impl Step for ReplacePlaceholderTest {
|
||||
type Output = ();
|
||||
const ONLY_HOSTS: bool = true;
|
||||
const DEFAULT: bool = true;
|
||||
|
||||
/// Ensure the version placeholder replacement tool builds
|
||||
fn run(self, builder: &Builder<'_>) {
|
||||
builder.info("build check for version replacement placeholder");
|
||||
|
||||
// Test the version placeholder replacement tool itself.
|
||||
let bootstrap_host = builder.config.build;
|
||||
let compiler = builder.compiler(0, bootstrap_host);
|
||||
let cargo = tool::prepare_tool_cargo(
|
||||
builder,
|
||||
compiler,
|
||||
Mode::ToolBootstrap,
|
||||
bootstrap_host,
|
||||
"test",
|
||||
"src/tools/replace-version-placeholder",
|
||||
SourceType::InTree,
|
||||
&[],
|
||||
);
|
||||
try_run(builder, &mut cargo.into());
|
||||
}
|
||||
|
||||
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
|
||||
run.path("src/tools/replace-version-placeholder")
|
||||
}
|
||||
|
||||
fn make_run(run: RunConfig<'_>) {
|
||||
run.builder.ensure(Self);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct LintDocs {
|
||||
pub compiler: Compiler,
|
||||
|
@ -378,6 +378,7 @@ fn run(self, builder: &Builder<'_>) -> PathBuf {
|
||||
JsonDocCk, "src/tools/jsondocck", "jsondocck";
|
||||
HtmlChecker, "src/tools/html-checker", "html-checker";
|
||||
BumpStage0, "src/tools/bump-stage0", "bump-stage0";
|
||||
ReplaceVersionPlaceholder, "src/tools/replace-version-placeholder", "replace-version-placeholder";
|
||||
);
|
||||
|
||||
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
|
||||
|
10
src/tools/replace-version-placeholder/Cargo.toml
Normal file
10
src/tools/replace-version-placeholder/Cargo.toml
Normal file
@ -0,0 +1,10 @@
|
||||
[package]
|
||||
name = "replace-version-placeholder"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
tidy = { path = "../tidy" }
|
||||
walkdir = "2"
|
30
src/tools/replace-version-placeholder/src/main.rs
Normal file
30
src/tools/replace-version-placeholder/src/main.rs
Normal file
@ -0,0 +1,30 @@
|
||||
use std::path::PathBuf;
|
||||
use tidy::{t, walk};
|
||||
|
||||
pub const VERSION_PLACEHOLDER: &str = "CURRENT_RUSTC_VERSION";
|
||||
|
||||
fn main() {
|
||||
let root_path: PathBuf = std::env::args_os().nth(1).expect("need path to root of repo").into();
|
||||
let version_path = root_path.join("src").join("version");
|
||||
let version_str = t!(std::fs::read_to_string(&version_path), version_path);
|
||||
let version_str = version_str.trim();
|
||||
walk::walk(
|
||||
&root_path,
|
||||
&mut |path| {
|
||||
walk::filter_dirs(path)
|
||||
// We exempt these as they require the placeholder
|
||||
// for their operation
|
||||
|| path.ends_with("compiler/rustc_passes/src/lib_features.rs")
|
||||
|| path.ends_with("src/tools/tidy/src/features/version.rs")
|
||||
|| path.ends_with("src/tools/replace-version-placeholder")
|
||||
},
|
||||
&mut |entry, contents| {
|
||||
if !contents.contains(VERSION_PLACEHOLDER) {
|
||||
return;
|
||||
}
|
||||
let new_contents = contents.replace(VERSION_PLACEHOLDER, version_str);
|
||||
let path = entry.path();
|
||||
t!(std::fs::write(&path, new_contents), path);
|
||||
},
|
||||
);
|
||||
}
|
Loading…
Reference in New Issue
Block a user