Skip to content

Commit

Permalink
update rust and apply lint fixes (#1236)
Browse files Browse the repository at this point in the history
  • Loading branch information
coffee-cup authored Dec 4, 2024
1 parent fd35d3c commit 668e5df
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 17 deletions.
9 changes: 6 additions & 3 deletions src/nixpacks/nix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ pub fn create_nix_expressions_for_phases(phases: &Phases) -> BTreeMap<String, St
archive_to_packages
.iter()
.fold(BTreeMap::new(), |mut acc, g| {
acc.insert(nix_file_name(&g.archive), nix_expression_for_group(g));
acc.insert(
nix_file_name(g.archive.as_ref()),
nix_expression_for_group(g),
);
acc
})
}
Expand All @@ -82,7 +85,7 @@ pub fn nix_file_names_for_phases(phases: &Phases) -> Vec<String> {
.filter(|p| p.uses_nix())
.map(|p| p.nixpkgs_archive.clone())
.collect::<BTreeSet<_>>();
archives.iter().map(nix_file_name).collect()
archives.iter().map(|a| nix_file_name(a.as_ref())).collect()
}

/// Returns all the Nix expression files used to install Nix dependencies for each phase.
Expand All @@ -101,7 +104,7 @@ pub fn setup_files_for_phases(phases: &Phases) -> Vec<String> {
}

/// Generates the filename for each Nix expression file.
fn nix_file_name(archive: &Option<String>) -> String {
fn nix_file_name(archive: Option<&String>) -> String {
match archive {
Some(archive) => format!("nixpkgs-{archive}.nix"),
None => "nixpkgs.nix".to_string(),
Expand Down
2 changes: 1 addition & 1 deletion src/nixpacks/plan/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub struct NixpacksBuildPlanGenerator<'a> {
}

/// NixpacksBuildPlanGenerators produce build plans using the options and providers they contain.
impl<'a> PlanGenerator for NixpacksBuildPlanGenerator<'a> {
impl PlanGenerator for NixpacksBuildPlanGenerator<'_> {
fn generate_plan(&mut self, app: &App, environment: &Environment) -> Result<(BuildPlan, App)> {
// If the provider defines a build plan in the new format, use that
let plan = self.get_build_plan(app, environment)?;
Expand Down
24 changes: 12 additions & 12 deletions src/nixpacks/plan/phase.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ impl Phase {
}
}

self.cmds = pin_option_vec(&self.cmds);
self.depends_on = pin_option_vec(&self.depends_on);
self.nix_pkgs = pin_option_vec(&self.nix_pkgs);
self.nix_libs = pin_option_vec(&self.nix_libs);
self.apt_pkgs = pin_option_vec(&self.apt_pkgs);
self.nix_overlays = pin_option_vec(&self.nix_overlays);
self.only_include_files = pin_option_vec(&self.only_include_files);
self.cache_directories = pin_option_vec(&self.cache_directories);
self.paths = pin_option_vec(&self.paths);
self.cmds = pin_option_vec(self.cmds.as_ref());
self.depends_on = pin_option_vec(self.depends_on.as_ref());
self.nix_pkgs = pin_option_vec(self.nix_pkgs.as_ref());
self.nix_libs = pin_option_vec(self.nix_libs.as_ref());
self.apt_pkgs = pin_option_vec(self.apt_pkgs.as_ref());
self.nix_overlays = pin_option_vec(self.nix_overlays.as_ref());
self.only_include_files = pin_option_vec(self.only_include_files.as_ref());
self.cache_directories = pin_option_vec(self.cache_directories.as_ref());
self.paths = pin_option_vec(self.paths.as_ref());
}
}

Expand Down Expand Up @@ -263,16 +263,16 @@ impl StartPhase {

/// Store the list of files to include in this phase for later reproducibility.
pub fn pin(&mut self) {
self.only_include_files = pin_option_vec(&self.only_include_files);
self.only_include_files = pin_option_vec(self.only_include_files.as_ref());
}
}

/// Store the list of options for this phase for later reproducibility.
fn pin_option_vec(vec: &Option<Vec<String>>) -> Option<Vec<String>> {
fn pin_option_vec(vec: Option<&Vec<String>>) -> Option<Vec<String>> {
if let Some(vec) = vec {
Some(remove_autos_from_vec(vec.clone()))
} else {
vec.clone()
vec.cloned()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/providers/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ impl NodeProvider {
}

let node_pkg = parse_node_version_into_pkg(&node_version);
return Ok(Pkg::new(node_pkg.as_str()));
Ok(Pkg::new(node_pkg.as_str()))
}

pub fn get_package_manager(app: &App) -> String {
Expand Down

0 comments on commit 668e5df

Please sign in to comment.