@@ -46,7 +46,6 @@ struct InstallablePackage<'gctx> {
4646 vers : Option < VersionReq > ,
4747 force : bool ,
4848 no_track : bool ,
49-
5049 pkg : Package ,
5150 ws : Workspace < ' gctx > ,
5251 rustc : Rustc ,
@@ -68,6 +67,7 @@ impl<'gctx> InstallablePackage<'gctx> {
6867 no_track : bool ,
6968 needs_update_if_source_is_index : bool ,
7069 current_rust_version : Option < & PartialVersion > ,
70+ lockfile_path : Option < PathBuf > ,
7171 ) -> CargoResult < Option < Self > > {
7272 if let Some ( name) = krate {
7373 if name == "." {
@@ -155,6 +155,7 @@ impl<'gctx> InstallablePackage<'gctx> {
155155 & root,
156156 & dst,
157157 force,
158+ lockfile_path. clone ( ) ,
158159 ) {
159160 let msg = format ! (
160161 "package `{}` is already installed, use --force to override" ,
@@ -179,8 +180,13 @@ impl<'gctx> InstallablePackage<'gctx> {
179180 }
180181 } ;
181182
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+ ) ?;
184190 // If we're installing in --locked mode and there's no `Cargo.lock` published
185191 // ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
186192 if gctx. locked ( ) && !ws. root ( ) . join ( "Cargo.lock" ) . exists ( ) {
@@ -189,6 +195,13 @@ impl<'gctx> InstallablePackage<'gctx> {
189195 pkg. to_string( )
190196 ) ) ?;
191197 }
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+ }
192205 let pkg = if source_id. is_git ( ) {
193206 // Don't use ws.current() in order to keep the package source as a git source so that
194207 // install tracking uses the correct source.
@@ -246,7 +259,6 @@ impl<'gctx> InstallablePackage<'gctx> {
246259 vers : vers. cloned ( ) ,
247260 force,
248261 no_track,
249-
250262 pkg,
251263 ws,
252264 rustc,
@@ -620,6 +632,7 @@ pub fn install(
620632 opts : & ops:: CompileOptions ,
621633 force : bool ,
622634 no_track : bool ,
635+ lockfile_path : Option < PathBuf > ,
623636) -> CargoResult < ( ) > {
624637 let root = resolve_root ( root, gctx) ?;
625638 let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
@@ -651,6 +664,7 @@ pub fn install(
651664 no_track,
652665 true ,
653666 current_rust_version. as_ref ( ) ,
667+ lockfile_path. clone ( ) ,
654668 ) ?;
655669 let mut installed_anything = true ;
656670 if let Some ( installable_pkg) = installable_pkg {
@@ -682,6 +696,7 @@ pub fn install(
682696 no_track,
683697 !did_update,
684698 current_rust_version. as_ref ( ) ,
699+ lockfile_path. clone ( ) ,
685700 ) {
686701 Ok ( Some ( installable_pkg) ) => {
687702 did_update = true ;
@@ -788,6 +803,7 @@ fn installed_exact_package<T>(
788803 root : & Filesystem ,
789804 dst : & Path ,
790805 force : bool ,
806+ lockfile_path : Option < PathBuf > ,
791807) -> CargoResult < Option < Package > >
792808where
793809 T : Source ,
@@ -803,7 +819,7 @@ where
803819 // best-effort check to see if we can avoid hitting the network.
804820 if let Ok ( pkg) = select_dep_pkg ( source, dep, gctx, false , None ) {
805821 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 ) ?;
807823 if let Ok ( true ) = is_installed ( & pkg, gctx, opts, & rustc, & target, root, dst, force) {
808824 return Ok ( Some ( pkg) ) ;
809825 }
@@ -816,6 +832,7 @@ fn make_ws_rustc_target<'gctx>(
816832 opts : & ops:: CompileOptions ,
817833 source_id : & SourceId ,
818834 pkg : Package ,
835+ lockfile_path : Option < PathBuf > ,
819836) -> CargoResult < ( Workspace < ' gctx > , Rustc , String ) > {
820837 let mut ws = if source_id. is_git ( ) || source_id. is_path ( ) {
821838 Workspace :: new ( pkg. manifest_path ( ) , gctx) ?
@@ -825,6 +842,11 @@ fn make_ws_rustc_target<'gctx>(
825842 ws
826843 } ;
827844 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+ }
828850 ws. set_require_optional_deps ( false ) ;
829851
830852 let rustc = gctx. load_global_rustc ( Some ( & ws) ) ?;
0 commit comments