Nice error message if no types.generated.go files.

Explains how to fix problem, instead of
saying "index" is an unbound reference.

Problem happens when previous run of codecgen deleted all the outputs
and then failed midway.
This commit is contained in:
Eric Tune 2015-12-17 10:07:30 -08:00
parent 05394f9301
commit fb3cfece9c

View File

@ -84,6 +84,14 @@ for (( i=0; i<number; i++ )); do
done
index=(${result})
haveindex=${index:-}
if [[ -z ${haveindex} ]]; then
echo No files found for $0
echo A previous run of $0 may have deleted all the files and then crashed.
echo Use 'touch' to create files named 'types.generated.go' listed as deleted in 'git status'
exit 1
fi
CODECGEN="${PWD}/codecgen_binary"
godep go build -o "${CODECGEN}" github.com/ugorji/go/codec/codecgen
@ -95,11 +103,13 @@ for (( i=0; i < number; i++ )); do
rm -f "${generated_files[${i}]}"
done
# Generate files in the dependency order.
for current in "${index[@]}"; do
generated_file=${generated_files[${current}]}
initial_dir=${PWD}
file=${generated_file//\.generated\.go/.go}
echo "codecgen processing ${file}"
# codecgen work only if invoked from directory where the file
# is located.
pushd "$(dirname ${file})" > /dev/null
@ -107,6 +117,7 @@ for current in "${index[@]}"; do
base_generated_file=$(basename "${generated_file}")
# We use '-d 1234' flag to have a deterministic output everytime.
# The constant was just randomly chosen.
echo Running ${CODECGEN} -d 1234 -o "${base_generated_file}" "${base_file}"
${CODECGEN} -d 1234 -o "${base_generated_file}" "${base_file}"
# Add boilerplate at the begining of the generated file.
sed 's/YEAR/2015/' "${initial_dir}/hack/boilerplate/boilerplate.go.txt" > "${base_generated_file}.tmp"