Skip to content

Commit

Permalink
Compile template-manifestor with bazel
Browse files Browse the repository at this point in the history
This allows running the whole `make` flow with unnested bazel.

Signed-off-by: Roman Mohr <[email protected]>
  • Loading branch information
rmohr committed Jan 12, 2021
1 parent ad89cb7 commit e410cdd
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,16 @@ genrule(
executable = 1,
)

genrule(
name = "build-manifest-templator",
srcs = [
"//tools/manifest-templator",
],
outs = ["manifest-templator-copier"],
cmd = "echo '#!/bin/sh\n\ncp $(SRCS) $$1' > \"$@\"",
executable = 1,
)

genrule(
name = "build-junit-merger",
srcs = [
Expand Down
15 changes: 10 additions & 5 deletions hack/build-manifests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,20 @@ kubevirt_logo_path="assets/kubevirt_logo.png"
rm -rf ${MANIFESTS_OUT_DIR}
rm -rf ${MANIFEST_TEMPLATES_OUT_DIR}

(cd ${KUBEVIRT_DIR}/tools/manifest-templator/ && go_build)
rm -rf "${TESTS_OUT_DIR}/tools"
mkdir -p "${TESTS_OUT_DIR}/tools"
templator=${TESTS_OUT_DIR}/tools/manifest-templator

bazel run \
--config=${ARCHITECTURE} \
//:build-manifest-templator -- ${templator}

# first process file includes only
args=$(cd ${KUBEVIRT_DIR}/manifests && find . -type f -name "*.yaml.in" -not -path "./generated/*")
for arg in $args; do
infile=${KUBEVIRT_DIR}/manifests/${arg}
outfile=${KUBEVIRT_DIR}/manifests/${arg}.tmp

${KUBEVIRT_DIR}/tools/manifest-templator/manifest-templator \
${templator} \
--process-files \
--generated-manifests-dir=${KUBEVIRT_DIR}/manifests/generated/ \
--input-file=${infile} >${outfile}
Expand Down Expand Up @@ -70,7 +75,7 @@ for arg in $args; do
outfile=${final_out_dir}/${manifest}
template_outfile=${final_templates_out_dir}/${manifest}.j2

${KUBEVIRT_DIR}/tools/manifest-templator/manifest-templator \
${templator} \
--process-vars \
--namespace=${namespace} \
--cdi-namespace=${cdi_namespace} \
Expand Down Expand Up @@ -98,7 +103,7 @@ for arg in $args; do
continue
fi

${KUBEVIRT_DIR}/tools/manifest-templator/manifest-templator \
${templator} \
--process-vars \
--namespace="{{ namespace }}" \
--cdi-namespace="{{ cdi_namespace }}" \
Expand Down
6 changes: 6 additions & 0 deletions tools/manifest-templator/manifest-templator.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ func main() {
pflag.CommandLine.ParseErrorsWhitelist.UnknownFlags = true
pflag.Parse()

if path := os.Getenv("BUILD_WORKSPACE_DIRECTORY"); path != "" {
if err := os.Chdir(path); err != nil {
panic(err)
}
}

if !(*processFiles || *processVars) {
panic("at least one of process-files or process-vars must be true")
}
Expand Down

0 comments on commit e410cdd

Please sign in to comment.