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

krane-bundle: clarify error message when go not in PATH #416

Merged
merged 1 commit into from
Dec 17, 2024
Merged
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
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
Loading