]> git.lizzy.rs Git - rust.git/blob - src/tools/replace-version-placeholder/src/main.rs
Rollup merge of #101322 - ChrisDenton:internal-doc, r=Mark-Simulacrum
[rust.git] / src / tools / replace-version-placeholder / src / main.rs
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_attr/src/builtin.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 }