@@ -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,15 +180,32 @@ impl<'gctx> InstallablePackage<'gctx> {
179180 }
180181 } ;
181182
182- let ( ws, rustc, target) =
183- make_ws_rustc_target ( gctx, & original_opts, & source_id, pkg. clone ( ) ) ?;
184- // If we're installing in --locked mode and there's no `Cargo.lock` published
185- // ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
186- if gctx. locked ( ) && !ws. root ( ) . join ( "Cargo.lock" ) . exists ( ) {
187- gctx. shell ( ) . warn ( format ! (
188- "no Cargo.lock file published in {}" ,
189- pkg. to_string( )
190- ) ) ?;
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+ ) ?;
190+
191+ if gctx. locked ( ) {
192+ // When --lockfile-path is set, check that passed lock file exists
193+ // (unlike the usual flag behavior, lockfile won't be created as we imply --locked)
194+ if let Some ( requested_lockfile_path) = ws. requested_lockfile_path ( ) {
195+ if !requested_lockfile_path. is_file ( ) {
196+ bail ! (
197+ "no Cargo.lock file found in the requested path {}" ,
198+ requested_lockfile_path. display( )
199+ ) ;
200+ }
201+ // If we're installing in --locked mode and there's no `Cargo.lock` published
202+ // ie. the bin was published before https://github.com/rust-lang/cargo/pull/7026
203+ } else if !ws. root ( ) . join ( "Cargo.lock" ) . exists ( ) {
204+ gctx. shell ( ) . warn ( format ! (
205+ "no Cargo.lock file published in {}" ,
206+ pkg. to_string( )
207+ ) ) ?;
208+ }
191209 }
192210 let pkg = if source_id. is_git ( ) {
193211 // Don't use ws.current() in order to keep the package source as a git source so that
@@ -246,7 +264,6 @@ impl<'gctx> InstallablePackage<'gctx> {
246264 vers : vers. cloned ( ) ,
247265 force,
248266 no_track,
249-
250267 pkg,
251268 ws,
252269 rustc,
@@ -636,6 +653,7 @@ pub fn install(
636653 force : bool ,
637654 no_track : bool ,
638655 dry_run : bool ,
656+ lockfile_path : Option < & Path > ,
639657) -> CargoResult < ( ) > {
640658 let root = resolve_root ( root, gctx) ?;
641659 let dst = root. join ( "bin" ) . into_path_unlocked ( ) ;
@@ -667,6 +685,7 @@ pub fn install(
667685 no_track,
668686 true ,
669687 current_rust_version. as_ref ( ) ,
688+ lockfile_path,
670689 ) ?;
671690 let mut installed_anything = true ;
672691 if let Some ( installable_pkg) = installable_pkg {
@@ -698,6 +717,7 @@ pub fn install(
698717 no_track,
699718 !did_update,
700719 current_rust_version. as_ref ( ) ,
720+ lockfile_path,
701721 ) {
702722 Ok ( Some ( installable_pkg) ) => {
703723 did_update = true ;
@@ -804,6 +824,7 @@ fn installed_exact_package<T>(
804824 root : & Filesystem ,
805825 dst : & Path ,
806826 force : bool ,
827+ lockfile_path : Option < & Path > ,
807828) -> CargoResult < Option < Package > >
808829where
809830 T : Source ,
@@ -819,7 +840,7 @@ where
819840 // best-effort check to see if we can avoid hitting the network.
820841 if let Ok ( pkg) = select_dep_pkg ( source, dep, gctx, false , None ) {
821842 let ( _ws, rustc, target) =
822- make_ws_rustc_target ( gctx, opts, & source. source_id ( ) , pkg. clone ( ) ) ?;
843+ make_ws_rustc_target ( gctx, opts, & source. source_id ( ) , pkg. clone ( ) , lockfile_path ) ?;
823844 if let Ok ( true ) = is_installed ( & pkg, gctx, opts, & rustc, & target, root, dst, force) {
824845 return Ok ( Some ( pkg) ) ;
825846 }
@@ -832,6 +853,7 @@ fn make_ws_rustc_target<'gctx>(
832853 opts : & ops:: CompileOptions ,
833854 source_id : & SourceId ,
834855 pkg : Package ,
856+ lockfile_path : Option < & Path > ,
835857) -> CargoResult < ( Workspace < ' gctx > , Rustc , String ) > {
836858 let mut ws = if source_id. is_git ( ) || source_id. is_path ( ) {
837859 Workspace :: new ( pkg. manifest_path ( ) , gctx) ?
@@ -841,6 +863,11 @@ fn make_ws_rustc_target<'gctx>(
841863 ws
842864 } ;
843865 ws. set_ignore_lock ( gctx. lock_update_allowed ( ) ) ;
866+ ws. set_requested_lockfile_path ( lockfile_path. map ( |p| p. to_path_buf ( ) ) ) ;
867+ // if --lockfile-path is set, imply --locked
868+ if ws. requested_lockfile_path ( ) . is_some ( ) {
869+ ws. set_ignore_lock ( false ) ;
870+ }
844871 ws. set_require_optional_deps ( false ) ;
845872
846873 let rustc = gctx. load_global_rustc ( Some ( & ws) ) ?;
0 commit comments