Skip to content

Commit

Permalink
Builder: Execute formula build steps
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkofler committed Oct 7, 2024
1 parent c8e6f8a commit ff28598
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/tools/builder.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{collections::HashMap, path::PathBuf, process::ExitStatus};
use std::{path::PathBuf, process::ExitStatus};

mod workdir;
use log::{debug, info};
pub use workdir::*;

use crate::{
env::{executable::CustomExecutable, BuildEnvironment, Environment},
env::{BuildEnvironment, Environment, EnvironmentExecutable},
error::{Error, ErrorExt, ErrorType, Throwable},
model::{Formula, Home, ObjectDB},
util::{
Expand Down Expand Up @@ -59,12 +59,20 @@ impl<'a> Builder<'a> {
.e_context(|| format!("Extracting object {} to {}", oid, path.str_lossy(),))?;
}

let buildsteps = self.formula.get_buildsteps(
formula_inner_path.clone(),
self.workdir.get_install_dir_inner(),
);

// Use a separate scope for all functions that
// need an active environment. This makes sure
// the environment is dropped and removed once
// it is no longer needed
{
let lower_dirs = vec![self.workdir.get_formula_dir()];
let lower_dirs = vec![
self.workdir.get_formula_dir(),
PathBuf::from("/home/max/x86_64-cross-toolchain"),
];

let overlay_mount = OverlayMount::new(
lower_dirs,
Expand All @@ -77,17 +85,19 @@ impl<'a> Builder<'a> {
let environment = BuildEnvironment::new(Box::new(overlay_mount))
.ctx(|| "Creating build environment")?;

let mut envs = HashMap::new();
envs.insert("PKG_NAME".to_owned(), self.formula.name.clone());
envs.insert("PKG_VERSION".to_owned(), self.formula.version.clone());
let signal_dispatcher = SignalDispatcher::default();

info!("Build environment is ready - executing buildsteps");

// For now, we execute 'sh' before implementing the build commands
let executable = CustomExecutable::new("sh".to_owned(), formula_inner_path, envs);
let dispatcher = SignalDispatcher::default();
for buildstep in buildsteps {
info!("Executing step '{}'...", buildstep.get_name());

info!("Build environment is ready - entering chroot");
environment
.execute(&buildstep, &signal_dispatcher)
.ctx(|| format!("Executing '{}' step", buildstep.get_name()))?;

environment.execute(&executable, &dispatcher)?;
info!("Executed step '{}'...", buildstep.get_name());
}
}

debug!("Exited from chroot, cleaning up...");
Expand Down

0 comments on commit ff28598

Please sign in to comment.