@@ -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 < PathBuf > ,
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. clone ( ) ,
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,13 @@ 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 ( ) && ws. get_requested_lockfile_path ( ) . is_some ( ) {
201
+ let requested_lockfile_path = ws. get_requested_lockfile_path ( ) . unwrap ( ) ;
202
+ paths:: create_dir_all ( ws. lock_root ( ) . as_path_unlocked ( ) ) ?;
203
+ fs:: rename ( ws. root ( ) . join ( "Cargo.lock" ) , requested_lockfile_path) ?;
204
+ }
192
205
let pkg = if source_id. is_git ( ) {
193
206
// Don't use ws.current() in order to keep the package source as a git source so that
194
207
// install tracking uses the correct source.
@@ -246,7 +259,6 @@ impl<'gctx> InstallablePackage<'gctx> {
246
259
vers : vers. cloned ( ) ,
247
260
force,
248
261
no_track,
249
-
250
262
pkg,
251
263
ws,
252
264
rustc,
@@ -620,6 +632,7 @@ pub fn install(
620
632
opts : & ops:: CompileOptions ,
621
633
force : bool ,
622
634
no_track : bool ,
635
+ lockfile_path : Option < PathBuf > ,
623
636
) -> CargoResult < ( ) > {
624
637
let root = resolve_root ( root, gctx) ?;
625
638
let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
@@ -651,6 +664,7 @@ pub fn install(
651
664
no_track,
652
665
true ,
653
666
current_rust_version. as_ref ( ) ,
667
+ lockfile_path. clone ( ) ,
654
668
) ?;
655
669
let mut installed_anything = true ;
656
670
if let Some ( installable_pkg) = installable_pkg {
@@ -682,6 +696,7 @@ pub fn install(
682
696
no_track,
683
697
!did_update,
684
698
current_rust_version. as_ref ( ) ,
699
+ lockfile_path. clone ( ) ,
685
700
) {
686
701
Ok ( Some ( installable_pkg) ) => {
687
702
did_update = true ;
@@ -788,6 +803,7 @@ fn installed_exact_package<T>(
788
803
root : & Filesystem ,
789
804
dst : & Path ,
790
805
force : bool ,
806
+ lockfile_path : Option < PathBuf > ,
791
807
) -> CargoResult < Option < Package > >
792
808
where
793
809
T : Source ,
@@ -803,7 +819,7 @@ where
803
819
// best-effort check to see if we can avoid hitting the network.
804
820
if let Ok ( pkg) = select_dep_pkg ( source, dep, gctx, false , None ) {
805
821
let ( _ws, rustc, target) =
806
- make_ws_rustc_target ( gctx, opts, & source. source_id ( ) , pkg. clone ( ) ) ?;
822
+ make_ws_rustc_target ( gctx, opts, & source. source_id ( ) , pkg. clone ( ) , lockfile_path ) ?;
807
823
if let Ok ( true ) = is_installed ( & pkg, gctx, opts, & rustc, & target, root, dst, force) {
808
824
return Ok ( Some ( pkg) ) ;
809
825
}
@@ -816,6 +832,7 @@ fn make_ws_rustc_target<'gctx>(
816
832
opts : & ops:: CompileOptions ,
817
833
source_id : & SourceId ,
818
834
pkg : Package ,
835
+ lockfile_path : Option < PathBuf > ,
819
836
) -> CargoResult < ( Workspace < ' gctx > , Rustc , String ) > {
820
837
let mut ws = if source_id. is_git ( ) || source_id. is_path ( ) {
821
838
Workspace :: new ( pkg. manifest_path ( ) , gctx) ?
@@ -825,6 +842,11 @@ fn make_ws_rustc_target<'gctx>(
825
842
ws
826
843
} ;
827
844
ws. set_ignore_lock ( gctx. lock_update_allowed ( ) ) ;
845
+ ws. set_requested_lockfile_path ( lockfile_path) ;
846
+ // if --lockfile-path is set, imply --locked
847
+ if ws. get_requested_lockfile_path ( ) . is_some ( ) {
848
+ ws. set_ignore_lock ( false ) ;
849
+ }
828
850
ws. set_require_optional_deps ( false ) ;
829
851
830
852
let rustc = gctx. load_global_rustc ( Some ( & ws) ) ?;
0 commit comments