mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-04 00:36:58 +03:00
6f6f3337c7
* Fixes 895: Improve DA Bazel rules for building javadocs. Extend the da_java_library Bazel macro to also build the Javadoc for the target. Add the Javadoc artefacts to the release procedure.
96 lines
2.7 KiB
Python
96 lines
2.7 KiB
Python
# Copyright (c) 2019 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
load("//bazel_tools:pom_file.bzl", "pom_file")
|
|
load("@os_info//:os_info.bzl", "is_windows")
|
|
load("@com_github_google_bazel_common//tools/javadoc:javadoc.bzl", "javadoc_library")
|
|
|
|
_java_home_runtime_build_template = """
|
|
java_runtime(
|
|
name = "{name}",
|
|
java_home = "{java_home}",
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
"""
|
|
|
|
def _java_home_runtime_impl(ctx):
|
|
java_home = ctx.os.environ.get("JAVA_HOME", default = "")
|
|
if java_home == "":
|
|
fail("Environment variable JAVA_HOME is empty.")
|
|
build_content = _java_home_runtime_build_template.format(
|
|
name = "javabase",
|
|
java_home = ctx.path(java_home),
|
|
)
|
|
ctx.file("BUILD", content = build_content, executable = False)
|
|
|
|
java_home_runtime = repository_rule(
|
|
implementation = _java_home_runtime_impl,
|
|
)
|
|
"""Define a java_runtime pointing to the JAVA_HOME environment variable."""
|
|
|
|
def _wrap_rule(rule, name = "", **kwargs):
|
|
rule(name = name, **kwargs)
|
|
|
|
def da_java_library(
|
|
name,
|
|
deps,
|
|
srcs,
|
|
data = [],
|
|
resources = [],
|
|
resource_jars = [],
|
|
resource_strip_prefix = None,
|
|
tags = [],
|
|
visibility = None,
|
|
exports = [],
|
|
**kwargs):
|
|
root_packages = None
|
|
for tag in tags:
|
|
if tag.startswith("javadoc_root_packages="):
|
|
root_packages = tag[len("javadoc_root_packages="):].split(":")
|
|
|
|
native.java_library(
|
|
name = name,
|
|
deps = deps,
|
|
srcs = srcs,
|
|
data = data,
|
|
resources = resources,
|
|
resource_jars = resource_jars,
|
|
resource_strip_prefix = resource_strip_prefix,
|
|
tags = tags,
|
|
visibility = visibility,
|
|
exports = exports,
|
|
**kwargs
|
|
)
|
|
pom_file(
|
|
name = name + "_pom",
|
|
tags = tags,
|
|
target = ":" + name,
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
# Disable the building of Javadoc on Windows as the rule fails to
|
|
# find the sources under Windows.
|
|
if root_packages and is_windows == False:
|
|
javadoc_library(
|
|
name = name + "_javadoc",
|
|
deps = deps + [name],
|
|
srcs = srcs,
|
|
root_packages = root_packages,
|
|
)
|
|
|
|
def da_java_binary(name, **kwargs):
|
|
_wrap_rule(native.java_binary, name, **kwargs)
|
|
pom_file(
|
|
name = name + "_pom",
|
|
target = ":" + name,
|
|
visibility = ["//visibility:public"],
|
|
)
|
|
|
|
def da_java_proto_library(name, **kwargs):
|
|
_wrap_rule(native.java_proto_library, name, **kwargs)
|
|
pom_file(
|
|
name = name + "_pom",
|
|
target = ":" + name,
|
|
visibility = ["//visibility:public"],
|
|
)
|