blob: 40a8f4a3367f8d5f06b05103ea24249881c28069 [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
László Csomor0783b9e2017-08-11 10:28:36 +020043(cd "${PACKAGE_DIR}" && tar -c -f "${OUTPUT}" --group=0 --owner=0 \
44 $(find . -type f | sort))