about summary refs log tree commit diff
path: root/third_party/bazel/rules_haskell/haskell/private/version_macros.bzl
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-07-04T10·18+0100
committerVincent Ambo <tazjin@google.com>2019-07-04T10·18+0100
commitf723b8b878a3c4a4687b9e337a875500bebb39b1 (patch)
treee85204cf042c355e90cff61c111e7d8cd15df311 /third_party/bazel/rules_haskell/haskell/private/version_macros.bzl
parent2eb1dc26e42ffbdc168f05ef744bd4b4f3e4c36f (diff)
feat(third_party/bazel): Check in rules_haskell from Tweag r/17
Diffstat (limited to 'third_party/bazel/rules_haskell/haskell/private/version_macros.bzl')
-rw-r--r--third_party/bazel/rules_haskell/haskell/private/version_macros.bzl47
1 files changed, 47 insertions, 0 deletions
diff --git a/third_party/bazel/rules_haskell/haskell/private/version_macros.bzl b/third_party/bazel/rules_haskell/haskell/private/version_macros.bzl
new file mode 100644
index 000000000000..35f913f26b01
--- /dev/null
+++ b/third_party/bazel/rules_haskell/haskell/private/version_macros.bzl
@@ -0,0 +1,47 @@
+load(":private/set.bzl", "set")
+
+def generate_version_macros(ctx, name, version):
+    """Generate a version macros header file.
+
+    Args:
+        ctx: Rule context. Needs to define a _version_macros executable attribute.
+        name: The package name.
+        version: The package version.
+
+    Returns:
+        Version macros header File.
+    """
+    version_macros_file = ctx.actions.declare_file("{}_version_macros.h".format(name))
+    ctx.actions.run_shell(
+        inputs = [ctx.executable._version_macros],
+        outputs = [version_macros_file],
+        command = """
+        "$1" "$2" "$3" > "$4"
+        """,
+        arguments = [
+            ctx.executable._version_macros.path,
+            name,
+            version,
+            version_macros_file.path,
+        ],
+    )
+    return version_macros_file
+
+def version_macro_includes(hs_info):
+    """Generate a list of version macro header includes.
+
+    Args:
+        hs_info: HaskellInfo provider.
+
+    Returns:
+        (files, flags):
+        files: Set of version macros header files.
+        flags: List of C preprocessor flags to include version macros.
+    """
+    files = hs_info.version_macros
+    flags = [
+        f
+        for include in set.to_list(files)
+        for f in ["-include", include.path]
+    ]
+    return (files, flags)