File tree Expand file tree Collapse file tree 4 files changed +18
-50
lines changed Expand file tree Collapse file tree 4 files changed +18
-50
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ pub struct PackageOpts<'cfg> {
41
41
static VCS_INFO_FILE : & ' static str = ".cargo_vcs_info.json" ;
42
42
43
43
pub fn package ( ws : & Workspace < ' _ > , opts : & PackageOpts < ' _ > ) -> CargoResult < Option < FileLock > > {
44
+ // Make sure the Cargo.lock is up-to-date and valid.
45
+ ops:: resolve_ws ( ws) ?;
44
46
let pkg = ws. current ( ) ?;
45
47
let config = ws. config ( ) ;
46
48
Original file line number Diff line number Diff line change @@ -181,6 +181,12 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
181
181
if self . config . cli_unstable ( ) . no_index_update {
182
182
return Ok ( ( ) ) ;
183
183
}
184
+ // Make sure the index is only updated once per session since it is an
185
+ // expensive operation. This generally only happens when the resolver
186
+ // is run multiple times, such as during `cargo publish`.
187
+ if self . config . updated_sources ( ) . contains ( & self . source_id ) {
188
+ return Ok ( ( ) ) ;
189
+ }
184
190
185
191
debug ! ( "updating the index" ) ;
186
192
@@ -208,6 +214,7 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
208
214
let repo = self . repo . borrow_mut ( ) . unwrap ( ) ;
209
215
git:: fetch ( repo, url, refspec, self . config )
210
216
. chain_err ( || format ! ( "failed to fetch `{}`" , url) ) ?;
217
+ self . config . updated_sources ( ) . insert ( self . source_id ) ;
211
218
Ok ( ( ) )
212
219
}
213
220
Original file line number Diff line number Diff line change @@ -74,6 +74,8 @@ pub struct Config {
74
74
env : HashMap < String , String > ,
75
75
/// Profiles loaded from config.
76
76
profiles : LazyCell < ConfigProfiles > ,
77
+ /// Tracks which sources have been updated to avoid multiple updates.
78
+ updated_sources : LazyCell < RefCell < HashSet < SourceId > > > ,
77
79
}
78
80
79
81
impl Config {
@@ -129,6 +131,7 @@ impl Config {
129
131
target_dir : None ,
130
132
env,
131
133
profiles : LazyCell :: new ( ) ,
134
+ updated_sources : LazyCell :: new ( ) ,
132
135
}
133
136
}
134
137
@@ -271,6 +274,12 @@ impl Config {
271
274
} )
272
275
}
273
276
277
+ pub fn updated_sources ( & self ) -> RefMut < ' _ , HashSet < SourceId > > {
278
+ self . updated_sources . borrow_with ( || {
279
+ RefCell :: new ( HashSet :: new ( ) )
280
+ } ) . borrow_mut ( )
281
+ }
282
+
274
283
pub fn values ( & self ) -> CargoResult < & HashMap < String , ConfigValue > > {
275
284
self . values . try_borrow_with ( || self . load_values ( ) )
276
285
}
Original file line number Diff line number Diff line change @@ -268,54 +268,6 @@ fn no_warn_workspace_extras() {
268
268
. run ( ) ;
269
269
}
270
270
271
- #[ test]
272
- fn out_of_date_lock_note ( ) {
273
- // Dependency is force-changed from an out-of-date Cargo.lock.
274
- Package :: new ( "dep" , "1.0.0" ) . publish ( ) ;
275
- Package :: new ( "dep" , "2.0.0" ) . publish ( ) ;
276
-
277
- let p = project ( )
278
- . file (
279
- "Cargo.toml" ,
280
- & pl_manifest (
281
- "foo" ,
282
- "0.0.1" ,
283
- r#"
284
- [dependencies]
285
- dep = "1.0"
286
- "# ,
287
- ) ,
288
- )
289
- . file ( "src/main.rs" , "fn main() {}" )
290
- . build ( ) ;
291
- p. cargo ( "generate-lockfile" )
292
- . masquerade_as_nightly_cargo ( )
293
- . run ( ) ;
294
- p. change_file (
295
- "Cargo.toml" ,
296
- & pl_manifest (
297
- "foo" ,
298
- "0.0.1" ,
299
- r#"
300
- [dependencies]
301
- dep = "2.0"
302
- "# ,
303
- ) ,
304
- ) ;
305
- p. cargo ( "package --no-verify -v --allow-dirty" )
306
- . masquerade_as_nightly_cargo ( )
307
- . with_stderr (
308
- "\
309
- [PACKAGING] foo v0.0.1 ([..])
310
- [ARCHIVING] Cargo.toml
311
- [ARCHIVING] src/main.rs
312
- [UPDATING] `[..]` index
313
- [NOTE] package `dep v2.0.0` added to the packaged Cargo.lock file, previous version was `1.0.0`
314
- " ,
315
- )
316
- . run ( ) ;
317
- }
318
-
319
271
#[ test]
320
272
fn warn_package_with_yanked ( ) {
321
273
Package :: new ( "bar" , "0.1.0" ) . publish ( ) ;
@@ -377,15 +329,13 @@ dependencies = [
377
329
)
378
330
. publish ( ) ;
379
331
380
- // It is unfortunate that this displays UPDATING twice.
381
332
cargo_process ( "install --locked foo" )
382
333
. with_stderr (
383
334
"\
384
335
[UPDATING] `[..]` index
385
336
[DOWNLOADING] crates ...
386
337
[DOWNLOADED] foo v0.1.0 (registry `[..]`)
387
338
[INSTALLING] foo v0.1.0
388
- [UPDATING] `[..]` index
389
339
[WARNING] package `bar v0.1.0` in Cargo.lock is yanked in registry \
390
340
`crates.io`, consider running without --locked
391
341
[DOWNLOADING] crates ...
You can’t perform that action at this time.
0 commit comments