forked from bazelbuild/bazel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a zip archive for the remote Java tools for Windows instead of a tar, which can not be parsed on some other platforms. Bazel doesn't have the equivalent of a `pkg_zip` rule and this PR introduces two new scripts that use `zip` directly: `third_party/merge_zip_files.sh`: merges all the given `zip` files into a single `zip` `third_party/zip_files.sh`: archives all the inputs files under the given directory structure in the output `zip` file Partial merge of bazelbuild#7708. PiperOrigin-RevId: 238969545
- Loading branch information
1 parent
6f52fca
commit 7aace9c
Showing
6 changed files
with
182 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/bash | ||
|
||
# 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. | ||
# 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. "-" can be passed if no top-level directory | ||
# structure is required. | ||
|
||
# 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: | ||
# 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 - 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_prefix="$1"; shift | ||
output="$1"; shift | ||
|
||
initial_pwd="$(pwd)" | ||
|
||
tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXX') | ||
trap "rm -fr $tmp_dir" EXIT | ||
tmp_zip="$tmp_dir/archive.zip" | ||
|
||
if [[ "$directory_prefix" == "-" ]]; then | ||
for curr_zip in "$@" | ||
do | ||
unzip -q "$curr_zip" -d "$tmp_dir" | ||
done | ||
|
||
cd "$tmp_dir" | ||
zip -9 -r -q "$tmp_zip" "." | ||
else | ||
mkdir -p "$tmp_dir/$directory_prefix" | ||
for curr_zip in "$@" | ||
do | ||
unzip -q "$curr_zip" -d "$tmp_dir/$directory_prefix" | ||
done | ||
|
||
cd "$tmp_dir" | ||
zip -9 -r -q "$tmp_zip" "$directory_prefix" | ||
fi | ||
|
||
cd "$initial_pwd" | ||
mv -f "$tmp_zip" "$output" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
# 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. | ||
# 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_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: | ||
# src/main/cpp/a.cc | ||
# src/main/cpp/b.cc | ||
|
||
set -euo pipefail | ||
|
||
directory_prefix="$1"; shift | ||
output="$1"; shift | ||
|
||
initial_pwd="$(pwd)" | ||
|
||
tmp_dir=$(mktemp -d -t 'tmp_bazel_zip_files_XXXXX') | ||
trap "rm -fr $tmp_dir" EXIT | ||
tmp_zip="$tmp_dir/archive.zip" | ||
|
||
zip -j -q "$tmp_zip" "$@" | ||
|
||
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_prefix" | ||
|
||
cd "$initial_pwd" | ||
mv -f "$tmp_zip" "$output" | ||
rm -r "$tmp_dir" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters