Skip to content

Commit

Permalink
Merge pull request #416 from cbgbt/go-err-msg
Browse files Browse the repository at this point in the history
krane-bundle: clarify error message when go not in PATH
  • Loading branch information
cbgbt authored Dec 17, 2024
2 parents 1a7935b + 57db067 commit 2ae29fa
Showing 1 changed file with 39 additions and 30 deletions.
69 changes: 39 additions & 30 deletions tools/krane/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,7 @@ use tar::Archive;

const CRANE_VERSION: &str = "0.20.1";

fn apply_source_patches(source_path: impl AsRef<Path>, patch_dir: impl AsRef<Path>) {
let source_path = source_path.as_ref();
let patch_dir = patch_dir.as_ref();

which::which("patch").expect("Must have the `patch` utility installed in PATH");

let mut patches = fs::read_dir(patch_dir)
.expect("Failed to read patch directory")
.filter_map(|entry| entry.ok())
.map(|entry| entry.path())
.filter(|path| path.extension().map(|ext| ext == "patch").unwrap_or(false))
.collect::<Vec<_>>();
patches.sort();

for patch in patches {
println!("Executing `patch -p1 -i '{}'`", patch.display());

let patch_status = Command::new("patch")
.current_dir(source_path)
.arg("-p1")
.arg("-i")
.arg(patch.as_os_str())
.status()
.expect("Failed to execute patch command");

if !patch_status.success() {
panic!("Failed to apply patch '{}'", patch.display());
}
}
}
const REQUIRED_TOOLS: &[&str] = &["patch", "go"];

fn main() {
let script_dir = env::current_dir().unwrap();
Expand All @@ -47,6 +18,8 @@ fn main() {
println!("cargo::rerun-if-changed=hashes/crane");
println!("cargo::rerun-if-changed=patches");

ensure_required_tools_installed();

// Download and checksum-verify crane
env::set_current_dir(&out_dir).expect("Failed to set current directory");
Command::new(script_dir.join("../build-cache-fetch"))
Expand Down Expand Up @@ -108,6 +81,42 @@ fn main() {
println!("cargo::rustc-env=KRANE_GZ_PATH={}", krane_gz_path.display());
}

fn ensure_required_tools_installed() {
for tool in REQUIRED_TOOLS {
which::which(tool)
.unwrap_or_else(|_| panic!("Must have the `{tool}` utility installed in PATH"));
}
}

fn apply_source_patches(source_path: impl AsRef<Path>, patch_dir: impl AsRef<Path>) {
let source_path = source_path.as_ref();
let patch_dir = patch_dir.as_ref();

let mut patches = fs::read_dir(patch_dir)
.expect("Failed to read patch directory")
.filter_map(|entry| entry.ok())
.map(|entry| entry.path())
.filter(|path| path.extension().map(|ext| ext == "patch").unwrap_or(false))
.collect::<Vec<_>>();
patches.sort();

for patch in patches {
println!("Executing `patch -p1 -i '{}'`", patch.display());

let patch_status = Command::new("patch")
.current_dir(source_path)
.arg("-p1")
.arg("-i")
.arg(patch.as_os_str())
.status()
.expect("Failed to execute patch command");

if !patch_status.success() {
panic!("Failed to apply patch '{}'", patch.display());
}
}
}

fn get_goos() -> &'static str {
let target_os = env::var("CARGO_CFG_TARGET_OS").expect("Failed to read CARGO_CFG_TARGET_OS");
match target_os.as_str() {
Expand Down

0 comments on commit 2ae29fa

Please sign in to comment.