blob: e54b26e59aae3eaf45606cc11356d1bfa6b303bd [file] [log] [blame]
Klaus Aehlig4ca79d42016-10-22 07:59:41 +00001#!/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
17set -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
25OUTPUT="${PWD}/$1"
26shift
27
28TMP_DIR=${TMPDIR:-/tmp}
29PACKAGE_DIR="$(mktemp -d ${TMP_DIR%%/}/bazel.XXXXXXXX)"
30trap "rm -fr \"${PACKAGE_DIR}\"" EXIT
31mkdir -p "${PACKAGE_DIR}"
32
33for i in $*
34do
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}")
41done
42
John Caterd8c8a2b2020-07-13 05:41:15 -070043ID_OPTS="--group=0 --owner=0"
philwo1ad391b2020-11-25 06:29:02 -080044if [ "$(uname -s)" = "Darwin" ]; then
John Caterd8c8a2b2020-07-13 05:41:15 -070045 ID_OPTS="--gid=0 --uid=0"
46fi
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)