Klaus Aehlig | 4ca79d4 | 2016-10-22 07:59:41 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | # Copyright 2016 The Bazel Authors. All rights reserved. |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | set -eu |
| 18 | |
| 19 | # Combine the archives passed to a single archive. |
| 20 | # NOTE: This assumes that the individual archives are already packed |
| 21 | # in a way to contain canonical timestamps. This assumption must be |
| 22 | # met in order to obtain reproducible output; the assumption is met |
| 23 | # for the source tree and the archive of the generated java files. |
| 24 | |
| 25 | OUTPUT="${PWD}/$1" |
| 26 | shift |
| 27 | |
| 28 | TMP_DIR=${TMPDIR:-/tmp} |
| 29 | PACKAGE_DIR="$(mktemp -d ${TMP_DIR%%/}/bazel.XXXXXXXX)" |
| 30 | trap "rm -fr \"${PACKAGE_DIR}\"" EXIT |
| 31 | mkdir -p "${PACKAGE_DIR}" |
| 32 | |
| 33 | for i in $* |
| 34 | do |
| 35 | ARCHIVE="${PWD}/$i" |
| 36 | case "$i" in |
| 37 | *.zip) UNPACK="unzip -q" ;; |
| 38 | *.tar) UNPACK="tar xf" ;; |
| 39 | esac |
| 40 | (cd "${PACKAGE_DIR}" && ${UNPACK} "${ARCHIVE}") |
| 41 | done |
| 42 | |
John Cater | d8c8a2b | 2020-07-13 05:41:15 -0700 | [diff] [blame] | 43 | ID_OPTS="--group=0 --owner=0" |
philwo | 1ad391b | 2020-11-25 06:29:02 -0800 | [diff] [blame] | 44 | if [ "$(uname -s)" = "Darwin" ]; then |
John Cater | d8c8a2b | 2020-07-13 05:41:15 -0700 | [diff] [blame] | 45 | ID_OPTS="--gid=0 --uid=0" |
| 46 | fi |
| 47 | |
| 48 | ( |
| 49 | cd "${PACKAGE_DIR}" |
| 50 | FILE_LIST="$(mktemp ${TMP_DIR%%/}/bazel-distfile-files.XXXXXXXX)" |
| 51 | trap "rm -fr \"${FILE_LIST}\"" EXIT |
| 52 | find . -type f | sort > "${FILE_LIST}" |
| 53 | tar -c -f "${OUTPUT}" ${ID_OPTS} -T "${FILE_LIST}" |
| 54 | ) |