Skip to content

Commit

Permalink
Allow passing a specific date to bump-stage0
Browse files Browse the repository at this point in the history
This allows regenerating `src/stage0.json` on changes to the tool,
without needing to hard-code the date in the source.
  • Loading branch information
jyn514 committed Jan 3, 2023
1 parent 7742995 commit 6f1d9ba
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/bootstrap/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl Step for BumpStage0 {

fn run(self, builder: &Builder<'_>) -> Self::Output {
let mut cmd = builder.tool_cmd(Tool::BumpStage0);
cmd.args(builder.config.cmd.args());
builder.run(&mut cmd);
}
}
Expand Down
27 changes: 16 additions & 11 deletions src/tools/bump-stage0/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::Error;
use anyhow::{Context, Error};
use curl::easy::Easy;
use indexmap::IndexMap;
use std::collections::HashMap;
Expand All @@ -13,12 +13,13 @@ struct Tool {
comments: Vec<String>,

channel: Channel,
date: Option<String>,
version: [u16; 3],
checksums: IndexMap<String, String>,
}

impl Tool {
fn new() -> Result<Self, Error> {
fn new(date: Option<String>) -> Result<Self, Error> {
let channel = match std::fs::read_to_string("src/ci/channel")?.trim() {
"stable" => Channel::Stable,
"beta" => Channel::Beta,
Expand All @@ -40,6 +41,7 @@ impl Tool {
Ok(Self {
channel,
version,
date,
config: existing.config,
comments: existing.comments,
checksums: IndexMap::new(),
Expand Down Expand Up @@ -84,7 +86,7 @@ impl Tool {
Channel::Nightly => "beta".to_string(),
};

let manifest = fetch_manifest(&self.config, &channel)?;
let manifest = fetch_manifest(&self.config, &channel, self.date.as_deref())?;
self.collect_checksums(&manifest, COMPILER_COMPONENTS)?;
Ok(Stage0Toolchain {
date: manifest.date,
Expand All @@ -110,7 +112,7 @@ impl Tool {
return Ok(None);
}

let manifest = fetch_manifest(&self.config, "nightly")?;
let manifest = fetch_manifest(&self.config, "nightly", self.date.as_deref())?;
self.collect_checksums(&manifest, RUSTFMT_COMPONENTS)?;
Ok(Some(Stage0Toolchain { date: manifest.date, version: "nightly".into() }))
}
Expand Down Expand Up @@ -141,16 +143,19 @@ impl Tool {
}

fn main() -> Result<(), Error> {
let tool = Tool::new()?;
let tool = Tool::new(std::env::args().nth(1))?;
tool.update_json()?;
Ok(())
}

fn fetch_manifest(config: &Config, channel: &str) -> Result<Manifest, Error> {
Ok(toml::from_slice(&http_get(&format!(
"{}/dist/channel-rust-{}.toml",
config.dist_server, channel
))?)?)
fn fetch_manifest(config: &Config, channel: &str, date: Option<&str>) -> Result<Manifest, Error> {
let url = if let Some(date) = date {
format!("{}/dist/{}/channel-rust-{}.toml", config.dist_server, date, channel)
} else {
format!("{}/dist/channel-rust-{}.toml", config.dist_server, channel)
};

Ok(toml::from_slice(&http_get(&url)?)?)
}

fn http_get(url: &str) -> Result<Vec<u8>, Error> {
Expand All @@ -164,7 +169,7 @@ fn http_get(url: &str) -> Result<Vec<u8>, Error> {
data.extend_from_slice(new_data);
Ok(new_data.len())
})?;
transfer.perform()?;
transfer.perform().context(format!("failed to fetch {url}"))?;
}
Ok(data)
}
Expand Down

0 comments on commit 6f1d9ba

Please sign in to comment.