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 } 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 { fn phase_context_for(recipe: &Recipe) -> PhaseContext {
let files = recipe.files_dir().map(|_| "/files".to_owned()); let files = recipe.files_dir().map(|_| "/files".to_owned());
PhaseContext::new( PhaseContext::new(source_dir_for(recipe), default_jobs(), files)
source_dir_for(recipe),
prefix_for(recipe.kind()),
default_jobs(),
files,
)
} }
fn source_dir_for(recipe: &Recipe) -> SourceDir { fn source_dir_for(recipe: &Recipe) -> SourceDir {
+5 -5
View File
@@ -211,18 +211,16 @@ impl<'v> StarlarkValue<'v> for SourceDir {
pub struct PhaseContext { pub struct PhaseContext {
source_dir: SourceDir, source_dir: SourceDir,
build_dir: String, build_dir: String,
prefix: String,
sysroot: String, sysroot: String,
files: Option<String>, files: Option<String>,
jobs: i32, jobs: i32,
} }
impl PhaseContext { 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 { Self {
source_dir, source_dir,
build_dir: "/build".to_owned(), build_dir: "/build".to_owned(),
prefix: prefix.to_owned(),
sysroot: "/sysroot".to_owned(), sysroot: "/sysroot".to_owned(),
files, files,
jobs, jobs,
@@ -285,6 +283,7 @@ fn phase_context_methods(builder: &mut MethodsBuilder) {
#[starlark(this)] _this: Value<'v>, #[starlark(this)] _this: Value<'v>,
#[starlark(require = pos)] argv: UnpackList<Value<'v>>, #[starlark(require = pos)] argv: UnpackList<Value<'v>>,
#[starlark(require = named)] env: Option<SmallMap<String, Value<'v>>>, #[starlark(require = named)] env: Option<SmallMap<String, Value<'v>>>,
#[starlark(require = named)] cwd: Option<String>,
) -> anyhow::Result<NoneType> { ) -> anyhow::Result<NoneType> {
let argv: Vec<String> = argv let argv: Vec<String> = argv
.items .items
@@ -297,7 +296,7 @@ fn phase_context_methods(builder: &mut MethodsBuilder) {
env_strings.insert(k, coerce_path_string(v)?); 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) Ok(NoneType)
} }
} }
@@ -305,6 +304,7 @@ fn phase_context_methods(builder: &mut MethodsBuilder) {
fn run_in_container( fn run_in_container(
argv: &[String], argv: &[String],
env_overrides: SmallMap<String, String>, env_overrides: SmallMap<String, String>,
cwd: &str,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let (container, env) = with_current(|runtime| { let (container, env) = with_current(|runtime| {
let mut env: Vec<(String, String)> = runtime let mut env: Vec<(String, String)> = runtime
@@ -328,7 +328,7 @@ fn run_in_container(
} }
(runtime.container.clone(), env) (runtime.container.clone(), env)
})?; })?;
container.borrow().exec(argv, &env, "/build") container.borrow().exec(argv, &env, cwd)
} }
#[derive(Debug, Clone, Allocative, ProvidesStaticType, NoSerialize)] #[derive(Debug, Clone, Allocative, ProvidesStaticType, NoSerialize)]