|
| 1 | +IMPL_NAME := $(notdir $(CURDIR)) |
| 2 | +IMAGE_PREFIX := local/santa-$(IMPL_NAME) |
| 3 | +IMAGE_BUILD := $(IMAGE_PREFIX):build |
| 4 | +IMAGE_CLI := $(IMAGE_PREFIX):cli |
| 5 | +REPO_ROOT := $(abspath $(CURDIR)/../..) |
| 6 | + |
| 7 | +# Optional flags for docker runs, e.g. --platform linux/amd64 |
| 8 | +DOCKER_FLAGS := $(SANTA_DOCKER_FLAGS) |
| 9 | + |
| 10 | +.PHONY: * |
| 11 | + |
| 12 | +help: |
| 13 | + @echo "Targets:" |
| 14 | + @echo " build-image - Build builder image (Dockerfile.build)" |
| 15 | + @echo " cli-image - Build CLI image (Dockerfile.cli)" |
| 16 | + @echo " shell - Interactive dev shell in builder image" |
| 17 | + @echo " exec CMD=... - Run single command in builder image" |
| 18 | + @echo " run ARGS=... - Run CLI image with args (tokens/ast/<file>)" |
| 19 | + @echo " print-uri - Print docker:// URI for santa-test" |
| 20 | + @echo " test - Run santa-test over all tests via docker" |
| 21 | + @echo " test-stage-1 - Run santa-test for tests/stage-1" |
| 22 | + @echo " test-stage-2 - Run santa-test for tests/stage-2" |
| 23 | + @echo " test-stage-3 - Run santa-test for tests/stage-3" |
| 24 | + @echo " test-stage-4 - Run santa-test for tests/stage-4" |
| 25 | + @echo " test-stage-5 - Run santa-test for tests/stage-5" |
| 26 | + @echo " test-file FILE=... - Run santa-test for a single .santat file" |
| 27 | + @echo " clean-images - Remove local images for this impl" |
| 28 | + |
| 29 | +build-image: |
| 30 | + docker build -f Dockerfile.build -t $(IMAGE_BUILD) . |
| 31 | + |
| 32 | +cli-image: build-image |
| 33 | + docker build -f Dockerfile.cli --build-arg BUILDER_IMAGE=$(IMAGE_BUILD) -t $(IMAGE_CLI) . |
| 34 | + |
| 35 | +shell: build-image |
| 36 | + docker run --rm -it $(DOCKER_FLAGS) \ |
| 37 | + -u "$$(id -u):$$(id -g)" \ |
| 38 | + -v "$(REPO_ROOT):$(REPO_ROOT)" -w "$(REPO_ROOT)" \ |
| 39 | + $(IMAGE_BUILD) bash |
| 40 | + |
| 41 | +# Usage: make exec CMD="go test ./..." (always in builder) |
| 42 | +exec: build-image |
| 43 | + docker run --rm $(DOCKER_FLAGS) \ |
| 44 | + -u "$$(id -u):$$(id -g)" \ |
| 45 | + -v "$(REPO_ROOT):$(REPO_ROOT)" -w "$(REPO_ROOT)" \ |
| 46 | + $(IMAGE_BUILD) sh -lc '$(CMD)' |
| 47 | + |
| 48 | +# Usage: make run ARGS="--help" or ARGS="tokens tests/stage-1/01_basic_tokens.santat" |
| 49 | +run: cli-image |
| 50 | + docker run --rm $(DOCKER_FLAGS) \ |
| 51 | + -v "$(REPO_ROOT):$(REPO_ROOT)" -w "$(REPO_ROOT)" \ |
| 52 | + $(IMAGE_CLI) $(ARGS) |
| 53 | + |
| 54 | +print-uri: cli-image |
| 55 | + @echo docker://$(IMAGE_CLI) |
| 56 | + |
| 57 | +test: cli-image |
| 58 | + cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests |
| 59 | + |
| 60 | +test-stage-1: cli-image |
| 61 | + cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-1 |
| 62 | + |
| 63 | +test-stage-2: cli-image |
| 64 | + cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-2 |
| 65 | + |
| 66 | +test-stage-3: cli-image |
| 67 | + cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-3 |
| 68 | + |
| 69 | +test-stage-4: cli-image |
| 70 | + cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-4 |
| 71 | + |
| 72 | +test-stage-5: cli-image |
| 73 | + cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) tests/stage-5 |
| 74 | + |
| 75 | +# Usage: make test-file FILE=tests/stage-1/01_basic_tokens.santat |
| 76 | +test-file: cli-image |
| 77 | + cd "$(REPO_ROOT)" && tools/bin/santa-test --bin docker://$(IMAGE_CLI) $(FILE) |
| 78 | + |
| 79 | +clean-images: |
| 80 | + - docker rmi $(IMAGE_CLI) $(IMAGE_BUILD) |
0 commit comments