Fix config rule reload

This commit is contained in:
Wildan M 2025-12-13 07:32:55 +07:00
parent 5dfb3d6e6a
commit e455f6139e
No known key found for this signature in database
GPG Key ID: 01AC53185C679C79
2 changed files with 39 additions and 28 deletions

View File

@ -514,32 +514,9 @@ fn parse_args(args: Vec<String>) -> anyhow::Result<(CliConfig, CliCommand, Vec<C
}
}
};
match last_rule {
// build from source as usual
"source" => {}
// keep local changes
"local" => recipe.recipe.source = None,
// download from remote build
"binary" => {
recipe.recipe.source = None;
recipe.recipe.build.set_as_remote();
}
// don't build this recipe (unlikely to go here unless some deps need it)
// TODO: Note that we're assuming this being ignored from e.g. metapackages
// TODO: Will totally broke build if this recipe needed as some other build dependencies
"ignore" => {
recipe.recipe.source = None;
recipe.recipe.build.set_as_none();
}
rule => {
bail!(
// Fail fast because we could risk losing local changes if "local" was typo'ed
"Invalid pkg config {} = \"{}\"\nExpecting either 'source', 'local', 'binary' or 'ignore'",
recipe.name.as_str(),
rule
);
}
}
recipe
.apply_filesystem_config(last_rule)
.map_err(|e| anyhow!(e))?;
}
}

View File

@ -200,6 +200,7 @@ pub struct CookRecipe {
pub target: &'static str,
/// If false, it's listed on install config
pub is_deps: bool,
pub rule: String,
}
impl Recipe {
@ -254,6 +255,7 @@ impl CookRecipe {
recipe,
target,
is_deps: false,
rule: "".into(),
})
}
@ -420,8 +422,8 @@ impl CookRecipe {
}
pub fn reload_recipe(&mut self) -> Result<(), PackageError> {
let r = Self::from_path(&self.dir, true, self.name.is_host())?;
self.recipe = r.recipe;
self.recipe = Self::from_path(&self.dir, true, self.name.is_host())?.recipe;
let _ = self.apply_filesystem_config(&self.rule.clone());
Ok(())
}
@ -437,6 +439,38 @@ impl CookRecipe {
pub fn target_dir(&self) -> PathBuf {
self.dir.join("target").join(self.target)
}
pub fn apply_filesystem_config(&mut self, rule: &str) -> Result<(), String> {
match rule {
// build from source as usual
"source" => {}
// keep local changes
"local" => self.recipe.source = None,
// download from remote build
"binary" => {
self.recipe.source = None;
self.recipe.build.set_as_remote();
}
// don't build this recipe (unlikely to go here unless some deps need it)
// TODO: Note that we're assuming this being ignored from e.g. metapackages
// TODO: Will totally broke build if this recipe needed as some other build dependencies
"ignore" => {
self.recipe.source = None;
self.recipe.build.set_as_none();
}
rule => {
return Err(format!(
// Fail fast because we could risk losing local changes if "local" was typo'ed
"Invalid pkg config {} = \"{}\"\nExpecting either 'source', 'local', 'binary' or 'ignore'",
self.name.as_str(),
rule
));
}
}
self.rule = rule.to_string();
Ok(())
}
}
#[derive(Serialize, Deserialize)]