From e48feed3d9c0c00452044c55793eecfd8d311a25 Mon Sep 17 00:00:00 2001 From: Paul Jolly Date: Sun, 1 Oct 2023 06:32:10 +0100 Subject: [PATCH] preprocessor: move logic on removing targets to preprocessor The logic to remove hugo/content and _public in _scripts/runPreprocessor.bash is too fragile. We have one exception rule already and in a later CL we would add another. This proves the logic does not belong here, and would actually be better placed (as coarse as it is) in the preprocessor itself. Make that change. Also turn of -x logging in _scripts/runPreprocessor.bash, and remove an old rm artefact from _scripts/build.bash. Note that we now fully rely on hugo removing _public, via the --cleanDestinationDir flag. This again seems like the right thing to do, rather than trying to code the logic (and timing) ourselves. Preprocessor-No-Write-Cache: true Signed-off-by: Paul Jolly Change-Id: I602f422163192e97e5400c1326c2199ee2921c30 Dispatch-Trailer: {"type":"trybot","CL":1170170,"patchset":2,"ref":"refs/changes/70/1170170/2","targetBranch":"alpha"} --- _scripts/build.bash | 6 ------ _scripts/runPreprocessor.bash | 13 +------------ internal/cmd/preprocessor/cmd/execute_context.go | 10 ++++++++++ 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/_scripts/build.bash b/_scripts/build.bash index 4e091cc309..a6f60c2ce4 100755 --- a/_scripts/build.bash +++ b/_scripts/build.bash @@ -39,12 +39,6 @@ fi # Build playground bash playground/_scripts/build.bash -# Remove preprocessor target directory. This ensures we don't leave any stale -# files lying around. -# -# TODO: make the prepreprocess smart enough to do this itself. -rm -rf hugo/content - # Run the preprocessor bash _scripts/runPreprocessor.bash execute --debug=all,-cache --norun=$norun $skipcache diff --git a/_scripts/runPreprocessor.bash b/_scripts/runPreprocessor.bash index 851dad2cb6..4cb0719e86 100755 --- a/_scripts/runPreprocessor.bash +++ b/_scripts/runPreprocessor.bash @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eux +set -eu # cd to the parent directory to that containing the script cd "$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )/.." @@ -26,15 +26,4 @@ fi GOBIN=$PWD/.gobin go install -trimpath -buildvcs=false ./internal/cmd/preprocessor -# Remove preprocessor and hugo target directories. This ensures we don't leave -# any stale files lying around. Slight hack: only do so if we are running the -# execute command (but not when running with the --serve or --check flags) . -# Note this ties this script to _scripts/serve.bash so if making changes to -# order or args in that script, make changes to the check here. -# -# TODO: make the prepreprocessor smart enough to do this itself. -if [[ "${1:-}" == "execute" && "${2:-}" != "--serve" && "${2:-}" != "--check" ]]; then - rm -rf _public hugo/content -fi - exec $PWD/.gobin/preprocessor "$@" diff --git a/internal/cmd/preprocessor/cmd/execute_context.go b/internal/cmd/preprocessor/cmd/execute_context.go index 966fb93003..ba15026c3b 100644 --- a/internal/cmd/preprocessor/cmd/execute_context.go +++ b/internal/cmd/preprocessor/cmd/execute_context.go @@ -88,6 +88,16 @@ func (ec *executeContext) execute() error { return errorIfInError(ec) } + // At this point we know we are not in --check mode, check we are not in + // serve mode and delete hugo/content as a temporary(ish) measure to ensure + // that we don't leave any stale files around. + if !flagServe.Bool(ec.executor.cmd) { + hugoContent := filepath.Join(ec.executor.root, "hugo", "content") + if err := os.RemoveAll(hugoContent); err != nil { + return ec.errorf("%v: failed to remove %s: %v", ec, hugoContent, err) + } + } + // Load all the CUE in one go cfg := &load.Config{ Dir: ec.executor.root,