File tree 2 files changed +49
-0
lines changed
2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change @@ -535,6 +535,10 @@ impl TomlManifest {
535
535
debug ! ( "manifest has no build targets" ) ;
536
536
}
537
537
538
+ if let Err ( e) = unique_build_targets ( & targets, layout) {
539
+ bail ! ( "duplicate build target found: `{}`" , e) ;
540
+ }
541
+
538
542
let mut deps = Vec :: new ( ) ;
539
543
let replace;
540
544
@@ -752,6 +756,18 @@ fn unique_names_in_targets(targets: &[TomlTarget]) -> Result<(), String> {
752
756
Ok ( ( ) )
753
757
}
754
758
759
+ /// Will check a list of build targets, and make sure the target names are unique within a vector.
760
+ /// If not, the name of the offending build target is returned.
761
+ fn unique_build_targets ( targets : & [ Target ] , layout : & Layout ) -> Result < ( ) , String > {
762
+ let mut seen = HashSet :: new ( ) ;
763
+ for v in targets. iter ( ) . map ( |e| layout. root . join ( e. src_path ( ) ) ) {
764
+ if !seen. insert ( v. clone ( ) ) {
765
+ return Err ( v. display ( ) . to_string ( ) ) ;
766
+ }
767
+ }
768
+ Ok ( ( ) )
769
+ }
770
+
755
771
impl TomlDependency {
756
772
fn to_dependency ( & self ,
757
773
name : & str ,
Original file line number Diff line number Diff line change @@ -101,6 +101,39 @@ Caused by:
101
101
src[..]Cargo.toml:1:5-1:6 expected a value\n \n ") )
102
102
}
103
103
104
+ #[ test]
105
+ fn cargo_compile_duplicate_build_targets ( ) {
106
+ let p = project ( "foo" )
107
+ . file ( "Cargo.toml" , r#"
108
+ [package]
109
+ name = "foo"
110
+ version = "0.0.1"
111
+ authors = []
112
+
113
+ [lib]
114
+ name = "main"
115
+ crate-type = ["dylib"]
116
+
117
+ [dependencies]
118
+ "# )
119
+ . file ( "src/main.rs" , r#"
120
+ fn main() {}
121
+ "# ) ;
122
+
123
+ let error_message = format ! ( "\
124
+ [ERROR] failed to parse manifest at `[..]`
125
+
126
+ Caused by:
127
+ duplicate build target found: `{}`" ,
128
+ p. root( ) . join( "src[..]main.rs" ) . display( ) ) ;
129
+
130
+ assert_that ( p. cargo_process ( "build" ) ,
131
+ execs ( )
132
+ . with_status ( 101 )
133
+ . with_stderr ( error_message)
134
+ )
135
+ }
136
+
104
137
#[ test]
105
138
fn cargo_compile_with_invalid_version ( ) {
106
139
let p = project ( "foo" )
You can’t perform that action at this time.
0 commit comments