Skip to content

Commit 0a21b99

Browse files
committed
Always create a file for exe stackage repository
When there are no executable components the repository rule would fail with a IOException, e.g.: ``` ERROR: /home/runner/.cache/bazel/_bazel_runner/8c1e0159f4edbec0d500d51744201c1f/bazel_testing/bazel_6/WORKSPACE:111:15: fetching _stack_executables rule //external:stackage-exe: java.io.IOException: _stack_executables rule //external:stackage-exe must create a directory ERROR: /home/runner/.cache/bazel/_bazel_runner/8c1e0159f4edbec0d500d51744201c1f/bazel_testing/bazel_6/BUILD.bazel:32:15: //:c2hs-toolchain-impl depends on @stackage-exe//c2hs:c2hs in repository @stackage-exe which failed to fetch. no such package '@stackage-exe//c2hs': _stack_executables rule //external:stackage-exe must create a directory ```
1 parent ad369aa commit 0a21b99

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

haskell/cabal.bzl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,10 +2283,11 @@ load("@{workspace}//:packages.bzl", "packages")
22832283
def _stack_executables_impl(repository_ctx):
22842284
workspace = repository_ctx.attr.unmangled_repo_name
22852285
all_components = json.decode(repository_ctx.read(repository_ctx.attr.components_json))
2286-
for (package, components) in all_components.items():
2287-
if not components["exe"]:
2288-
continue
2289-
repository_ctx.file(package + "/BUILD.bazel", executable = False, content = """\
2286+
executables = [package for package, components in all_components.items() if components["exe"]]
2287+
2288+
if executables:
2289+
for package in executables:
2290+
repository_ctx.file(package + "/BUILD.bazel", executable = False, content = """\
22902291
load("@{workspace}//:packages.bzl", "packages")
22912292
[
22922293
alias(
@@ -2297,9 +2298,12 @@ load("@{workspace}//:packages.bzl", "packages")
22972298
for exe in packages["{package}"].executables
22982299
]
22992300
""".format(
2300-
workspace = workspace,
2301-
package = package,
2302-
))
2301+
workspace = workspace,
2302+
package = package,
2303+
))
2304+
else:
2305+
# a repository rule has to create a file
2306+
repository_ctx.file("BUILD", executable = False)
23032307

23042308
_stack_executables = repository_rule(
23052309
_stack_executables_impl,

0 commit comments

Comments
 (0)