Merge branch 'fix_recipe_find' into 'master'

Fix make clean.

See merge request redox-os/cookbook!359
This commit is contained in:
Jeremy Soller 2024-03-23 13:46:04 +00:00
commit 05e733a0c9
7 changed files with 48 additions and 19 deletions

7
Cargo.lock generated
View File

@ -68,6 +68,12 @@ dependencies = [
"winapi",
]
[[package]]
name = "anyhow"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247"
[[package]]
name = "arg_parser"
version = "0.1.0"
@ -1213,6 +1219,7 @@ dependencies = [
name = "redox_cookbook"
version = "0.1.0"
dependencies = [
"anyhow",
"blake3 1.5.0",
"pbr",
"pkgar",

View File

@ -10,7 +10,7 @@ else
recipes="$@"
fi
for recipe in $recipes
for recipe_path in $recipes
do
./cook.sh "$recipe" distclean
./cook.sh "$recipe_path" distclean
done

13
cook.sh
View File

@ -365,7 +365,14 @@ function op {
if [ -n "$1" ]
then
recipe_path=`target/release/find_recipe $1`
if (echo "$1" | grep '.*/.*' >/dev/null); then
recipe_name=$(basename "$1")
recipe_path="recipes/$1"
else
recipe_name="$1"
recipe_path=`target/release/find_recipe $recipe_name`
fi
if [ -d "$ROOT/$recipe_path" ]
then
export COOKBOOK_RECIPE="${ROOT}/$recipe_path"
@ -402,10 +409,10 @@ then
for i in "${ops[@]}"
do
op "$1" "$i"
op "$recipe_name" "$i"
done
else
echo "cook.sh: recipe '$1' not found" >&2
echo "cook.sh: recipe '$recipe_name' at not found" >&2
exit 1
fi
else

View File

@ -10,14 +10,12 @@ else
recipes="$@"
fi
for recipe in $recipes
for recipe_path in $recipes
do
recipe_path=`target/release/find_recipe $recipe`
if [ -e "$recipe_path/recipe.toml" ]
then
target/release/cook --fetch-only "$recipe"
continue
target/release/cook --fetch-only "$recipe_path"
else
./cook.sh "$recipe_path" fetch
fi
./cook.sh "$recipe" fetch
done

View File

@ -4,7 +4,9 @@ use std::process::exit;
// use clap::Parser;
fn main() {
let result = list_recipes( Path::new("recipes"));
let print_short = std::env::args().nth(1).map_or(false, |a| a == "-s" || a == "--short");
let result = list_recipes( Path::new("recipes"), Default::default());
match result {
Ok(result) => {
@ -12,7 +14,17 @@ fn main() {
eprintln!("recipes not found");
exit(1);
} else {
result.iter().for_each(|recipe| println!("{recipe}"));
for path in result {
let Some(file_name) = path.file_name() else {
continue;
};
if print_short {
println!("{}", file_name.to_string_lossy());
} else {
println!("{}", path.to_string_lossy());
}
}
exit(0);
}
}

View File

@ -45,8 +45,8 @@ pub fn recipe_find(recipe: &str, dir: &Path) -> Result<Option<PathBuf>, String>
Ok(recipe_path)
}
pub fn list_recipes(dir: &Path) -> Result<Vec<String>, String> {
let mut recipes = Vec::<String>::new();
pub fn list_recipes(dir: &Path, prefix: PathBuf) -> Result<Vec<PathBuf>, String> {
let mut recipes = Vec::<PathBuf>::new();
if !dir.is_dir() {
return Ok(recipes);
}
@ -55,7 +55,7 @@ pub fn list_recipes(dir: &Path) -> Result<Vec<String>, String> {
if entry.file_name() == OsStr::new("recipe.sh")
|| entry.file_name() == OsStr::new("recipe.toml")
{
recipes.push(dir.file_name().ok_or(format!("could not unwrap the filename for {:?}", dir))?.to_string_lossy().to_string());
recipes.push(prefix);
return Ok(recipes);
}
}
@ -65,7 +65,12 @@ pub fn list_recipes(dir: &Path) -> Result<Vec<String>, String> {
if !entry.file_type().map_err(|e| e.to_string())?.is_dir() {
continue;
}
let mut found = list_recipes(entry.path().as_path())?;
let name = entry.file_name();
let Some(name) = name.to_str() else {
eprintln!("invalid UTF-8 for entry {entry:?}");
continue;
};
let mut found = list_recipes(entry.path().as_path(), prefix.join(name))?;
recipes.append(&mut found);
}
recipes.sort();

View File

@ -10,7 +10,7 @@ else
recipes="$@"
fi
for recipe in $recipes
for recipe_path in $recipes
do
./cook.sh "$recipe" unfetch
./cook.sh "$recipe_path" unfetch
done