xtask: patch gen_init_cpio.c

Recent changes[0][1] have broken compatibility with macOS; add a patch
to conditionally compile these snippets.

[0] ae18b94099
[1] 97169cd6d9
reviewable/pr1358/r1
Tamir Duberstein 1 month ago
parent 8e31f5fa43
commit 3f0544513d
No known key found for this signature in database

@ -0,0 +1,32 @@
diff --git a/gen_init_cpio.c b/gen_init_cpio.c
index 75e9561b..406c4d0a 100644
--- a/gen_init_cpio.c
+++ b/gen_init_cpio.c
@@ -453,6 +453,7 @@ static int cpio_mkfile(const char *name, const char *location,
push_pad(namepadlen ? namepadlen : padlen(offset, 4)) < 0)
goto error;
+#ifdef __linux__
if (size) {
this_read = copy_file_range(file, NULL, outfd, NULL, size, 0);
if (this_read > 0) {
@@ -463,6 +464,7 @@ static int cpio_mkfile(const char *name, const char *location,
}
/* short or failed copy falls back to read/write... */
}
+#endif
while (size) {
unsigned char filebuf[65536];
@@ -671,7 +673,10 @@ int main (int argc, char *argv[])
break;
case 'o':
outfd = open(optarg,
- O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC,
+#ifdef O_LARGEFILE
+ O_LARGEFILE |
+#endif
+ O_WRONLY | O_CREAT | O_TRUNC,
0600);
if (outfd < 0) {
fprintf(stderr, "failed to open %s\n", optarg);

@ -1,7 +1,7 @@
use std::{ use std::{
ffi::OsString, ffi::OsString,
fmt::Write as _, fmt::Write as _,
fs::{OpenOptions, copy, create_dir_all}, fs::{OpenOptions, copy, create_dir_all, write},
io::{BufRead as _, BufReader, Write as _}, io::{BufRead as _, BufReader, Write as _},
ops::Deref as _, ops::Deref as _,
path::{Path, PathBuf}, path::{Path, PathBuf},
@ -16,6 +16,8 @@ use clap::Parser;
use walkdir::WalkDir; use walkdir::WalkDir;
use xtask::{AYA_BUILD_INTEGRATION_BPF, Errors}; use xtask::{AYA_BUILD_INTEGRATION_BPF, Errors};
const GEN_INIT_CPIO_PATCH: &str = include_str!("../patches/gen_init_cpio.c.macos.diff");
#[derive(Parser)] #[derive(Parser)]
enum Environment { enum Environment {
/// Runs the integration tests locally. /// Runs the integration tests locally.
@ -277,22 +279,45 @@ pub(crate) fn run(opts: Options) -> Result<()> {
}; };
if !gen_init_cpio_source.is_empty() { if !gen_init_cpio_source.is_empty() {
let tmp_dir = tempfile::tempdir().context("tempdir failed")?;
let source_path = tmp_dir.path().join("gen_init_cpio.c");
write(&source_path, &gen_init_cpio_source)
.with_context(|| format!("failed to write {}", source_path.display()))?;
let mut patch = Command::new("patch");
patch
.current_dir(tmp_dir.path())
.args(["-p1", "-s", "-o", "-"])
.stdin(Stdio::piped())
.stdout(Stdio::piped());
let mut patch_child = patch
.spawn()
.with_context(|| format!("failed to spawn {patch:?}"))?;
let Child { stdin, stdout, .. } = &mut patch_child;
let mut stdin = stdin.take().unwrap();
stdin
.write_all(GEN_INIT_CPIO_PATCH.as_bytes())
.with_context(|| format!("failed to write to {patch:?} stdin"))?;
drop(stdin); // Must explicitly close to signal EOF.
let stdout = stdout.take().unwrap();
let mut clang = Command::new("clang"); let mut clang = Command::new("clang");
clang clang
.args(["-g", "-O2", "-x", "c", "-", "-o"]) .args(["-g", "-O2", "-x", "c", "-", "-o"])
.arg(&gen_init_cpio) .arg(&gen_init_cpio)
.stdin(Stdio::piped()); .stdin(stdout);
let mut clang_child = clang let clang_child = clang
.spawn() .spawn()
.with_context(|| format!("failed to spawn {clang:?}"))?; .with_context(|| format!("failed to spawn {clang:?}"))?;
let Child { stdin, .. } = &mut clang_child; let output = patch_child
.wait_with_output()
let mut stdin = stdin.take().unwrap(); .with_context(|| format!("failed to wait for {patch:?}"))?;
stdin let Output { status, .. } = &output;
.write_all(&gen_init_cpio_source) if status.code() != Some(0) {
.with_context(|| format!("failed to write to {clang:?} stdin"))?; bail!("{patch:?} failed: {output:?}")
drop(stdin); // Must explicitly close to signal EOF. }
let output = clang_child let output = clang_child
.wait_with_output() .wait_with_output()

Loading…
Cancel
Save