Skip to content

Commit

Permalink
preprocessor: move logic on removing targets to preprocessor
Browse files Browse the repository at this point in the history
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 <[email protected]>
Change-Id: I602f422163192e97e5400c1326c2199ee2921c30
Dispatch-Trailer: {"type":"trybot","CL":1170170,"patchset":2,"ref":"refs/changes/70/1170170/2","targetBranch":"alpha"}
  • Loading branch information
myitcv authored and cueckoo committed Oct 2, 2023
1 parent e7b1655 commit e48feed
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
6 changes: 0 additions & 6 deletions _scripts/build.bash
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 1 addition & 12 deletions _scripts/runPreprocessor.bash
Original file line number Diff line number Diff line change
@@ -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 )/.."
Expand All @@ -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 "$@"
10 changes: 10 additions & 0 deletions internal/cmd/preprocessor/cmd/execute_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit e48feed

Please sign in to comment.