Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[crater] Compute and store 'hash' of python packages #1075

Merged
merged 1 commit into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion fontc_crater/src/ci.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ struct RunSummary {
began: DateTime<Utc>,
finished: DateTime<Utc>,
fontc_rev: String,
#[serde(default)]
pip_freeze_sha: String,
results_file: PathBuf,
// the name of the file listing targets used by this run.
// it is intended that when this list is updated, the filename is changed.
Expand Down Expand Up @@ -81,11 +83,13 @@ fn run_crater_and_save_results(args: &CiArgs) -> Result<(), Error> {
let mut prev_runs: Vec<RunSummary> = load_json_if_exists_else_default(&summary_file)?;
// todo: fontc_repo should be checked out by us, and have a known path
let fontc_rev = super::get_git_rev(None).unwrap();
let pip_freeze_sha = super::pip_freeze_sha();
if let Some(last_run) = prev_runs.last() {
if last_run.fontc_rev == fontc_rev
&& Some(last_run.input_file.as_os_str()) == args.to_run.file_name()
&& pip_freeze_sha == last_run.pip_freeze_sha
{
log::info!("fontc rev & inputs is unchanged from last run, skipping");
log::info!("no changes since last run, skipping");
return Ok(());
}
}
Expand Down Expand Up @@ -121,6 +125,7 @@ fn run_crater_and_save_results(args: &CiArgs) -> Result<(), Error> {
began,
finished,
fontc_rev,
pip_freeze_sha,
results_file: out_file.into(),
input_file,
stats: summary,
Expand Down
17 changes: 17 additions & 0 deletions fontc_crater/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
collections::BTreeMap,
fmt::Display,
path::{Path, PathBuf},
process::{Command, Stdio},
str::FromStr,
sync::atomic::{AtomicUsize, Ordering},
};
Expand Down Expand Up @@ -135,6 +136,22 @@ fn get_git_rev(repo_path: Option<&Path>) -> Option<String> {
)
}

fn pip_freeze_sha() -> String {
let pipfreeze = Command::new("pip")
.arg("freeze")
.stdout(Stdio::piped())
.spawn()
.unwrap();
let sha1sum = Command::new("shasum")
.stdin(Stdio::from(pipfreeze.stdout.unwrap()))
.output()
.expect("shasum should be preinstalled everywhere");
assert!(sha1sum.status.success());
std::str::from_utf8(sha1sum.stdout.trim_ascii())
.expect("shasum output always ascii")
.to_owned()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't really need a crytographic hash or to spawn although I suppose it's harmless enough

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was just the quickest way I could think of to do this in a consistent and portable way. 🤷


impl Target {
pub(crate) fn id(&self) -> TargetId {
TargetId {
Expand Down
Loading