Skip to content

Commit 65b6c7f

Browse files
committed
Validate the uniqueness of build scripts
1 parent 08f83e3 commit 65b6c7f

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/cargo/util/toml/targets.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ pub(super) fn to_targets(
104104
if metabuild.is_some() {
105105
anyhow::bail!("cannot specify both `metabuild` and `build`");
106106
}
107+
validate_unique_build_scripts(custom_build)?;
107108
for script in custom_build {
108109
let script_path = Path::new(script);
109110
let name = format!(
@@ -901,6 +902,22 @@ fn validate_unique_names(targets: &[TomlTarget], target_kind: &str) -> CargoResu
901902
Ok(())
902903
}
903904

905+
/// Will check a list of build scripts, and make sure script file stems are unique within a vector.
906+
fn validate_unique_build_scripts(scripts: &[String]) -> CargoResult<()> {
907+
let mut seen = HashSet::new();
908+
for script in scripts {
909+
let stem = Path::new(script).file_stem().unwrap().to_str().unwrap();
910+
if !seen.insert(stem) {
911+
anyhow::bail!(
912+
"found duplicate build script file stem {}, \
913+
but all build scripts must have a unique file stem",
914+
stem
915+
);
916+
}
917+
}
918+
Ok(())
919+
}
920+
904921
fn configure(
905922
toml: &TomlTarget,
906923
target: &mut Target,

0 commit comments

Comments
 (0)