-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmakefile
50 lines (35 loc) · 1.25 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
.DEFAULT_GOAL := all
root = $(patsubst %/,%,$(dir $(realpath $(firstword $(MAKEFILE_LIST)))))
##
define assert # assert cmd selector operator sample
$(1) | jq 'select($(2) $(3) $(4) | not) | [ "not matched", "operator:", "$(3)", "actual $(2):", $(2), "want:", $(4) ] | halt_error(1)'
echo '$(2) $(3) $(4)'
endef
define nix-cage
cd /tmp && $(root)/nix-cage $(1)
endef
.PHONY: all
all: # does nothing
.PHONY: build
build: # build package
nix-build .
.PHONY: test
test: build # runs integration tests
$(info == basic tests)
@mkdir -p /tmp/foo
@$(call nix-cage,--show-config > /dev/null)
@$(call assert,$(call nix-cage,--show-config),.mounts.rw[0][0],==,"/tmp")
@$(call assert,$(call nix-cage,-C /tmp/foo --show-config),.mounts.rw[0][0],==,"/tmp/foo")
@rmdir /tmp/foo
$(info == sandbox tests)
echo '{}' > /tmp/emptyjson
$(root)/result/bin/nix-cage --config /var/nonexistent --command 'ls'
$(root)/result/bin/nix-cage --config /tmp/emptyjson --command 'ls'
@rm -f /tmp/emptyjson
##
.PHONY: help
help: # print defined targets and their comments
@grep -Po '^[a-zA-Z%_/\-\s]+:+(\s.*$$|$$)' $(MAKEFILE_LIST) \
| sort \
| sed 's|:.*#|#|;s|#\s*|#|' \
| column -t -s '#' -o ' | '