-
Notifications
You must be signed in to change notification settings - Fork 5
/
Makefile
165 lines (117 loc) · 5.32 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
SHELL = /bin/bash
PROJECT_NAME = d4ft
PROJECT_FOLDER = $(PROJECT_NAME) third_party
PYTHON_FILES = $(shell find . -type f -name "*.py" -not -path '*/.venv/*' -not -path './d4ft/integral/obara_saika/boys_table.py')
CPP_FILES = $(shell find $(PROJECT_NAME) -type f \( -name "*.h" -o -name "*.cc" \) -not -name "comb.h" -not -path '*/.venv/*')
BAZEL_FILES = $(shell find . -type f -name "*BUILD" -o -name "*.bzl" -not -path '*/.venv/*')
COMMIT_HASH = $(shell git log -1 --format=%h)
COPYRIGHT = "Garena Online Private Limited"
BAZELOPT =
REG_URL =
DATE = $(shell date "+%Y-%m-%d")
DOCKER_TAG = $(DATE)-$(COMMIT_HASH)
PATH := $(HOME)/go/bin:$(PATH)
# installation
check_install = python3 -c "import $(1)" || (cd && pip3 install $(1) --upgrade && cd -)
check_install_extra = python3 -c "import $(1)" || (cd && pip3 install $(2) --upgrade && cd -)
flake8-install:
$(call check_install, flake8)
$(call check_install_extra, bugbear, flake8_bugbear)
py-format-install:
$(call check_install, isort)
$(call check_install, yapf)
mypy-install:
$(call check_install, mypy)
cpplint-install:
$(call check_install, cpplint)
clang-format-install:
command -v clang-format || sudo apt-get install -y clang-format
clang-tidy-install:
command -v clang-tidy || sudo apt-get install -y clang-tidy
go-install:
# requires go >= 1.16
command -v go || (sudo apt-get install -y golang-1.18 && sudo ln -sf /usr/lib/go-1.18/bin/go /usr/bin/go)
bazel-install: go-install
command -v bazel || (go install github.com/bazelbuild/bazelisk@latest && ln -sf $(HOME)/go/bin/bazelisk $(HOME)/go/bin/bazel)
buildifier-install: go-install
command -v buildifier || go install github.com/bazelbuild/buildtools/buildifier@latest
addlicense-install: go-install
command -v addlicense || go install github.com/google/addlicense@latest
doc-install:
$(call check_install, pydocstyle)
$(call check_install_extra, doc8, "doc8<1")
$(call check_install, sphinx)
$(call check_install, sphinx_rtd_theme)
$(call check_install_extra, sphinxcontrib.spelling, sphinxcontrib.spelling pyenchant)
auditwheel-install:
$(call check_install_extra, auditwheel, auditwheel typed-ast patchelf)
# python linter. -fix version applies the fixes
flake8: flake8-install
flake8 $(PYTHON_FILES) --count --show-source --statistics
flake8-fix: flake8-install
flake8 $(PYTHON_FILES)
py-format: py-format-install
isort --check $(PYTHON_FILES) && yapf -r -d $(PYTHON_FILES)
py-format-fix: py-format-install
isort $(PYTHON_FILES) && yapf -ir $(PYTHON_FILES)
mypy: mypy-install
mypy $(PROJECT_NAME)
# c++ linter
cpplint: cpplint-install
cpplint $(CPP_FILES)
clang-format: clang-format-install
clang-format --style=file -i $(CPP_FILES) -n --Werror
clang-format-fix: clang-format-install
clang-format --style=file -i $(CPP_FILES)
# bazel file linter
buildifier: buildifier-install
buildifier -r -lint=warn $(BAZEL_FILES)
buildifier-fix: buildifier-install
buildifier -r -lint=fix $(BAZEL_FILES)
# bazel build/test
bazel-pip-requirement-dev:
cd third_party/pip_requirements && (cmp requirements.txt requirements-dev.txt || ln -sf requirements-dev.txt requirements.txt)
bazel-pip-requirement-release:
cd third_party/pip_requirements && (cmp requirements.txt requirements-release.txt || ln -sf requirements-release.txt requirements.txt)
clang-tidy: clang-tidy-install bazel-pip-requirement-dev
bazel build $(BAZELOPT) //... --config=clang-tidy --config=test
bazel-debug: bazel-install bazel-pip-requirement-dev
bazel run $(BAZELOPT) //:setup --config=debug -- bdist_wheel
mkdir -p dist
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
bazel-build: bazel-install bazel-pip-requirement-dev
bazel run $(BAZELOPT) //:setup --config=test -- bdist_wheel
mkdir -p dist
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
bazel-release: bazel-install bazel-pip-requirement-release
bazel run $(BAZELOPT) //:setup --config=release -- bdist_wheel
mkdir -p dist
cp bazel-bin/setup.runfiles/$(PROJECT_NAME)/dist/*.whl ./dist
bazel-test: bazel-install bazel-pip-requirement-dev
bazel test --test_output=all $(BAZELOPT) //... --config=test --spawn_strategy=local --color=yes
bazel-clean: bazel-install
bazel clean --expunge
# documentation
addlicense: addlicense-install
addlicense -c $(COPYRIGHT) -l apache -check $(PROJECT_FOLDER)
addlicense-fix: addlicense-install
addlicense -c $(COPYRIGHT) -l apache $(PROJECT_FOLDER)
docstyle: doc-install
pydocstyle $(PROJECT_NAME) && doc8 docs && cd docs && make html SPHINXOPTS="-W"
doc: doc-install
cd docs && make html && cd _build/html && python3 -m http.server
spelling: doc-install
cd docs && make spelling SPHINXOPTS="-W"
doc-clean:
cd docs && make clean
lint: buildifier flake8 py-format # docstyle
format: py-format-install buildifier-install addlicense-install py-format-fix clang-format-fix buildifier-fix addlicense-fix
# Build docker images
docker-build:
docker build --network=host -t $(PROJECT_NAME):$(DOCKER_TAG) -f docker/dev.dockerfile .
echo successfully build docker image with tag $(PROJECT_NAME):$(DOCKER_TAG)
docker-push: docker-build
docker tag $(PROJECT_NAME):$(DOCKER_TAG) $(REG_URL)/$(PROJECT_NAME):$(DOCKER_TAG)
docker push $(REG_URL)/$(PROJECT_NAME):$(DOCKER_TAG)
pypi-wheel: auditwheel-install bazel-release
ls dist/*.whl -Art | tail -n 1 | xargs auditwheel repair --plat manylinux_2_24_x86_64