1
1
//! Tests for multiple build scripts feature.
2
2
3
+ use cargo_test_support:: compare:: assert_e2e;
3
4
use cargo_test_support:: git;
4
5
use cargo_test_support:: prelude:: * ;
6
+ use cargo_test_support:: publish:: validate_crate_contents;
5
7
use cargo_test_support:: str;
6
8
use cargo_test_support:: { project, Project } ;
9
+ use std:: fs:: File ;
7
10
8
11
#[ cargo_test]
9
12
fn build_without_feature_enabled_aborts_with_error ( ) {
@@ -64,12 +67,10 @@ fn empty_multiple_build_script_project() {
64
67
let p = basic_empty_project ( ) ;
65
68
p. cargo ( "check" )
66
69
. masquerade_as_nightly_cargo ( & [ "multiple-build-scripts" ] )
67
- . with_status ( 101 )
70
+ . with_status ( 0 )
68
71
. with_stderr_data ( str![ [ r#"
69
- [ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
70
-
71
- Caused by:
72
- multiple build scripts feature is not implemented yet!
72
+ [COMPILING] foo v0.1.0 ([ROOT]/foo)
73
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
73
74
74
75
"# ] ] )
75
76
. run ( ) ;
@@ -80,14 +81,107 @@ fn multiple_build_scripts_metadata() {
80
81
let p = basic_empty_project ( ) ;
81
82
p. cargo ( "metadata --format-version=1" )
82
83
. masquerade_as_nightly_cargo ( & [ "multiple-build-scripts" ] )
83
- . with_status ( 101 )
84
- . with_stderr_data ( str![ [ r#"
85
- [ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
86
-
87
- Caused by:
88
- multiple build scripts feature is not implemented yet!
89
-
90
- "# ] ] )
84
+ . with_status ( 0 )
85
+ . with_stderr_data ( "" )
86
+ . with_stdout_data (
87
+ str![ [ r#"
88
+ {
89
+ "metadata": null,
90
+ "packages": [
91
+ {
92
+ "authors": [],
93
+ "categories": [],
94
+ "default_run": null,
95
+ "dependencies": [],
96
+ "description": null,
97
+ "documentation": null,
98
+ "edition": "2024",
99
+ "features": {},
100
+ "homepage": null,
101
+ "id": "path+[ROOTURL]/foo#0.1.0",
102
+ "keywords": [],
103
+ "license": null,
104
+ "license_file": null,
105
+ "links": null,
106
+ "manifest_path": "[ROOT]/foo/Cargo.toml",
107
+ "metadata": null,
108
+ "name": "foo",
109
+ "publish": null,
110
+ "readme": null,
111
+ "repository": null,
112
+ "rust_version": null,
113
+ "source": null,
114
+ "targets": [
115
+ {
116
+ "crate_types": [
117
+ "bin"
118
+ ],
119
+ "doc": true,
120
+ "doctest": false,
121
+ "edition": "2024",
122
+ "kind": [
123
+ "bin"
124
+ ],
125
+ "name": "foo",
126
+ "src_path": "[ROOT]/foo/src/main.rs",
127
+ "test": true
128
+ },
129
+ {
130
+ "crate_types": [
131
+ "bin"
132
+ ],
133
+ "doc": false,
134
+ "doctest": false,
135
+ "edition": "2024",
136
+ "kind": [
137
+ "custom-build"
138
+ ],
139
+ "name": "build-script-build1",
140
+ "src_path": "[ROOT]/foo/build1.rs",
141
+ "test": false
142
+ },
143
+ {
144
+ "crate_types": [
145
+ "bin"
146
+ ],
147
+ "doc": false,
148
+ "doctest": false,
149
+ "edition": "2024",
150
+ "kind": [
151
+ "custom-build"
152
+ ],
153
+ "name": "build-script-build2",
154
+ "src_path": "[ROOT]/foo/build2.rs",
155
+ "test": false
156
+ }
157
+ ],
158
+ "version": "0.1.0"
159
+ }
160
+ ],
161
+ "resolve": {
162
+ "nodes": [
163
+ {
164
+ "dependencies": [],
165
+ "deps": [],
166
+ "features": [],
167
+ "id": "path+[ROOTURL]/foo#0.1.0"
168
+ }
169
+ ],
170
+ "root": "path+[ROOTURL]/foo#0.1.0"
171
+ },
172
+ "target_directory": "[ROOT]/foo/target",
173
+ "version": 1,
174
+ "workspace_default_members": [
175
+ "path+[ROOTURL]/foo#0.1.0"
176
+ ],
177
+ "workspace_members": [
178
+ "path+[ROOTURL]/foo#0.1.0"
179
+ ],
180
+ "workspace_root": "[ROOT]/foo"
181
+ }
182
+ "# ] ]
183
+ . is_json ( ) ,
184
+ )
91
185
. run ( ) ;
92
186
}
93
187
@@ -119,15 +213,91 @@ fn verify_package_multiple_build_scripts() {
119
213
120
214
p. cargo ( "package" )
121
215
. masquerade_as_nightly_cargo ( & [ "multiple-build-scripts" ] )
122
- . with_status ( 101 )
216
+ . with_status ( 0 )
123
217
. with_stderr_data ( str![ [ r#"
124
- [ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
125
-
126
- Caused by:
127
- multiple build scripts feature is not implemented yet!
218
+ [PACKAGING] foo v0.1.0 ([ROOT]/foo)
219
+ [PACKAGED] 5 files, [FILE_SIZE]B ([FILE_SIZE]B compressed)
220
+ [VERIFYING] foo v0.1.0 ([ROOT]/foo)
221
+ [COMPILING] foo v0.1.0 ([ROOT]/foo/target/package/foo-0.1.0)
222
+ [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
128
223
129
224
"# ] ] )
130
225
. run ( ) ;
226
+
227
+ let f = File :: open ( & p. root ( ) . join ( "target/package/foo-0.1.0.crate" ) ) . unwrap ( ) ;
228
+ validate_crate_contents (
229
+ f,
230
+ "foo-0.1.0.crate" ,
231
+ & [
232
+ "Cargo.toml" ,
233
+ "Cargo.toml.orig" ,
234
+ "src/main.rs" ,
235
+ "build1.rs" ,
236
+ "Cargo.lock" ,
237
+ ] ,
238
+ [ (
239
+ "Cargo.toml" ,
240
+ str![ [ r##"
241
+ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
242
+ #
243
+ # When uploading crates to the registry Cargo will automatically
244
+ # "normalize" Cargo.toml files for maximal compatibility
245
+ # with all versions of Cargo and also rewrite `path` dependencies
246
+ # to registry (e.g., crates.io) dependencies.
247
+ #
248
+ # If you are reading this file be aware that the original Cargo.toml
249
+ # will likely look very different (and much more reasonable).
250
+ # See Cargo.toml.orig for the original contents.
251
+
252
+ cargo-features = ["multiple-build-scripts"]
253
+
254
+ [package]
255
+ edition = "2024"
256
+ name = "foo"
257
+ version = "0.1.0"
258
+ authors = []
259
+ build = [
260
+ "build1.rs",
261
+ "build2.rs",
262
+ ]
263
+ include = [
264
+ "src/main.rs",
265
+ "build1.rs",
266
+ ]
267
+ autolib = false
268
+ autobins = false
269
+ autoexamples = false
270
+ autotests = false
271
+ autobenches = false
272
+ description = "foo"
273
+ documentation = "docs.rs/foo"
274
+ readme = false
275
+ license = "MIT"
276
+
277
+ [[bin]]
278
+ name = "foo"
279
+ path = "src/main.rs"
280
+
281
+ "## ] ] ,
282
+ ) ] ,
283
+ ) ;
284
+ }
285
+
286
+ fn add_git_vendor_config ( p : & Project , git_project : & Project ) {
287
+ p. change_file (
288
+ ".cargo/config.toml" ,
289
+ & format ! (
290
+ r#"
291
+ [source."git+{url}"]
292
+ git = "{url}"
293
+ replace-with = 'vendor'
294
+
295
+ [source.vendor]
296
+ directory = 'vendor'
297
+ "# ,
298
+ url = git_project. url( )
299
+ ) ,
300
+ ) ;
131
301
}
132
302
133
303
#[ cargo_test]
@@ -180,31 +350,67 @@ fn verify_vendor_multiple_build_scripts() {
180
350
181
351
p. cargo ( "vendor --respect-source-config" )
182
352
. masquerade_as_nightly_cargo ( & [ "multiple-build-scripts" ] )
183
- . with_status ( 101 )
353
+ . with_status ( 0 )
184
354
. with_stderr_data ( str![ [ r#"
185
355
[UPDATING] git repository `[ROOTURL]/dep`
186
- [ERROR] failed to sync
356
+ [LOCKING] 1 package to latest [..] compatible version
357
+ Vendoring dep v0.1.0 ([ROOTURL]/dep#[..]) ([ROOT]/home/.cargo/git/checkouts/dep-[HASH]/[..]) to vendor/dep
358
+ To use vendored sources, add this to your .cargo/config.toml for this project:
187
359
188
- Caused by:
189
- failed to load lockfile for [ROOT]/foo
190
-
191
- Caused by:
192
- failed to get `dep` as a dependency of package `foo v0.1.0 ([ROOT]/foo)`
193
-
194
- Caused by:
195
- failed to load source for dependency `dep`
196
-
197
- Caused by:
198
- Unable to update [ROOTURL]/dep
199
-
200
- Caused by:
201
- failed to parse manifest at `[ROOT]/home/.cargo/git/checkouts/dep-[HASH]/[..]/Cargo.toml`
202
-
203
- Caused by:
204
- multiple build scripts feature is not implemented yet!
205
360
206
361
"# ] ] )
207
362
. run ( ) ;
363
+ add_git_vendor_config ( & p, & git_project) ;
364
+
365
+ assert_e2e ( ) . eq (
366
+ p. read_file ( "vendor/dep/Cargo.toml" ) ,
367
+ str![ [ r##"
368
+ # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
369
+ #
370
+ # When uploading crates to the registry Cargo will automatically
371
+ # "normalize" Cargo.toml files for maximal compatibility
372
+ # with all versions of Cargo and also rewrite `path` dependencies
373
+ # to registry (e.g., crates.io) dependencies.
374
+ #
375
+ # If you are reading this file be aware that the original Cargo.toml
376
+ # will likely look very different (and much more reasonable).
377
+ # See Cargo.toml.orig for the original contents.
378
+
379
+ cargo-features = ["multiple-build-scripts"]
380
+
381
+ [package]
382
+ edition = "2024"
383
+ name = "dep"
384
+ version = "0.1.0"
385
+ authors = []
386
+ build = [
387
+ "build1.rs",
388
+ "build2.rs",
389
+ ]
390
+ include = [
391
+ "src/main.rs",
392
+ "build1.rs",
393
+ ]
394
+ autolib = false
395
+ autobins = false
396
+ autoexamples = false
397
+ autotests = false
398
+ autobenches = false
399
+ description = "dependency of foo"
400
+ documentation = "docs.rs/dep"
401
+ readme = false
402
+ license = "MIT"
403
+
404
+ [[bin]]
405
+ name = "dep"
406
+ path = "src/main.rs"
407
+
408
+ "## ] ] ,
409
+ ) ;
410
+
411
+ p. cargo ( "check" )
412
+ . masquerade_as_nightly_cargo ( & [ "multiple-build-scripts" ] )
413
+ . run ( ) ;
208
414
}
209
415
210
416
#[ cargo_test]
0 commit comments