Implement update tag

This commit is contained in:
Wildan M 2025-12-05 16:55:35 +07:00
parent 99f61754b3
commit d7a4af7cbd
No known key found for this signature in database
GPG Key ID: 01AC53185C679C79
3 changed files with 49 additions and 7 deletions

View File

@ -78,6 +78,7 @@ struct CliConfig {
sysroot_dir: PathBuf,
logs_dir: Option<PathBuf>,
category: Option<PathBuf>,
update_tag: Option<PathBuf>,
filesystem: Option<redox_installer::Config>,
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<String>) -> anyhow::Result<(CliConfig, CliCommand, Vec<C
"--repo" => 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))?;

View File

@ -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<PathBuf, String> {
pub fn fetch(
recipe_dir: &Path,
recipe: &Recipe,
update_tag: &Option<PathBuf>,
logger: &PtyOut,
) -> Result<PathBuf, String> {
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<Path
Some(SourceRecipe::SameAs { same_as }) => {
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<Path
}) => {
//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<Path
// Move source.tmp to source atomically
rename(&source_dir_tmp, &source_dir)?;
None
} else {
let source_git_dir = source_dir.join(".git");
if !source_git_dir.is_dir() {
@ -191,7 +198,14 @@ pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result<Path
command.arg("-C").arg(&source_dir);
command.arg("fetch").arg("origin");
run_command(command, logger)?;
}
if update_tag.is_some() {
Some(get_git_head_rev(&source_dir)?)
} else {
// not needed
None
}
};
if let Some(_upstream) = upstream {
//TODO: set upstream URL
@ -253,6 +267,17 @@ pub fn fetch(recipe_dir: &Path, recipe: &Recipe, logger: &PtyOut) -> Result<Path
}
run_command(command, logger)?;
if let Some(update_tag) = update_tag {
if match origin_commit {
Some(origin_commit) => 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 {

View File

@ -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<String, String> {
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())
}
}