@@ -103,13 +103,14 @@ def _find_cabal(srcs):
103
103
fail ("A .cabal file was not found in the srcs attribute." )
104
104
return cabal
105
105
106
- def _find_setup (hs , cabal , srcs ):
106
+ def _find_setup (hs , cabal , srcs , ignore_setup = False ):
107
107
"""Check that a Setup script exists. If not, create a default one."""
108
108
setup = None
109
- for f in srcs :
110
- if f .basename in ["Setup.hs" , "Setup.lhs" ]:
111
- if not setup or f .dirname < setup .dirname :
112
- setup = f
109
+ if not ignore_setup :
110
+ for f in srcs :
111
+ if f .basename in ["Setup.hs" , "Setup.lhs" ]:
112
+ if not setup or f .dirname < setup .dirname :
113
+ setup = f
113
114
if not setup :
114
115
setup = hs .actions .declare_file ("Setup.hs" , sibling = cabal )
115
116
hs .actions .write (
@@ -424,8 +425,10 @@ def _shorten_library_symlink(dynamic_library):
424
425
425
426
def _haskell_cabal_args_impl (ctx ):
426
427
is_empty = ctx .attr .is_empty
428
+ ignore_setup = ctx .attr .ignore_setup
427
429
cabal_args = HaskellCabalArgs (
428
430
is_empty = is_empty ,
431
+ ignore_setup = ignore_setup
429
432
)
430
433
return [cabal_args ]
431
434
@@ -437,6 +440,10 @@ haskell_cabal_args = rule(
437
440
doc = """True if this (sub) library is empty, with only re-exports, and no source files of its own.
438
441
It is necessary to set this, otherwise bazel will complain about missing "*libHS.a" files.""" ,
439
442
),
443
+ "ignore_setup" : attr .bool (
444
+ default = False ,
445
+ doc = """True if this package has a "Setup.hs" that is not a cabal "Setup.hs". """ ,
446
+ ),
440
447
},
441
448
provides = [HaskellCabalArgs ],
442
449
)
@@ -452,8 +459,10 @@ def _haskell_cabal_library_impl(ctx):
452
459
)
453
460
454
461
is_empty = False
462
+ ignore_setup = False
455
463
if ctx .attr .cabal_args :
456
464
is_empty = ctx .attr .cabal_args [HaskellCabalArgs ].is_empty
465
+ ignore_setup = ctx .attr .cabal_args [HaskellCabalArgs ].ignore_setup
457
466
458
467
# All C and Haskell library dependencies.
459
468
cc_info = cc_common .merge_cc_infos (
@@ -482,7 +491,7 @@ def _haskell_cabal_library_impl(ctx):
482
491
fail ("ERROR: `compiler_flags` attribute was removed. Use `cabalopts` with `--ghc-option` instead." )
483
492
484
493
cabal = _find_cabal (ctx .files .srcs )
485
- setup = _find_setup (hs , cabal , ctx .files .srcs )
494
+ setup = _find_setup (hs , cabal , ctx .files .srcs , ignore_setup )
486
495
package_database = hs .actions .declare_file (
487
496
"_install/{}.conf.d/package.cache" .format (package_id ),
488
497
sibling = cabal ,
@@ -823,6 +832,10 @@ def _haskell_cabal_binary_impl(ctx):
823
832
override_cc_toolchain = hs .tools_config .maybe_exec_cc_toolchain ,
824
833
)
825
834
835
+ ignore_setup = False
836
+ if ctx .attr .cabal_args :
837
+ ignore_setup = ctx .attr .cabal_args [HaskellCabalArgs ].ignore_setup
838
+
826
839
# All C and Haskell library dependencies.
827
840
cc_info = cc_common .merge_cc_infos (
828
841
cc_infos = [dep [CcInfo ] for dep in ctx .attr .deps if CcInfo in dep ],
@@ -844,7 +857,7 @@ def _haskell_cabal_binary_impl(ctx):
844
857
fail ("ERROR: `compiler_flags` attribute was removed. Use `cabalopts` with `--ghc-option` instead." )
845
858
846
859
cabal = _find_cabal (ctx .files .srcs )
847
- setup = _find_setup (hs , cabal , ctx .files .srcs )
860
+ setup = _find_setup (hs , cabal , ctx .files .srcs , ignore_setup )
848
861
package_database = hs .actions .declare_file (
849
862
"_install/{}.conf.d/package.cache" .format (hs .label .name ),
850
863
sibling = cabal ,
@@ -984,6 +997,10 @@ haskell_cabal_binary = rule(
984
997
"flags" : attr .string_list (
985
998
doc = "List of Cabal flags, will be passed to `Setup.hs configure --flags=...`." ,
986
999
),
1000
+ "cabal_args" : attr .label (
1001
+ doc = """A haskell_cabal_args target with cabal specific settings for this package.""" ,
1002
+ providers = [[HaskellCabalArgs ]],
1003
+ ),
987
1004
"_cabal_wrapper" : attr .label (
988
1005
executable = True ,
989
1006
cfg = "exec" ,
0 commit comments