2
2
3
3
use cargo_test_support:: registry:: Package ;
4
4
use cargo_test_support:: {
5
- basic_bin_manifest, basic_lib_manifest, basic_manifest, git, main_file, project, project_in,
6
- rustc_host,
5
+ basic_bin_manifest, basic_manifest, git, main_file, project, project_in, rustc_host,
7
6
} ;
8
7
use glob:: GlobError ;
9
8
use std:: env;
@@ -112,6 +111,18 @@ fn clean_multiple_packages_in_glob_char_path() {
112
111
assert_eq ! ( get_build_artifacts( foo_path, file_glob) . len( ) , 0 ) ;
113
112
}
114
113
114
+ fn get_build_artifacts ( path : & PathBuf , file_glob : & str ) -> Vec < Result < PathBuf , GlobError > > {
115
+ let pattern = path. to_str ( ) . expect ( "expected utf-8 path" ) ;
116
+ let pattern = glob:: Pattern :: escape ( pattern) ;
117
+
118
+ let path = PathBuf :: from ( pattern) . join ( file_glob) ;
119
+ let path = path. to_str ( ) . expect ( "expected utf-8 path" ) ;
120
+ glob:: glob ( path)
121
+ . expect ( "expected glob to run" )
122
+ . into_iter ( )
123
+ . collect :: < Vec < Result < PathBuf , GlobError > > > ( )
124
+ }
125
+
115
126
#[ cargo_test]
116
127
fn clean_p_only_cleans_specified_package ( ) {
117
128
let p = project ( )
@@ -122,46 +133,74 @@ fn clean_p_only_cleans_specified_package() {
122
133
members = [
123
134
"foo",
124
135
"foo_core",
136
+ "foo-base",
125
137
]
126
138
"# ,
127
139
)
128
- . file ( "foo/Cargo.toml" , & basic_lib_manifest ( "foo" ) )
140
+ . file ( "foo/Cargo.toml" , & basic_manifest ( "foo" , "0.1.0 ") )
129
141
. file ( "foo/src/lib.rs" , "//! foo" )
130
- . file ( "foo_core/Cargo.toml" , & basic_lib_manifest ( "foo_core" ) )
142
+ . file ( "foo_core/Cargo.toml" , & basic_manifest ( "foo_core" , "0.1.0 ") )
131
143
. file ( "foo_core/src/lib.rs" , "//! foo_core" )
144
+ . file ( "foo-base/Cargo.toml" , & basic_manifest ( "foo-base" , "0.1.0" ) )
145
+ . file ( "foo-base/src/lib.rs" , "//! foo-base" )
132
146
. build ( ) ;
133
147
134
- let deps_path = & p. build_dir ( ) . join ( "debug" ) . join ( "deps " ) ;
135
- let foo_glob = "foo-*" ;
136
- let foo_core_glob = " foo_core-*" ;
148
+ let fingerprint_path = & p. build_dir ( ) . join ( "debug" ) . join ( ".fingerprint " ) ;
149
+
150
+ p . cargo ( "build -p foo -p foo_core -p foo-base" ) . run ( ) ;
137
151
138
- p . cargo ( "build -p foo -p foo_core" ) . run ( ) ;
152
+ let mut fingerprint_names = get_fingerprints_without_hashes ( fingerprint_path ) ;
139
153
140
- // Artifacts present for both after building
141
- assert ! ( !get_build_artifacts( deps_path, foo_glob) . is_empty( ) ) ;
142
- let num_foo_core_artifacts = get_build_artifacts ( deps_path, foo_core_glob) . len ( ) ;
154
+ // Artifacts present for all after building
155
+ assert ! ( fingerprint_names. iter( ) . any( |e| e == "foo" ) ) ;
156
+ let num_foo_core_artifacts = fingerprint_names
157
+ . iter ( )
158
+ . filter ( |& e| e == "foo_core" )
159
+ . count ( ) ;
143
160
assert_ne ! ( num_foo_core_artifacts, 0 ) ;
161
+ let num_foo_base_artifacts = fingerprint_names
162
+ . iter ( )
163
+ . filter ( |& e| e == "foo-base" )
164
+ . count ( ) ;
165
+ assert_ne ! ( num_foo_base_artifacts, 0 ) ;
144
166
145
167
p. cargo ( "clean -p foo" ) . run ( ) ;
146
168
147
- // Cleaning `foo` leaves artifacts for `foo_core`
148
- assert ! ( get_build_artifacts( deps_path, foo_glob) . is_empty( ) ) ;
169
+ fingerprint_names = get_fingerprints_without_hashes ( fingerprint_path) ;
170
+
171
+ // Cleaning `foo` leaves artifacts for the others
172
+ assert ! ( !fingerprint_names. iter( ) . any( |e| e == "foo" ) ) ;
149
173
assert_eq ! (
174
+ fingerprint_names
175
+ . iter( )
176
+ . filter( |& e| e == "foo_core" )
177
+ . count( ) ,
178
+ num_foo_core_artifacts,
179
+ ) ;
180
+ assert_eq ! (
181
+ fingerprint_names
182
+ . iter( )
183
+ . filter( |& e| e == "foo-base" )
184
+ . count( ) ,
150
185
num_foo_core_artifacts,
151
- get_build_artifacts( deps_path, foo_core_glob) . len( )
152
186
) ;
153
187
}
154
188
155
- fn get_build_artifacts ( path : & PathBuf , file_glob : & str ) -> Vec < Result < PathBuf , GlobError > > {
156
- let pattern = path. to_str ( ) . expect ( "expected utf-8 path" ) ;
157
- let pattern = glob:: Pattern :: escape ( pattern) ;
158
-
159
- let path = PathBuf :: from ( pattern) . join ( file_glob) ;
160
- let path = path. to_str ( ) . expect ( "expected utf-8 path" ) ;
161
- glob:: glob ( path)
162
- . expect ( "expected glob to run" )
163
- . into_iter ( )
164
- . collect :: < Vec < Result < PathBuf , GlobError > > > ( )
189
+ fn get_fingerprints_without_hashes ( fingerprint_path : & Path ) -> Vec < String > {
190
+ std:: fs:: read_dir ( fingerprint_path)
191
+ . expect ( "Build dir should be readable" )
192
+ . filter_map ( |entry| entry. ok ( ) )
193
+ . map ( |entry| {
194
+ let name = entry. file_name ( ) ;
195
+ let name = name
196
+ . into_string ( )
197
+ . expect ( "fingerprint name should be UTF-8" ) ;
198
+ name. rsplit_once ( '-' )
199
+ . expect ( "Name should contain at least one hyphen" )
200
+ . 0
201
+ . to_owned ( )
202
+ } )
203
+ . collect ( )
165
204
}
166
205
167
206
#[ cargo_test]
0 commit comments