forked from elastic/ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
132 lines (112 loc) · 3.54 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
121
122
123
124
125
126
127
128
129
130
131
132
#
# Variables
#
.DEFAULT_GOAL := generate
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)
#
# Check verifies that all of the committed files that are generated are
# up-to-date.
.PHONY: check
check: generate 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 schema.json build
rm -rf generated/legacy/template.json
# Clean all markdown files for use-cases
find ./use-cases -type f -name '*.md' -not -name 'README.md' -print0 | xargs -0 rm --
# 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=1 $(OPEN_DOCS) --out ./build/html_docs
# 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: template legacy_use_cases codegen generator schema.json
# Run the new generator
.PHONY: generator
generator:
$(PYTHON) scripts/generator.py --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
# Generate the Use Cases
.PHONY: legacy_use_cases
legacy_use_cases: ve
$(PYTHON) scripts/use-cases.py --stdout=true >> /dev/null
# 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
.PHONY: reload_docs
reload_docs: generator docs
# Generate schema.json.
.PHONY: schema.json
schema.json: ve
$(PYTHON) scripts/schemas.py
# Download and setup tooling dependencies.
.PHONY: setup
setup: ve
cd scripts && $(FORCE_GO_MODULES) go mod download
# Build an Elasticsearch index template.
.PHONY: template
template:
cd scripts \
&& $(FORCE_GO_MODULES) go run cmd/template/template.go \
-version=$(VERSION) \
-schema=../schemas \
> ../generated/legacy/template.json
# Run the ECS tests
.PHONY: test
test:
$(PYTHON) -m unittest discover --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 || virtualenv 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