Skip to content

Commit 5d5fbe0

Browse files
authored
xtask: Handle being in the right git dir without looking for ADOPTERS.md (#2077)
It turns out that things like `fedpkg local` break today because they'll do a build directly from dist-git and our code gets confused by this (because dist-git != upstream git). It doesn't affect "production" Koji builds because I think for historical reasons that doesn't mount the dist-git .git dir? Anyways...make this work more nicely by looking for ADOPTERS.md first and if we're already in the right dir, then we're done and no need to look for git. Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 1f80a21 commit 5d5fbe0

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

crates/xtask/src/xtask.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ mod man;
2121
mod tmt;
2222

2323
const NAME: &str = "bootc";
24+
/// File used to identify the bootc source tree toplevel.
25+
const TOPLEVEL_MARKER: &str = "ADOPTERS.md";
2426
const TAR_REPRODUCIBLE_OPTS: &[&str] = &[
2527
"--sort=name",
2628
"--owner=0",
@@ -201,9 +203,20 @@ fn main() {
201203
}
202204
}
203205

206+
/// Check if we're in a bootc source tree by looking for [`TOPLEVEL_MARKER`].
207+
fn in_bootc_source_tree() -> Result<bool> {
208+
Utf8Path::new(TOPLEVEL_MARKER)
209+
.try_exists()
210+
.context("Checking for toplevel")
211+
}
212+
204213
fn try_main() -> Result<()> {
205-
// Ensure our working directory is the toplevel (if we're in a git repo)
206-
{
214+
// Ensure our working directory is the bootc source toplevel.
215+
// First check if we're already there (e.g. when invoked from extracted
216+
// tarball during RPM build). Only try git if we're not already in the
217+
// right place - this avoids issues when building inside a different
218+
// git repository.
219+
if !in_bootc_source_tree()? {
207220
if let Ok(toplevel_path) = Command::new("git")
208221
.args(["rev-parse", "--show-toplevel"])
209222
.output()
@@ -213,12 +226,9 @@ fn try_main() -> Result<()> {
213226
std::env::set_current_dir(path.trim()).context("Changing to toplevel")?;
214227
}
215228
}
216-
// Otherwise verify we're in the toplevel
217-
if !Utf8Path::new("ADOPTERS.md")
218-
.try_exists()
219-
.context("Checking for toplevel")?
220-
{
221-
anyhow::bail!("Not in toplevel")
229+
// Verify we're now in the toplevel
230+
if !in_bootc_source_tree()? {
231+
anyhow::bail!("Not in toplevel (no {TOPLEVEL_MARKER} found)")
222232
}
223233
}
224234

0 commit comments

Comments
 (0)