Merge pull request #1920 from bzub/1919-build_go_plugins_script

Add script to detect/build Go plugins.
This commit is contained in:
Jeff Regan
2019-12-12 09:56:37 -08:00
committed by GitHub
2 changed files with 54 additions and 0 deletions

View File

@@ -229,6 +229,20 @@ $(MYGOBIN)/helm:
rm -rf $$d \
)
.PHONY: build-external-go-plugins
build-external-go-plugins:
( \
cd plugin; \
../hack/buildExternalGoPlugins.sh; \
)
.PHONY: clean-external-go-plugins
clean-external-go-plugins:
( \
cd plugin; \
../hack/buildExternalGoPlugins.sh clean; \
)
.PHONY: clean
clean:
go clean --cache

40
hack/buildExternalGoPlugins.sh Executable file
View File

@@ -0,0 +1,40 @@
#!/usr/bin/env sh
set -e
# We assume one go file per plugin, and the desired name of the plugin .so
# matches the basename of said go file.
# Example: ReplacementTransformer.go -> ReplacementTransformer.so
#
# We also assume the script is run from a kustomize plugin directory.
# Usually one of:
# - ${HOME}/.config/kustomize/plugin
# - ${kustomize_git_repo}/plugin
plugins_dir="${PWD}"
command="${1}"
function buildPlugin {
pushd "${1}" >& /dev/null
plugin_src="$(find "${1}" -name '*.go'|grep -Ev '.*_test.go'|head -n1)"
plugin_bin="$(echo "${plugin_src}"|sed 's/\(.*\).go/\1.so/')"
if [ "${command}" = "clean" ]; then
echo "Deleting ${plugin_bin}"
rm -f "${plugin_bin}"
return
fi
echo "Building ${plugin_bin}"
go build -buildmode plugin -o "${plugin_bin}" "${plugin_src}"
popd >& /dev/null
}
for goMod in $(find "${plugins_dir}" -name 'go.mod'); do
d=$(dirname "${goMod}")
# Skip "builtin" plugins in kustomize repo.
if [ ! -z "$(echo "${goMod}" | grep -F "/plugin/builtin/")" ]; then
continue
fi
# Skip plugins with only test Go files.
if [ -z "$(find "${d}" -maxdepth 1 -name '*.go' | grep -Ev ".*_test.go")" ]; then
continue
fi
buildPlugin "${d}"
done