forked from elastic/ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
120 lines (101 loc) · 3.26 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#
# Variables
#
.DEFAULT_GOAL := all
FIND := find . -type f -not -path './build/*' -not -path './.git/*'
FORCE_GO_MODULES := GO111MODULE=on
OPEN_DOCS ?= "--open"
PYTHON := build/ve/bin/python
VERSION := $(shell cat version)
#
# Targets (sorted alphabetically)
#
# Default build generates main and experimental artifacts
.PHONY: all
all: generate experimental
# Check verifies that all of the committed files that are generated are
# up-to-date.
.PHONY: check
check: generate experimental test fmt misspell makelint check-license-headers
# Check if diff is empty.
git diff | cat
git update-index --refresh
git diff-index --exit-code HEAD --
# Check license headers on files (currently .go files only).
.PHONY: check-license-headers
check-license-headers:
go get github.com/elastic/go-licenser
go-licenser -d
# Clean deletes all temporary and generated content.
.PHONY: clean
clean:
rm -rf build generated/elasticsearch/component experimental/generated/elasticsearch/component
# Alias to generate source code for all languages.
.PHONY: codegen
codegen: gocodegen
# Build the asciidoc book.
.PHONY: docs
docs:
if [ ! -d $(PWD)/build/docs ]; then \
git clone --depth=1 https://github.com/elastic/docs.git ./build/docs ; \
fi
./build/docs/build_docs --asciidoctor --doc ./docs/index.asciidoc --chunk=2 $(OPEN_DOCS) --out ./build/html_docs
# Alias to generate experimental artifacts
.PHONY: experimental
experimental: ve
$(PYTHON) scripts/generator.py --include experimental/schemas --out experimental
# Format code and files in the repo.
.PHONY: fmt
fmt: ve
$(FIND) -name '*.py' -exec build/ve/bin/autopep8 --ignore E402 --in-place --max-line-length 120 {} \;
go get golang.org/x/tools/cmd/goimports
goimports -w -l -local github.com/elastic $(shell $(FIND) -name '*.go')
# Alias to generate everything.
.PHONY: generate
generate: generator codegen
$(PYTHON) --version
# Run the new generator
.PHONY: generator
generator: ve
$(PYTHON) scripts/generator.py --strict --include "${INCLUDE}"
# Generate Go code from the schema.
.PHONY: gocodegen
gocodegen:
find code/go/ecs -name '*.go' -not -name 'doc.go' | xargs rm
cd scripts \
&& $(FORCE_GO_MODULES) go run cmd/gocodegen/gocodegen.go \
-version=$(VERSION) \
-schema=../schemas \
-out=../code/go/ecs
# Check Makefile format.
.PHONY: makelint
makelint: SHELL:=/bin/bash
makelint:
@diff <(grep ^.PHONY Makefile | sort) <(grep ^.PHONY Makefile) \
|| echo Makefile targets need to be sorted.
# Check for basic misspellings.
.PHONY: misspell
misspell:
go get github.com/client9/misspell/cmd/misspell
misspell README.md CONTRIBUTING.md schemas/*
.PHONY: reload_docs
reload_docs: generator docs
# Download and setup tooling dependencies.
.PHONY: setup
setup: ve
cd scripts && $(FORCE_GO_MODULES) go mod download
# Run the ECS tests
.PHONY: test
test: ve
$(PYTHON) -m unittest discover -v --start-directory scripts/tests
# Create a virtualenv to run Python.
.PHONY: ve
ve: build/ve/bin/activate
build/ve/bin/activate: scripts/requirements.txt
@test -d build/ve || python3 -mvenv build/ve
@build/ve/bin/pip install -Ur scripts/requirements.txt
@touch build/ve/bin/activate
# Check YAML syntax (currently not enforced).
.PHONY: yamllint
yamllint: ve
build/ve/bin/yamllint schemas/*.yml