diff --git a/src/builder.rs b/src/builder.rs index 386b420..57bf72f 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -1023,21 +1023,9 @@ fn plural<'a>(count: usize, singular: &'a str, plural: &'a str) -> &'a str { if count == 1 { singular } else { plural } } -fn prefix_for(kind: RecipeKind) -> &'static str { - match kind { - RecipeKind::Package => "/usr", - RecipeKind::HostPackage => "/usr/local", - } -} - fn phase_context_for(recipe: &Recipe) -> PhaseContext { let files = recipe.files_dir().map(|_| "/files".to_owned()); - PhaseContext::new( - source_dir_for(recipe), - prefix_for(recipe.kind()), - default_jobs(), - files, - ) + PhaseContext::new(source_dir_for(recipe), default_jobs(), files) } fn source_dir_for(recipe: &Recipe) -> SourceDir { diff --git a/src/phase.rs b/src/phase.rs index c8b9e21..7e1b8d1 100644 --- a/src/phase.rs +++ b/src/phase.rs @@ -211,18 +211,16 @@ impl<'v> StarlarkValue<'v> for SourceDir { pub struct PhaseContext { source_dir: SourceDir, build_dir: String, - prefix: String, sysroot: String, files: Option, jobs: i32, } impl PhaseContext { - pub fn new(source_dir: SourceDir, prefix: &str, jobs: i32, files: Option) -> Self { + pub fn new(source_dir: SourceDir, jobs: i32, files: Option) -> Self { Self { source_dir, build_dir: "/build".to_owned(), - prefix: prefix.to_owned(), sysroot: "/sysroot".to_owned(), files, jobs, @@ -285,6 +283,7 @@ fn phase_context_methods(builder: &mut MethodsBuilder) { #[starlark(this)] _this: Value<'v>, #[starlark(require = pos)] argv: UnpackList>, #[starlark(require = named)] env: Option>>, + #[starlark(require = named)] cwd: Option, ) -> anyhow::Result { let argv: Vec = argv .items @@ -297,7 +296,7 @@ fn phase_context_methods(builder: &mut MethodsBuilder) { env_strings.insert(k, coerce_path_string(v)?); } } - run_in_container(&argv, env_strings)?; + run_in_container(&argv, env_strings, cwd.as_deref().unwrap_or("/build"))?; Ok(NoneType) } } @@ -305,6 +304,7 @@ fn phase_context_methods(builder: &mut MethodsBuilder) { fn run_in_container( argv: &[String], env_overrides: SmallMap, + cwd: &str, ) -> anyhow::Result<()> { let (container, env) = with_current(|runtime| { let mut env: Vec<(String, String)> = runtime @@ -328,7 +328,7 @@ fn run_in_container( } (runtime.container.clone(), env) })?; - container.borrow().exec(argv, &env, "/build") + container.borrow().exec(argv, &env, cwd) } #[derive(Debug, Clone, Allocative, ProvidesStaticType, NoSerialize)]