Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use release_archive to create java_tools' zips. #12615

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 20 additions & 68 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
load("//tools/python:private/defs.bzl", "py_binary", "py_library")
load(":embedded_tools.bzl", "srcsfile")
load(":rule_size_test.bzl", "rule_size_test")
load("//src:release_archive.bzl", "release_archive")

exports_files(["jdeps_modules.golden"])

Expand Down Expand Up @@ -583,8 +584,6 @@ genrule(
)

# Following targets build java_tools.zip - platform independent part of java_tools
# It is painstainkingly built by renaming single files, zipping them and merging zips together
# TODO(bazel-team): Replace this with a single target, for example "release_archive" in rules_kotlin
JAVA_TOOLS_DEPLOY_JARS = [
"//src/java_tools/buildjar:JavaBuilder_deploy.jar",
"//src/java_tools/buildjar:VanillaJavaBuilder_deploy.jar",
Expand All @@ -595,88 +594,43 @@ JAVA_TOOLS_DEPLOY_JARS = [
"//src/java_tools/singlejar/java/com/google/devtools/build/singlejar:bazel-singlejar_deploy.jar",
]

genrule(
release_archive(
name = "jars_java_tools_zip",
srcs = JAVA_TOOLS_DEPLOY_JARS + [
"@java_tools_langtools_javac11//:jdk_compiler_jar",
"@java_tools_langtools_javac11//:java_compiler_jar",
"@java_tools_langtools_javac11//:javac_jar",
],
outs = ["jars_java_tools.zip"],
cmd = "zip -qjX $@ $$(echo $(SRCS) | sort)",
package_dir = "java_tools",
visibility = ["//visibility:private"],
)

genrule(
name = "java_tools_build_zip",
srcs = ["//tools/jdk:BUILD.java_tools"],
outs = ["java_tools_build.zip"],
cmd = "cat $(SRCS) > BUILD; zip -qjX $@ BUILD",
)

genrule(
name = "java_tools_no_build_zip",
srcs = [
":jars_java_tools.zip",
release_archive(
name = "java_tools_zip",
src_map = {
"//tools/jdk:BUILD.java_tools": "BUILD",
},
visibility = ["//src/test/shell/bazel:__pkg__"],
deps = [
":jars_java_tools_zip",
"//src/tools/singlejar:singlejar_transitive_zip",
"//third_party/ijar:ijar_transitive_srcs_zip",
"//third_party/java/jacoco:jacoco_jars_zip",
"//third_party/java/proguard:proguard_zip",
],
outs = ["java_tools_no_build.zip"],
cmd = "$(location //src:merge_zip_files) java_tools $@ $(SRCS)",
output_to_bindir = 1,
tools = ["//src:merge_zip_files"],
visibility = ["//src/test/shell/bazel:__pkg__"],
)

genrule(
name = "java_tools_zip",
srcs = [
"java_tools_no_build.zip",
"java_tools_build.zip",
],
outs = ["java_tools.zip"],
cmd = "$(location //src:merge_zip_files) - $@ $(SRCS)",
output_to_bindir = 1,
tools = ["//src:merge_zip_files"],
# Following target builds java_tools_prebuilt.zip part of java_tools
release_archive(
name = "java_tools_prebuilt_zip",
src_map = {
"//tools/jdk:BUILD.java_tools_prebuilt": "BUILD",
},
visibility = ["//src/test/shell/bazel:__pkg__"],
)

# Following targets build java_tools_prebuilt.zip part of java_tools
# It is painstainkingly built by renaming single files, zipping them and merging zips together
# TODO(bazel-team): Replace this with a single target, for example "release_archive" in rules_kotlin
genrule(
name = "java_tools_prebuilt_build_zip",
srcs = ["//tools/jdk:BUILD.java_tools_prebuilt"],
outs = ["java_tools_prebuilt_build.zip"],
cmd = "cat $(SRCS) > BUILD; zip -qjX $@ BUILD",
)

genrule(
name = "java_tools_prebuilt_no_build_zip",
srcs = [
deps = [
"//src/tools/singlejar:singlejar_deploy_zip",
"//third_party/ijar:ijar_deploy_zip",
],
outs = ["java_tools_prebuilt_no_build.zip"],
cmd = "$(location //src:merge_zip_files) java_tools $@ $(SRCS)",
output_to_bindir = True,
tools = ["//src:merge_zip_files"],
visibility = ["//src/test/shell/bazel:__pkg__"],
)

genrule(
name = "java_tools_prebuilt_zip",
srcs = [
"java_tools_prebuilt_no_build.zip",
"java_tools_prebuilt_build.zip",
],
outs = ["java_tools_prebuilt.zip"],
cmd = "$(location //src:merge_zip_files) - $@ $(SRCS)",
output_to_bindir = 1,
tools = ["//src:merge_zip_files"],
visibility = ["//src/test/shell/bazel:__pkg__"],
)

# Following targets used by the java_tools_binaries Buildkite pipeline to upload
Expand Down Expand Up @@ -727,12 +681,10 @@ sh_binary(
)

# Part of the Java tools remote archive. Not embedded or used in Bazel.
genrule(
release_archive(
name = "zlib_zip",
srcs = ["//third_party/zlib:embedded_tools"],
outs = ["zlib.zip"],
cmd = "$(location //src:zip_files) zlib $@ $(SRCS)",
tools = ["//src:zip_files"],
package_dir = "zlib",
visibility = [
"//src/tools/singlejar:__pkg__",
"//third_party/ijar:__pkg__",
Expand Down
98 changes: 98 additions & 0 deletions src/release_archive.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Copyright 2020 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

def release_archive(name, srcs = [], src_map = {}, package_dir = "-", deps = [], visibility = []):
meteorcloudy marked this conversation as resolved.
Show resolved Hide resolved
"""
Creates an zip of the srcs, and renamed label artifacts.
Usage:
//:BUILD
load("//src:release_archive.bzl", "release_archive")
release_archive(
name = "release_archive",
src_map = {
"BUILD.release.bazel.bazel": "BUILD.bazel",
"WORKSPACE.release.bazel": "WORKSPACE",
},
deps = [
"//dep:pkg"
],
)
//dep:BUILD
load("//src:release_archive.bzl", "release_archive")
release_archive(
name = "pkg",
srcs = [
":label_of_artifact",
],
)
Args:
name: target identifier, points to a pkg_tar target.
package_dir: directory to place the srcs, src_map, and dist_files under. Defaults to the current directory.
dist_files: dict of <filename string>:<contents string> for files to be generated in the distribution artifact.
src_map: dict of <label>:<name string> for labels to be renamed and included in the distribution.
srcs: files to include in the distribution.
deps: release_archives to be included.
"""
srcs = list(srcs)
for source, target in src_map.items():
rename_name = name + "_" + target
_rename(
name = rename_name,
source = source,
target = target,
)
srcs += [rename_name]

if srcs != []:
native.genrule(
name = name + "_srcs",
srcs = srcs,
outs = [name + "_srcs.zip"],
cmd = "zip -qjX $@ $$(echo $(SRCS) | sort)",
visibility = ["//visibility:private"],
)
deps = [name + "_srcs.zip"] + deps

native.genrule(
name = name,
srcs = deps,
outs = [(name[:-len("_zip")] if name.endswith("_zip") else name) + ".zip"],
cmd = "$(location //src:merge_zip_files) %s $@ $(SRCS)" % package_dir,
output_to_bindir = 1,
tools = ["//src:merge_zip_files"],
visibility = visibility,
)

def _rename_impl(ctx):
out_file = ctx.actions.declare_file(ctx.label.name + "/" + ctx.attr.target)
in_file = ctx.file.source
ctx.actions.run_shell(
inputs = [in_file],
outputs = [out_file],
progress_message = "%s -> %s" % (in_file, ctx.attr.target),
command = "mkdir -p {dir} && cp {in_file} {out_file}".format(
dir = out_file.dirname,
in_file = in_file.path,
out_file = out_file.path,
),
)
return [DefaultInfo(files = depset([out_file]))]

_rename = rule(
implementation = _rename_impl,
attrs = {
"source": attr.label(allow_single_file = True, mandatory = True),
"target": attr.string(mandatory = True),
},
)
23 changes: 9 additions & 14 deletions src/tools/singlejar/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
load("@rules_java//java:defs.bzl", "java_library")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//src:release_archive.bzl", "release_archive")

# Description:
# singlejar C++ implementation.
Expand Down Expand Up @@ -43,35 +44,29 @@ filegroup(
visibility = ["//src:__pkg__"],
)

genrule(
release_archive(
name = "singlejar_transitive_zip",
srcs = [
package_dir = "java_tools",
visibility = ["//src:__pkg__"],
deps = [
":singlejar_zip",
"//src:zlib_zip",
"//src/main/cpp/util:cpp_util_with_deps_zip",
"//src/main/protobuf:desugar_deps_zip",
],
outs = ["singlejar_transitive.zip"],
cmd = "$(location //src:merge_zip_files) - $@ $(SRCS)",
tools = ["//src:merge_zip_files"],
visibility = ["//src:__pkg__"],
)

genrule(
release_archive(
name = "singlejar_zip",
srcs = SOURCES,
outs = ["singlejar.zip"],
cmd = "$(location //src:zip_files) src/tools/singlejar $@ $$(echo $(SRCS) | sort)",
tools = ["//src:zip_files"],
package_dir = "src/tools/singlejar",
visibility = ["//visibility:private"],
)

genrule(
release_archive(
name = "singlejar_deploy_zip",
srcs = [":singlejar_local"],
outs = ["singlejar_deploy.zip"],
cmd = "$(location //src:zip_files) src/tools/singlejar $@ $$(echo $(SRCS) | sort)",
tools = ["//src:zip_files"],
package_dir = "java_tools/src/tools/singlejar",
visibility = ["//src:__pkg__"],
)

Expand Down
18 changes: 2 additions & 16 deletions third_party/ijar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -122,20 +122,6 @@ filegroup(
visibility = ["//visibility:public"],
)

genrule(
name = "ijar_transitive_zip",
srcs = [
":ijar_srcs_zip",
":ijar_deploy_zip",
"//src:zlib_zip",
"//src/main/cpp/util:cpp_util_with_deps_zip",
],
outs = ["ijar_with_deps.zip"],
cmd = "$(location //src:merge_zip_files) - $@ $(SRCS)",
tools = ["//src:merge_zip_files"],
visibility = ["//visibility:public"],
)

genrule(
name = "ijar_transitive_srcs_zip",
srcs = [
Expand All @@ -144,7 +130,7 @@ genrule(
"//src/main/cpp/util:cpp_util_with_deps_zip",
],
outs = ["ijar_srcs_with_deps.zip"],
cmd = "$(location //src:merge_zip_files) - $@ $(SRCS)",
cmd = "$(location //src:merge_zip_files) java_tools $@ $(SRCS)",
tools = ["//src:merge_zip_files"],
visibility = ["//visibility:public"],
)
Expand All @@ -156,7 +142,7 @@ genrule(
":zipper",
],
outs = ["ijar_deploy.zip"],
cmd = "$(location //src:zip_files) ijar $@ $(SRCS)",
cmd = "$(location //src:zip_files) java_tools/ijar $@ $(SRCS)",
tools = ["//src:zip_files"],
visibility = ["//visibility:public"],
)
Expand Down
9 changes: 4 additions & 5 deletions third_party/java/jacoco/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# http://search.maven.org/remotecontent?filepath=org/jacoco/jacoco/0.8.3/jacoco-0.8.3.zip

load("//tools/distributions:distribution_rules.bzl", "distrib_jar_filegroup", "distrib_java_import")
load("//src:release_archive.bzl", "release_archive")

licenses(["reciprocal"]) # EPL 1.0 (Eclipse Public License)

Expand All @@ -18,17 +19,15 @@ filegroup(
srcs = glob(["**"]),
)

genrule(
release_archive(
name = "jacoco_jars_zip",
srcs = glob(["*.jar"]) + ["LICENSE"] + [
"//third_party:asm",
"//third_party:asm-commons",
"//third_party:asm-tree",
],
outs = ["jacoco_jars.zip"],
cmd = "$(location //src:zip_files) third_party/java/jacoco $@ $(SRCS)",
output_to_bindir = 1,
tools = ["//src:zip_files"],
package_dir = "java_tools/third_party/java/jacoco",
visibility = ["//visibility:public"],
)

filegroup(
Expand Down
8 changes: 4 additions & 4 deletions third_party/java/proguard/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
licenses(["restricted"]) # GNU GPL v2

load("//src:release_archive.bzl", "release_archive")

filegroup(
name = "srcs",
srcs = glob(["**"]),
Expand All @@ -19,14 +21,12 @@ filegroup(
visibility = ["//src:__pkg__"],
)

genrule(
release_archive(
name = "proguard_zip",
srcs = [
"proguard5.3.3/docs/GPL.html",
"proguard5.3.3/lib/proguard.jar",
],
outs = ["proguard.zip"],
cmd = "$(location //src:zip_files) third_party/java/proguard $@ $(SRCS)",
tools = ["//src:zip_files"],
package_dir = "java_tools/third_party/java/proguard",
visibility = ["//src:__pkg__"],
)