#!/bin/bash # Copyright 2014 The Kubernetes Authors. # # 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 finds, caches, and prints a list of all directories that hold # *.go files. If any directory is newer than the cache, re-find everything and # update the cache. Otherwise use the cached file. set -o errexit set -o nounset set -o pipefail if [[ -z "${1:-}" ]] { echo "usage: $0 " exit 1 } global CACHE := $1; shift trap "rm -f '$(CACHE)'" HUP INT TERM ERR # This is a partial 'find' command. The caller is expected to pass the # remaining arguments. # # Example: # kfind -type f -name foobar.go proc kfind { # include the "special" vendor directories which are actually part # of the Kubernetes source tree - generators will use these for # including certain core API concepts. find -H . ./vendor/k8s.io/apimachinery ./vendor/k8s.io/apiserver ./vendor/k8s.io/kube-aggregator ./vendor/k8s.io/apiextensions-apiserver ./vendor/k8s.io/metrics ./vendor/k8s.io/sample-apiserver ./vendor/k8s.io/api ./vendor/k8s.io/client-go ./vendor/k8s.io/code-generator \ '(' \ -not '(' \ '(' \ -path ./vendor -o \ -path ./staging -o \ -path ./_'*' -o \ -path ./.'*' -o \ -path ./docs -o \ -path ./examples \ ')' -prune \ ')' \ ')' \ @Argv } global NEED_FIND := 'true' # It's *significantly* faster to check whether any directories are newer than # the cache than to blindly rebuild it. if [[ -f "${CACHE}" ]] { global N := $[kfind -type d -newer $(CACHE) -print -quit | wc -l] [[ "${N}" == 0 ]] && global NEED_FIND := 'false' } mkdir -p $[dirname $(CACHE)] if $[$(NEED_FIND)] { kfind -type f -name '*'.go \ | sed 's|/[^/]*$||' \ | sed 's|^./||' \ | env LC_ALL=C sort -u \ > $(CACHE) } cat $(CACHE) (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(nounset)}) (C {(set)} {(-o)} {(pipefail)}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_z child: { (DQ (BracedVarSub token: suffix_op: (StringUnary op_id:VTest_ColonHyphen arg_word:{(SQ )}) spids: [80 83] ) ) } ) ) terminator: ) ] action: [ (C {(echo)} {(DQ ("usage: ") ($ VSub_Number "$0") (" "))}) (C {(exit)} {(1)}) ] spids: [-1 89] ) ] spids: [-1 105] ) (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:CACHE) op: Equal rhs: {(DQ ($ VSub_Number "$1"))} spids: [107] ) ] spids: [107] ) terminator: ) (C {(shift)}) (C {(trap)} {(DQ ("rm -f '") (${ VSub_Name CACHE) ("'"))} {(HUP)} {(INT)} {(TERM)} {(ERR)}) (FuncDef name: kfind body: (BraceGroup children: [ (C {(find)} {(-H)} {(.)} {(./vendor/k8s.io/apimachinery)} {(./vendor/k8s.io/apiserver)} {(./vendor/k8s.io/kube-aggregator)} {(./vendor/k8s.io/apiextensions-apiserver)} {(./vendor/k8s.io/metrics)} {(./vendor/k8s.io/sample-apiserver)} {(./vendor/k8s.io/api)} {(./vendor/k8s.io/client-go)} {(./vendor/k8s.io/code-generator)} {(EscapedLiteralPart token:)} {(-not)} {(EscapedLiteralPart token:)} {(EscapedLiteralPart token:)} {(-path)} {(./vendor)} {(-o)} {(-path)} {(./staging)} {(-o)} {(-path)} {(./_) (EscapedLiteralPart token:)} {(-o)} {(-path)} {(./.) (EscapedLiteralPart token:)} {(-o)} {(-path)} {(./docs)} {(-o)} {(-path)} {(./examples)} {(EscapedLiteralPart token:)} {(-prune)} {(EscapedLiteralPart token:)} {(EscapedLiteralPart token:)} {(DQ ($ VSub_At "$@"))} ) ] spids: [156] ) spids: [150 155] ) (Assignment keyword: Assign_None pairs: [(assign_pair lhs:(LhsName name:NEED_FIND) op:Equal rhs:{(true)} spids:[280])] spids: [280] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr:(BoolUnary op_id:BoolUnary_f child:{(DQ (${ VSub_Name CACHE))})) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:N) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(kfind)} {(-type)} {(d)} {(-newer)} {(DQ (${ VSub_Name CACHE))} {(-print)} {(-quit)} ) (C {(wc)} {(-l)}) ] negated: False ) ] ) left_token: spids: [308 332] ) } spids: [307] ) ] spids: [307] ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ (${ VSub_Name N))} right: {(0)} ) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:NEED_FIND) op: Equal rhs: {(false)} spids: [351] ) ] spids: [351] ) ] op_id: Op_DAmp ) ] spids: [-1 304] ) ] spids: [-1 354] ) (C {(mkdir)} {(-p)} { (CommandSubPart command_list: (CommandList children:[(C {(dirname)} {(DQ (${ VSub_Name CACHE))})]) left_token: spids: [360 368] ) } ) (If arms: [ (if_arm cond: [ (Sentence child: (C { (CommandSubPart command_list: (CommandList children:[(C {(DQ (${ VSub_Name NEED_FIND))})]) left_token: spids: [372 378] ) } ) terminator: ) ] action: [ (Pipeline children: [ (C {(kfind)} {(-type)} {(f)} {(-name)} {(EscapedLiteralPart token:) (.go)} ) (C {(sed)} {(SQ <"s|/[^/]*$||">)}) (C {(sed)} {(SQ <"s|^./||">)}) (SimpleCommand words: [{(sort)} {(-u)}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name CACHE))} spids: [428] ) ] more_env: [(env_pair name:LC_ALL val:{(C)} spids:[419])] ) ] negated: False ) ] spids: [-1 381] ) ] spids: [-1 436] ) (C {(cat)} {(DQ (${ VSub_Name CACHE))}) ] )