Skip to content

Commit

Permalink
apply clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
hellow554 committed Feb 16, 2023
1 parent 69d97f3 commit 52cbbee
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
38 changes: 19 additions & 19 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected]: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()
};
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -164,31 +164,31 @@ 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");
}

#[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");
}

#[test]
fn remote_ssh() {
let repo = "[email protected]: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://[email protected]/rust-lang/cargo.git;protocol=ssh;nobranch=1;name=cargo;destsuffix=cargo");
}

#[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"
Expand All @@ -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"
Expand All @@ -208,7 +208,7 @@ mod test {
#[test]
fn remote_ssh_nosuffix() {
let repo = "[email protected]: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://[email protected]/rust-lang/cargo.git;protocol=ssh;nobranch=1"
Expand All @@ -218,31 +218,31 @@ 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");
}

#[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");
}

#[test]
fn cargo_ssh() {
let repo = "ssh://[email protected]/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://[email protected]/rust-lang/cargo.git;protocol=ssh;nobranch=1;name=cargo;destsuffix=cargo");
}

#[test]
fn remote_ssh_with_submodules() {
let repo = "[email protected]: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://[email protected]/rust-lang/cargo.git;protocol=ssh;nobranch=1;name=cargo;destsuffix=cargo");
}
Expand Down
2 changes: 1 addition & 1 deletion src/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
39 changes: 20 additions & 19 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 52cbbee

Please sign in to comment.