2
2
This module extension gathers packages and configuration from all the modules that use it,
3
3
in order to make a unique call to `stack_snapshot` to generate a "stackage" shared repository.
4
4
5
- Most of the configuration can only be made by the root module, and
5
+ Most of the configuration can only be made by the root module, and
6
6
other modules can declare the packages they want installed.
7
7
8
8
The rules_haskell module itself has more permissions, so that it can
@@ -13,6 +13,23 @@ snapshot to use.
13
13
load ("@rules_haskell//haskell:cabal.bzl" , _stack_snapshot = "stack_snapshot" )
14
14
load ("@bazel_skylib//lib:new_sets.bzl" , "sets" )
15
15
load ("@os_info//:os_info.bzl" , "cpu_value" , "is_darwin" , "is_linux" , "is_windows" )
16
+ load ("@rules_haskell_ghc_version//:ghc_version.bzl" , "GHC_VERSION" )
17
+
18
+ def _ghc_versioned (label , is_rules_haskell ):
19
+ """
20
+ Add the GHC version to the name of the given label.
21
+ """
22
+ if not GHC_VERSION or not is_rules_haskell :
23
+ return label
24
+
25
+ name , ext = label .name .split ("." )
26
+ versioned = ":{name}_{version}.{ext}" .format (
27
+ name = name ,
28
+ version = GHC_VERSION ,
29
+ ext = ext ,
30
+ )
31
+
32
+ return label .relative (versioned )
16
33
17
34
_snapshot_tag = tag_class (
18
35
doc = "The stack snapshot to use." ,
@@ -228,6 +245,7 @@ def _stack_snapshot_impl(mctx):
228
245
rules_haskell_modules = []
229
246
kwargs = {}
230
247
for module in mctx .modules :
248
+ print (module )
231
249
if module .is_root :
232
250
root_module = module
233
251
if module .name == "rules_haskell" :
@@ -241,7 +259,7 @@ def _stack_snapshot_impl(mctx):
241
259
snapshot_tag = module .tags .snapshot [0 ]
242
260
if "snapshot" not in kwargs and "local_snapshot" not in kwargs :
243
261
if snapshot_tag .local_snapshot :
244
- kwargs ["local_snapshot" ] = snapshot_tag .local_snapshot
262
+ kwargs ["local_snapshot" ] = _ghc_versioned ( snapshot_tag .local_snapshot , is_rules_haskell = module in rules_haskell_modules )
245
263
if snapshot_tag .name :
246
264
kwargs ["snapshot" ] = snapshot_tag .name
247
265
else :
@@ -260,7 +278,7 @@ def _stack_snapshot_impl(mctx):
260
278
cpu_value in os_list ,
261
279
])
262
280
):
263
- kwargs ["stack_snapshot_json" ] = stack_snapshot_json_tag .label
281
+ kwargs ["stack_snapshot_json" ] = _ghc_versioned ( stack_snapshot_json_tag .label , is_rules_haskell = module in rules_haskell_modules )
264
282
break
265
283
266
284
if module .tags .verbose :
0 commit comments