Skip to content

Commit

Permalink
(apro) build-aux: Avoid needing things in build-aux/bin/ during clean…
Browse files Browse the repository at this point in the history
… & clobber

So, I run `make clobber`.

common.mk says:

    clobber: clean

The 'clean' target wants to run

    ./build-aux/bin/gubernaut -release $$(cat $*.knaut.claim)

prelude.mk says:

    clobber: _clobber-prelude

The '_clobber-prelude' target wants to run

   rm -rf ./build-aux/bin

Because there is no ordering between dependencies of 'clobber', it is
possible that '_clobber-prelude' deletes bin/gubernaut before 'clean'
tries to run bin/gubernaut.

Avoid this by using `go run` instead of binaries when doing cleanup rules.

This is very awkward and gross because of having to cd to get the correct
Go module, and then that makes us use $(abspath) for file arguments.
  • Loading branch information
LukeShu committed Aug 14, 2019
1 parent cdf5d82 commit 0a01be4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<!-- -*- fill-column: 100 -*- -->
# Datawire build-aux CHANGELOG

- 2019-08-13: Fix race condition in `make clobber` where it attempted to use compiled programs used
for cleanup, after the programs themselves had already been deleted.

- 2019-07-10: `var.mk`: Introduce

- 2019-07-05: `build-aux-push`: Work around problem with `git subtree`; avoid accidentally pushing
Expand Down
8 changes: 8 additions & 0 deletions HACKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
value.
- Make sure to pass `--fail` to `curl` when downloading things;
otherwise it will silently save 404 HTML/XML pages.
- Don't depend on anything in ./build-aux/bin/ during clean and
clobber rules. The `prelude.mk` cleanup might remove it before
your cleanup bit runs. For Go programs, `cd` to the program's
sourcedirectory, and use `go run .` to run it:

cd $(dir $(_myfile.mk))bin-go/PROGRAM && GO111MODULE=on go run . ARGS...

Only tolerate that grossness in your cleanup rules.

## Naming conventions

Expand Down
7 changes: 5 additions & 2 deletions docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ _docker.port-forward = $(dir $(_docker.mk))docker-port-forward
docker push '$(DOCKER_IMAGE)'
.PHONY: %.docker.push

_clean-docker: $(FLOCK)
$(FLOCK) $(_docker.port-forward).lock rm $(_docker.port-forward).lock
# This `go run` bit is gross, compared to just depending on and using
# $(FLOCK). But if the user runs `make clobber`, the prelude.mk
# cleanup might delete $(FLOCK) before we get to run it.
_clean-docker:
cd $(dir $(_docker.mk))bin-go/flock && GO111MODULE=on go run . $(abspath $(_docker.port-forward).lock) rm $(abspath $(_docker.port-forward).lock)
rm -f $(_docker.port-forward).log
rm -f $(dir $(_docker.mk))docker-registry.yaml.o
clean: _clean-docker
Expand Down
7 changes: 5 additions & 2 deletions kubernaut.mk
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ GUBERNAUT ?= $(build-aux.bindir)/gubernaut
$(GUBERNAUT) -release $$(cat $<)
$(GUBERNAUT) -claim $$(cat $<) -output $@

%.knaut.clean: $(GUBERNAUT)
if [ -e $*.knaut.claim ]; then $(GUBERNAUT) -release $$(cat $*.knaut.claim); fi
# This `go run` bit is gross, compared to just depending on and using
# $(GUBERNAUT). But if the user runs `make clobber`, the prelude.mk
# cleanup might delete $(GUBERNAUT) before we get to run it.
%.knaut.clean:
if [ -e $*.knaut.claim ]; then cd $(dir $(_kubernaut.mk))bin-go/gubernaut && GO111MODULE=on go run . -release $$(cat $(abspath $*.knaut.claim)); fi
rm -f $*.knaut $*.knaut.claim
.PHONY: %.knaut.clean

Expand Down

0 comments on commit 0a01be4

Please sign in to comment.