diff options
author | Vincent Ambo <tazjin@google.com> | 2019-07-04T10·18+0100 |
---|---|---|
committer | Vincent Ambo <tazjin@google.com> | 2019-07-04T10·18+0100 |
commit | f723b8b878a3c4a4687b9e337a875500bebb39b1 (patch) | |
tree | e85204cf042c355e90cff61c111e7d8cd15df311 /third_party/bazel/rules_haskell/haskell/private/java.bzl | |
parent | 2eb1dc26e42ffbdc168f05ef744bd4b4f3e4c36f (diff) |
feat(third_party/bazel): Check in rules_haskell from Tweag r/17
Diffstat (limited to 'third_party/bazel/rules_haskell/haskell/private/java.bzl')
-rw-r--r-- | third_party/bazel/rules_haskell/haskell/private/java.bzl | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/third_party/bazel/rules_haskell/haskell/private/java.bzl b/third_party/bazel/rules_haskell/haskell/private/java.bzl new file mode 100644 index 000000000000..44c4e114d7ba --- /dev/null +++ b/third_party/bazel/rules_haskell/haskell/private/java.bzl @@ -0,0 +1,48 @@ +"""Interop with Java.""" + +load("@bazel_skylib//lib:collections.bzl", "collections") + +JavaInteropInfo = provider( + doc = "Information needed for interop with Java rules.", + fields = { + "inputs": "Files needed during build.", + "env": "Dict with env variables that should be set during build.", + }, +) + +def java_interop_info(ctx): + """Gather information from any Java dependencies. + + Args: + ctx: Rule context. + + Returns: + JavaInteropInfo: Information needed for Java interop. + """ + + inputs = depset( + transitive = [ + # We only expose direct dependencies, though we could + # expose transitive ones as well. Only exposing the direct + # ones corresponds to Bazel's "strict Java dependencies" + # mode. See + # https://github.com/tweag/rules_haskell/issues/96. + dep[JavaInfo].compile_jars + for dep in ctx.attr.deps + if JavaInfo in dep + ], + ) + + env_dict = dict() + uniq_classpath = collections.uniq([ + f.path + for f in inputs + ]) + + if len(uniq_classpath) > 0: + env_dict["CLASSPATH"] = ":".join(uniq_classpath) + + return JavaInteropInfo( + inputs = inputs, + env = env_dict, + ) |