Update codegen script to remove workarounds
Signed-off-by: James Munnelly <jmunnelly@apple.com>
This commit is contained in:
parent
538683bdf3
commit
b2353bee4b
@ -165,7 +165,6 @@ sh_binary(
|
||||
"@io_k8s_code_generator//cmd/lister-gen",
|
||||
],
|
||||
deps = [
|
||||
":utils", # This is added to ensure that if ./utils.sh changes Bazel knows to re-run this target
|
||||
"@bazel_tools//tools/bash/runfiles",
|
||||
],
|
||||
)
|
||||
@ -277,8 +276,3 @@ filegroup(
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
sh_library(
|
||||
name = "utils",
|
||||
srcs = ["utils.sh"],
|
||||
)
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Copyright 2020 The cert-manager Authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@ -14,6 +13,10 @@
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
if [[ -n "${BUILD_WORKSPACE_DIRECTORY:-}" ]]; then # Running inside bazel
|
||||
echo "Updating generated clients..." >&2
|
||||
elif ! command -v bazel &>/dev/null; then
|
||||
@ -27,38 +30,8 @@ else
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Source runfiles.bash to to be able to use the rlocation function that is
|
||||
# defined in the above linked script. This function finds runtime location of
|
||||
# scripts thus allowing us to source other bash scripts when this script is run
|
||||
# by Bazel.
|
||||
# https://github.com/bazelbuild/bazel/blob/master/tools/bash/runfiles/runfiles.bash .
|
||||
|
||||
# The runfiles.bash is added as a dep of the update-codegen target that is
|
||||
# used to run this script. Bazel places deps of sh_binary targets in runfiles
|
||||
# https://docs.bazel.build/versions/main/be/shell.html#sh_binary_args and the
|
||||
# following lines attempt to source this script from one of the known runfile
|
||||
# location for runfiles for this target.
|
||||
|
||||
# set -e pipefail needs to happen after sourcing runfiles.bash, see
|
||||
# https://github.com/bazelbuild/bazel/blob/master/tools/bash/runfiles/runfiles.bash#L21
|
||||
|
||||
# --- begin runfiles.bash initialization v2 ---
|
||||
# Copy-pasted from the Bazel Bash runfiles library v2.
|
||||
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
|
||||
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
|
||||
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
|
||||
source "$0.runfiles/$f" 2>/dev/null || \
|
||||
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
|
||||
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
|
||||
# --- end runfiles.bash initialization v2 ---
|
||||
|
||||
|
||||
module_name="github.com/jetstack/cert-manager"
|
||||
|
||||
# Access to util functions
|
||||
source "$(rlocation com_github_jetstack_cert_manager/hack/utils.sh)"
|
||||
|
||||
# Generate deepcopy functions for all internal and external APIs
|
||||
deepcopy_inputs=(
|
||||
pkg/apis/certmanager/v1alpha2 \
|
||||
@ -270,53 +243,27 @@ gen-defaulters() {
|
||||
done
|
||||
}
|
||||
|
||||
# TODO: fix the workarounds in this function, files that start with "// +build
|
||||
# !ignore_autogenerated" and "//go:build !ignore_autogenerated" are ignored by the
|
||||
# conversion-gen tool, causing an incorrect 'zz_generated.conversion.go' to be
|
||||
# generated. This bug should get resolved in
|
||||
# https://github.com/kubernetes/kubernetes/issues/101567
|
||||
gen-conversions() {
|
||||
clean internal/apis 'zz_generated.conversion.go'
|
||||
clean pkg/webhook/handlers/testdata/apis 'zz_generated.conversion.go'
|
||||
echo "Generating conversion functions..." >&2
|
||||
|
||||
# meta api
|
||||
"$conversiongen" --go-header-file hack/boilerplate/boilerplate.generatego.txt \
|
||||
--input-dirs github.com/jetstack/cert-manager/internal/apis/meta/v1 \
|
||||
-O zz_generated.conversion
|
||||
|
||||
# Workaround (see: https://github.com/kubernetes/kubernetes/issues/101567).
|
||||
remove_go_autogen_tags "internal/apis/meta/v1/zz_generated.conversion.go"
|
||||
CONVERSION_EXTRA_PEER_PKGS=(
|
||||
github.com/jetstack/cert-manager/internal/apis/meta \
|
||||
github.com/jetstack/cert-manager/internal/apis/meta/v1 \
|
||||
github.com/jetstack/cert-manager/pkg/apis/meta/v1
|
||||
)
|
||||
CONVERSION_PKGS=( "${conversion_inputs[@]/#/$module_name/}" )
|
||||
|
||||
# acme and certmanager apis
|
||||
for v in v1alpha2 v1alpha3 v1beta1 v1
|
||||
do
|
||||
"$conversiongen" --go-header-file hack/boilerplate/boilerplate.generatego.txt \
|
||||
--input-dirs "github.com/jetstack/cert-manager/internal/apis/acme/$v" \
|
||||
-O zz_generated.conversion \
|
||||
--extra-dirs github.com/jetstack/cert-manager/internal/apis/meta/v1
|
||||
|
||||
# Workaround (see: https://github.com/kubernetes/kubernetes/issues/101567)
|
||||
remove_go_autogen_tags "internal/apis/acme/$v/zz_generated.conversion.go"
|
||||
"$conversiongen" \
|
||||
--go-header-file hack/boilerplate/boilerplate.generatego.txt \
|
||||
--extra-peer-dirs $( IFS=$','; echo "${CONVERSION_EXTRA_PEER_PKGS[*]}" ) \
|
||||
--extra-dirs $( IFS=$','; echo "${CONVERSION_PKGS[*]}" ) \
|
||||
--input-dirs $( IFS=$','; echo "${CONVERSION_PKGS[*]}" ) \
|
||||
-O zz_generated.conversion
|
||||
|
||||
"$conversiongen" --go-header-file hack/boilerplate/boilerplate.generatego.txt \
|
||||
--input-dirs "github.com/jetstack/cert-manager/internal/apis/certmanager/$v" \
|
||||
-O zz_generated.conversion \
|
||||
--extra-dirs "github.com/jetstack/cert-manager/internal/apis/meta/v1,github.com/jetstack/cert-manager/internal/apis/acme/$v"
|
||||
|
||||
# Workaround (see: https://github.com/kubernetes/kubernetes/issues/101567)
|
||||
remove_go_autogen_tags "internal/apis/certmanager/$v/zz_generated.conversion.go"
|
||||
done
|
||||
|
||||
# test apis
|
||||
"$conversiongen" --go-header-file hack/boilerplate/boilerplate.generatego.txt \
|
||||
--input-dirs github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup/v2,github.com/jetstack/cert-manager/pkg/webhook/handlers/testdata/apis/testgroup/v1 \
|
||||
-O zz_generated.conversion
|
||||
|
||||
# copy into source folder
|
||||
for dir in "${conversion_inputs[@]}"; do
|
||||
# Workaround (see: https://github.com/kubernetes/kubernetes/issues/101567)
|
||||
replace_go_autogen_tags "$dir/zz_generated.conversion.go"
|
||||
copyfiles "$dir" "zz_generated.conversion.go"
|
||||
done
|
||||
}
|
||||
|
||||
@ -1,70 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Copyright 2021 The cert-manager 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
|
||||
|
||||
REPLACE_NEW=TEMP_REPLACE_IGNORE_AUTOGENERATED_NEW_SYNTAX
|
||||
REPLACE_OLD=TEMP_REPLACE_IGNORE_AUTOGENERATED_OLD_SYNTAX
|
||||
|
||||
remove_go_autogen_tags() {
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: hack::lib::remove_go_autogen_tags <file>"
|
||||
exit 1
|
||||
fi
|
||||
local file="$1"
|
||||
|
||||
local sed_args
|
||||
if [[ $(uname) == 'Darwin' ]]; then
|
||||
sed_args=''
|
||||
elif [[ $(uname) == 'Linux' ]]; then
|
||||
sed_args+=('-i')
|
||||
else
|
||||
echo "Unsupported OS: $(uname), please raise an issue if you would like it to be supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Currently (Go 1.17) both // +build and //go: build lines are added to files.
|
||||
# This code should keep working with a new version of Go that only adds //go: build lines.
|
||||
# https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md
|
||||
sed "${sed_args}" -e "s/\+build \!ignore_autogenerated/$REPLACE_OLD/" "${file}" \
|
||||
-e "s/go\:build\ \!ignore_autogenerated/$REPLACE_NEW/" "${file}"
|
||||
}
|
||||
|
||||
replace_go_autogen_tags() {
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: hack::lib::remove_go_autogen_tags <file>"
|
||||
exit 1
|
||||
fi
|
||||
local file="$1"
|
||||
|
||||
local sed_args
|
||||
if [[ $(uname) == 'Darwin' ]]; then
|
||||
sed_args=''
|
||||
elif [[ $(uname) == 'Linux' ]]; then
|
||||
sed_args='-i'
|
||||
else
|
||||
echo "Unsupported OS: $(uname), please raise an issue if you would like it to be supported"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Currently (Go 1.17) both // +build and //go: build lines are added to
|
||||
# files.
|
||||
# This code should keep working with a new version of Go that only adds //go: build lines.
|
||||
# See https://go.googlesource.com/proposal/+/master/design/draft-gobuild.md
|
||||
sed "${sed_args}" -e "s/$REPLACE_NEW/go\:build\ \!ignore_autogenerated/" "${file}" \
|
||||
-e "s/$REPLACE_OLD/\+build \!ignore_autogenerated/" "${file}"
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user