k3s/hack/verify-generated-files-rema...

360 lines
9.1 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
2017-08-21 22:54:43 +00:00
# Copyright 2017 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 nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2017-08-21 22:54:43 +00:00
source "${KUBE_ROOT}/hack/lib/init.sh"
kube::util::ensure_clean_working_dir
_tmpdir="$(kube::realpath "$(mktemp -d -t verify-generated-files.XXXXXX)")"
kube::util::trap_add "rm -rf ${_tmpdir}" EXIT
_tmp_gopath="${_tmpdir}/go"
_tmp_kuberoot="${_tmp_gopath}/src/k8s.io/kubernetes"
mkdir -p "${_tmp_kuberoot}/.."
cp -a "${KUBE_ROOT}" "${_tmp_kuberoot}/.."
cd "${_tmp_kuberoot}"
# clean out anything from the temp dir that's not checked in
git clean -ffxd
# $1 = filename pattern as in "zz_generated.$1.go"
function find_genfiles() {
find . \
\( \
-not \( \
\( \
-path ./_\* -o \
-path ./.\* \
\) -prune \
\) \
\) -name "zz_generated.$1.go"
}
# $1 = filename pattern as in "zz_generated.$1.go"
# $2 timestamp file
function newer() {
find_genfiles "$1" | while read -r F; do
if [[ "${F}" -nt "$2" ]]; then
echo "${F}"
fi
done
}
# $1 = filename pattern as in "zz_generated.$1.go"
# $2 timestamp file
function older() {
find_genfiles "$1" | while read -r F; do
if [[ "$2" -nt "${F}" ]]; then
echo "${F}"
fi
done
}
function assert_clean() {
make generated_files >/dev/null
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(newer deepcopy "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated files changed on back-to-back 'make' runs:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
return 1
fi
true
}
STAMP=/tmp/stamp.$RANDOM
#
# Test when we touch a file in a package that needs codegen.
#
assert_clean
DIR=staging/src/k8s.io/sample-apiserver/pkg/apis/wardle/v1alpha1
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
touch "${DIR}/types.go"
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(newer deepcopy "${STAMP}")"
if [[ -z "${X}" || ${X} != "./${DIR}/zz_generated.deepcopy.go" ]]; then
echo "Wrong generated deepcopy files changed after touching src file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X:-(none)}" | tr '\n' ' '
echo ""
exit 1
fi
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(newer defaults "${STAMP}")"
if [[ -z "${X}" || ${X} != "./${DIR}/zz_generated.defaults.go" ]]; then
echo "Wrong generated defaults files changed after touching src file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X:-(none)}" | tr '\n' ' '
echo ""
exit 1
fi
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(newer conversion "${STAMP}")"
if [[ -z "${X}" || ${X} != "./${DIR}/zz_generated.conversion.go" ]]; then
echo "Wrong generated conversion files changed after touching src file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X:-(none)}" | tr '\n' ' '
echo ""
exit 1
fi
#
# Test when the codegen tool itself changes: deepcopy
#
assert_clean
touch staging/src/k8s.io/code-generator/cmd/deepcopy-gen/main.go
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older deepcopy "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated deepcopy files did not change after touching code-generator file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch staging/src/k8s.io/code-generator/cmd/deepcopy-gen/
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older deepcopy "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated deepcopy files did not change after touching code-generator dir:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch vendor/k8s.io/gengo/examples/deepcopy-gen/generators/deepcopy.go
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older deepcopy "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated deepcopy files did not change after touching code-generator dep file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch vendor/k8s.io/gengo/examples/deepcopy-gen/generators/
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older deepcopy "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated deepcopy files did not change after touching code-generator dep dir:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
#
# Test when the codegen tool itself changes: defaults
#
assert_clean
touch staging/src/k8s.io/code-generator/cmd/defaulter-gen/main.go
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older defaults "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated defaults files did not change after touching code-generator file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch staging/src/k8s.io/code-generator/cmd/defaulter-gen/
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older defaults "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated defaults files did not change after touching code-generator dir:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch vendor/k8s.io/gengo/examples/defaulter-gen/generators/defaulter.go
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older defaults "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated defaults files did not change after touching code-generator dep file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch vendor/k8s.io/gengo/examples/defaulter-gen/generators/
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older defaults "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated defaults files did not change after touching code-generator dep dir:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
#
# Test when the codegen tool itself changes: conversion
#
assert_clean
touch staging/src/k8s.io/code-generator/cmd/conversion-gen/main.go
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older conversion "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated conversion files did not change after touching code-generator file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch staging/src/k8s.io/code-generator/cmd/conversion-gen/
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older conversion "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated conversion files did not change after touching code-generator dir:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch vendor/k8s.io/code-generator/cmd/conversion-gen/generators/conversion.go
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older conversion "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated conversion files did not change after touching code-generator dep file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch vendor/k8s.io/code-generator/cmd/conversion-gen/generators/
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older conversion "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated conversion files did not change after touching code-generator dep dir:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
#
# Test when we touch a file in a package that needs codegen.
#
assert_clean
touch "staging/src/k8s.io/api/core/v1/types.go"
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(newer openapi "${STAMP}")"
if [[ -z "${X}" || ${X} != "./pkg/generated/openapi/zz_generated.openapi.go" ]]; then
echo "Wrong generated openapi files changed after touching src file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X:-(none)}" | tr '\n' ' '
echo ""
exit 1
fi
#
# Test when the codegen tool itself changes: openapi
#
assert_clean
touch vendor/k8s.io/kube-openapi/cmd/openapi-gen/openapi-gen.go
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older openapi "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated openapi files did not change after touching code-generator file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch vendor/k8s.io/kube-openapi/cmd/openapi-gen/
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older openapi "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated openapi files did not change after touching code-generator dir:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch vendor/k8s.io/kube-openapi/pkg/generators/openapi.go
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older openapi "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated openapi files did not change after touching code-generator dep file:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
exit 1
fi
assert_clean
touch vendor/k8s.io/kube-openapi/pkg/generators
touch "${STAMP}"
make generated_files >/dev/null
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
X="$(older openapi "${STAMP}")"
if [[ -n "${X}" ]]; then
echo "Generated openapi files did not change after touching code-generator dep dir:"
verify-generated-files-remake.sh: use strings instead of arrays. Move away from arrays to strings to fix several shellcheck-reported issues. It isn't useful to expand the found files into arrays, because only things that are checked are if the array is empty or the contents of the first array item. Fix also a shellcheck issue about using a literal string as regexp match. It appears that the original reason for using a regexp was to avoid specifying the directory in which the script is run. However, due to the need of calling 'make generated_files', the directory is fixed anyway, and the regexp can be left out. Testing the change can be done with the following script which emulates the different cases which the script can see. In the output the variable 'X' is the array and 'Z' is the string. #!/bin/bash set -o errexit set -o nounset set -o pipefail function find_genfiles() { find . \ \( \ -not \( \ \( \ -path ./_\* -o \ -path ./.\* \ \) -prune \ \) \ \) -name "$1" } # $1 = filename pattern as in "zz_generated.$1.go" # $2 timestamp file function newer() { find_genfiles "$1" | while read -r F; do if [[ "${F}" -nt "$2" ]]; then echo "${F}" fi done } STAMP=stamp mkdir -p xxx touch xxx/foobar touch "${STAMP}" mkdir -p foo touch foo/foobar mkdir -p bar touch bar/foobar # two newer files X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X1:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z1:" echo " ${Z}" | tr '\n' ' ' echo "" fi # no newer files touch "${STAMP}" X=($(newer foobar "${STAMP}")) if [[ "${#X[*]}" != 0 ]]; then echo "X2:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -n "$Z" ]]; then echo "Z2:" echo " ${Z}" | tr '\n' ' ' echo "" fi # one newer file, name matches touch "${STAMP}" touch bar/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X3:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z3:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi # one newer file, name doesn't match touch "${STAMP}" touch foo/foobar X=($(newer foobar "${STAMP}")) if [[ "${#X[@]}" != 1 || ! ( "${X[0]}" =~ "bar/foobar" ) ]]; then echo "X4:" echo " ${X[*]:-(none)}" fi Z="$(newer foobar "${STAMP}")" if [[ -z "${Z}" || ${Z} != "./bar/foobar" ]]; then echo "Z4:" echo " ${Z:-(none)}" | tr '\n' ' ' echo "" fi The expected output from running this script: X1: ./bar/foobar ./foo/foobar Z1: ./bar/foobar ./foo/foobar X4: ./foo/foobar Z4: ./foo/foobar
2019-01-31 15:37:56 +00:00
echo " ${X}" | tr '\n' ' '
echo ""
2017-08-21 22:54:43 +00:00
exit 1
fi