@@ -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 < & Path > ,
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,
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,14 @@ 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 ( ) {
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+ }
192206 let pkg = if source_id. is_git ( ) {
193207 // Don't use ws.current() in order to keep the package source as a git source so that
194208 // install tracking uses the correct source.
@@ -246,7 +260,6 @@ impl<'gctx> InstallablePackage<'gctx> {
246260 vers : vers. cloned ( ) ,
247261 force,
248262 no_track,
249-
250263 pkg,
251264 ws,
252265 rustc,
@@ -636,6 +649,7 @@ pub fn install(
636649 force : bool ,
637650 no_track : bool ,
638651 dry_run : bool ,
652+ lockfile_path : Option < & Path > ,
639653) -> CargoResult < ( ) > {
640654 let root = resolve_root ( root, gctx) ?;
641655 let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
@@ -667,6 +681,7 @@ pub fn install(
667681 no_track,
668682 true ,
669683 current_rust_version. as_ref ( ) ,
684+ lockfile_path,
670685 ) ?;
671686 let mut installed_anything = true ;
672687 if let Some ( installable_pkg) = installable_pkg {
@@ -698,6 +713,7 @@ pub fn install(
698713 no_track,
699714 !did_update,
700715 current_rust_version. as_ref ( ) ,
716+ lockfile_path,
701717 ) {
702718 Ok ( Some ( installable_pkg) ) => {
703719 did_update = true ;
@@ -804,6 +820,7 @@ fn installed_exact_package<T>(
804820 root : & Filesystem ,
805821 dst : & Path ,
806822 force : bool ,
823+ lockfile_path : Option < & Path > ,
807824) -> CargoResult < Option < Package > >
808825where
809826 T : Source ,
@@ -819,7 +836,7 @@ where
819836 // best-effort check to see if we can avoid hitting the network.
820837 if let Ok ( pkg) = select_dep_pkg ( source, dep, gctx, false , None ) {
821838 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 ) ?;
823840 if let Ok ( true ) = is_installed ( & pkg, gctx, opts, & rustc, & target, root, dst, force) {
824841 return Ok ( Some ( pkg) ) ;
825842 }
@@ -832,6 +849,7 @@ fn make_ws_rustc_target<'gctx>(
832849 opts : & ops:: CompileOptions ,
833850 source_id : & SourceId ,
834851 pkg : Package ,
852+ lockfile_path : Option < & Path > ,
835853) -> CargoResult < ( Workspace < ' gctx > , Rustc , String ) > {
836854 let mut ws = if source_id. is_git ( ) || source_id. is_path ( ) {
837855 Workspace :: new ( pkg. manifest_path ( ) , gctx) ?
@@ -841,6 +859,11 @@ fn make_ws_rustc_target<'gctx>(
841859 ws
842860 } ;
843861 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+ }
844867 ws. set_require_optional_deps ( false ) ;
845868
846869 let rustc = gctx. load_global_rustc ( Some ( & ws) ) ?;
0 commit comments