From bf76d8ad185f5bdc4d26a6bec31af4f9ccc20492 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Fri, 10 Jul 2026 12:32:47 +0700 Subject: [PATCH] Recipe rule improvements --- mk/repo.mk | 10 +++++++--- src/bin/repo.rs | 17 +++++++++-------- src/cook/fetch.rs | 9 +++++++++ 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/mk/repo.mk b/mk/repo.mk index 71ce48477..7ba8ff275 100644 --- a/mk/repo.mk +++ b/mk/repo.mk @@ -42,6 +42,7 @@ fetch: prefix $(FSTOOLS_TAG) FORCE ifeq ($(PODMAN_BUILD),1) $(PODMAN_RUN) make $@ else + rm -f $(REPO_TAG) export PATH="$(PREFIX_PATH):$$PATH" && \ export COOKBOOK_HOST_SYSROOT="$(ROOT)/$(PREFIX_INSTALL)" && \ $(REPO_BIN) fetch $(COOKBOOK_OPTS) --with-package-deps @@ -150,7 +151,7 @@ else endif # Push all recipes specified by the filesystem config -push: $(FSTOOLS_TAG) FORCE +push: $(REPO_TAG) $(FSTOOLS_TAG) FORCE ifeq ($(ALLOW_FSTOOLS),1) @rm -f $(MOUNTED_TAG) @if [ ! -d "$(MOUNT_DIR)" ]; then \ @@ -172,7 +173,6 @@ endif # Rebuild and push all recipes specified by the filesystem config rebuild-push: $(FSTOOLS_TAG) FORCE - rm -f $(REPO_TAG) $(MAKE) repo $(MAKE) push @@ -244,7 +244,6 @@ install: # Rebuild and install all recipes specified by the filesystem config rebuild-install: $(FSTOOLS_TAG) FORCE - rm -f $(REPO_TAG) $(MAKE) repo $(MAKE) install @@ -336,6 +335,11 @@ scrp.%: $(FSTOOLS_TAG) FORCE $(MAKE) scr.$* $(MAKE) p.$* +# Set specific recipe rule to "local" then invoke clean, rebuild and push +lcrp.%: $(FSTOOLS_TAG) FORCE + $(MAKE) lcr.$* + $(MAKE) p.$* + # Save current git rev for next recipe fetch, locking git recipes frozen in time repo-lock: $(FSTOOLS_TAG) FORCE ifeq ($(PODMAN_BUILD),1) diff --git a/src/bin/repo.rs b/src/bin/repo.rs index 435d3a398..2d0837128 100644 --- a/src/bin/repo.rs +++ b/src/bin/repo.rs @@ -866,15 +866,21 @@ fn handle_nonstop_fail(recipe: &CookRecipe) -> cookbook::Result<()> { fn handle_clean(recipe: &CookRecipe, _config: &CliConfig, command: &CliCommand) -> Result { let mut dir = recipe.dir.join("target"); let mut cached = true; + let unfetch = matches!(*command, CliCommand::Unfetch); + let mut clean_target = true; if matches!(*command, CliCommand::CleanTarget) { dir = dir.join(redoxer::target()) } - if dir.exists() { + if unfetch && recipe.rule == "binary" { + // may contains downloaded binaries + clean_target = false; + } + if clean_target && dir.exists() { remove_all(&dir)?; cached = false; } let dir = recipe.dir.join("source"); - if dir.exists() && matches!(*command, CliCommand::Unfetch) { + if dir.exists() && unfetch { remove_all(&dir)?; cached = false; } @@ -1100,12 +1106,7 @@ fn handle_change_rule( let mut fetch_cached = true; if is_change_rule_local && !recipe.dir.join("source").exists() { // previously, this is "binary", then user wants to hack around with the source, so we do fetch here - let mut recipe = recipe.clone(); - recipe.rule = "source".into(); - recipe.reload_recipe()?; - if recipe.recipe.source.is_some() { - fetch_cached = handle_fetch(&recipe, config, false, &None)?.cached; - } + fetch_cached = handle_fetch(&recipe, config, false, &None)?.cached; } let clean_cached = if !cached && is_change_rule { handle_clean(recipe, config, &CliCommand::Clean)? diff --git a/src/cook/fetch.rs b/src/cook/fetch.rs index 8c30205ef..625ce2153 100644 --- a/src/cook/fetch.rs +++ b/src/cook/fetch.rs @@ -137,6 +137,15 @@ pub fn fetch_offline(recipe: &CookRecipe, logger: &PtyOut) -> Result Result { let recipe_dir = &recipe.dir; let source_dir = recipe_dir.join("source"); + let mut recipe = recipe; + let mut recipe_owned; + if recipe.rule == "local" && !source_dir.exists() { + // local source, but the source is missing + recipe_owned = recipe.clone(); + recipe_owned.rule = "source".into(); + recipe_owned.reload_recipe()?; + recipe = &recipe_owned; + } match recipe.recipe.build.kind { BuildKind::None => { // the build function doesn't need source dir exists