mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-07-02 09:38:42 +08:00
Merge branch 'update-tag' into 'master'
Implement update tag See merge request redox-os/redox!1737
This commit is contained in:
commit
05bb7a1f93
@ -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));
|
||||
@ -537,7 +540,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))?;
|
||||
|
||||
|
||||
@ -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 {
|
||||
|
||||
@ -285,3 +285,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())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user