Makefile.generated_files: build code-generator+sample-apiserver OpenAPI schemas

This commit is contained in:
Dr. Stefan Schimanski
2019-07-08 22:46:20 +02:00
parent 1bdcabd638
commit e920d9bc14
5 changed files with 174 additions and 62 deletions

View File

@@ -56,7 +56,7 @@ function newer() {
if [[ "${F}" -nt "$2" ]]; then
echo "${F}"
fi
done
done | LC_ALL=C sort
}
# $1 = filename pattern as in "zz_generated.$1.go"
@@ -66,7 +66,7 @@ function older() {
if [[ "$2" -nt "${F}" ]]; then
echo "${F}"
fi
done
done | LC_ALL=C sort
}
function assert_clean() {
@@ -286,12 +286,32 @@ if [[ -n "${X}" ]]; then
fi
#
# Test when we touch a file in a package that needs codegen.
# Test when we touch a file in a package that needs codegen for all openapi specs.
#
assert_clean
touch "staging/src/k8s.io/api/core/v1/types.go"
touch "staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go"
touch "${STAMP}"
make generated_files >/dev/null
X="$(newer openapi "${STAMP}")"
if [[ -z "${X}" || ${X} != "./pkg/generated/openapi/zz_generated.openapi.go
./staging/src/k8s.io/apiextensions-apiserver/pkg/generated/openapi/zz_generated.openapi.go
./staging/src/k8s.io/code-generator/_examples/apiserver/openapi/zz_generated.openapi.go
./staging/src/k8s.io/sample-apiserver/pkg/generated/openapi/zz_generated.openapi.go" ]]; then
echo "Wrong generated openapi files changed after touching src file:"
echo " ${X:-(none)}" | tr '\n' ' '
echo ""
exit 1
fi
#
# Test when we touch a file in a package that needs codegen for only the main openapi spec.
#
assert_clean
touch "staging/src/k8s.io/api/apps/v1/types.go"
touch "${STAMP}"
make generated_files >/dev/null
X="$(newer openapi "${STAMP}")"
@@ -302,6 +322,40 @@ if [[ -z "${X}" || ${X} != "./pkg/generated/openapi/zz_generated.openapi.go" ]];
exit 1
fi
#
# Test when we touch a file, modify the violation file it should fail, and UPDATE_API_KNOWN_VIOLATIONS=true updates it.
#
assert_clean
touch "staging/src/k8s.io/apimachinery/pkg/apis/meta/v1/types.go"
echo > api/api-rules/violation_exceptions.list
echo > api/api-rules/codegen_violation_exceptions.list
if make generated_files >/dev/null; then
echo "Expected make generated_files to fail with API violations."
echo ""
exit 1
fi
touch "${STAMP}"
make generated_files UPDATE_API_KNOWN_VIOLATIONS=true >/dev/null
X="$(newer openapi "${STAMP}")"
if [[ -z "${X}" || ${X} != "./pkg/generated/openapi/zz_generated.openapi.go
./staging/src/k8s.io/apiextensions-apiserver/pkg/generated/openapi/zz_generated.openapi.go
./staging/src/k8s.io/code-generator/_examples/apiserver/openapi/zz_generated.openapi.go
./staging/src/k8s.io/sample-apiserver/pkg/generated/openapi/zz_generated.openapi.go" ]]; then
echo "Wrong generated openapi files changed after updating violation files:"
echo " ${X:-(none)}" | tr '\n' ' '
echo ""
exit 1
fi
for f in api/api-rules/violation_exceptions.list api/api-rules/codegen_violation_exceptions.list; do
if ! git diff --quiet "$f"; then
echo "Violation file \"$f\" was not updated with UPDATE_API_KNOWN_VIOLATIONS=true."
echo ""
exit 1
fi
done
#
# Test when the codegen tool itself changes: openapi
#