get rid of ctx.prefix and add run cwd kwarg

This commit is contained in:
2026-05-20 20:52:42 +02:00
parent 16d81f509f
commit f9b6036c95
2 changed files with 6 additions and 18 deletions
+1 -13
View File
@@ -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 {
+5 -5
View File
@@ -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<String>,
jobs: i32,
}
impl PhaseContext {
pub fn new(source_dir: SourceDir, prefix: &str, jobs: i32, files: Option<String>) -> Self {
pub fn new(source_dir: SourceDir, jobs: i32, files: Option<String>) -> 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<Value<'v>>,
#[starlark(require = named)] env: Option<SmallMap<String, Value<'v>>>,
#[starlark(require = named)] cwd: Option<String>,
) -> anyhow::Result<NoneType> {
let argv: Vec<String> = 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<String, String>,
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)]