#!/bin/bash # Copyright 2016 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. set -o errexit set -o pipefail set -o nounset if [[ -z "${KUBE_ROOT:-}" ]] { global KUBE_ROOT := "$[dirname $(BASH_SOURCE)]/.." } source "$(KUBE_ROOT)/cluster/lib/logging.sh" if [[ ! -d "${KUBE_ROOT}/examples" ]] { echo "$(KUBE_ROOT)/examples not detected. This script should be run from a location where the source dirs are available." exit 1 } # kube::golang::build_kube_toolchain installs the vendored go-bindata in # $GOPATH/bin, so make sure that's explicitly part of our $PATH. export PATH="$(GOPATH)/bin:$(PATH)" if ! which go-bindata &>/dev/null ; { echo "Cannot find go-bindata." exit 5 } # run the generation from the root directory for stable output pushd $(KUBE_ROOT) # These are files for e2e tests. global BINDATA_OUTPUT := '"test/e2e/generated/bindata.go'" go-bindata -nometadata -o "$(BINDATA_OUTPUT).tmp" -pkg generated \ -ignore .jpg -ignore .png -ignore .md \ "examples/..." \ "test/e2e/testing-manifests/..." \ "test/images/..." \ "test/fixtures/..." gofmt -s -w "$(BINDATA_OUTPUT).tmp" # Here we compare and overwrite only if different to avoid updating the # timestamp and triggering a rebuild. The 'cat' redirect trick to preserve file # permissions of the target file. if ! cmp -s "$(BINDATA_OUTPUT).tmp" $(BINDATA_OUTPUT) { cat "$(BINDATA_OUTPUT).tmp" > $(BINDATA_OUTPUT) env V=2 kube::log::info "Generated bindata file : $(BINDATA_OUTPUT) has $[wc -l $(BINDATA_OUTPUT)] lines of lovely automated artifacts" } else { env V=2 kube::log::info "No changes in generated bindata file: $(BINDATA_OUTPUT)" } rm -f "$(BINDATA_OUTPUT).tmp" # These are files for runtime code global BINDATA_OUTPUT := '"pkg/generated/bindata.go'" go-bindata -nometadata -nocompress -o "$(BINDATA_OUTPUT).tmp" -pkg generated \ -ignore .jpg -ignore .png -ignore .md \ "translations/..." gofmt -s -w "$(BINDATA_OUTPUT).tmp" # Here we compare and overwrite only if different to avoid updating the # timestamp and triggering a rebuild. The 'cat' redirect trick to preserve file # permissions of the target file. if ! cmp -s "$(BINDATA_OUTPUT).tmp" $(BINDATA_OUTPUT) { cat "$(BINDATA_OUTPUT).tmp" > $(BINDATA_OUTPUT) env V=2 kube::log::info "Generated bindata file : $(BINDATA_OUTPUT) has $[wc -l $(BINDATA_OUTPUT)] lines of lovely automated artifacts" } else { env V=2 kube::log::info "No changes in generated bindata file: $(BINDATA_OUTPUT)" } rm -f "$(BINDATA_OUTPUT).tmp" popd (CommandList children: [ (C {(set)} {(-o)} {(errexit)}) (C {(set)} {(-o)} {(pipefail)}) (C {(set)} {(-o)} {(nounset)}) (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: [70 73] ) ) } ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:KUBE_ROOT) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [(C {(dirname)} {(DQ (${ VSub_Name BASH_SOURCE))})] ) left_token: spids: [83 91] ) (/..) } spids: [82] ) ] spids: [82] ) ] spids: [-1 79] ) ] spids: [-1 94] ) (C {(source)} {(DQ (${ VSub_Name KUBE_ROOT) (/cluster/lib/logging.sh))}) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (LogicalNot child: (BoolUnary op_id: BoolUnary_d child: {(DQ (${ VSub_Name KUBE_ROOT) (/examples))} ) ) ) terminator: ) ] action: [ (C {(echo)} { (DQ (${ VSub_Name KUBE_ROOT) ( "/examples not detected. This script should be run from a location where the source dirs are available." ) ) } ) (C {(exit)} {(1)}) ] spids: [-1 125] ) ] spids: [-1 142] ) (C {(export)} {(Lit_VarLike "PATH=") (DQ (${ VSub_Name GOPATH) ("/bin:") (${ VSub_Name PATH))}) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children:[(C {(which)} {(go-bindata)})] negated:True) terminator: ) (Sentence child: (SimpleCommand redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(/dev/null)} spids:[174])] ) terminator: ) ] action: [(C {(echo)} {(DQ ("Cannot find go-bindata."))}) (C {(exit)} {(5)})] spids: [-1 179] ) ] spids: [-1 193] ) (C {(pushd)} {(DQ (${ VSub_Name KUBE_ROOT))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BINDATA_OUTPUT) op: Equal rhs: {(DQ (test/e2e/generated/bindata.go))} spids: [211] ) ] spids: [211] ) (C {(go-bindata)} {(-nometadata)} {(-o)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))} {(-pkg)} {(generated)} {(-ignore)} {(.jpg)} {(-ignore)} {(.png)} {(-ignore)} {(.md)} {(DQ (examples/...))} {(DQ (test/e2e/testing-manifests/...))} {(DQ (test/images/...))} {(DQ (test/fixtures/...))} ) (C {(gofmt)} {(-s)} {(-w)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))}) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(cmp)} {(-s)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))} {(DQ (${ VSub_Name BINDATA_OUTPUT))} ) ] negated: True ) terminator: ) ] action: [ (SimpleCommand words: [{(cat)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name BINDATA_OUTPUT))} spids: [330] ) ] ) (SimpleCommand words: [ {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (info)} { (DQ ("Generated bindata file : ") (${ VSub_Name BINDATA_OUTPUT) (" has ") (CommandSubPart command_list: (CommandList children: [(C {(wc)} {(-l)} {(${ VSub_Name BINDATA_OUTPUT)})] ) left_token: spids: [356 364] ) (" lines of lovely automated artifacts") ) } ] more_env: [(env_pair name:V val:{(2)} spids:[339])] ) ] spids: [-1 318] ) ] else_action: [ (SimpleCommand words: [ {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (info)} {(DQ ("No changes in generated bindata file: ") (${ VSub_Name BINDATA_OUTPUT))} ] more_env: [(env_pair name:V val:{(2)} spids:[371])] ) ] spids: [368 389] ) (C {(rm)} {(-f)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))}) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:BINDATA_OUTPUT) op: Equal rhs: {(DQ (pkg/generated/bindata.go))} spids: [407] ) ] spids: [407] ) (C {(go-bindata)} {(-nometadata)} {(-nocompress)} {(-o)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))} {(-pkg)} {(generated)} {(-ignore)} {(.jpg)} {(-ignore)} {(.png)} {(-ignore)} {(.md)} {(DQ (translations/...))} ) (C {(gofmt)} {(-s)} {(-w)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))}) (If arms: [ (if_arm cond: [ (Sentence child: (Pipeline children: [ (C {(cmp)} {(-s)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))} {(DQ (${ VSub_Name BINDATA_OUTPUT))} ) ] negated: True ) terminator: ) ] action: [ (SimpleCommand words: [{(cat)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))}] redirects: [ (Redir op_id: Redir_Great fd: -1 arg_word: {(DQ (${ VSub_Name BINDATA_OUTPUT))} spids: [510] ) ] ) (SimpleCommand words: [ {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (info)} { (DQ ("Generated bindata file : ") (${ VSub_Name BINDATA_OUTPUT) (" has ") (CommandSubPart command_list: (CommandList children: [(C {(wc)} {(-l)} {(${ VSub_Name BINDATA_OUTPUT)})] ) left_token: spids: [536 544] ) (" lines of lovely automated artifacts") ) } ] more_env: [(env_pair name:V val:{(2)} spids:[519])] ) ] spids: [-1 498] ) ] else_action: [ (SimpleCommand words: [ {(kube) (Lit_Other ":") (Lit_Other ":") (log) (Lit_Other ":") (Lit_Other ":") (info)} {(DQ ("No changes in generated bindata file: ") (${ VSub_Name BINDATA_OUTPUT))} ] more_env: [(env_pair name:V val:{(2)} spids:[551])] ) ] spids: [548 569] ) (C {(rm)} {(-f)} {(DQ (${ VSub_Name BINDATA_OUTPUT) (.tmp))}) (C {(popd)}) ] )