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

Zip Java tools for windows #7708

Closed
wants to merge 11 commits into from
27 changes: 25 additions & 2 deletions src/main/cpp/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,29 @@ filegroup(
visibility = ["//visibility:public"],
)

ARCHIVE_PACKAGE_DIR = "src/main/cpp/util"

genrule(
name = "cpp_util_with_deps_zip",
srcs = [
":cpp_util_zip",
"//src/main/native/windows:native_windows_zip",
],
outs = ["cpp_util_with_deps.zip"],
cmd = "$(location //third_party:merge_zip_files.sh) nodir $(OUTS) $(SRCS)",
tools = ["//third_party:merge_zip_files.sh"],
visibility = ["//third_party/ijar:__pkg__"],
)

genrule(
name = "cpp_util_zip",
srcs = glob(["*.cc"]) + glob(["*.h"]),
outs = ["cpp_util.zip"],
cmd = "$(location //third_party:zip_files.sh) " + ARCHIVE_PACKAGE_DIR + " $(OUTS) $(SRCS)",
tools = ["//third_party:zip_files.sh"],
visibility = ["//visibility:private"],
)

pkg_tar(
name = "cpp_util_with_deps_archive",
extension = "tar.gz",
Expand All @@ -212,7 +235,7 @@ pkg_tar(
srcs = glob(["*.cc"]) + glob(["*.h"]),
extension = "tar.gz",
mode = "755",
# Create a pkg_tar to preserve the directory structure src/main/cpp/util.
package_dir = "src/main/cpp/util",
# Create a pkg_tar to preserve the directory structure.
package_dir = ARCHIVE_PACKAGE_DIR,
visibility = ["//visibility:private"],
)
18 changes: 17 additions & 1 deletion src/main/native/windows/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ filegroup(
visibility = ["//src/main/native:__pkg__"],
)

ARCHIVE_PACKAGE_DIR = "src/main/native/windows"

genrule(
name = "native_windows_zip",
srcs = [
"file.cc",
"file.h",
"util.cc",
"util.h",
],
outs = ["native_windows.zip"],
cmd = "$(location //third_party:zip_files.sh) " + ARCHIVE_PACKAGE_DIR + " $(OUTS) $(SRCS)",
tools = ["//third_party:zip_files.sh"],
visibility = ["//src/main/cpp/util:__pkg__"],
)

pkg_tar(
name = "src_main_native_windows",
srcs = [
Expand All @@ -19,7 +35,7 @@ pkg_tar(
extension = "tar.gz",
mode = "755",
# Create a pkg_tar to preserve the directory structure src/main/native/windows.
package_dir = "src/main/native/windows",
package_dir = ARCHIVE_PACKAGE_DIR,
visibility = ["//src/main/cpp/util:__pkg__"],
)

Expand Down
61 changes: 40 additions & 21 deletions third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -605,34 +605,35 @@ filegroup(
],
)

# Part of the Java tools remote archive. Not embedded or used in Bazel.
pkg_tar(
name = "zlib_pkg",
srcs = ["//third_party/zlib:embedded_tools"],
extension = "tar.gz",
mode = "755",
# Create a new pkg_tar to preserve the directory structure (zlib/).
package_dir = "zlib",
)

# Part of the Java tools remote archive. Not embedded or used in Bazel.
pkg_tar(
name = "ijar_pkg",
filegroup(
name = "java_tools_archive",
srcs = select({
"//src/conditions:windows": [
":java_tools.zip",
],
"//conditions:default": [
":java_tools.tar.gz",
],
}),
)

genrule(
name = "java_tools_zip",
srcs = [
"//third_party/ijar",
"//third_party/ijar:embed_into_java_tools",
"//third_party/ijar:zipper",
"//third_party/ijar:ijar_with_deps_zip",
"//third_party/java/java_tools:java_tools_zip",
":zlib_zip",
],
extension = "tar.gz",
mode = "755",
# Create a new pkg_tar to preserve the directory structure (ijar/).
package_dir = "ijar",
outs = ["java_tools.zip"],
cmd = "$(location :merge_zip_files.sh) java_tools $(OUTS) $(SRCS)",
output_to_bindir = 1,
tools = [":merge_zip_files.sh"],
)

# Builds the remote Java tools archive. Not embedded or used in Bazel, but used
# by the Java tools release process.
pkg_tar(
name = "java_tools_pkg-gz",
name = "java_tools_tar",
srcs = [
"//third_party/java/java_tools",
"//third_party/java/jdk/langtools:java_compiler_jar",
Expand All @@ -650,6 +651,24 @@ pkg_tar(
],
)

# Part of the Java tools remote archive. Not embedded or used in Bazel.
pkg_tar(
name = "zlib_pkg",
srcs = ["//third_party/zlib:embedded_tools"],
extension = "tar.gz",
mode = "755",
# Create a new pkg_tar to preserve the directory structure (zlib/).
package_dir = "zlib",
)

genrule(
name = "zlib_zip",
srcs = ["//third_party/zlib:embedded_tools"],
outs = ["zlib.zip"],
cmd = "$(location //third_party:zip_files.sh) zlib $(OUTS) $(SRCS)",
tools = ["//third_party:zip_files.sh"],
)

load(":compiler_config_setting.bzl", "create_compiler_config_setting")

create_compiler_config_setting(
Expand Down
42 changes: 33 additions & 9 deletions third_party/ijar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,43 @@ pkg_tar(
],
)

genrule(
name = "ijar_with_deps_zip",
srcs = [
":ijar_srcs_zip",
"//src/main/cpp/util:cpp_util_with_deps_zip",
],
outs = ["ijar_srcs_with_deps.zip"],
cmd = "$(location //third_party:merge_zip_files.sh) nodir $(OUTS) $(SRCS)",
tools = ["//third_party:merge_zip_files.sh"],
visibility = ["//third_party:__pkg__"],
)

IJAR_SOURCES_AND_BINARIES = glob(
["**"],
exclude = ["BUILD"],
) + [
":ijar",
":zipper",
]

IJAR_ARCHIVE_PACKAGE_DIR = "ijar"

genrule(
name = "ijar_srcs_zip",
srcs = IJAR_SOURCES_AND_BINARIES,
outs = ["ijar_srcs.zip"],
cmd = "$(location //third_party:zip_files.sh) " + IJAR_ARCHIVE_PACKAGE_DIR + " $(OUTS) $(SRCS)",
tools = ["//third_party:zip_files.sh"],
visibility = ["//third_party:__pkg__"],
)

pkg_tar(
name = "ijar_archive",
srcs = glob(
["**"],
exclude = ["BUILD"]
) + [
# Also archive the binaries.
":ijar",
":zipper",
],
srcs = IJAR_SOURCES_AND_BINARIES,
extension = "tar.gz",
mode = "755",
# Create a new pkg_tar to preserve the directory structure (ijar/).
package_dir = "ijar",
package_dir = IJAR_ARCHIVE_PACKAGE_DIR,
visibility = ["//visibility:private"],
)
13 changes: 13 additions & 0 deletions third_party/java/java_tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ filegroup(
"BUILD.pkg",
],
)

genrule(
name = "java_tools_zip",
srcs = [
":java_tools",
"//third_party/java/jdk/langtools:java_compiler_jar",
"//third_party/java/jdk/langtools:javac_jar",
"//third_party/java/jdk/langtools:jdk_compiler_jar",
],
outs = ["java_tools.zip"],
cmd = "zip -j $(OUTS) $(SRCS)",
visibility = ["//third_party:__pkg__"],
)
83 changes: 83 additions & 0 deletions third_party/merge_zip_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/bash

# Copyright 2018 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.

# A script that zips the content of the inputs zip files under a given directory
# structure in the output zip file. "nodir" can be passed if no top-level directory
# structure is required.

# Usage: third_party/merge_zip_files.sh directory_structure output_zip [input_zip_files]
#
# For example, if we have the following zips and their content:
# a.zip:
# dir1/a1.cc
# a2.cc
# b.zip:
# dir2/b1.cc
# b2.cc
#
# third_party_zip_files.sh src/main/cpp my_archive.zip a.zip b.zip
# will create the archive my_archive.zip containing:
# src/main/cpp/a2.cc
# src/main/cpp/b2.cc
# src/main/cpp/dir1/a1.cc
# src/main/cpp/dir2/b1.cc
#
# third_party_zip_files.sh nodir my_archive.zip a.zip b.zip
# will create the archive my_archive.zip containing:
# a2.cc
# b2.cc
# dir1/a1.cc
# dir2/b1.cc

set -euo pipefail

directory_structure="$1"; shift
output="$1"; shift

initial_pwd="$(pwd)"

tmp_dir=$(mktemp -d -t)
tmp_zip="$tmp_dir/archive.zip"

if [[ "$directory_structure" == "nodir" ]]; then
for curr_zip in "$@"
do
unzip -q "$curr_zip" -d "$tmp_dir"
done

cd "$tmp_dir"
zip -r -q "$tmp_zip" "."
else
mkdir -p "$tmp_dir/$directory_structure"
for curr_zip in "$@"
do
unzip -q "$curr_zip" -d "$tmp_dir/$directory_structure"
done

cd "$tmp_dir"
zip -r -q "$tmp_zip" "$directory_structure"
fi

cd "$initial_pwd"
mv -f "$tmp_zip" "$output"
rm -r "$tmp_dir"







49 changes: 49 additions & 0 deletions third_party/zip_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash

# Copyright 2018 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.

# A script that zips all the inputs files under the given directory structure
# in the output zip file.

# Usage: third_party/zip_files.sh directory_structure output_zip [input_files]
#
# For example: third_party_zip_files.sh src/main/cpp my_archive.zip a.cc b.cc
# will create the archive my_archive.zip containing:
# src/main/cpp/a.cc
# src/main/cpp/b.cc

set -euo pipefail

directory_structure="$1"; shift
output="$1"; shift

initial_pwd="$(pwd)"

tmp_dir=$(mktemp -d -t)
tmp_zip="$tmp_dir/archive.zip"

zip -j -q "$tmp_zip" "$@"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sort input files for determinism; consider using -D


mkdir -p "$tmp_dir/$directory_structure"
cd "$tmp_dir/$directory_structure"
unzip -q "$tmp_zip"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why unzip and zip again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unzipping everything under the given directory_prefixso that when zipping directory_prefix the zip content has the same directory structure. I couldn't find a way to get the same results only by using zip. If you have any experience with this I'm happy to replace this part of the script.

rm -f "$tmp_zip"
cd "$tmp_dir"
zip -r -q "$tmp_zip" "$directory_structure"

cd "$initial_pwd"
mv -f "$tmp_zip" "$output"
rm -r "$tmp_dir"

5 changes: 4 additions & 1 deletion third_party/zlib/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ cc_library(
srcs = glob(["*.c"]),
hdrs = glob(["*.h"]),
# Use -Dverbose=-1 to turn off zlib's trace logging. (#3280)
copts = ["-w", "-Dverbose=-1"],
copts = [
"-w",
"-Dverbose=-1",
],
includes = ["."],
visibility = ["//visibility:public"],
)