daml/bazel_tools/java.bzl
Gary Verhaegen 1872c668a5
replace DAML Authors with DA in copyright headers (#5228)
Change requested by Manoj.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-27 01:26:10 +01:00

118 lines
3.4 KiB
Python

# Copyright (c) 2020 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")
load("//bazel_tools:pkg.bzl", "pkg_empty_zip")
_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"],
)
# Create empty javadoc JAR for uploading deploy jars to Maven Central
pkg_empty_zip(
name = name + "_javadoc",
out = name + "_javadoc.jar",
)
# Create empty src JAR for uploading deploy jars to Maven Central
pkg_empty_zip(
name = name + "_src",
out = name + "_src.jar",
)
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"],
)
# Create empty javadoc JAR for uploading proto jars to Maven Central
pkg_empty_zip(
name = name + "_javadoc",
out = name + "_javadoc.jar",
)
# we don't need to create an empty zip for sources, because java_proto_library
# creates a sources jar as a side effect automatically