forked from elastic/ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
133 lines (115 loc) · 3.69 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
133
#
# 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 ?= 1.0.0-beta2
#
# Targets (sorted alphabetically)
#
# Check verifies that all of the committed files that are generated are
# up-to-date.
.PHONY: check
check: generate 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.csv schema.md schema.json fields.yml build
# 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 schema.csv from schema files.
.PHONY: csv
csv: ve
$(PYTHON) scripts/schemas.py
# 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.pl --doc ./docs/index.asciidoc --chunk=1 $(OPEN_DOCS) -out ./build/html_docs
# Build the fields.yml file.
.PHONY: fields
fields:
cat schemas/*.yml > fields.tmp.yml
sed -i.bak 's/^/ /g' fields.tmp.yml
sed -i.bak 's/---//g' fields.tmp.yml
cat scripts/fields_header.yml > fields.yml
cat fields.tmp.yml >> fields.yml
rm -f fields.tmp.yml fields.tmp.yml.bak
# Format code and files in the repo.
.PHONY: fmt
fmt: ve
$(FIND) -name '*.py' -exec build/ve/bin/autopep8 --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: csv readme template fields codegen
# 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
# Build README.md by concatenating various markdown snippets.
.PHONY: readme
readme:
cat docs/intro.md > README.md
$(PYTHON) scripts/schemas.py --stdout=true >> README.md
cat docs/use-cases-header.md >> README.md
$(PYTHON) scripts/use-cases.py --stdout=true >> README.md
cat docs/implementing.md >> README.md
cat docs/about.md >> README.md
# 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 \
> ../template.json
# 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