Debian Codegraph @

Makefile

raw
1 VERSION != git describe --dirty --tags --always
2 COMMIT != git rev-parse HEAD
3 DATE != date -u +"%Y-%m-%dT%H:%M:%SZ"
4
5 all: clean nerdlog
6
7 .PHONY: nerdlog
8 nerdlog:
9 @go build \
10 -o bin/nerdlog \
11 -ldflags "\
12 -X 'github.com/dimonomid/nerdlog/version.version=$(patsubst v%,%,$(VERSION))' \
13 -X 'github.com/dimonomid/nerdlog/version.commit=$(COMMIT)' \
14 -X 'github.com/dimonomid/nerdlog/version.date=$(DATE)' \
15 -X 'github.com/dimonomid/nerdlog/version.builtBy=make' \
16 " \
17 ./cmd/nerdlog
18
19 .PHONY: clean
20 clean:
21 @rm -rf bin
22
23 PREFIX ?= /usr/local
24 DESTDIR ?=
25 BINDIR := $(DESTDIR)$(PREFIX)/bin
26 INSTALL := install
27 INSTALL_FLAGS := -m 755
28
29 .PHONY: install
30 install:
31 $(INSTALL) $(INSTALL_FLAGS) -D bin/nerdlog $(BINDIR)/nerdlog
32
33 # Run (almost) all tests (core tests will run for a single hostname: localhost
34 # by default, can be overridden using the NERDLOG_CORE_TEST_HOSTNAME env var).
35 #
36 # To skip the repetitions of the agent tests with shorter index file (expecting
37 # it to "index up"), because it's the slowest part of the tests, set env var
38 # NERDLOG_AGENT_TEST_SKIP_INDEX_UP
39 test:
40 @# This step is needed to make sure that we don't get extra output like
41 @# "go: downloading github.com/spf13/pflag v1.0.6" when running journalctl_mock,
42 @# since it ends up in the debug output from the script which we then compare
43 @# with the expected output.
44 cd cmd/journalctl_mock && go build -o /dev/null
45 @# The tests run rather slow so we use "-v -p 1" so that we get the unbuffered
46 @# output.
47 go test ./... -count 1 -v -p 1 $(ARGS)
48
49 # Same as test above, but run all the possible variations of the tests.
50 # For it to work, you need to be able to "ssh 127.0.0.1" without password.
51 test-all-variations:
52 @# Run all the default test configurations, which means that for core tests,
53 @# we'll use "localhost" as the hostname, which will use local transport.
54 make test
55 @# Rerun core tests using "127.0.0.1" as the hostname, which will use ssh
56 @# transport.
57 NERDLOG_CORE_TEST_HOSTNAME=127.0.0.1 make test ARGS='-run TestCoreScenarios'
58 @# Rerun core tests using "127.0.0.1" as the hostname and external ssh bin.
59 NERDLOG_CORE_TEST_HOSTNAME=127.0.0.1 NERDLOG_CORE_TEST_TRANSPORT_SSH_BIN=1 \
60 make test ARGS='-run TestCoreScenarios'
61
62 # Run the tests (without the index-up repetitions), and update all the expected
63 # outputs in the repo.
64 #
65 # After running it, it's your job to examine the diff carefully, and if all the
66 # changes look legit, commit them.
67 update-test-expectations:
68 rm -rf \
69 /tmp/nerdlog_agent_test_output \
70 /tmp/nerdlog_core_test_output \
71 /tmp/nerdlog_e2e_test_output
72 -NERDLOG_AGENT_TEST_SKIP_INDEX_UP=1 make test
73 bash util/copy_agent_test_results.sh
74 bash util/copy_core_test_results.sh
75 bash util/copy_e2e_test_results.sh
76 @# Also run core tests with 127.0.0.1 as the host, to update host-dependent
77 @# payloads for that hostname.
78 rm -rf /tmp/nerdlog_core_test_output
79 -NERDLOG_CORE_TEST_HOSTNAME=127.0.0.1 make test ARGS='-run TestCoreScenarios'
80 bash util/copy_core_test_results.sh
81 @# Also run core tests with 127.0.0.1 and ssh-bin, to update host-dependent
82 @# payloads for that hostname.
83 rm -rf /tmp/nerdlog_core_test_output
84 -NERDLOG_CORE_TEST_HOSTNAME=127.0.0.1 \
85 NERDLOG_CORE_TEST_TRANSPORT_SSH_BIN=1 \
86 make test ARGS='-run TestCoreScenarios'
87 bash util/copy_core_test_results.sh
88
89 bench:
90 # The -run=^$ is needed to avoid running the regular tests as well.
91 go test ./core -bench=BenchmarkNerdlogAgent -benchtime=3s -run=^$