mirror of
https://gitlab.redox-os.org/redox-os/redox.git
synced 2026-11-05 04:06:38 +08:00
Merge branch 'cargo-fix' into 'master'
Apply cargo fix and fmt See merge request redox-os/redox!2305
This commit is contained in:
commit
9da7a98926
@ -199,11 +199,10 @@ impl TuiApp {
|
||||
recipe_name: &PackageName,
|
||||
) -> (Option<&Vec<String>>, Option<Cow<'_, str>>) {
|
||||
let log_text = self.logs.get(recipe_name);
|
||||
let log_line = if let Some(b) = self.log_byte_buffer.get(recipe_name) {
|
||||
Some(String::from_utf8_lossy(b))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let log_line = self
|
||||
.log_byte_buffer
|
||||
.get(recipe_name)
|
||||
.map(|b| String::from_utf8_lossy(b));
|
||||
(log_text, log_line)
|
||||
}
|
||||
|
||||
@ -215,7 +214,7 @@ impl TuiApp {
|
||||
if !str.trim_end().is_empty() {
|
||||
std::fs::write(log_path, str).map_err(|e| Error::from_io_error(e, "Writing log"))?;
|
||||
}
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Update the state based on a message from a worker thread
|
||||
@ -400,10 +399,10 @@ pub fn run_tui_cook(config: CliConfig, recipes: Vec<CookRecipe>) -> Result<TuiAp
|
||||
let (input_tx, input_rx) = mpsc::channel::<Event>();
|
||||
let _input_handle = thread::spawn(move || {
|
||||
for evt in mstdin.events() {
|
||||
if let Ok(evt) = evt {
|
||||
if input_tx.send(evt).is_err() {
|
||||
return;
|
||||
}
|
||||
if let Ok(evt) = evt
|
||||
&& input_tx.send(evt).is_err()
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -569,7 +568,7 @@ pub fn run_tui_cook(config: CliConfig, recipes: Vec<CookRecipe>) -> Result<TuiAp
|
||||
app.cook_list_state.select(Some(index));
|
||||
let index_u16 = index;
|
||||
let center_offset = panel_height / 2;
|
||||
let new_offset = index_u16.saturating_sub(center_offset) as usize;
|
||||
let new_offset = index_u16.saturating_sub(center_offset);
|
||||
|
||||
*app.cook_list_state.offset_mut() = new_offset;
|
||||
}
|
||||
@ -597,8 +596,7 @@ pub fn run_tui_cook(config: CliConfig, recipes: Vec<CookRecipe>) -> Result<TuiAp
|
||||
app.log_view_job.to_string(),
|
||||
if app.is_inspecting {
|
||||
staged_pkg::find(active_name.as_str())
|
||||
.map(|s| s.to_str())
|
||||
.flatten()
|
||||
.and_then(|s| s.to_str())
|
||||
.unwrap_or(active_name.as_str())
|
||||
} else {
|
||||
active_name.as_str()
|
||||
@ -752,8 +750,8 @@ pub fn run_tui_cook(config: CliConfig, recipes: Vec<CookRecipe>) -> Result<TuiAp
|
||||
}
|
||||
|
||||
fn handle_main_event(app: &mut TuiApp, event: &Event) {
|
||||
match event {
|
||||
Event::Key(key) => match key {
|
||||
if let Event::Key(key) = event {
|
||||
match key {
|
||||
Key::Char('1') => {
|
||||
app.log_view_job = JobType::Fetch;
|
||||
}
|
||||
@ -788,8 +786,7 @@ fn handle_main_event(app: &mut TuiApp, event: &Event) {
|
||||
app.log_scroll = 0;
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -854,7 +851,7 @@ fn handle_inspect_event(event: &Event, app: &mut TuiApp) -> bool {
|
||||
}
|
||||
Key::Backspace if app.search_results.is_some() => {
|
||||
app.search_query.pop();
|
||||
if app.search_query.len() == 0 {
|
||||
if app.search_query.is_empty() {
|
||||
app.search_results.take();
|
||||
} else {
|
||||
perform_search(app);
|
||||
|
||||
@ -266,7 +266,7 @@ fn main_inner() -> Result<()> {
|
||||
let _ = stderr().write(err.as_bytes());
|
||||
let _ = stderr().write(b"\n\n");
|
||||
print_failed(&command, &name);
|
||||
return Err(Error::from(format!("Execution has failed")));
|
||||
return Err(Error::from("Execution has failed".to_string()));
|
||||
}
|
||||
Ok(app) => {
|
||||
for (recipe, status) in app.recipes {
|
||||
@ -705,12 +705,10 @@ fn parse_args(args: Vec<String>) -> Result<(CliConfig, CliCommand, Vec<CookRecip
|
||||
while i < source_recipe_names.len() {
|
||||
let name = &source_recipe_names[i];
|
||||
match special_rules.get(name) {
|
||||
Some(s) if s.as_str() == "source" => {
|
||||
if binary_names.contains(name) {
|
||||
let bin = source_recipe_names.remove(i);
|
||||
binary_recipe_names.push(bin);
|
||||
continue;
|
||||
}
|
||||
Some(s) if s.as_str() == "source" && binary_names.contains(name) => {
|
||||
let bin = source_recipe_names.remove(i);
|
||||
binary_recipe_names.push(bin);
|
||||
continue;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@ -742,7 +740,7 @@ fn parse_args(args: Vec<String>) -> Result<(CliConfig, CliCommand, Vec<CookRecip
|
||||
// host recipe binaries is currently not supported
|
||||
continue;
|
||||
}
|
||||
recipe.apply_filesystem_config(&special_rule)?;
|
||||
recipe.apply_filesystem_config(special_rule)?;
|
||||
continue;
|
||||
}
|
||||
let rule = match (
|
||||
@ -772,8 +770,7 @@ fn parse_args(args: Vec<String>) -> Result<(CliConfig, CliCommand, Vec<CookRecip
|
||||
for recipe in recipes.iter_mut() {
|
||||
if let Some(gitrev) = lock
|
||||
.get(recipe.name.as_str())
|
||||
.map(|r| r.gitrev.clone())
|
||||
.flatten()
|
||||
.and_then(|r| r.gitrev.clone())
|
||||
{
|
||||
if let Some(SourceRecipe::Git { rev, branch, .. }) = &mut recipe.recipe.source {
|
||||
*rev = Some(gitrev.clone());
|
||||
@ -821,8 +818,8 @@ fn handle_fetch(
|
||||
logger: &PtyOut,
|
||||
) -> Result<FetchResult> {
|
||||
match config.cook.offline && allow_offline {
|
||||
true => fetch_offline(&recipe, logger),
|
||||
false => fetch(&recipe, !recipe.is_deps, logger),
|
||||
true => fetch_offline(recipe, logger),
|
||||
false => fetch(recipe, !recipe.is_deps, logger),
|
||||
}
|
||||
}
|
||||
|
||||
@ -838,19 +835,19 @@ fn handle_cook(
|
||||
recipe_dir,
|
||||
&source_dir,
|
||||
&target_dir,
|
||||
&recipe,
|
||||
recipe,
|
||||
&config.cook,
|
||||
logger,
|
||||
)?;
|
||||
|
||||
package(&recipe, &build_result, &config.cook, logger)?;
|
||||
package(recipe, &build_result, &config.cook, logger)?;
|
||||
|
||||
if config.cook.clean_target || config.cook.write_filetree {
|
||||
for stage_dir in &build_result.stage_dirs {
|
||||
if stage_dir.is_dir() {
|
||||
if config.cook.write_filetree {
|
||||
let mut stage_files_buf = Vec::new();
|
||||
tree::walk_file_tree(&stage_dir, "", &mut stage_files_buf)
|
||||
tree::walk_file_tree(stage_dir, "", &mut stage_files_buf)
|
||||
.map_err(|e| Error::from_io_error(e, "Walking files tree"))?;
|
||||
stage_files_buf.push("".into()); // trailing eol
|
||||
fs::write(
|
||||
@ -860,7 +857,7 @@ fn handle_cook(
|
||||
.map_err(|e| Error::from_io_error(e, "Writing files tree"))?;
|
||||
}
|
||||
if config.cook.clean_target {
|
||||
remove_all(&stage_dir)?;
|
||||
remove_all(stage_dir)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -941,11 +938,11 @@ fn handle_push(recipes: &Vec<CookRecipe>, config: &CliConfig) -> Result<()> {
|
||||
let install_path = &config.sysroot_dir;
|
||||
let archive_path = item.recipe.stage_paths().1;
|
||||
let mut state = if !config.no_metadata {
|
||||
Some(PackageState::from_sysroot(&install_path).map_err(Error::from)?)
|
||||
Some(PackageState::from_sysroot(install_path).map_err(Error::from)?)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let r = package_handle_push(state.as_mut(), &archive_path, &install_path);
|
||||
let r = package_handle_push(state.as_mut(), &archive_path, install_path);
|
||||
if matches!(r, Ok(false)) && state.is_some() {
|
||||
state
|
||||
.unwrap()
|
||||
@ -998,7 +995,7 @@ fn handle_push(recipes: &Vec<CookRecipe>, config: &CliConfig) -> Result<()> {
|
||||
}
|
||||
|
||||
if config.cook.verbose {
|
||||
println!("");
|
||||
println!();
|
||||
println!(
|
||||
"Pushed {} of {} {}",
|
||||
tree::format_size(data.total_size),
|
||||
@ -1021,7 +1018,7 @@ fn handle_tree(recipes: &Vec<CookRecipe>, cmd: TreeOptions, config: &CliConfig)
|
||||
let data = tree::display_tree_entry(&roots[..], &recipe_map, cmd, config.display)?;
|
||||
|
||||
if matches!(config.display, DisplayOptions::Tree) {
|
||||
println!("");
|
||||
println!();
|
||||
match cmd {
|
||||
TreeOptions::Repo => {}
|
||||
TreeOptions::Cook => println!(
|
||||
@ -1123,7 +1120,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
|
||||
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)?
|
||||
|
||||
@ -152,7 +152,7 @@ pub fn init_config() {
|
||||
config.cook_opt.jobs = Some(extract_env(
|
||||
"COOKBOOK_MAKE_JOBS",
|
||||
std::thread::available_parallelism()
|
||||
.map(|f| usize::from(f))
|
||||
.map(usize::from)
|
||||
.unwrap_or(1),
|
||||
));
|
||||
}
|
||||
@ -191,7 +191,7 @@ pub fn init_config() {
|
||||
config.cook_opt.clean_target.unwrap_or(false) || extract_env("COOKBOOK_WEB", false),
|
||||
));
|
||||
}
|
||||
if config.mirrors.len() == 0 {
|
||||
if config.mirrors.is_empty() {
|
||||
// The GNU FTP mirror below is automatically inserted for convenience
|
||||
// You can choose other mirrors by setting it on cookbook.toml
|
||||
config.mirrors.insert(
|
||||
@ -223,7 +223,7 @@ pub fn init_config() {
|
||||
#[allow(unused_variables)]
|
||||
fn extract_env<T: FromStr>(key: &str, default: T) -> T {
|
||||
#[cfg(not(test))]
|
||||
if let Ok(e) = std::env::var(&key) {
|
||||
if let Ok(e) = std::env::var(key) {
|
||||
str::parse(&e).unwrap_or(default)
|
||||
} else {
|
||||
default
|
||||
@ -235,12 +235,12 @@ fn extract_env<T: FromStr>(key: &str, default: T) -> T {
|
||||
}
|
||||
|
||||
pub fn get_config() -> &'static CookbookConfig {
|
||||
return CONFIG.get().expect("Configuration is not initialized");
|
||||
CONFIG.get().expect("Configuration is not initialized")
|
||||
}
|
||||
|
||||
/// Fallible version of get_config(), because it's not loaded when testing
|
||||
pub fn try_get_config() -> Option<&'static CookbookConfig> {
|
||||
return CONFIG.get();
|
||||
CONFIG.get()
|
||||
}
|
||||
|
||||
pub fn translate_mirror(original_url: &str) -> String {
|
||||
|
||||
@ -91,10 +91,10 @@ fn auto_deps_from_dynamic_linking(
|
||||
let Ok(name) = str::from_utf8(val) else {
|
||||
continue;
|
||||
};
|
||||
if let Ok(relative_path) = path.strip_prefix(rel_path) {
|
||||
if verbose {
|
||||
log_to_pty!(logger, "DEBUG: {} needs {}", relative_path.display(), name);
|
||||
}
|
||||
if let Ok(relative_path) = path.strip_prefix(rel_path)
|
||||
&& verbose
|
||||
{
|
||||
log_to_pty!(logger, "DEBUG: {} needs {}", relative_path.display(), name);
|
||||
}
|
||||
needed.insert(name.to_string());
|
||||
} else {
|
||||
@ -270,7 +270,7 @@ pub fn build(
|
||||
} else {
|
||||
&dep_pkgars
|
||||
};
|
||||
let have_toolchain = !name.is_host() && dep_host_pkgars.len() > 0;
|
||||
let have_toolchain = !name.is_host() && !dep_host_pkgars.is_empty();
|
||||
let (sysroot_cached, toolchain_cached) = (
|
||||
build_deps_dir(logger, &sysroot_dir, deps_sysroot)?,
|
||||
if have_toolchain {
|
||||
@ -364,10 +364,10 @@ pub fn build(
|
||||
flags_fn("COOKBOOK_CARGO_FLAGS", cargoflags),
|
||||
cargopath.as_deref().unwrap_or(".")
|
||||
);
|
||||
if cargopackages.len() == 0 && cargoexamples.len() == 0 {
|
||||
if cargopackages.is_empty() && cargoexamples.is_empty() {
|
||||
script += "cookbook_cargo\n"
|
||||
} else {
|
||||
if cargopackages.len() > 0 {
|
||||
if !cargopackages.is_empty() {
|
||||
script += if *cargopackagesprefixed {
|
||||
"cookbook_cargo_packages_prefixed"
|
||||
} else {
|
||||
@ -379,7 +379,7 @@ pub fn build(
|
||||
}
|
||||
script += "\n";
|
||||
}
|
||||
if cargoexamples.len() > 0 {
|
||||
if !cargoexamples.is_empty() {
|
||||
script += "cookbook_cargo_examples";
|
||||
for example in cargoexamples {
|
||||
script += " ";
|
||||
@ -469,7 +469,7 @@ pub fn build(
|
||||
} else {
|
||||
command.env_remove("COOKBOOK_OFFLINE");
|
||||
}
|
||||
if let Ok(ident_source) = fetch::fetch_get_source_info(&cook_recipe) {
|
||||
if let Ok(ident_source) = fetch::fetch_get_source_info(cook_recipe) {
|
||||
command.env("COOKBOOK_SOURCE_IDENT", ident_source.source_identifier);
|
||||
command.env("COOKBOOK_COMMIT_IDENT", ident_source.commit_identifier);
|
||||
}
|
||||
@ -486,9 +486,9 @@ pub fn build(
|
||||
let mut globs = Vec::new();
|
||||
for (i, feat) in recipe.optional_packages.iter().enumerate() {
|
||||
let stage_dir = &stage_dirs[i];
|
||||
fs::create_dir_clean(&stage_dir)?;
|
||||
fs::create_dir_clean(stage_dir)?;
|
||||
for path in &feat.files {
|
||||
let glob = globset::Glob::new(&path).map_err(|e| format!("{}", e))?;
|
||||
let glob = globset::Glob::new(path).map_err(|e| format!("{}", e))?;
|
||||
globs.push((glob.compile_matcher(), stage_dir.clone()));
|
||||
}
|
||||
}
|
||||
@ -506,7 +506,7 @@ pub fn build(
|
||||
.map_err(wrap_io_err!("Moving to stages dir"))?;
|
||||
|
||||
// Move stage.tmp to stage atomically
|
||||
fs::rename(&stage_dir_tmp, &stage_dir)?;
|
||||
fs::rename(&stage_dir_tmp, stage_dir)?;
|
||||
}
|
||||
|
||||
if cook_config.clean_target {
|
||||
@ -539,11 +539,11 @@ fn build_is_source_newer(
|
||||
return false;
|
||||
};
|
||||
let mut recipe_is_newest = false;
|
||||
if let Ok(recipe_modified) = fs::modified(&recipe_dir.join("recipe.toml")) {
|
||||
if recipe_modified > source_modified {
|
||||
source_modified = recipe_modified;
|
||||
recipe_is_newest = true;
|
||||
}
|
||||
if let Ok(recipe_modified) = fs::modified(&recipe_dir.join("recipe.toml"))
|
||||
&& recipe_modified > source_modified
|
||||
{
|
||||
source_modified = recipe_modified;
|
||||
recipe_is_newest = true;
|
||||
}
|
||||
let newer = source_modified > stage_modified;
|
||||
if newer {
|
||||
@ -558,7 +558,7 @@ fn build_is_source_newer(
|
||||
|
||||
pub fn remove_stage_dir(stage_dir: &PathBuf) -> crate::Result<()> {
|
||||
if stage_dir.is_dir() {
|
||||
fs::remove_all(&stage_dir)?;
|
||||
fs::remove_all(stage_dir)?;
|
||||
}
|
||||
let stage_file = stage_dir.with_added_extension("pkgar");
|
||||
if stage_file.is_file() {
|
||||
@ -605,10 +605,10 @@ fn build_deps_dir(
|
||||
dep_pkgars: &BTreeSet<(PackageName, PathBuf)>,
|
||||
) -> Result<bool> {
|
||||
let pkey_path = "build/id_ed25519.pub.toml";
|
||||
let pkey_file = match PublicKeyFile::open(&pkey_path) {
|
||||
let pkey_file = match PublicKeyFile::open(pkey_path) {
|
||||
Ok(k) => k.pkey,
|
||||
Err(e) => {
|
||||
if dep_pkgars.len() > 0 {
|
||||
if !dep_pkgars.is_empty() {
|
||||
return Err(Error::from(e));
|
||||
} else {
|
||||
// should never be accessed
|
||||
@ -670,7 +670,7 @@ fn build_deps_dir(
|
||||
fs::create_dir(&usr_dir.join(folder))?;
|
||||
|
||||
// Link sysroot/$folder sysroot/usr/$folder
|
||||
fs::symlink(Path::new("usr").join(folder), &deps_dir_tmp.join(folder))?;
|
||||
fs::symlink(Path::new("usr").join(folder), deps_dir_tmp.join(folder))?;
|
||||
}
|
||||
|
||||
for (name, archive_path) in dep_pkgars {
|
||||
@ -678,7 +678,7 @@ fn build_deps_dir(
|
||||
let mut package = PackageFile::new(archive_path, &pkey_file)?;
|
||||
Transaction::install(&mut package, &deps_dir_tmp)?.commit()?;
|
||||
let hash = blake3::Hash::from_bytes(package.header().blake3).to_hex();
|
||||
std::fs::write(&tag_file, &hash.as_bytes()).map_err(wrap_io_err!("Writing tag"))?;
|
||||
std::fs::write(&tag_file, hash.as_bytes()).map_err(wrap_io_err!("Writing tag"))?;
|
||||
}
|
||||
|
||||
// Move sysroot.tmp to sysroot atomically
|
||||
@ -692,8 +692,8 @@ fn clean_deps_dir(deps_dir: &PathBuf) -> Result<bool> {
|
||||
let tags_dir = deps_dir.join(".tags");
|
||||
let tags_dir_tmp = deps_dir.with_added_extension("tags");
|
||||
fs::rename(&tags_dir, &tags_dir_tmp)?;
|
||||
fs::remove_all(&deps_dir)?;
|
||||
fs::create_dir(&deps_dir)?;
|
||||
fs::remove_all(deps_dir)?;
|
||||
fs::create_dir(deps_dir)?;
|
||||
fs::rename(&tags_dir_tmp, &tags_dir)?;
|
||||
Ok(false)
|
||||
}
|
||||
@ -712,11 +712,11 @@ fn build_auto_deps(
|
||||
if cook_config.verbose {
|
||||
log_to_pty!(logger, "DEBUG: updating {}", auto_deps_path.display());
|
||||
}
|
||||
fs::remove_all(&auto_deps_path)?;
|
||||
fs::remove_all(auto_deps_path)?;
|
||||
}
|
||||
|
||||
let auto_deps = if auto_deps_path.exists() {
|
||||
let wrapper: AutoDeps = fs::read_toml(&auto_deps_path)?;
|
||||
let wrapper: AutoDeps = fs::read_toml(auto_deps_path)?;
|
||||
wrapper.packages
|
||||
} else {
|
||||
let mut dynamic_deps = auto_deps_from_dynamic_linking(stage_dirs, &dep_pkgars, logger);
|
||||
@ -728,7 +728,7 @@ fn build_auto_deps(
|
||||
let wrapper = AutoDeps {
|
||||
packages: dynamic_deps,
|
||||
};
|
||||
fs::serialize_and_write(&auto_deps_path, &wrapper)?;
|
||||
fs::serialize_and_write(auto_deps_path, &wrapper)?;
|
||||
wrapper.packages
|
||||
};
|
||||
Ok(auto_deps)
|
||||
@ -755,8 +755,8 @@ pub fn build_remote(
|
||||
break;
|
||||
}
|
||||
|
||||
let (_, source_pkgar, _) = package_source_paths(*package, &target_dir);
|
||||
if fs::modified(&source_pkgar)? > fs::modified(&stage_pkgar)? {
|
||||
let (_, source_pkgar, _) = package_source_paths(*package, target_dir);
|
||||
if fs::modified(&source_pkgar)? > fs::modified(stage_pkgar)? {
|
||||
cached = false;
|
||||
break;
|
||||
}
|
||||
@ -770,9 +770,9 @@ pub fn build_remote(
|
||||
|
||||
for (i, package) in packages.into_iter().enumerate() {
|
||||
let stage_dir = &stage_dirs[i];
|
||||
let (_, source_pkgar, _) = package_source_paths(package, &target_dir);
|
||||
let (_, source_pkgar, _) = package_source_paths(package, target_dir);
|
||||
fs::create_dir_clean(stage_dir)?;
|
||||
pkgar::extract(&source_pubkey, &source_pkgar, &stage_dir).map_err(|e| {
|
||||
pkgar::extract(&source_pubkey, &source_pkgar, stage_dir).map_err(|e| {
|
||||
if matches!(e, pkgar::Error::Core(pkgar_core::Error::Dryoc(_))) {
|
||||
hint_incorrect_pkey(logger, &source_pubkey, &source_pkgar);
|
||||
}
|
||||
|
||||
@ -71,7 +71,7 @@ pub fn fetch_offline(recipe: &CookRecipe, logger: &PtyOut) -> Result<FetchResult
|
||||
BuildKind::None => {
|
||||
// the build function doesn't need source dir exists
|
||||
let (source, patch) = ("".to_string(), "".to_string());
|
||||
return FetchResult::cached(source_dir, source, patch).apply_info(&recipe);
|
||||
return FetchResult::cached(source_dir, source, patch).apply_info(recipe);
|
||||
}
|
||||
BuildKind::Remote => {
|
||||
return fetch_remote(recipe_dir, recipe, true, source_dir, logger);
|
||||
@ -82,10 +82,10 @@ pub fn fetch_offline(recipe: &CookRecipe, logger: &PtyOut) -> Result<FetchResult
|
||||
let result = match &recipe.recipe.source {
|
||||
Some(SourceRecipe::Path { path: _ }) | None => fetch(recipe, true, logger)?,
|
||||
Some(SourceRecipe::SameAs { same_as }) => {
|
||||
let recipe = fetch_resolve_canon(&same_as, &recipe)?;
|
||||
let recipe = fetch_resolve_canon(same_as, recipe)?;
|
||||
// recursively fetch
|
||||
let r = fetch_offline(&recipe, logger)?;
|
||||
fetch_make_symlink(&source_dir, &same_as)?;
|
||||
fetch_make_symlink(&source_dir, same_as)?;
|
||||
r
|
||||
}
|
||||
Some(SourceRecipe::Git {
|
||||
@ -99,7 +99,7 @@ pub fn fetch_offline(recipe: &CookRecipe, logger: &PtyOut) -> Result<FetchResult
|
||||
}) => {
|
||||
offline_check_exists(&source_dir)?;
|
||||
let (head_rev, _) = get_git_head_rev(&source_dir)?;
|
||||
let patches_blake3 = get_patches_blake3(&recipe_dir, patches, script)?;
|
||||
let patches_blake3 = get_patches_blake3(recipe_dir, patches, script)?;
|
||||
FetchResult::cached(source_dir, head_rev, patches_blake3)
|
||||
}
|
||||
Some(SourceRecipe::Tar {
|
||||
@ -109,7 +109,7 @@ pub fn fetch_offline(recipe: &CookRecipe, logger: &PtyOut) -> Result<FetchResult
|
||||
script,
|
||||
}) => {
|
||||
let ident = blake3.clone().unwrap_or("no_tar_blake3_hash_info".into());
|
||||
let patches_blake3 = get_patches_blake3(&recipe_dir, patches, script)?;
|
||||
let patches_blake3 = get_patches_blake3(recipe_dir, patches, script)?;
|
||||
let cached = source_dir.is_dir();
|
||||
if !cached {
|
||||
let source_tar = recipe_dir.join("source.tar");
|
||||
@ -138,7 +138,7 @@ pub fn fetch_offline(recipe: &CookRecipe, logger: &PtyOut) -> Result<FetchResult
|
||||
}
|
||||
};
|
||||
|
||||
result.apply_info(&recipe)
|
||||
result.apply_info(recipe)
|
||||
}
|
||||
|
||||
pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result<FetchResult> {
|
||||
@ -157,7 +157,7 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
|
||||
BuildKind::None => {
|
||||
// the build function doesn't need source dir exists
|
||||
let (source, patch) = ("".to_string(), "".to_string());
|
||||
return FetchResult::cached(source_dir, source, patch).apply_info(&recipe);
|
||||
return FetchResult::cached(source_dir, source, patch).apply_info(recipe);
|
||||
}
|
||||
BuildKind::Remote => {
|
||||
return fetch_remote(recipe_dir, recipe, false, source_dir, logger);
|
||||
@ -168,10 +168,10 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
|
||||
let cached_info = fetch_get_source_info(recipe).ok();
|
||||
let result = match &recipe.recipe.source {
|
||||
Some(SourceRecipe::SameAs { same_as }) => {
|
||||
let recipe = fetch_resolve_canon(&same_as, &recipe)?;
|
||||
let recipe = fetch_resolve_canon(same_as, recipe)?;
|
||||
// recursively fetch
|
||||
let r = fetch(&recipe, check_source, logger)?;
|
||||
fetch_make_symlink(&source_dir, &same_as)?;
|
||||
fetch_make_symlink(&source_dir, same_as)?;
|
||||
r
|
||||
}
|
||||
Some(SourceRecipe::Path { path }) => {
|
||||
@ -210,7 +210,7 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
|
||||
let shallow_clone =
|
||||
shallow_clone.unwrap_or_else(|| crate::config::get_config().cook.git_treeless);
|
||||
let mut fetch_is_ran = false;
|
||||
let patches_ident = get_patches_blake3(&recipe_dir, patches, script)?;
|
||||
let patches_ident = get_patches_blake3(recipe_dir, patches, script)?;
|
||||
let cached = if !source_dir.is_dir() {
|
||||
// Create source.tmp
|
||||
let source_dir_tmp = recipe_dir.join("source.tmp");
|
||||
@ -221,7 +221,7 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
|
||||
command
|
||||
.arg("clone")
|
||||
.arg("--recursive")
|
||||
.arg(translate_mirror(&git));
|
||||
.arg(translate_mirror(git));
|
||||
if let Some(branch) = branch {
|
||||
command.arg("--branch").arg(branch);
|
||||
}
|
||||
@ -263,7 +263,7 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
|
||||
match (cached_info, rev, detached_rev) {
|
||||
(None, _, _) => false,
|
||||
(Some(s), _, _) if !s.is_updated(&head_rev, &patches_ident) => false,
|
||||
(_, Some(rev), true) => get_git_tag_rev(&source_dir, &rev, logger)
|
||||
(_, Some(rev), true) => get_git_tag_rev(&source_dir, rev, logger)
|
||||
.is_ok_and(|exp_rev| exp_rev == head_rev),
|
||||
(_, None, false) => match get_git_remote_tracking(&source_dir) {
|
||||
Ok(remote) if !remote.check_updated(git, branch) => false,
|
||||
@ -382,12 +382,12 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
|
||||
}) => {
|
||||
let source_tar = recipe_dir.join("source.tar");
|
||||
let source_ident = blake3.clone().unwrap_or("no_tar_blake3_hash_info".into());
|
||||
let patches_ident = get_patches_blake3(&recipe_dir, patches, script)?;
|
||||
let patches_ident = get_patches_blake3(recipe_dir, patches, script)?;
|
||||
let mut tar_updated = false;
|
||||
loop {
|
||||
if !source_tar.is_file() {
|
||||
tar_updated = true;
|
||||
download_wget(&tar, &source_tar, logger)?;
|
||||
download_wget(tar, &source_tar, logger)?;
|
||||
}
|
||||
if !check_source {
|
||||
break;
|
||||
@ -420,16 +420,15 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
|
||||
}
|
||||
}
|
||||
let mut cached = true;
|
||||
if source_dir.is_dir() {
|
||||
if tar_updated
|
||||
|| cached_info.is_none_or(|s| !s.is_updated(&source_ident, &patches_ident))
|
||||
{
|
||||
log_to_pty!(
|
||||
logger,
|
||||
"DEBUG: source tar or patches is newer than the source directory"
|
||||
);
|
||||
remove_all(&source_dir)?
|
||||
}
|
||||
if source_dir.is_dir()
|
||||
&& (tar_updated
|
||||
|| cached_info.is_none_or(|s| !s.is_updated(&source_ident, &patches_ident)))
|
||||
{
|
||||
log_to_pty!(
|
||||
logger,
|
||||
"DEBUG: source tar or patches is newer than the source directory"
|
||||
);
|
||||
remove_all(&source_dir)?
|
||||
}
|
||||
if !source_dir.is_dir() {
|
||||
// Create source.tmp
|
||||
@ -458,13 +457,13 @@ pub fn fetch(recipe: &CookRecipe, check_source: bool, logger: &PtyOut) -> Result
|
||||
}
|
||||
};
|
||||
|
||||
if let BuildKind::Cargo { cargopath, .. } = &recipe.recipe.build.kind {
|
||||
if !result.cached {
|
||||
fetch_cargo(&result.source_dir, cargopath.as_ref(), logger)?;
|
||||
}
|
||||
if let BuildKind::Cargo { cargopath, .. } = &recipe.recipe.build.kind
|
||||
&& !result.cached
|
||||
{
|
||||
fetch_cargo(&result.source_dir, cargopath.as_ref(), logger)?;
|
||||
}
|
||||
|
||||
result.apply_info(&recipe)
|
||||
result.apply_info(recipe)
|
||||
}
|
||||
|
||||
fn git_run_fetch(logger: &PtyOut, source_dir: &PathBuf, git: &String) -> Result<()> {
|
||||
@ -496,8 +495,8 @@ fn manual_git_recursive_submodule(
|
||||
let mut dirty_git = false;
|
||||
|
||||
let output = Command::new("find")
|
||||
.args(&[".", "-name", ".git"])
|
||||
.current_dir(&source_dir)
|
||||
.args([".", "-name", ".git"])
|
||||
.current_dir(source_dir)
|
||||
.output()
|
||||
.map_err(wrap_io_err!("Failed to execute find"))?;
|
||||
|
||||
@ -534,7 +533,7 @@ fn manual_git_recursive_submodule(
|
||||
println!("==> Processing: {:?}", repo);
|
||||
|
||||
let mut command = Command::new("git");
|
||||
command.arg("-C").arg(&repo).current_dir(&source_dir);
|
||||
command.arg("-C").arg(&repo).current_dir(source_dir);
|
||||
command.arg("submodule");
|
||||
|
||||
for cmd in &cmd {
|
||||
@ -612,13 +611,11 @@ pub(crate) fn fetch_resolve_canon(
|
||||
if let Some(gitrev) = crate::config::get_config()
|
||||
.recipe_lock
|
||||
.get(recipe.name.without_prefix())
|
||||
.map(|r| r.gitrev.clone())
|
||||
.flatten()
|
||||
.and_then(|r| r.gitrev.clone())
|
||||
&& let Some(SourceRecipe::Git { rev, branch, .. }) = &mut recipe.recipe.source
|
||||
{
|
||||
if let Some(SourceRecipe::Git { rev, branch, .. }) = &mut recipe.recipe.source {
|
||||
*rev = Some(gitrev.clone());
|
||||
*branch = None;
|
||||
}
|
||||
*rev = Some(gitrev.clone());
|
||||
*branch = None;
|
||||
}
|
||||
Ok(recipe)
|
||||
}
|
||||
@ -740,7 +737,7 @@ pub fn fetch_remote(
|
||||
let toml_file =
|
||||
File::create(&tmp_toml).map_err(wrap_io_err!(tmp_toml, "Creating file"))?;
|
||||
let mut writer = DownloadBackendWriter::ToFile(toml_file);
|
||||
manager.download(&format!("{}.toml", &source_name), None, &mut writer)?;
|
||||
manager.download(&format!("{}.toml", source_name), None, &mut writer)?;
|
||||
read_source_toml(&tmp_toml)?
|
||||
};
|
||||
|
||||
@ -751,7 +748,7 @@ pub fn fetch_remote(
|
||||
File::create(&tmp_pkgar).map_err(wrap_io_err!(tmp_pkgar, "Creating file"))?;
|
||||
let mut writer = DownloadBackendWriter::ToFile(pkgar_file);
|
||||
manager.download(
|
||||
&format!("{}.pkgar", &source_name),
|
||||
&format!("{}.pkgar", source_name),
|
||||
Some(pkg_toml.network_size),
|
||||
&mut writer,
|
||||
)?;
|
||||
@ -820,7 +817,7 @@ pub(crate) fn fetch_apply_patches(
|
||||
command.arg("--strip=1");
|
||||
run_command_stdin(command, patch.as_bytes(), logger)?;
|
||||
}
|
||||
Ok(if let Some(script) = script {
|
||||
let _: () = if let Some(script) = script {
|
||||
let mut command = Command::new("bash");
|
||||
command.arg("-ex");
|
||||
command.current_dir(source_dir_tmp);
|
||||
@ -829,7 +826,8 @@ pub(crate) fn fetch_apply_patches(
|
||||
format!("{SHARED_PRESCRIPT}\n{script}").as_bytes(),
|
||||
logger,
|
||||
)?;
|
||||
})
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn fetch_apply_source_info(
|
||||
@ -841,11 +839,11 @@ pub(crate) fn fetch_apply_source_info(
|
||||
let info = SourceIdentifier {
|
||||
commit_identifier: ident.commit.to_string(),
|
||||
time_identifier: ident.time.to_string(),
|
||||
source_identifier: source_identifier,
|
||||
patch_identifier: patch_identifier,
|
||||
source_identifier,
|
||||
patch_identifier,
|
||||
};
|
||||
|
||||
fetch_apply_source_info_from_remote(&recipe, &info)?;
|
||||
fetch_apply_source_info_from_remote(recipe, &info)?;
|
||||
|
||||
Ok((info.source_identifier, info.patch_identifier))
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ use pkg::{
|
||||
// TODO: This is a workaround, but as long as whole
|
||||
// fetch operation is in single thread, this is ok
|
||||
thread_local! {
|
||||
static BINARY_REPO: RefCell<Option<(RepoManager, Repository)>> = RefCell::new(None);
|
||||
static BINARY_REPO: RefCell<Option<(RepoManager, Repository)>> = const { RefCell::new(None) };
|
||||
}
|
||||
|
||||
fn load_cached_repo(path: &Path) -> Option<Repository> {
|
||||
@ -51,15 +51,14 @@ fn init_binary_repo() -> (RepoManager, Repository) {
|
||||
let repo_toml =
|
||||
load_cached_repo(&repo_path.join(format!("repo_{}_{target}.toml", repo.remotes[0])))
|
||||
.unwrap_or_else(|| {
|
||||
let repo = download_repo(&repo, repo_path)
|
||||
download_repo(&repo, repo_path)
|
||||
.map_err(|e| {
|
||||
eprintln!(
|
||||
"Unable to load server repo.toml, all recipes will build from source: {e}"
|
||||
);
|
||||
e
|
||||
})
|
||||
.unwrap_or_default();
|
||||
repo
|
||||
.unwrap_or_default()
|
||||
});
|
||||
// reset here to not clobber pty
|
||||
repo.callback = Rc::new(RefCell::new(PlainCallback::new()));
|
||||
@ -203,11 +202,7 @@ impl Callback for PlainPtyCallback {
|
||||
// keep using MB for consistency
|
||||
let pos_mb = self.pos as f64 / 1_048_576.0;
|
||||
let size_mb = self.size as f64 / 1_048_576.0;
|
||||
let file_name = self
|
||||
.download_file
|
||||
.as_ref()
|
||||
.map(|s| s.as_str())
|
||||
.unwrap_or("");
|
||||
let file_name = self.download_file.as_deref().unwrap_or("");
|
||||
let _ = write!(
|
||||
&self.pty,
|
||||
"{RESET_LINE}{} {} [{:.2} MB / {:.2} MB]",
|
||||
@ -221,7 +216,7 @@ impl Callback for PlainPtyCallback {
|
||||
|
||||
fn download_end(&mut self) {
|
||||
if !self.unknown_size {
|
||||
let _ = writeln!(&self.pty, "");
|
||||
let _ = writeln!(&self.pty);
|
||||
self.download_file = None;
|
||||
}
|
||||
}
|
||||
|
||||
@ -92,7 +92,7 @@ fn move_dir_all_inner_fn<'a>(
|
||||
}
|
||||
for (src, srcrel, dst) in files {
|
||||
let path = dst.join(&srcrel);
|
||||
fs::create_dir_all(&path.parent().unwrap())?;
|
||||
fs::create_dir_all(path.parent().unwrap())?;
|
||||
std::fs::rename(&src, &path)?;
|
||||
}
|
||||
Ok(())
|
||||
@ -285,7 +285,7 @@ pub fn download_wget(url: &str, dest: &PathBuf, logger: &PtyOut) -> Result<()> {
|
||||
command.arg(translate_mirror(url));
|
||||
command.arg("--continue").arg("-O").arg(&dest_tmp);
|
||||
run_command(command, logger)?;
|
||||
rename(&dest_tmp, &dest)?;
|
||||
rename(&dest_tmp, dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -299,7 +299,7 @@ pub fn get_file_blake3(path: &PathBuf) -> Result<String> {
|
||||
}
|
||||
|
||||
fn get_blake3(path: &PathBuf) -> Result<Hash> {
|
||||
let mut f = fs::File::open(&path).map_err(wrap_io_err!(path, "Opening file for blake3"))?;
|
||||
let mut f = fs::File::open(path).map_err(wrap_io_err!(path, "Opening file for blake3"))?;
|
||||
let hash = blake3::Hasher::new()
|
||||
.update_reader(&mut f)
|
||||
.map_err(wrap_io_err!(path, "Reading file for blake3"))?
|
||||
@ -397,10 +397,10 @@ pub fn get_git_ref_entry(dir: &PathBuf, entry: &str) -> Result<String> {
|
||||
.split_whitespace()
|
||||
.next()
|
||||
.ok_or_else(wrap_other_err!("Packed-refs line is malformed"))?;
|
||||
if let Some(next_line) = lines.next() {
|
||||
if next_line.starts_with('^') {
|
||||
sha = &next_line[1..];
|
||||
}
|
||||
if let Some(next_line) = lines.next()
|
||||
&& next_line.starts_with('^')
|
||||
{
|
||||
sha = &next_line[1..];
|
||||
}
|
||||
return Ok(sha.to_string());
|
||||
}
|
||||
@ -467,7 +467,7 @@ impl GitRemoteTracking {
|
||||
if branch.is_none() && self.remote_branch != self.tracking_branch {
|
||||
return false;
|
||||
}
|
||||
if self.remote_name != "origin" || &self.remote_url != chop_dot_git(url) {
|
||||
if self.remote_name != "origin" || self.remote_url != chop_dot_git(url) {
|
||||
return false;
|
||||
}
|
||||
true
|
||||
@ -591,7 +591,7 @@ fn get_git_branch_name(branch_path: &str) -> Result<String> {
|
||||
// TODO: incorrectly handle branch with slashes
|
||||
Ok(branch_path
|
||||
.split('/')
|
||||
.last()
|
||||
.next_back()
|
||||
.ok_or_else(wrap_other_err!(
|
||||
"Failed to parse branch name of {:?}",
|
||||
branch_path
|
||||
|
||||
@ -17,7 +17,7 @@ impl IdentifierConfig {
|
||||
.unwrap_or(("".into(), false));
|
||||
// better than importing heavy deps like chrono
|
||||
let time = String::from_utf8_lossy(
|
||||
&Command::new("date")
|
||||
Command::new("date")
|
||||
.arg("-u")
|
||||
.arg("+%Y-%m-%dT%H:%M:%SZ")
|
||||
.stdout(Stdio::piped())
|
||||
|
||||
@ -34,7 +34,7 @@ pub fn package(
|
||||
None,
|
||||
None,
|
||||
recipe.recipe.package.dependencies.clone(),
|
||||
&auto_deps,
|
||||
auto_deps,
|
||||
)?;
|
||||
return Ok(());
|
||||
}
|
||||
@ -188,7 +188,7 @@ pub fn package_toml(
|
||||
};
|
||||
|
||||
serialize_and_write(&toml_path, &package)?;
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn package_target(name: &PackageName) -> &'static str {
|
||||
|
||||
@ -97,14 +97,14 @@ pub fn flush_pty(logger: &mut PtyOut) {
|
||||
|
||||
pub fn spawn_to_pipe(command: &mut Command, stdout_pipe: &PtyOut) -> Result<Child> {
|
||||
match stdout_pipe {
|
||||
Some(stdout) => stdout.0.spawn_command(command.into()),
|
||||
Some(stdout) => stdout.0.spawn_command(command),
|
||||
None => Ok(command.spawn().map_err(wrap_io_err!("Spawning"))?),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_to_pipe_with_stdin(command: &mut Command, stdout_pipe: &PtyOut) -> Result<Child> {
|
||||
match stdout_pipe {
|
||||
Some(stdout) => stdout.0.spawn_command_stdin(command.into()),
|
||||
Some(stdout) => stdout.0.spawn_command_stdin(command),
|
||||
None => Ok(command.spawn().map_err(wrap_io_err!("Spawning"))?),
|
||||
}
|
||||
}
|
||||
@ -201,10 +201,7 @@ pub struct PtyPair {
|
||||
impl UnixPtySystem {
|
||||
fn openpty(&self, size: PtySize) -> Result<PtyPair> {
|
||||
let (master, slave) = openpty(size)?;
|
||||
Ok(PtyPair {
|
||||
master: master,
|
||||
slave: slave,
|
||||
})
|
||||
Ok(PtyPair { master, slave })
|
||||
}
|
||||
}
|
||||
|
||||
@ -368,10 +365,10 @@ fn cloexec(fd: RawFd) -> Result<()> {
|
||||
|
||||
impl UnixSlavePty {
|
||||
fn spawn_command(&self, builder: &mut Command) -> Result<std::process::Child> {
|
||||
Ok(self.fd.spawn_command(builder, false)?)
|
||||
self.fd.spawn_command(builder, false)
|
||||
}
|
||||
fn spawn_command_stdin(&self, builder: &mut Command) -> Result<std::process::Child> {
|
||||
Ok(self.fd.spawn_command(builder, true)?)
|
||||
self.fd.spawn_command(builder, true)
|
||||
}
|
||||
fn flush(&mut self) -> Result<()> {
|
||||
self.fd.flush()
|
||||
|
||||
@ -19,7 +19,7 @@ pub enum WalkTreeEntry {
|
||||
|
||||
impl WalkTreeEntry {
|
||||
pub fn is_valid(&self) -> bool {
|
||||
return matches!(self, WalkTreeEntry::Built(_) | WalkTreeEntry::NotBuilt);
|
||||
matches!(self, WalkTreeEntry::Built(_) | WalkTreeEntry::NotBuilt)
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,6 +53,12 @@ pub struct TreeItem<'a> {
|
||||
pub dependents: Option<&'a HashSet<PackageName>>,
|
||||
}
|
||||
|
||||
impl Default for TreeData {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl TreeData {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@ -66,20 +72,15 @@ impl TreeData {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
#[derive(Clone, Copy, Default)]
|
||||
pub enum DisplayOptions {
|
||||
Name,
|
||||
Path,
|
||||
Csv,
|
||||
#[default]
|
||||
Tree,
|
||||
}
|
||||
|
||||
impl Default for DisplayOptions {
|
||||
fn default() -> Self {
|
||||
Self::Tree
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for DisplayOptions {
|
||||
type Err = Error;
|
||||
|
||||
@ -271,10 +272,10 @@ pub fn walk_tree_entry(
|
||||
|
||||
data.visited.insert(package_name.clone());
|
||||
if !cached {
|
||||
if matches!(tree_opt, TreeOptions::Push) {
|
||||
if let WalkTreeEntry::Built(pkg_size) = &entry {
|
||||
data.total_size += pkg_size;
|
||||
}
|
||||
if matches!(tree_opt, TreeOptions::Push)
|
||||
&& let WalkTreeEntry::Built(pkg_size) = &entry
|
||||
{
|
||||
data.total_size += pkg_size;
|
||||
}
|
||||
if matches!(entry, WalkTreeEntry::NotBuilt) {
|
||||
data.total_notbuilt += 1;
|
||||
@ -292,7 +293,7 @@ pub fn walk_tree_entry(
|
||||
for (i, dep_name) in dependencies.iter().enumerate() {
|
||||
data.dependents
|
||||
.entry((*dep_name).clone())
|
||||
.or_insert_with(|| HashSet::new())
|
||||
.or_insert_with(HashSet::new)
|
||||
.insert(package_name.clone());
|
||||
walk_tree_entry(
|
||||
dep_name,
|
||||
@ -380,7 +381,7 @@ pub fn walk_file_tree(
|
||||
return Ok(0);
|
||||
}
|
||||
let mut entries: Vec<_> = std::fs::read_dir(dir)?.filter_map(|e| e.ok()).collect();
|
||||
entries.sort_by(|a, b| a.file_name().cmp(&b.file_name()));
|
||||
entries.sort_by_key(|a| a.file_name());
|
||||
let mut total_size = 0;
|
||||
for (index, entry) in entries.iter().enumerate() {
|
||||
let path = entry.path();
|
||||
|
||||
@ -17,9 +17,9 @@ pub fn drain_buffer_to_lines(buffer: &mut Vec<u8>, lines: &mut Vec<String>) -> u
|
||||
// TODO: multibyte-aware line split?
|
||||
while let Some(newline_pos) = buffer.iter().position(|&b| b == b'\n') {
|
||||
let line_bytes = buffer.drain(..=newline_pos);
|
||||
let line_str = String::from_utf8_lossy(&line_bytes.as_slice());
|
||||
let line_str = String::from_utf8_lossy(line_bytes.as_slice());
|
||||
let line_str_pos = line_str.trim_end();
|
||||
let line_str = line_str_pos.rsplit('\r').next().unwrap_or(&line_str_pos);
|
||||
let line_str = line_str_pos.rsplit('\r').next().unwrap_or(line_str_pos);
|
||||
lines.push(line_str.to_owned());
|
||||
addition += 1;
|
||||
}
|
||||
@ -39,7 +39,7 @@ pub fn render_build_log<'a>(
|
||||
let mut log_lines: Vec<Line> = if let Some(log_text) = log_text
|
||||
&& !log_text.is_empty()
|
||||
{
|
||||
let total_log_lines = log_text.len() as usize;
|
||||
let total_log_lines = log_text.len();
|
||||
|
||||
let start = if *enable_auto_scroll {
|
||||
if total_log_lines > panel_height {
|
||||
@ -119,7 +119,7 @@ pub fn render_build_log<'a>(
|
||||
pub fn join_logs(log: &Vec<String>, line: Option<Cow<'_, str>>) -> String {
|
||||
let mut logs = log.join("\n");
|
||||
if let Some(line) = line {
|
||||
logs.push_str("\n");
|
||||
logs.push('\n');
|
||||
logs.push_str(handle_cr(&line));
|
||||
}
|
||||
logs
|
||||
@ -127,7 +127,7 @@ pub fn join_logs(log: &Vec<String>, line: Option<Cow<'_, str>>) -> String {
|
||||
|
||||
fn handle_cr<'a>(buffer: &'a Cow<'_, str>) -> &'a str {
|
||||
let st = buffer.trim_end();
|
||||
st.rsplit('\r').next().unwrap_or(&st)
|
||||
st.rsplit('\r').next().unwrap_or(st)
|
||||
}
|
||||
|
||||
/// Check if point is in rect
|
||||
@ -166,7 +166,7 @@ pub fn get_clicked_tab_index(
|
||||
pub fn kill_everything(pid: Option<u32>) {
|
||||
process::Command::new("bash")
|
||||
.arg("-c")
|
||||
.arg(KILL_ALL_PID.replace("$PID", &pid.unwrap_or_else(|| process::id()).to_string()))
|
||||
.arg(KILL_ALL_PID.replace("$PID", &pid.unwrap_or_else(process::id).to_string()))
|
||||
.stdout(process::Stdio::null())
|
||||
.stderr(process::Stdio::null())
|
||||
.spawn()
|
||||
|
||||
@ -18,7 +18,7 @@ pub fn is_redox() -> bool {
|
||||
pub fn cross_target() -> Option<String> {
|
||||
std::env::var("COOKBOOK_CROSS_TARGET")
|
||||
.ok()
|
||||
.and_then(|s| if s.is_empty() { None } else { Some(s) })
|
||||
.filter(|s| !s.is_empty())
|
||||
}
|
||||
|
||||
// Errors
|
||||
@ -217,7 +217,7 @@ impl From<walkdir::Error> for Error {
|
||||
let path = value.path().map(|s| s.to_path_buf());
|
||||
Error::Io {
|
||||
source: value.into_io_error().unwrap(),
|
||||
path: path,
|
||||
path,
|
||||
context: "Walkdir error",
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -66,9 +66,11 @@ pub enum SourceRecipe {
|
||||
/// Specifies how to build a recipe
|
||||
#[derive(Debug, Clone, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(tag = "template")]
|
||||
#[derive(Default)]
|
||||
pub enum BuildKind {
|
||||
/// Will not build (for meta packages)
|
||||
#[serde(rename = "none")]
|
||||
#[default]
|
||||
None,
|
||||
/// Will download compiled package from remote
|
||||
#[serde(rename = "remote")]
|
||||
@ -134,12 +136,6 @@ pub enum BuildKind {
|
||||
Custom { script: String },
|
||||
}
|
||||
|
||||
impl Default for BuildKind {
|
||||
fn default() -> Self {
|
||||
BuildKind::None
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(default)]
|
||||
pub struct BuildRecipe {
|
||||
@ -222,7 +218,7 @@ impl Recipe {
|
||||
if !file.is_file() {
|
||||
return Err(PackageError::FileMissing(file.clone()));
|
||||
}
|
||||
let toml = fs::read_to_string(&file)
|
||||
let toml = fs::read_to_string(file)
|
||||
.map_err(|err| PackageError::FileError(err.raw_os_error(), file.clone()))?;
|
||||
let recipe: Recipe =
|
||||
toml::from_str(&toml).map_err(|err| PackageError::Parse(err, Some(file.clone())))?;
|
||||
@ -231,7 +227,7 @@ impl Recipe {
|
||||
|
||||
pub fn get_packages_list(&self) -> Vec<Option<&OptionalPackageRecipe>> {
|
||||
let mut packages: Vec<Option<&OptionalPackageRecipe>> =
|
||||
self.optional_packages.iter().map(|p| Some(p)).collect();
|
||||
self.optional_packages.iter().map(Some).collect();
|
||||
// the mandatory package, put last because of cook_build
|
||||
packages.push(None);
|
||||
packages
|
||||
@ -540,7 +536,7 @@ impl CookRecipe {
|
||||
patches: _,
|
||||
script: _,
|
||||
} => {
|
||||
if let Some(ver) = re.extract_ver(&tar) {
|
||||
if let Some(ver) = re.extract_ver(tar) {
|
||||
return Some(ver);
|
||||
}
|
||||
}
|
||||
@ -553,15 +549,15 @@ impl CookRecipe {
|
||||
patches: _,
|
||||
script: _,
|
||||
} => {
|
||||
if let Some(rev) = rev {
|
||||
if let Some(ver) = re.extract_ver(&rev) {
|
||||
return Some(ver);
|
||||
}
|
||||
if let Some(rev) = rev
|
||||
&& let Some(ver) = re.extract_ver(rev)
|
||||
{
|
||||
return Some(ver);
|
||||
}
|
||||
if let Some(branch) = branch {
|
||||
if let Some(ver) = re.extract_ver(&branch) {
|
||||
return Some(ver);
|
||||
}
|
||||
if let Some(branch) = branch
|
||||
&& let Some(ver) = re.extract_ver(branch)
|
||||
{
|
||||
return Some(ver);
|
||||
}
|
||||
}
|
||||
SourceRecipe::SameAs { same_as } => {
|
||||
@ -635,6 +631,12 @@ pub struct VersionExtractor {
|
||||
regex: Regex,
|
||||
}
|
||||
|
||||
impl Default for VersionExtractor {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl VersionExtractor {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
@ -642,7 +644,7 @@ impl VersionExtractor {
|
||||
}
|
||||
}
|
||||
pub fn extract_ver(&self, text: &str) -> Option<String> {
|
||||
if let Some(arm) = self.regex.captures(&text) {
|
||||
if let Some(arm) = self.regex.captures(text) {
|
||||
return Some(arm.get(0)?.as_str().to_string());
|
||||
}
|
||||
None
|
||||
|
||||
@ -92,11 +92,11 @@ pub fn new_recursive(
|
||||
nonstop: bool,
|
||||
recursion: usize,
|
||||
) -> Result<Vec<Package>, PackageError> {
|
||||
if names.len() == 0 {
|
||||
if names.is_empty() {
|
||||
return Ok(vec![]);
|
||||
}
|
||||
let (list, map) = new_recursive_nonstop(names, recursion);
|
||||
if nonstop && list.len() > 0 {
|
||||
if nonstop && !list.is_empty() {
|
||||
Ok(list)
|
||||
} else if !nonstop && map.len() == list.len() {
|
||||
Ok(list)
|
||||
@ -141,10 +141,10 @@ pub fn new_recursive_nonstop(
|
||||
}
|
||||
for (dep_name, result) in dependencies_map {
|
||||
if let Err(mut e) = result {
|
||||
if !packages_map.contains_key(&dep_name) {
|
||||
packages_map.entry(dep_name).or_insert_with(|| {
|
||||
e.append_recursion(name);
|
||||
packages_map.insert(dep_name, Err(e));
|
||||
}
|
||||
Err(e)
|
||||
});
|
||||
has_invalid_dependency = true;
|
||||
}
|
||||
}
|
||||
|
||||
12
src/web.rs
12
src/web.rs
@ -69,11 +69,11 @@ pub fn generate_web(all_packages: &Vec<String>, config: &CliWebConfig) {
|
||||
let Some(recipe_path) = staged_pkg::find(package_name.name()) else {
|
||||
continue;
|
||||
};
|
||||
let Ok(mut package) = staged_pkg::from_path(&recipe_path, package_name.suffix()) else {
|
||||
let Ok(mut package) = staged_pkg::from_path(recipe_path, package_name.suffix()) else {
|
||||
// TODO: report failed build
|
||||
continue;
|
||||
};
|
||||
let Ok(mut recipe) = CookRecipe::from_path(&recipe_path, true, false) else {
|
||||
let Ok(mut recipe) = CookRecipe::from_path(recipe_path, true, false) else {
|
||||
continue;
|
||||
};
|
||||
|
||||
@ -104,12 +104,12 @@ pub fn generate_web(all_packages: &Vec<String>, config: &CliWebConfig) {
|
||||
let html_path = repo_path.join(format!("{}.html", package.name.as_str()));
|
||||
|
||||
generate_html_pkg(
|
||||
&package,
|
||||
&recipe,
|
||||
package,
|
||||
recipe,
|
||||
&dependents.into_iter().collect(),
|
||||
&stage_files,
|
||||
&html_path,
|
||||
&config,
|
||||
config,
|
||||
);
|
||||
|
||||
if let Some(file_map) = stage_files {
|
||||
@ -126,7 +126,7 @@ pub fn generate_web(all_packages: &Vec<String>, config: &CliWebConfig) {
|
||||
|
||||
let index_path = repo_path.join("index.html");
|
||||
let style_path = repo_path.join("style.css");
|
||||
generate_html_index(grouped_packages, &index_path, &config);
|
||||
generate_html_index(grouped_packages, &index_path, config);
|
||||
fs::write(style_path, CSS).expect("Failed to write style.css");
|
||||
|
||||
let mut index_files = search::FileIndexBuilder::new();
|
||||
|
||||
@ -18,13 +18,7 @@ pub fn generate_html_pkg(
|
||||
let version = &package.version;
|
||||
let target = &package.target;
|
||||
let category = &get_category(&recipe.dir);
|
||||
let description = recipe
|
||||
.recipe
|
||||
.package
|
||||
.description
|
||||
.as_ref()
|
||||
.map(|p| p.as_str())
|
||||
.unwrap_or("-");
|
||||
let description = recipe.recipe.package.description.as_deref().unwrap_or("-");
|
||||
|
||||
let desc_html = recipe
|
||||
.recipe
|
||||
@ -124,7 +118,7 @@ pub fn generate_html_pkg(
|
||||
let target_split: Vec<&str> = package.target.split('-').collect();
|
||||
(
|
||||
target_split
|
||||
.get(0)
|
||||
.first()
|
||||
.map(|s| s.to_string())
|
||||
.unwrap_or("-".into()),
|
||||
target_split
|
||||
@ -196,7 +190,7 @@ pub fn generate_html_pkg(
|
||||
</html>"#,
|
||||
network_size = format_size(package.network_size),
|
||||
storage_size = format_size(package.storage_size),
|
||||
published_short = &package.time_identifier.get(0..10).unwrap_or("-"),
|
||||
published_short = package.time_identifier.get(0..10).unwrap_or("-"),
|
||||
published = package.time_identifier,
|
||||
blake3 = package.blake3,
|
||||
);
|
||||
@ -275,7 +269,7 @@ pub fn generate_html_index(
|
||||
</html>"#,
|
||||
target = redoxer::target(),
|
||||
category_sections = categories_html.join("\n\n"),
|
||||
commit_time = &ident::get_ident().time,
|
||||
commit_time = ident::get_ident().time,
|
||||
commit_hash = get_short_commit(&ident::get_ident().commit),
|
||||
commit_tree = get_tree_url(
|
||||
&config.this_repo,
|
||||
|
||||
@ -16,6 +16,12 @@ enum FsNode {
|
||||
pub struct FileIndexBuilder {
|
||||
inner: BTreeMap<String, FsNode>,
|
||||
}
|
||||
impl Default for FileIndexBuilder {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl FileIndexBuilder {
|
||||
pub const fn new() -> Self {
|
||||
Self {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user