File tree Expand file tree Collapse file tree 4 files changed +31
-11
lines changed Expand file tree Collapse file tree 4 files changed +31
-11
lines changed Original file line number Diff line number Diff line change @@ -645,6 +645,7 @@ def _generate_hub_and_spokes(
645645 config_path = config_file ,
646646 output_dir = tag_path .get_child ("splicing-output" ),
647647 debug_workspace_dir = tag_path .get_child ("splicing-workspace" ),
648+ skip_cargo_lockfile_overwrite = cfg .skip_cargo_lockfile_overwrite ,
648649 repository_name = cfg .name ,
649650 )
650651
Original file line number Diff line number Diff line change @@ -497,9 +497,7 @@ def execute_generator(
497497 ])
498498
499499 if skip_cargo_lockfile_overwrite :
500- args .extend ([
501- "--skip-cargo-lockfile-overwrite" ,
502- ])
500+ args .append ("--skip-cargo-lockfile-overwrite" )
503501
504502 # Some components are not required unless re-pinning is enabled
505503 if metadata :
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ def splice_workspace_manifest(
123123 config_path ,
124124 output_dir ,
125125 repository_name ,
126+ skip_cargo_lockfile_overwrite ,
126127 debug_workspace_dir = None ):
127128 """Splice together a Cargo workspace from various other manifests and package definitions
128129
@@ -134,6 +135,9 @@ def splice_workspace_manifest(
134135 config_path (path): The path to the config file (containing `cargo_bazel::config::Config`.)
135136 output_dir (path): THe location in which to write splicing outputs.
136137 repository_name (str): Name of the repository being generated.
138+ skip_cargo_lockfile_overwrite (bool): Whether to skip writing the cargo lockfile back after resolving.
139+ You may want to set this if your dependency versions are maintained externally through a non-trivial set-up.
140+ But you probably don't want to set this.
137141 debug_workspace_dir (path): The location in which to save splicing outputs for future review.
138142
139143 Returns:
@@ -159,6 +163,9 @@ def splice_workspace_manifest(
159163 cargo_lockfile ,
160164 ])
161165
166+ if skip_cargo_lockfile_overwrite :
167+ arguments .append ("--skip-cargo-lockfile-overwrite" )
168+
162169 # Optionally set the splicing workspace directory to somewhere within the repository directory
163170 # to improve the debugging experience.
164171 if CARGO_BAZEL_DEBUG in repository_ctx .os .environ :
Original file line number Diff line number Diff line change @@ -64,6 +64,12 @@ pub struct SpliceOptions {
6464 /// The name of the repository being generated.
6565 #[ clap( long) ]
6666 pub repository_name : String ,
67+
68+ /// Whether to skip writing the cargo lockfile back after resolving.
69+ /// You may want to set this if your dependency versions are maintained externally through a non-trivial set-up.
70+ /// But you probably don't want to set this.
71+ #[ clap( long) ]
72+ pub skip_cargo_lockfile_overwrite : bool ,
6773}
6874
6975/// Combine a set of disjoint manifests into a single workspace.
@@ -94,14 +100,22 @@ pub fn splice(opt: SpliceOptions) -> Result<()> {
94100 . splice ( & splicing_dir)
95101 . with_context ( || format ! ( "Failed to splice workspace {}" , opt. repository_name) ) ?;
96102
97- // Generate a lockfile
98- let cargo_lockfile = generate_lockfile (
99- & manifest_path,
100- & opt. cargo_lockfile ,
101- cargo. clone ( ) ,
102- & opt. repin ,
103- )
104- . context ( "Failed to generate lockfile" ) ?;
103+ // Use the existing lockfile if possible, otherwise generate a new one.
104+ let cargo_lockfile = if opt. cargo_lockfile . is_some ( ) && opt. skip_cargo_lockfile_overwrite {
105+ let cargo_lockfile_path = opt. cargo_lockfile . unwrap ( ) ;
106+ cargo_lock:: Lockfile :: load ( & cargo_lockfile_path) . context ( format ! (
107+ "Failed to load lockfile: {}" ,
108+ cargo_lockfile_path. display( )
109+ ) ) ?
110+ } else {
111+ generate_lockfile (
112+ & manifest_path,
113+ & opt. cargo_lockfile ,
114+ cargo. clone ( ) ,
115+ & opt. repin ,
116+ )
117+ . context ( "Failed to generate lockfile" ) ?
118+ } ;
105119
106120 let config = Config :: try_from_path ( & opt. config ) . context ( "Failed to parse config" ) ?;
107121
You can’t perform that action at this time.
0 commit comments