diff --git a/src/git.rs b/src/git.rs index eade79d..564a1e7 100644 --- a/src/git.rs +++ b/src/git.rs @@ -27,36 +27,36 @@ lazy_static! { } #[derive(Copy, Clone, Debug, Eq, PartialEq)] -pub enum GitPrefix { +pub enum Prefix { Git, GitSubmodule, } -impl Default for GitPrefix { +impl Default for Prefix { fn default() -> Self { Self::Git } } -impl Display for GitPrefix { +impl Display for Prefix { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { write!( f, "{}", match *self { - GitPrefix::Git => "git", - GitPrefix::GitSubmodule => "gitsm", + Self::Git => "git", + Self::GitSubmodule => "gitsm", } ) } } /// converts a GIT URL to a Yocto GIT URL -pub fn git_to_yocto_git_url(url: &str, name: Option<&str>, prefix: GitPrefix) -> String { +pub fn git_to_yocto_git_url(url: &str, name: Option<&str>, prefix: Prefix) -> String { // check if its a git@github.com:cardoe/cargo-bitbake.git style URL // and fix it up if it is let fixed_url = if SSH_STYLE_REMOTE.is_match(url) { - format!("ssh://{}", url.replace(":", "/")) + format!("ssh://{}", url.replace(':', "/")) } else { url.to_string() }; @@ -105,9 +105,9 @@ impl ProjectRepo { .submodules() .context("Unable to determine the submodules")?; let prefix = if submodules.is_empty() { - GitPrefix::Git + Prefix::Git } else { - GitPrefix::GitSubmodule + Prefix::GitSubmodule }; let uri = remote @@ -164,7 +164,7 @@ mod test { #[test] fn remote_http() { let repo = "http://github.com/rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, Some("cargo"), GitPrefix::Git); + let url = git_to_yocto_git_url(repo, Some("cargo"), Prefix::Git); assert_eq!(url, "git://github.com/rust-lang/cargo.git;protocol=http;nobranch=1;name=cargo;destsuffix=cargo"); } @@ -172,7 +172,7 @@ mod test { #[test] fn remote_https() { let repo = "https://github.com/rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, Some("cargo"), GitPrefix::Git); + let url = git_to_yocto_git_url(repo, Some("cargo"), Prefix::Git); assert_eq!(url, "git://github.com/rust-lang/cargo.git;protocol=https;nobranch=1;name=cargo;destsuffix=cargo"); } @@ -180,7 +180,7 @@ mod test { #[test] fn remote_ssh() { let repo = "git@github.com:rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, Some("cargo"), GitPrefix::Git); + let url = git_to_yocto_git_url(repo, Some("cargo"), Prefix::Git); assert_eq!(url, "git://git@github.com/rust-lang/cargo.git;protocol=ssh;nobranch=1;name=cargo;destsuffix=cargo"); } @@ -188,7 +188,7 @@ mod test { #[test] fn remote_http_nosuffix() { let repo = "http://github.com/rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, None, GitPrefix::Git); + let url = git_to_yocto_git_url(repo, None, Prefix::Git); assert_eq!( url, "git://github.com/rust-lang/cargo.git;protocol=http;nobranch=1" @@ -198,7 +198,7 @@ mod test { #[test] fn remote_https_nosuffix() { let repo = "https://github.com/rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, None, GitPrefix::Git); + let url = git_to_yocto_git_url(repo, None, Prefix::Git); assert_eq!( url, "git://github.com/rust-lang/cargo.git;protocol=https;nobranch=1" @@ -208,7 +208,7 @@ mod test { #[test] fn remote_ssh_nosuffix() { let repo = "git@github.com:rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, None, GitPrefix::Git); + let url = git_to_yocto_git_url(repo, None, Prefix::Git); assert_eq!( url, "git://git@github.com/rust-lang/cargo.git;protocol=ssh;nobranch=1" @@ -218,7 +218,7 @@ mod test { #[test] fn cargo_http() { let repo = "http://github.com/rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, Some("cargo"), GitPrefix::Git); + let url = git_to_yocto_git_url(repo, Some("cargo"), Prefix::Git); assert_eq!(url, "git://github.com/rust-lang/cargo.git;protocol=http;nobranch=1;name=cargo;destsuffix=cargo"); } @@ -226,7 +226,7 @@ mod test { #[test] fn cargo_https() { let repo = "https://github.com/rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, Some("cargo"), GitPrefix::Git); + let url = git_to_yocto_git_url(repo, Some("cargo"), Prefix::Git); assert_eq!(url, "git://github.com/rust-lang/cargo.git;protocol=https;nobranch=1;name=cargo;destsuffix=cargo"); } @@ -234,7 +234,7 @@ mod test { #[test] fn cargo_ssh() { let repo = "ssh://git@github.com/rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, Some("cargo"), GitPrefix::Git); + let url = git_to_yocto_git_url(repo, Some("cargo"), Prefix::Git); assert_eq!(url, "git://git@github.com/rust-lang/cargo.git;protocol=ssh;nobranch=1;name=cargo;destsuffix=cargo"); } @@ -242,7 +242,7 @@ mod test { #[test] fn remote_ssh_with_submodules() { let repo = "git@github.com:rust-lang/cargo.git"; - let url = git_to_yocto_git_url(repo, Some("cargo"), GitPrefix::GitSubmodule); + let url = git_to_yocto_git_url(repo, Some("cargo"), Prefix::GitSubmodule); assert_eq!(url, "gitsm://git@github.com/rust-lang/cargo.git;protocol=ssh;nobranch=1;name=cargo;destsuffix=cargo"); } diff --git a/src/license.rs b/src/license.rs index 438c91e..0f8f8de 100644 --- a/src/license.rs +++ b/src/license.rs @@ -32,7 +32,7 @@ pub fn file(crate_root: &Path, rel_dir: &Path, license_name: &str, single_licens // that means this is closed source and there is no license // under which this is released. So special case it if license_name == CLOSED_LICENSE { - return "".into(); + return String::new(); } // if the license exists at the top level then diff --git a/src/main.rs b/src/main.rs index 64d592e..436bd2e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -138,7 +138,7 @@ struct Args { bin_name = "cargo", author, version, - about = "Generates a BitBake recipe for a given Cargo project", + about = "Generates a BitBake recipe for a given Cargo project" )] enum Opt { /// Generates a BitBake recipe for a given Cargo project @@ -151,13 +151,13 @@ fn main() { let Opt::Bitbake(opt) = Opt::parse(); let result = real_main(opt, &mut config); if let Err(e) = result { - cargo::exit_with_error(e, &mut *config.shell()); + cargo::exit_with_error(e, &mut config.shell()); } } fn real_main(options: Args, config: &mut Config) -> CliResult { config.configure( - options.verbose as u32, + u32::from(options.verbose), options.quiet, /* color */ None, @@ -222,7 +222,7 @@ fn real_main(options: Args, config: &mut Config) -> CliResult { let url = git::git_to_yocto_git_url( src_id.url().as_str(), Some(pkg.name().as_str()), - git::GitPrefix::default(), + git::Prefix::default(), ); // save revision @@ -242,14 +242,10 @@ fn real_main(options: Args, config: &mut Config) -> CliResult { GitReference::Rev(ref s) => { if s.len() == 40 { // avoid reduced hashes - s + s.as_str() } else { let precise = src_id.precise(); - if let Some(p) = precise { - p - } else { - panic!("cannot find rev in correct format!"); - } + precise.expect("cannot find rev in correct format!") } } GitReference::Branch(ref s) => { @@ -289,7 +285,7 @@ fn real_main(options: Args, config: &mut Config) -> CliResult { println!("No package.description set in your Cargo.toml, using package.name"); package.name() }, - |s| cargo::util::interning::InternedString::new(&s.trim().replace("\n", " \\\n")), + |s| cargo::util::interning::InternedString::new(&s.trim().replace('\n', " \\\n")), ); // package homepage (or source code location) @@ -344,23 +340,28 @@ fn real_main(options: Args, config: &mut Config) -> CliResult { // attempt to figure out the git repo for this project let project_repo = git::ProjectRepo::new(config).unwrap_or_else(|e| { println!("{}", e); - Default::default() + git::ProjectRepo::default() }); // if this is not a tag we need to include some data about the version in PV so that // the sstate cache remains valid let git_srcpv = if !project_repo.tag && project_repo.rev.len() > 10 { - let mut pv_append_key = "PV:append"; - // Override PV override with legacy syntax if flagged - if options.legacy_overrides { - pv_append_key = "PV_append"; - } + let pv_append_key = if options.legacy_overrides { + // Override PV override with legacy syntax if flagged + "PV_append" + } else { + "PV:append" + }; // we should be using ${SRCPV} here but due to a bitbake bug we cannot. see: // https://github.com/meta-rust/meta-rust/issues/136 - format!("{} = \".AUTOINC+{}\"", pv_append_key, &project_repo.rev[..10]) + format!( + "{} = \".AUTOINC+{}\"", + pv_append_key, + &project_repo.rev[..10] + ) } else { // its a tag so nothing needed - "".into() + String::new() }; // build up the path