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(
645
645
config_path = config_file ,
646
646
output_dir = tag_path .get_child ("splicing-output" ),
647
647
debug_workspace_dir = tag_path .get_child ("splicing-workspace" ),
648
+ skip_cargo_lockfile_overwrite = cfg .skip_cargo_lockfile_overwrite ,
648
649
repository_name = cfg .name ,
649
650
)
650
651
Original file line number Diff line number Diff line change @@ -497,9 +497,7 @@ def execute_generator(
497
497
])
498
498
499
499
if skip_cargo_lockfile_overwrite :
500
- args .extend ([
501
- "--skip-cargo-lockfile-overwrite" ,
502
- ])
500
+ args .append ("--skip-cargo-lockfile-overwrite" )
503
501
504
502
# Some components are not required unless re-pinning is enabled
505
503
if metadata :
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ def splice_workspace_manifest(
123
123
config_path ,
124
124
output_dir ,
125
125
repository_name ,
126
+ skip_cargo_lockfile_overwrite ,
126
127
debug_workspace_dir = None ):
127
128
"""Splice together a Cargo workspace from various other manifests and package definitions
128
129
@@ -134,6 +135,9 @@ def splice_workspace_manifest(
134
135
config_path (path): The path to the config file (containing `cargo_bazel::config::Config`.)
135
136
output_dir (path): THe location in which to write splicing outputs.
136
137
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.
137
141
debug_workspace_dir (path): The location in which to save splicing outputs for future review.
138
142
139
143
Returns:
@@ -159,6 +163,9 @@ def splice_workspace_manifest(
159
163
cargo_lockfile ,
160
164
])
161
165
166
+ if skip_cargo_lockfile_overwrite :
167
+ arguments .append ("--skip-cargo-lockfile-overwrite" )
168
+
162
169
# Optionally set the splicing workspace directory to somewhere within the repository directory
163
170
# to improve the debugging experience.
164
171
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 {
64
64
/// The name of the repository being generated.
65
65
#[ clap( long) ]
66
66
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 ,
67
73
}
68
74
69
75
/// Combine a set of disjoint manifests into a single workspace.
@@ -94,14 +100,22 @@ pub fn splice(opt: SpliceOptions) -> Result<()> {
94
100
. splice ( & splicing_dir)
95
101
. with_context ( || format ! ( "Failed to splice workspace {}" , opt. repository_name) ) ?;
96
102
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
+ } ;
105
119
106
120
let config = Config :: try_from_path ( & opt. config ) . context ( "Failed to parse config" ) ?;
107
121
You can’t perform that action at this time.
0 commit comments