#!/bin/sh # Copyright 2016 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. set -eu # Combine the archives passed to a single archive. # NOTE: This assumes that the individual archives are already packed # in a way to contain canonical timestamps. This assumption must be # met in order to obtain reproducible output; the assumption is met # for the source tree and the archive of the generated java files. global OUTPUT := ""$(PWD)/$1"" shift global TMP_DIR := $(TMPDIR:-/tmp) global PACKAGE_DIR := $[mktemp -d $(TMP_DIR%%/)/bazel.XXXXXXXX] trap "rm -fr \"$(PACKAGE_DIR)\"" EXIT mkdir -p $(PACKAGE_DIR) for i in [$ifsjoin(Argv)] { global ARCHIVE := ""$(PWD)/$i"" matchstr $i { *.zip { global UNPACK := '"unzip -q'" } *.tar { global UNPACK := '"tar xf'" } } shell {cd $(PACKAGE_DIR) && $(UNPACK) $(ARCHIVE)} } shell {cd $(PACKAGE_DIR) && find . -type f | sort | zip -qDX@ $(OUTPUT)} (CommandList children: [ (C {(set)} {(-eu)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OUTPUT) op: Equal rhs: {(DQ (${ VSub_Name PWD) (/) ($ VSub_Number "$1"))} spids: [65] ) ] spids: [65] ) (C {(shift)}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:TMP_DIR) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(Lit_Slash /) (tmp)}) spids: [78 83] ) } spids: [77] ) ] spids: [77] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:PACKAGE_DIR) op: Equal rhs: { (DQ (CommandSubPart command_list: (CommandList children: [ (C {(mktemp)} {(-d)} { (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_DPercent arg_word:{(Lit_Slash /)}) spids: [92 96] ) (/bazel.XXXXXXXX) } ) ] ) left_token: spids: [87 98] ) ) } spids: [85] ) ] spids: [85] ) (C {(trap)} { (DQ ("rm -fr ") (EscapedLiteralPart token:) (${ VSub_Name PACKAGE_DIR) (EscapedLiteralPart token:) ) } {(EXIT)} ) (C {(mkdir)} {(-p)} {(DQ (${ VSub_Name PACKAGE_DIR))}) (ForEach iter_name: i iter_words: [{($ VSub_Star "$*")}] do_arg_iter: False body: (DoGroup children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ARCHIVE) op: Equal rhs: {(DQ (${ VSub_Name PWD) (/) ($ VSub_Name "$i"))} spids: [136] ) ] spids: [136] ) (Case to_match: {(DQ ($ VSub_Name "$i"))} arms: [ (case_arm pat_list: [{(Lit_Other "*") (.zip)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:UNPACK) op: Equal rhs: {(DQ ("unzip -q"))} spids: [159] ) ] spids: [159] ) ] spids: [155 157 164 -1] ) (case_arm pat_list: [{(Lit_Other "*") (.tar)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:UNPACK) op: Equal rhs: {(DQ ("tar xf"))} spids: [171] ) ] spids: [171] ) ] spids: [167 169 176 -1] ) ] spids: [146 152 179] ) (Subshell child: (AndOr children: [ (C {(cd)} {(DQ (${ VSub_Name PACKAGE_DIR))}) (C {(${ VSub_Name UNPACK)} {(DQ (${ VSub_Name ARCHIVE))}) ] op_id: Op_DAmp ) spids: [182 202] ) ] spids: [133 204] ) spids: [130 -1] ) (Subshell child: (AndOr children: [ (C {(cd)} {(DQ (${ VSub_Name PACKAGE_DIR))}) (Pipeline children: [ (C {(find)} {(.)} {(-type)} {(f)}) (C {(sort)}) (C {(zip)} {(-qDX) (Lit_Other "@")} {(DQ (${ VSub_Name OUTPUT))}) ] negated: False ) ] op_id: Op_DAmp ) spids: [207 242] ) ] )