Skip to content

Commit

Permalink
fix: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Daanvdplas committed Dec 4, 2024
1 parent 0fca3d9 commit 39b26ed
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/pop-cli/src/commands/build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub(crate) struct BuildArgs {
#[arg(short = 'p', long)]
pub(crate) package: Option<String>,
/// For production, always build in release mode to exclude debug features.
#[clap(short = 'r', long, conflicts_with = "profile")]
#[clap(short, long, conflicts_with = "profile")]
pub(crate) release: bool,
/// Build profile [default: debug].
#[clap(long, value_enum)]
Expand Down Expand Up @@ -145,7 +145,7 @@ mod tests {
for package in [None, Some(name.to_string())] {
for release in [true, false] {
for profile in Profile::VARIANTS {
let profile = if release { Profile::Release } else { Profile::Debug };
let profile = if release { Profile::Release } else { profile.clone() };
let project = if package.is_some() { "package" } else { "project" };
let mut cli = MockCli::new()
.expect_intro(format!("Building your {project}"))
Expand Down
17 changes: 9 additions & 8 deletions crates/pop-cli/src/commands/build/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use std::{
env::current_dir,
fs::create_dir_all,
path::{Path, PathBuf},
thread::sleep,
time::Duration,
};
#[cfg(not(test))]
use std::{thread::sleep, time::Duration};
use strum::{EnumMessage, VariantArray};
use strum_macros::{AsRefStr, Display, EnumString};

Expand Down Expand Up @@ -473,12 +473,12 @@ impl BuildSpec {
..
} = self;
// Ensure binary is built.
let binary_path = ensure_binary_exists(cli, &profile)?;
let binary_path = ensure_binary_exists(cli, profile)?;
let spinner = spinner();
spinner.start("Generating chain specification...");

// Generate chain spec.
generate_plain_chain_spec(&binary_path, &output_file, default_bootnode, &chain)?;
generate_plain_chain_spec(&binary_path, output_file, default_bootnode, chain)?;
// Customize spec based on input.
self.customize()?;
generated_files.push(format!(
Expand All @@ -494,7 +494,7 @@ impl BuildSpec {
.unwrap_or(DEFAULT_SPEC_NAME)
.trim_end_matches(".json");
let raw_spec_name = format!("{spec_name}-raw.json");
let raw_chain_spec = generate_raw_chain_spec(&binary_path, &output_file, &raw_spec_name)?;
let raw_chain_spec = generate_raw_chain_spec(&binary_path, output_file, &raw_spec_name)?;
generated_files.push(format!(
"Raw chain specification file generated at: {}",
raw_chain_spec.display()
Expand Down Expand Up @@ -534,7 +534,7 @@ impl BuildSpec {
fn customize(&self) -> anyhow::Result<()> {
let mut chain_spec = ChainSpec::from(&self.output_file)?;
chain_spec.replace_para_id(self.id)?;
chain_spec.replace_relay_chain(&self.relay.to_string())?;
chain_spec.replace_relay_chain(&self.relay.as_ref())?;
chain_spec.replace_chain_type(&self.chain_type.to_string())?;
chain_spec.replace_protocol_id(&self.protocol_id)?;
chain_spec.to_file(&self.output_file)?;
Expand Down Expand Up @@ -803,8 +803,8 @@ mod tests {
// Create a temporary file to act as the existing chain spec file.
let temp_dir = tempdir()?;
let chain_spec_path = temp_dir.path().join("existing-chain-spec.json");
std::fs::write(&chain_spec_path, "{}")?; // Write a dummy JSON to the file.
// Use the deprcrated release flag.
std::fs::write(&chain_spec_path, "{}")?;
// Use the deprcrated release flag.
let release = true;
let build_spec_cmd = BuildSpecCommand {
release,
Expand All @@ -817,6 +817,7 @@ mod tests {
false,
).expect_warning("NOTE: release flag is deprecated. Use `--profile` instead.");
let build_spec = build_spec_cmd.configure_build_spec(&mut cli).await?;
assert_eq!(build_spec.profile, release.into());
cli.verify()?;
Ok(())
}
Expand Down
6 changes: 1 addition & 5 deletions crates/pop-common/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ impl Profile {

impl From<Profile> for bool {
fn from(value: Profile) -> Self {
if value == Profile::Debug {
false
} else {
true
}
value != Profile::Debug
}
}

Expand Down
5 changes: 1 addition & 4 deletions crates/pop-common/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,6 @@ pub fn add_crate_to_workspace(workspace_toml: &Path, crate_path: &Path) -> anyho
Ok(())
}

use std::fs;

/// Adds a "production" profile to the Cargo.toml manifest if it doesn't already exist.
///
/// # Arguments
Expand All @@ -108,7 +106,7 @@ pub fn add_production_profile(project: &Path) -> anyhow::Result<()> {
let root_toml_path = project.join("Cargo.toml");
let mut manifest = Manifest::from_path(&root_toml_path)?;
// Check if the `production` profile already exists.
if manifest.profile.custom.get("production").is_some() {
if manifest.profile.custom.contains_key("production") {
return Ok(());
}
// Create the production profile with required fields.
Expand Down Expand Up @@ -475,7 +473,6 @@ mod tests {

// Call the function to add the production profile
let result = add_production_profile(project_path);
println!("{:?}", result);
assert!(result.is_ok());

// Verify the production profile is added
Expand Down
2 changes: 1 addition & 1 deletion crates/pop-parachains/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub fn binary_path(target_path: &Path, node_path: &Path) -> Result<PathBuf, Erro
/// * `plain_chain_spec` - Location of the plain_parachain_spec file to be generated.
/// * `default_bootnode` - Whether to include localhost as a bootnode.
/// * `chain` - The chain specification. It can be one of the predefined ones (e.g. dev, local or a
/// custom one) or the path to an existing chain spec.
/// custom one) or the path to an existing chain spec.
pub fn generate_plain_chain_spec(
binary_path: &Path,
plain_chain_spec: &Path,
Expand Down

0 comments on commit 39b26ed

Please sign in to comment.