#!/bin/bash # # 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. # This script takes in a regular expression and a zip file and writes a file # containing the names of all files in the zip file that match the regular # expression with one per line. Names of directories are not included. if test "$Argc" -ne 3 { echo "Usage: zip_manifest_creator.sh " exit 1 } global REGEX := $1 global INPUT_ZIP := $2 global OUTPUT_MANIFEST := $3 global RUNFILES := $(RUNFILES:-$0.runfiles) # For the sh_binary in BUILD.tools, zipper is here. global ZIPPER := "$RUNFILES/*/tools/zip/zipper/zipper" if test ! -x $ZIPPER { # For the sh_test in BUILD.oss, zipper is here. global ZIPPER := "$RUNFILES/third_party/ijar/zipper" } if test ! -x $ZIPPER { echo "zip_manifest_creator could not find zipper executable" exit 1 } $ZIPPER v $INPUT_ZIP \ | cut -d ' ' -f3 \ | grep -v '/'$ \ | grep -x $REGEX \ > $OUTPUT_MANIFEST exit 0 (CommandList children: [ (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(DQ ($ VSub_Pound "$#"))} {(-ne)} {(3)} {(Lit_Other "]")}) terminator: ) ] action: [ (C {(echo)} {(DQ ("Usage: zip_manifest_creator.sh "))}) (C {(exit)} {(1)}) ] spids: [-1 71] ) ] spids: [-1 85] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:REGEX) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [88] ) ] spids: [88] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:INPUT_ZIP) op: Equal rhs: {(DQ ($ VSub_Number "$2"))} spids: [93] ) ] spids: [93] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:OUTPUT_MANIFEST) op: Equal rhs: {(DQ ($ VSub_Number "$3"))} spids: [98] ) ] spids: [98] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:RUNFILES) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {($ VSub_Number "$0") (.runfiles)} ) spids: [105 110] ) } spids: [104] ) ] spids: [104] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ZIPPER) op: Equal rhs: {($ VSub_Name "$RUNFILES") (/) (Lit_Other "*") (/tools/zip/zipper/zipper)} spids: [116] ) ] spids: [116] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-x)} {($ VSub_Name "$ZIPPER")} {(Lit_Other "]")}) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:ZIPPER) op: Equal rhs: {($ VSub_Name "$RUNFILES") (/third_party/ijar/zipper)} spids: [142] ) ] spids: [142] ) ] spids: [-1 135] ) ] spids: [-1 146] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(KW_Bang "!")} {(-x)} {($ VSub_Name "$ZIPPER")} {(Lit_Other "]")}) terminator: ) ] action: [ (C {(echo)} {(DQ ("zip_manifest_creator could not find zipper executable"))}) (C {(exit)} {(1)}) ] spids: [-1 161] ) ] spids: [-1 175] ) (Pipeline children: [ (C {($ VSub_Name "$ZIPPER")} {(v)} {(DQ ($ VSub_Name "$INPUT_ZIP"))}) (C {(cut)} {(-d)} {(SQ <" ">)} {(-f3)}) (C {(grep)} {(-v)} {(EscapedLiteralPart token:) (Lit_Other "$")}) (SimpleCommand words: [{(grep)} {(-x)} {(DQ ($ VSub_Name "$REGEX"))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ ($ VSub_Name "$OUTPUT_MANIFEST"))} spids: [225] ) ] ) ] negated: False ) (C {(exit)} {(0)}) ] )