1
1
"""Implementation for `swift_deps` bzlmod extension."""
2
2
3
3
load ("@bazel_skylib//lib:dicts.bzl" , "dicts" )
4
+ load ("@bazel_skylib//lib:paths.bzl" , "paths" )
4
5
load ("//swiftpkg/internal:bazel_repo_names.bzl" , "bazel_repo_names" )
5
6
load ("//swiftpkg/internal:local_swift_package.bzl" , "local_swift_package" )
6
7
load ("//swiftpkg/internal:pkginfos.bzl" , "pkginfos" )
@@ -59,11 +60,21 @@ def _declare_pkgs_from_package(module_ctx, from_package, config_pkgs, config_swi
59
60
# Get the package info.
60
61
pkg_swift = module_ctx .path (from_package .swift )
61
62
debug_path = module_ctx .path ("." )
63
+ workspace_root = str (pkg_swift .dirname )
64
+
65
+ root_cached_json_directory = None
66
+ if from_package .cached_json_directory :
67
+ root_cached_json_directory = paths .join (
68
+ workspace_root ,
69
+ from_package .cached_json_directory ,
70
+ )
71
+
62
72
pkg_info = pkginfos .get (
63
73
module_ctx ,
64
- directory = str ( pkg_swift . dirname ) ,
74
+ directory = workspace_root ,
65
75
env = env ,
66
76
debug_path = str (debug_path ),
77
+ cached_json_directory = root_cached_json_directory ,
67
78
resolved_pkg_map = resolved_pkg_map ,
68
79
collect_src_info = False ,
69
80
registries_directory = registries_directory ,
@@ -157,10 +168,18 @@ the Swift package to make it available.\
157
168
processing = to_process
158
169
to_process = []
159
170
for dep in processing :
171
+ dep_cached_json_directory = None
172
+
173
+ if from_package .cached_json_directory :
174
+ dep_cached_json_directory = paths .join (
175
+ dep .file_system .path ,
176
+ from_package .cached_json_directory ,
177
+ )
160
178
dep_pkg_info = pkginfos .get (
161
179
module_ctx ,
162
180
directory = dep .file_system .path ,
163
181
debug_path = None ,
182
+ cached_json_directory = dep_cached_json_directory ,
164
183
resolved_pkg_map = None ,
165
184
collect_src_info = False ,
166
185
)
@@ -185,7 +204,13 @@ the Swift package to make it available.\
185
204
config_pkg = config_pkgs .get (
186
205
bazel_repo_names .from_identity (dep .identity ),
187
206
)
188
- _declare_pkg_from_dependency (dep , config_pkg , from_package , config_swift_package )
207
+ _declare_pkg_from_dependency (
208
+ dep ,
209
+ config_pkg ,
210
+ from_package ,
211
+ config_swift_package ,
212
+ from_package .cached_json_directory ,
213
+ )
189
214
190
215
# Add all transitive dependencies to direct_dep_repo_names if `publicly_expose_all_targets` flag is set.
191
216
for dep in all_deps_by_id .values ():
@@ -199,7 +224,15 @@ the Swift package to make it available.\
199
224
200
225
return direct_dep_repo_names
201
226
202
- def _declare_pkg_from_dependency (dep , config_pkg , from_package , config_swift_package ):
227
+ def _declare_pkg_from_dependency (
228
+ dep ,
229
+ config_pkg ,
230
+ from_package ,
231
+ config_swift_package ,
232
+ cached_json_directory ):
233
+ if cached_json_directory :
234
+ cached_json_directory = paths .join (cached_json_directory , dep .name )
235
+
203
236
name = bazel_repo_names .from_identity (dep .identity )
204
237
if dep .source_control :
205
238
init_submodules = None
@@ -236,7 +269,7 @@ def _declare_pkg_from_dependency(dep, config_pkg, from_package, config_swift_pac
236
269
dependencies_index = None ,
237
270
env = from_package .env ,
238
271
env_inherit = from_package .env_inherit ,
239
- init_submodules = init_submodules ,
272
+ cached_json_directory = cached_json_directory , init_submodules = init_submodules ,
240
273
recursive_init_submodules = recursive_init_submodules ,
241
274
patch_args = patch_args ,
242
275
patch_cmds = patch_cmds ,
@@ -256,6 +289,7 @@ def _declare_pkg_from_dependency(dep, config_pkg, from_package, config_swift_pac
256
289
env_inherit = from_package .env_inherit ,
257
290
path = dep .file_system .path ,
258
291
dependencies_index = None ,
292
+ cached_json_directory = cached_json_directory ,
259
293
)
260
294
261
295
elif dep .registry :
@@ -350,6 +384,7 @@ bazel run @swift_package//:resolve
350
384
```
351
385
""" ,
352
386
),
387
+ "cached_json_directory" : attr .string (),
353
388
"env" : attr .string_dict (
354
389
doc = """\
355
390
Environment variables that will be passed to the execution environments for \
0 commit comments