-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
preinstall-toolchains
binary and run it in CI
- Loading branch information
Showing
4 changed files
with
69 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
use anyhow::{Context, Result}; | ||
use assert_cmd::output::OutputError; | ||
use regex::Regex; | ||
use std::{ | ||
fs::read_to_string, | ||
io::{BufRead, BufReader}, | ||
process::{Child, Command, Stdio}, | ||
}; | ||
|
||
fn main() -> Result<()> { | ||
let re = Regex::new(r"\<nightly-[0-9]{4}-[0-9]{2}-[0-9]{2}\>")?; | ||
|
||
let mut ls_files_child = Command::new("git") | ||
.arg("ls-files") | ||
.stdout(Stdio::piped()) | ||
.spawn() | ||
.with_context(|| "Could not spawn `git ls-files`")?; | ||
|
||
let ls_files_stdout = ls_files_child.stdout.take().unwrap(); | ||
let mut toolchains = BufReader::new(ls_files_stdout).lines().try_fold( | ||
Vec::new(), | ||
|mut toolchains, result| -> Result<Vec<_>> { | ||
let path = result.with_context(|| "Could not read from `git ls-files`")?; | ||
if let Ok(contents) = read_to_string(&path) { | ||
toolchains.extend(re.find_iter(&contents).map(|m| m.as_str().to_owned())); | ||
} else { | ||
eprintln!("Could not read `{path}`"); | ||
} | ||
Ok(toolchains) | ||
}, | ||
)?; | ||
|
||
ensure_child_success(ls_files_child)?; | ||
|
||
toolchains.sort(); | ||
toolchains.dedup(); | ||
|
||
let rustup_children = toolchains | ||
.into_iter() | ||
.map(|toolchain| -> Result<Child> { | ||
Command::new("rustup") | ||
.args(["toolchain", "install", &toolchain, "--no-self-update"]) | ||
.spawn() | ||
.map_err(Into::into) | ||
}) | ||
.collect::<Result<Vec<_>>>() | ||
.with_context(|| "Could not spawn `rustup`")?; | ||
|
||
for rustup_child in rustup_children { | ||
ensure_child_success(rustup_child)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
fn ensure_child_success(child: Child) -> Result<()> { | ||
let output = child.wait_with_output()?; | ||
if !output.status.success() { | ||
eprintln!("child failed: {}", OutputError::new(output)); | ||
} | ||
Ok(()) | ||
} |