about summary refs log tree commit diff
diff options
context:
space:
mode:
authorest31 <MTest31@outlook.com>2022-08-23 22:14:12 +0200
committerest31 <MTest31@outlook.com>2022-08-27 17:39:11 +0200
commitd32ff14b86c72f55a113a3f477c42b2995e8c620 (patch)
treed14a78a6b93f5daab2206353450547a28d11ead9
parenta2e2d7676822600c81a519343c7eccab9204334b (diff)
downloadrust-d32ff14b86c72f55a113a3f477c42b2995e8c620.tar.gz
rust-d32ff14b86c72f55a113a3f477c42b2995e8c620.zip
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.
-rw-r--r--Cargo.lock8
-rw-r--r--Cargo.toml1
-rw-r--r--src/bootstrap/builder.rs8
-rw-r--r--src/bootstrap/run.rs22
-rw-r--r--src/bootstrap/test.rs37
-rw-r--r--src/bootstrap/tool.rs1
-rw-r--r--src/tools/replace-version-placeholder/Cargo.toml10
-rw-r--r--src/tools/replace-version-placeholder/src/main.rs30
8 files changed, 116 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2ea32a80120..dda8c03e256 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3294,6 +3294,14 @@ dependencies = [
 ]
 
 [[package]]
+name = "replace-version-placeholder"
+version = "0.1.0"
+dependencies = [
+ "tidy",
+ "walkdir",
+]
+
+[[package]]
 name = "rls"
 version = "1.41.0"
 dependencies = [
diff --git a/Cargo.toml b/Cargo.toml
index ffc886d47f3..1e83f05e0ca 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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",
 ]
 
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index ba732cd7742..c4710e8faec 100644
--- a/src/bootstrap/builder.rs
+++ b/src/bootstrap/builder.rs
@@ -647,6 +647,7 @@ impl<'a> Builder<'a> {
                 test::CrateRustdocJsonTypes,
                 test::Linkcheck,
                 test::TierCheck,
+                test::ReplacePlaceholderTest,
                 test::Cargotest,
                 test::Cargo,
                 test::Rls,
@@ -746,7 +747,12 @@ impl<'a> Builder<'a> {
                 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![],
         }
diff --git a/src/bootstrap/run.rs b/src/bootstrap/run.rs
index 25abe7a72fd..511872903d1 100644
--- a/src/bootstrap/run.rs
+++ b/src/bootstrap/run.rs
@@ -103,3 +103,25 @@ impl Step for BumpStage0 {
         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);
+    }
+}
diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs
index c759d9b88e2..9cbdb3aca32 100644
--- a/src/bootstrap/test.rs
+++ b/src/bootstrap/test.rs
@@ -2528,6 +2528,43 @@ impl Step for TierCheck {
 }
 
 #[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,
     pub target: TargetSelection,
diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs
index 570da20e7d6..5bb40014eb9 100644
--- a/src/bootstrap/tool.rs
+++ b/src/bootstrap/tool.rs
@@ -378,6 +378,7 @@ bootstrap_tool!(
     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)]
diff --git a/src/tools/replace-version-placeholder/Cargo.toml b/src/tools/replace-version-placeholder/Cargo.toml
new file mode 100644
index 00000000000..346ce6bd1db
--- /dev/null
+++ b/src/tools/replace-version-placeholder/Cargo.toml
@@ -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"
diff --git a/src/tools/replace-version-placeholder/src/main.rs b/src/tools/replace-version-placeholder/src/main.rs
new file mode 100644
index 00000000000..146e53f2e9a
--- /dev/null
+++ b/src/tools/replace-version-placeholder/src/main.rs
@@ -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);
+        },
+    );
+}