Skip to content

Commit

Permalink
Replace '-' with "_" in crate names
Browse files Browse the repository at this point in the history
  • Loading branch information
smoelius committed Mar 16, 2022
1 parent e7ae412 commit b728be3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dylint-link/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn copy_library(path: &Path) -> Result<()> {
if_chain! {
if let Some(lib_name) = parse_path(path);
let cargo_pkg_name = var(env::CARGO_PKG_NAME)?;
if lib_name == cargo_pkg_name.replace("-", "_");
if lib_name == cargo_pkg_name.replace('-', "_");
then {
let rustup_toolchain = var(env::RUSTUP_TOOLCHAIN)?;
let filename_with_toolchain = library_filename(&lib_name, &rustup_toolchain);
Expand Down
11 changes: 8 additions & 3 deletions utils/testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn rustc_flags(metadata: &Metadata, package: &Package, target: &Target) -> Resul
&& args
.as_slice()
.windows(2)
.any(|window| window == ["--crate-name", &target.name])
.any(|window| window == ["--crate-name", &snake_case(&target.name)])
{
Some(args)
} else {
Expand Down Expand Up @@ -244,8 +244,9 @@ fn remove_example(metadata: &Metadata, _package: &Package, target: &Target) -> R

if let Some(file_name) = path.file_name() {
let s = file_name.to_string_lossy();
if s == target.name.clone() + consts::EXE_SUFFIX
|| s.starts_with(&(target.name.clone() + "-"))
let target_name = snake_case(&target.name);
if s == target_name.clone() + consts::EXE_SUFFIX
|| s.starts_with(&(target_name.clone() + "-"))
{
remove_file(&path).with_context(|| {
format!("`remove_file` failed for `{}`", path.to_string_lossy())
Expand Down Expand Up @@ -292,3 +293,7 @@ fn run_tests<'test>(
};
compiletest::run_tests(&config);
}

fn snake_case(name: &str) -> String {
name.replace('-', "_")
}

0 comments on commit b728be3

Please sign in to comment.