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
12 changes: 12 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -549,3 +549,15 @@ alias(
actual = "//src/conditions:windows",
visibility = ["//visibility:public"],
)

sh_binary(
name = "zip_files",
srcs = ["zip_files.sh"],
visibility = ["//visibility:public"],
)

sh_binary(
name = "merge_zip_files",
srcs = ["merge_zip_files.sh"],
visibility = ["//visibility:public"],
)
8 changes: 4 additions & 4 deletions src/main/cpp/util/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -204,16 +204,16 @@ genrule(
"//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"],
cmd = "$(location //src:merge_zip_files) - $@ $(SRCS)",
tools = ["//src:merge_zip_files"],
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) src/main/cpp/util $(OUTS) $(SRCS)",
tools = ["//third_party:zip_files.sh"],
cmd = "$(location //src:zip_files) src/main/cpp/util $@ $(SRCS)",
tools = ["//src:zip_files"],
visibility = ["//visibility:private"],
)
4 changes: 2 additions & 2 deletions src/main/native/windows/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ genrule(
"util.h",
],
outs = ["native_windows.zip"],
cmd = "$(location //third_party:zip_files.sh) src/main/native/windows $(OUTS) $(SRCS)",
tools = ["//third_party:zip_files.sh"],
cmd = "$(location //src:zip_files) src/main/native/windows $@ $(SRCS)",
tools = ["//src:zip_files"],
visibility = ["//src/main/cpp/util:__pkg__"],
)
20 changes: 10 additions & 10 deletions third_party/merge_zip_files.sh → src/merge_zip_files.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2018 The Bazel Authors. All rights reserved.
# Copyright 2019 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.
Expand All @@ -15,10 +15,10 @@
# 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 in the output zip file. "-" 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]
# Usage: third_party/merge_zip_files.sh directory_prefix output_zip [input_zip_files]
#
# For example, if we have the following zips and their content:
# a.zip:
Expand All @@ -35,7 +35,7 @@
# 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
# third_party_zip_files.sh - my_archive.zip a.zip b.zip
# will create the archive my_archive.zip containing:
# a2.cc
# b2.cc
Expand All @@ -44,15 +44,16 @@

set -euo pipefail

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

initial_pwd="$(pwd)"

tmp_dir=$(mktemp -d -t 'tmpdirXXXXX')
trap "rm -fr $tmp_dir" EXIT
tmp_zip="$tmp_dir/archive.zip"

if [[ "$directory_structure" == "nodir" ]]; then
if [[ "$directory_prefix" == "-" ]]; then
for curr_zip in "$@"
do
unzip -q "$curr_zip" -d "$tmp_dir"
Expand All @@ -61,16 +62,15 @@ if [[ "$directory_structure" == "nodir" ]]; then
cd "$tmp_dir"
zip -9 -r -q "$tmp_zip" "."
else
mkdir -p "$tmp_dir/$directory_structure"
mkdir -p "$tmp_dir/$directory_prefix"
for curr_zip in "$@"
do
unzip -q "$curr_zip" -d "$tmp_dir/$directory_structure"
unzip -q "$curr_zip" -d "$tmp_dir/$directory_prefix"
done

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

cd "$initial_pwd"
mv -f "$tmp_zip" "$output"
rm -r "$tmp_dir"
13 changes: 7 additions & 6 deletions third_party/zip_files.sh → src/zip_files.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2018 The Bazel Authors. All rights reserved.
# Copyright 2019 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.
Expand All @@ -17,7 +17,7 @@
# 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]
# Usage: third_party/zip_files.sh directory_prefix 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:
Expand All @@ -26,22 +26,23 @@

set -euo pipefail

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

initial_pwd="$(pwd)"

tmp_dir=$(mktemp -d -t 'tmpdirXXXXX')
trap "rm -fr $tmp_dir" EXIT
tmp_zip="$tmp_dir/archive.zip"

zip -j -q "$tmp_zip" "$@"

mkdir -p "$tmp_dir/$directory_structure"
cd "$tmp_dir/$directory_structure"
mkdir -p "$tmp_dir/$directory_prefix"
cd "$tmp_dir/$directory_prefix"
unzip -q "$tmp_zip"
rm -f "$tmp_zip"
cd "$tmp_dir"
zip -r -q "$tmp_zip" "$directory_structure"
zip -r -q "$tmp_zip" "$directory_prefix"

cd "$initial_pwd"
mv -f "$tmp_zip" "$output"
Expand Down
8 changes: 4 additions & 4 deletions third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -615,18 +615,18 @@ genrule(
":zlib_zip",
],
outs = ["java_tools.zip"],
cmd = "$(location :merge_zip_files.sh) java_tools $(OUTS) $(SRCS)",
cmd = "$(location //src:merge_zip_files) java_tools $@ $(SRCS)",
output_to_bindir = 1,
tools = [":merge_zip_files.sh"],
tools = ["//src:merge_zip_files"],
)

# Part of the Java tools remote archive. Not embedded or used in Bazel.
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"],
cmd = "$(location //src:zip_files) zlib $@ $(SRCS)",
tools = ["//src:zip_files"],
visibility = ["//visibility:private"],
)

Expand Down
8 changes: 4 additions & 4 deletions third_party/ijar/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ genrule(
"//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"],
cmd = "$(location //src:merge_zip_files) - $@ $(SRCS)",
tools = ["//src:merge_zip_files"],
visibility = ["//third_party:__pkg__"],
)

Expand All @@ -133,7 +133,7 @@ genrule(
":zipper",
],
outs = ["ijar_srcs.zip"],
cmd = "$(location //third_party:zip_files.sh) ijar $(OUTS) $(SRCS)",
tools = ["//third_party:zip_files.sh"],
cmd = "$(location //src:zip_files) ijar $@ $(SRCS)",
tools = ["//src:zip_files"],
visibility = ["//visibility:private"],
)
2 changes: 1 addition & 1 deletion third_party/java/java_tools/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ genrule(
"//third_party/java/jdk/langtools:jdk_compiler_jar",
],
outs = ["java_tools.zip"],
cmd = "zip -j $(OUTS) $(SRCS)",
cmd = "zip -j $@ cat $(SRCS) | sort",
visibility = ["//third_party:__pkg__"],
)