From 69ef10f035dc62c519d579e28c4e89938eb0747d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 21 May 2020 11:14:00 -0600 Subject: [PATCH] Improve ability to override cookbook items, improve C support --- src/bin/cook.rs | 154 +++++++++++++++++++++++++++++++----------------- 1 file changed, 100 insertions(+), 54 deletions(-) diff --git a/src/bin/cook.rs b/src/bin/cook.rs index e9ed47e8..43c188dd 100644 --- a/src/bin/cook.rs +++ b/src/bin/cook.rs @@ -282,6 +282,21 @@ fn build(recipe_dir: &Path, source_dir: &Path, build: &BuildRecipe) -> Result Result { - let mut command = Command::new("redoxer"); - command.arg("install"); - //TODO: --debug if desired - command.arg("--path").arg(&source_dir); - command.arg("--root").arg(&stage_dir_tmp); - command.env("CARGO_TARGET_DIR", &build_dir); - run_command(command)?; - }, - BuildKind::Configure => { - //TODO: Add more configurability, convert script to Rust - let mut command = Command::new("redoxer"); - command.arg("env"); - command.arg("bash").arg("-ex"); - //TODO: remove unwraps - command.env("COOKBOOK_STAGE", &stage_dir_tmp.canonicalize().unwrap()); - command.env("COOKBOOK_SOURCE", &source_dir.canonicalize().unwrap()); - command.env("COOKBOOK_SYSROOT", &sysroot_dir.canonicalize().unwrap()); - command.current_dir(&build_dir); - run_command_stdin(command, r#" - export CFLAGS="-I'${COOKBOOK_SYSROOT}/include'" - export LDFLAGS="-L'${COOKBOOK_SYSROOT}/lib' --static" - "${COOKBOOK_SOURCE}/configure" \ - --host="${TARGET}" \ - --prefix="" \ - --disable-shared \ - --enable-static - make -j "$(nproc)" - make install DESTDIR="${COOKBOOK_STAGE}" + //TODO: Add more configurability, convert scripts to Rust? + let script = match &build.kind { + BuildKind::Cargo => "cookbook_cargo", + BuildKind::Configure => "cookbook_configure", + BuildKind::Custom { script } => script + }; - # Strip binaries - if [ -d "${COOKBOOK_STAGE}/bin" ] - then - find "${COOKBOOK_STAGE}/bin" -type f -exec "${TARGET}-strip" -v {} ';' - fi + let command = { + let mut command = Command::new("redoxer"); + command.arg("env"); + command.arg("bash").arg("-ex"); - # Remove libtool files - if [ -d "${COOKBOOK_STAGE}/lib" ] - then - find "${COOKBOOK_STAGE}/lib" -type f -name '*.la' -exec rm -fv {} ';' - fi - "#.as_bytes())?; - }, - BuildKind::Custom { script } => { - let mut command = Command::new("redoxer"); - command.arg("env"); - command.arg("bash").arg("-ex"); - //TODO: remove unwraps - command.env("COOKBOOK_STAGE", &stage_dir_tmp.canonicalize().unwrap()); - command.env("COOKBOOK_SOURCE", &source_dir.canonicalize().unwrap()); - command.env("COOKBOOK_SYSROOT", &sysroot_dir.canonicalize().unwrap()); - command.current_dir(&build_dir); - run_command_stdin(command, script.as_bytes())?; - }, - } + //TODO: remove unwraps + let cookbook_build = build_dir.canonicalize().unwrap(); + let cookbook_recipe = recipe_dir.canonicalize().unwrap(); + let cookbook_stage = stage_dir_tmp.canonicalize().unwrap(); + let cookbook_source = source_dir.canonicalize().unwrap(); + let cookbook_sysroot = sysroot_dir.canonicalize().unwrap(); + command.current_dir(&cookbook_build); + command.env("COOKBOOK_BUILD", &cookbook_build); + command.env("COOKBOOK_RECIPE", &cookbook_recipe); + command.env("COOKBOOK_STAGE", &cookbook_stage); + command.env("COOKBOOK_SOURCE", &cookbook_source); + command.env("COOKBOOK_SYSROOT", &cookbook_sysroot); + command + }; + + let full_script = format!("{}\n{}\n{}", pre_script, script, post_script); + run_command_stdin(command, full_script.as_bytes())?; // Move stage.tmp to stage atomically rename(&stage_dir_tmp, &stage_dir)?;