22This module extension gathers packages and configuration from all the modules that use it,
33in order to make a unique call to `stack_snapshot` to generate a "stackage" shared repository.
44
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
66other modules can declare the packages they want installed.
77
88The rules_haskell module itself has more permissions, so that it can
@@ -13,6 +13,23 @@ snapshot to use.
1313load ("@rules_haskell//haskell:cabal.bzl" , _stack_snapshot = "stack_snapshot" )
1414load ("@bazel_skylib//lib:new_sets.bzl" , "sets" )
1515load ("@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 )
1633
1734_snapshot_tag = tag_class (
1835 doc = "The stack snapshot to use." ,
@@ -228,6 +245,7 @@ def _stack_snapshot_impl(mctx):
228245 rules_haskell_modules = []
229246 kwargs = {}
230247 for module in mctx .modules :
248+ print (module )
231249 if module .is_root :
232250 root_module = module
233251 if module .name == "rules_haskell" :
@@ -241,7 +259,7 @@ def _stack_snapshot_impl(mctx):
241259 snapshot_tag = module .tags .snapshot [0 ]
242260 if "snapshot" not in kwargs and "local_snapshot" not in kwargs :
243261 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 )
245263 if snapshot_tag .name :
246264 kwargs ["snapshot" ] = snapshot_tag .name
247265 else :
@@ -260,7 +278,7 @@ def _stack_snapshot_impl(mctx):
260278 cpu_value in os_list ,
261279 ])
262280 ):
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 )
264282 break
265283
266284 if module .tags .verbose :
0 commit comments