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

PHD: allow patched Crucible dependencies #778

Merged
merged 4 commits into from
Oct 3, 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
35 changes: 21 additions & 14 deletions phd-tests/runner/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,24 @@ fn main() -> anyhow::Result<()> {
}

fn set_crucible_git_rev() -> anyhow::Result<()> {
const CRUCIBLE_REPO: &str = "https://github.com/oxidecomputer/crucible";
fn extract_crucible_dep_sha(
src: &cargo_metadata::Source,
) -> anyhow::Result<&str> {
const CRUCIBLE_REPO: &str = "https://github.com/oxidecomputer/crucible";

let src = src.repr.strip_prefix("git+").ok_or_else(|| {
anyhow::anyhow!("Crucible package's source should be from git")
anyhow::anyhow!("Crucible is not a Git dependency")
})?;

if !src.starts_with(CRUCIBLE_REPO) {
println!("cargo:warning=expected Crucible package's source to be {CRUCIBLE_REPO:?}, but is {src:?}");
}

let rev = src.split("?rev=").nth(1).ok_or_else(|| {
anyhow::anyhow!("Crucible package's source should have a revision")
anyhow::anyhow!("Crucible package's source did not have a revision")
})?;
let mut parts = rev.split('#');
let sha = parts.next().ok_or_else(|| {
anyhow::anyhow!("Crucible package's source should have a revision")
anyhow::anyhow!("Crucible package's source did not have a revision")
})?;
assert_eq!(Some(sha), parts.next());
Ok(sha)
Expand All @@ -48,16 +47,24 @@ fn set_crucible_git_rev() -> anyhow::Result<()> {
anyhow::anyhow!("Failed to find Crucible package in cargo metadata")
})?;

let crucible_src = crucible_pkg.source.as_ref().ok_or_else(|| {
anyhow::anyhow!("Crucible package should not be a workspace member, and therefore should have source metadata")
})?;

let crucible_sha =
extract_crucible_dep_sha(crucible_src).with_context(|| {
format!(
"Failed to extract Crucible source SHA from {crucible_src:?}"
let mut errmsg = String::new();
let crucible_sha = crucible_pkg
.source
.as_ref()
.ok_or_else(|| {
anyhow::anyhow!(
"Crucible dependency is patched with a local checkout"
)
})?;
})
.and_then(extract_crucible_dep_sha)
.unwrap_or_else(|err| {
println!(
"cargo:warning={err}, so the `--crucible-downstairs-commit auto` \
flag will be disabled in this PHD build",
);
errmsg = format!("CANT_GET_YE_CRUCIBLE_SHA{err}");
&errmsg
});

println!("cargo:rustc-env=PHD_CRUCIBLE_GIT_REV={crucible_sha}");

Expand Down
19 changes: 16 additions & 3 deletions phd-tests/runner/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,22 @@ impl RunOptions {
// The Git revision of Crucible we depend on is determined when building
// `phd-runner` by the build script, so that the `phd-runner` binary can
// be run even after moving it out of the Propolis cargo workspace.
let commit = env!("PHD_CRUCIBLE_GIT_REV").parse().context(
"PHD_CRUCIBLE_GIT_REV must be set to a valid Git revision by the build script",
)?;
let commit = env!("PHD_CRUCIBLE_GIT_REV");
if let Some(reason) =
commit.strip_prefix("CANT_GET_YE_CRUCIBLE_SHA")
{
anyhow::bail!(
"Because {reason}, phd-runner's build script could not determine \
the Crucible Git SHA, so the `--crucible-downstairs-commit auto` \
option has been disabled.\n\tYou can provide a local Crucible \
binary using `--crucible-downstairs-cmd`.",
)
}

let commit = commit.parse().context(
"PHD_CRUCIBLE_GIT_REV must be set to a valid Git \
revision by the build script",
)?;
Ok(Some(CrucibleDownstairsSource::BuildomatGitRev(commit)))
}
None => Ok(None),
Expand Down
Loading