Skip to content

Commit 30846f6

Browse files
authored
Rollup merge of rust-lang#106396 - jyn514:bump-stage-date, r=pietroalbini
Allow passing a specific date to `bump-stage0` This allows regenerating `src/stage0.json` on changes to the tool, without needing to hard-code the date in the source. It was useful for rust-lang#106394, which added clippy to the list of required components. r? `@pietroalbini`
2 parents 11020b9 + 6f1d9ba commit 30846f6

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

src/bootstrap/run.rs

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl Step for BumpStage0 {
105105

106106
fn run(self, builder: &Builder<'_>) -> Self::Output {
107107
let mut cmd = builder.tool_cmd(Tool::BumpStage0);
108+
cmd.args(builder.config.cmd.args());
108109
builder.run(&mut cmd);
109110
}
110111
}

src/tools/bump-stage0/src/main.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::Error;
1+
use anyhow::{Context, Error};
22
use curl::easy::Easy;
33
use indexmap::IndexMap;
44
use std::collections::HashMap;
@@ -13,12 +13,13 @@ struct Tool {
1313
comments: Vec<String>,
1414

1515
channel: Channel,
16+
date: Option<String>,
1617
version: [u16; 3],
1718
checksums: IndexMap<String, String>,
1819
}
1920

2021
impl Tool {
21-
fn new() -> Result<Self, Error> {
22+
fn new(date: Option<String>) -> Result<Self, Error> {
2223
let channel = match std::fs::read_to_string("src/ci/channel")?.trim() {
2324
"stable" => Channel::Stable,
2425
"beta" => Channel::Beta,
@@ -40,6 +41,7 @@ impl Tool {
4041
Ok(Self {
4142
channel,
4243
version,
44+
date,
4345
config: existing.config,
4446
comments: existing.comments,
4547
checksums: IndexMap::new(),
@@ -84,7 +86,7 @@ impl Tool {
8486
Channel::Nightly => "beta".to_string(),
8587
};
8688

87-
let manifest = fetch_manifest(&self.config, &channel)?;
89+
let manifest = fetch_manifest(&self.config, &channel, self.date.as_deref())?;
8890
self.collect_checksums(&manifest, COMPILER_COMPONENTS)?;
8991
Ok(Stage0Toolchain {
9092
date: manifest.date,
@@ -110,7 +112,7 @@ impl Tool {
110112
return Ok(None);
111113
}
112114

113-
let manifest = fetch_manifest(&self.config, "nightly")?;
115+
let manifest = fetch_manifest(&self.config, "nightly", self.date.as_deref())?;
114116
self.collect_checksums(&manifest, RUSTFMT_COMPONENTS)?;
115117
Ok(Some(Stage0Toolchain { date: manifest.date, version: "nightly".into() }))
116118
}
@@ -141,16 +143,19 @@ impl Tool {
141143
}
142144

143145
fn main() -> Result<(), Error> {
144-
let tool = Tool::new()?;
146+
let tool = Tool::new(std::env::args().nth(1))?;
145147
tool.update_json()?;
146148
Ok(())
147149
}
148150

149-
fn fetch_manifest(config: &Config, channel: &str) -> Result<Manifest, Error> {
150-
Ok(toml::from_slice(&http_get(&format!(
151-
"{}/dist/channel-rust-{}.toml",
152-
config.dist_server, channel
153-
))?)?)
151+
fn fetch_manifest(config: &Config, channel: &str, date: Option<&str>) -> Result<Manifest, Error> {
152+
let url = if let Some(date) = date {
153+
format!("{}/dist/{}/channel-rust-{}.toml", config.dist_server, date, channel)
154+
} else {
155+
format!("{}/dist/channel-rust-{}.toml", config.dist_server, channel)
156+
};
157+
158+
Ok(toml::from_slice(&http_get(&url)?)?)
154159
}
155160

156161
fn http_get(url: &str) -> Result<Vec<u8>, Error> {
@@ -164,7 +169,7 @@ fn http_get(url: &str) -> Result<Vec<u8>, Error> {
164169
data.extend_from_slice(new_data);
165170
Ok(new_data.len())
166171
})?;
167-
transfer.perform()?;
172+
transfer.perform().context(format!("failed to fetch {url}"))?;
168173
}
169174
Ok(data)
170175
}

0 commit comments

Comments
 (0)