From d7a4af7cbdd01b8c3fef56e71a604bcad6922108 Mon Sep 17 00:00:00 2001 From: Wildan M Date: Fri, 5 Dec 2025 16:55:35 +0700 Subject: [PATCH] Implement update tag --- src/bin/repo.rs | 5 ++++- src/cook/fetch.rs | 37 +++++++++++++++++++++++++++++++------ src/cook/fs.rs | 14 ++++++++++++++ 3 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/bin/repo.rs b/src/bin/repo.rs index adaf0682d..b4d8132c2 100644 --- a/src/bin/repo.rs +++ b/src/bin/repo.rs @@ -78,6 +78,7 @@ struct CliConfig { sysroot_dir: PathBuf, logs_dir: Option, category: Option, + update_tag: Option, filesystem: Option, with_package_deps: bool, all: bool, @@ -160,6 +161,7 @@ impl CliConfig { } else { current_dir.join("sysroot") }, + update_tag: None, with_package_deps: false, cook: get_config().cook.clone(), all: false, @@ -372,6 +374,7 @@ fn parse_args(args: Vec) -> anyhow::Result<(CliConfig, CliCommand, Vec config.repo_dir = PathBuf::from(value), "--sysroot" => config.sysroot_dir = PathBuf::from(value), "--category" => config.category = Some(PathBuf::from(value)), + "--update-tag" => config.update_tag = Some(PathBuf::from(value)), "--filesystem" => { config.filesystem = Some({ let r = redox_installer::Config::from_file(&PathBuf::from(value)); @@ -557,7 +560,7 @@ fn handle_fetch( let recipe_dir = &recipe.dir; let source_dir = match config.cook.offline && allow_offline { true => fetch_offline(recipe_dir, &recipe.recipe, logger), - false => fetch(recipe_dir, &recipe.recipe, logger), + false => fetch(recipe_dir, &recipe.recipe, &config.update_tag, logger), } .map_err(|e| anyhow!("failed to fetch: {:?}", e))?; diff --git a/src/cook/fetch.rs b/src/cook/fetch.rs index 9bbef81a0..119b1d540 100644 --- a/src/cook/fetch.rs +++ b/src/cook/fetch.rs @@ -47,10 +47,10 @@ pub fn fetch_offline( match &recipe.source { Some(SourceRecipe::Path { path: _ }) | None => { - return fetch(recipe_dir, recipe, logger); + return fetch(recipe_dir, recipe, &None, logger); } Some(SourceRecipe::SameAs { same_as: _ }) => { - return fetch(recipe_dir, recipe, logger); + return fetch(recipe_dir, recipe, &None, logger); } Some(SourceRecipe::Git { git: _, @@ -99,7 +99,12 @@ pub fn fetch_offline( Ok(source_dir) } -pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result { +pub fn fetch( + recipe_dir: &Path, + recipe: &Recipe, + update_tag: &Option, + logger: &PtyOut, +) -> Result { let source_dir = recipe_dir.join("source"); if recipe.build.kind == BuildKind::None { // the build function doesn't need source dir exists @@ -114,7 +119,7 @@ pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result { let (canon_dir, recipe) = fetch_resolve_canon(recipe_dir, &same_as)?; // recursively fetch - fetch(&canon_dir, &recipe, logger)?; + fetch(&canon_dir, &recipe, update_tag, logger)?; fetch_make_symlink(&source_dir, &same_as)?; } Some(SourceRecipe::Path { path }) => { @@ -147,7 +152,7 @@ pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result { //TODO: use libgit? let shallow_clone = *shallow_clone == Some(true); - if !source_dir.is_dir() { + let origin_commit = if !source_dir.is_dir() { // Create source.tmp let source_dir_tmp = recipe_dir.join("source.tmp"); create_dir_clean(&source_dir_tmp)?; @@ -171,6 +176,8 @@ pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result Result Result origin_commit != get_git_head_rev(&source_dir)?, + None => true, + } { + let mut command = Command::new("touch"); + command.arg(&update_tag); + run_command(command, logger)?; + }; + } + fetch_apply_patches(recipe_dir, patches, script, &source_dir, logger)?; } Some(SourceRecipe::Tar { diff --git a/src/cook/fs.rs b/src/cook/fs.rs index 31e61c3ae..816845d95 100644 --- a/src/cook/fs.rs +++ b/src/cook/fs.rs @@ -286,3 +286,17 @@ pub fn download_wget(url: &str, dest: &PathBuf, logger: &PtyOut) -> Result<(), S } Ok(()) } + +pub fn get_git_head_rev(dir: &PathBuf) -> Result { + let git_head = dir.join(".git/HEAD"); + let head_str = fs::read_to_string(&git_head) + .map_err(|e| format!("unable to read {path}: {e}", path = git_head.display()))?; + if head_str.starts_with("ref: ") { + let git_ref = dir.join(head_str["ref: ".len()..].trim_end()); + let ref_str = fs::read_to_string(&git_ref) + .map_err(|e| format!("unable to read {path}: {e}", path = git_ref.display()))?; + Ok(ref_str) + } else { + Ok(head_str.trim_end().to_string()) + } +}