@@ -46,7 +46,6 @@ struct InstallablePackage<'gctx> {
46
46
vers : Option < VersionReq > ,
47
47
force : bool ,
48
48
no_track : bool ,
49
-
50
49
pkg : Package ,
51
50
ws : Workspace < ' gctx > ,
52
51
rustc : Rustc ,
@@ -68,6 +67,7 @@ impl<'gctx> InstallablePackage<'gctx> {
68
67
no_track : bool ,
69
68
needs_update_if_source_is_index : bool ,
70
69
current_rust_version : Option < & PartialVersion > ,
70
+ lockfile_path : Option < & Path > ,
71
71
) -> CargoResult < Option < Self > > {
72
72
if let Some ( name) = krate {
73
73
if name == "." {
@@ -155,6 +155,7 @@ impl<'gctx> InstallablePackage<'gctx> {
155
155
& root,
156
156
& dst,
157
157
force,
158
+ lockfile_path,
158
159
) {
159
160
let msg = format ! (
160
161
"package `{}` is already installed, use --force to override" ,
@@ -179,8 +180,13 @@ impl<'gctx> InstallablePackage<'gctx> {
179
180
}
180
181
} ;
181
182
182
- let ( ws, rustc, target) =
183
- make_ws_rustc_target ( gctx, & original_opts, & source_id, pkg. clone ( ) ) ?;
183
+ let ( ws, rustc, target) = make_ws_rustc_target (
184
+ gctx,
185
+ & original_opts,
186
+ & source_id,
187
+ pkg. clone ( ) ,
188
+ lockfile_path. clone ( ) ,
189
+ ) ?;
184
190
// If we're installing in --locked mode and there's no `Cargo.lock` published
185
191
// ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
186
192
if gctx. locked ( ) && !ws. root ( ) . join ( "Cargo.lock" ) . exists ( ) {
@@ -189,6 +195,14 @@ impl<'gctx> InstallablePackage<'gctx> {
189
195
pkg. to_string( )
190
196
) ) ?;
191
197
}
198
+ // When --lockfile-path is set, move lock file to the new location
199
+ // (the new location is expected downstream and will be used during compilation)
200
+ if gctx. locked ( ) {
201
+ if let Some ( requested_lockfile_path) = ws. requested_lockfile_path ( ) {
202
+ paths:: create_dir_all ( ws. lock_root ( ) . as_path_unlocked ( ) ) ?;
203
+ fs:: rename ( ws. root ( ) . join ( "Cargo.lock" ) , requested_lockfile_path) ?;
204
+ }
205
+ }
192
206
let pkg = if source_id. is_git ( ) {
193
207
// Don't use ws.current() in order to keep the package source as a git source so that
194
208
// install tracking uses the correct source.
@@ -246,7 +260,6 @@ impl<'gctx> InstallablePackage<'gctx> {
246
260
vers : vers. cloned ( ) ,
247
261
force,
248
262
no_track,
249
-
250
263
pkg,
251
264
ws,
252
265
rustc,
@@ -636,6 +649,7 @@ pub fn install(
636
649
force : bool ,
637
650
no_track : bool ,
638
651
dry_run : bool ,
652
+ lockfile_path : Option < & Path > ,
639
653
) -> CargoResult < ( ) > {
640
654
let root = resolve_root ( root, gctx) ?;
641
655
let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
@@ -667,6 +681,7 @@ pub fn install(
667
681
no_track,
668
682
true ,
669
683
current_rust_version. as_ref ( ) ,
684
+ lockfile_path,
670
685
) ?;
671
686
let mut installed_anything = true ;
672
687
if let Some ( installable_pkg) = installable_pkg {
@@ -698,6 +713,7 @@ pub fn install(
698
713
no_track,
699
714
!did_update,
700
715
current_rust_version. as_ref ( ) ,
716
+ lockfile_path,
701
717
) {
702
718
Ok ( Some ( installable_pkg) ) => {
703
719
did_update = true ;
@@ -804,6 +820,7 @@ fn installed_exact_package<T>(
804
820
root : & Filesystem ,
805
821
dst : & Path ,
806
822
force : bool ,
823
+ lockfile_path : Option < & Path > ,
807
824
) -> CargoResult < Option < Package > >
808
825
where
809
826
T : Source ,
@@ -819,7 +836,7 @@ where
819
836
// best-effort check to see if we can avoid hitting the network.
820
837
if let Ok ( pkg) = select_dep_pkg ( source, dep, gctx, false , None ) {
821
838
let ( _ws, rustc, target) =
822
- make_ws_rustc_target ( gctx, opts, & source. source_id ( ) , pkg. clone ( ) ) ?;
839
+ make_ws_rustc_target ( gctx, opts, & source. source_id ( ) , pkg. clone ( ) , lockfile_path ) ?;
823
840
if let Ok ( true ) = is_installed ( & pkg, gctx, opts, & rustc, & target, root, dst, force) {
824
841
return Ok ( Some ( pkg) ) ;
825
842
}
@@ -832,6 +849,7 @@ fn make_ws_rustc_target<'gctx>(
832
849
opts : & ops:: CompileOptions ,
833
850
source_id : & SourceId ,
834
851
pkg : Package ,
852
+ lockfile_path : Option < & Path > ,
835
853
) -> CargoResult < ( Workspace < ' gctx > , Rustc , String ) > {
836
854
let mut ws = if source_id. is_git ( ) || source_id. is_path ( ) {
837
855
Workspace :: new ( pkg. manifest_path ( ) , gctx) ?
@@ -841,6 +859,11 @@ fn make_ws_rustc_target<'gctx>(
841
859
ws
842
860
} ;
843
861
ws. set_ignore_lock ( gctx. lock_update_allowed ( ) ) ;
862
+ ws. set_requested_lockfile_path ( lockfile_path. map ( |p| p. to_path_buf ( ) ) ) ;
863
+ // if --lockfile-path is set, imply --locked
864
+ if ws. requested_lockfile_path ( ) . is_some ( ) {
865
+ ws. set_ignore_lock ( false ) ;
866
+ }
844
867
ws. set_require_optional_deps ( false ) ;
845
868
846
869
let rustc = gctx. load_global_rustc ( Some ( & ws) ) ?;
0 commit comments