-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathformat.mk
140 lines (114 loc) · 4.57 KB
/
format.mk
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
.PHONY: format
format: format/bazel format/clang format/dart format/ts format/line-endings format/markdown
@echo "Finished running make target: format"
.PHONY: format/bazel
format/bazel:
buildifier -r .
.PHONY: format/clang
format/clang:
git ls-files -z | grep --null-data "\.h$$\|\.hpp$$\|\.cc$$\|\.cpp$$\|\.proto$$" | xargs --null --no-run-if-empty clang-format -i --style=file
.PHONY: format/dart/pub-get
format/dart/pub-get:
cd flutter && ${_start_args} dart pub get
.PHONY: format/dart
format/dart: format/dart/pub-get
cd flutter && ${_start_args} dart run import_sorter:main
dart format flutter
.PHONY: format/swift
format/swift:
git ls-files -z | grep --null-data "\.swift$$" | xargs --null --no-run-if-empty swift-format format --in-place
.PHONY: format/ts
format/ts:
@echo "No typescripts files to format"
.PHONY: format/line-endings
format/line-endings:
git ls-files -z | xargs --null ${_start_args} dos2unix --keep-bom --quiet --
.PHONY: format/markdown
format/markdown:
git ls-files -z | \
grep --null-data -v "LICENSE.md" | \
grep --null-data "\.md$$" --exclude="*LICENSE.md" | \
xargs --null --no-run-if-empty markdownlint -c tools/formatter/configs/markdownlint.yml --fix
.PHONY: lint
lint: lint/bazel lint/clang lint/dart lint/ts lint/yaml lint/markdown lint/prohibited-extensions lint/big-files
@echo "Finished running make target: lint"
.PHONY: lint/bazel
lint/bazel:
buildifier -lint=warn -mode=check -r .
.PHONY: lint/clang
lint/clang:
git ls-files -z | grep --null-data "\.h$$\|\.hpp$$\|\.cc$$\|\.cpp$$\|\.proto$$" | xargs --null --no-run-if-empty clang-format -i --style=file --Werror --dry-run
.PHONY: lint/dart
lint/dart: format/dart/pub-get
cd flutter && ${_start_args} dart run import_sorter:main --exit-if-changed
dart format --output=none --set-exit-if-changed flutter
dart analyze --fatal-infos flutter
.PHONY: lint/yaml
lint/yaml:
git ls-files -z | grep --null-data "\.yml$$\|\.yaml$$" | xargs --null --no-run-if-empty yamllint -c tools/formatter/configs/yamllint.yml
.PHONY: lint/swift
lint/swift:
git ls-files -z | grep --null-data "\.swift$$" | xargs --null --no-run-if-empty swift-format lint --strict
.PHONY: lint/ts
lint/ts:
@echo "No typescripts files to lint"
.PHONY: lint/prohibited-extensions
lint/prohibited-extensions:
@echo checking prohibited extensions...
@_files=$$(git ls-files -z | grep --null-data "\.so$$\|\.apk$$\|\.tflite$$\|\.dlc$$\|\.zip$$\|\.jar$$\|\.tgz$$"); \
if [ ! -z "$$_files" ]; then echo -e "found prohibited files:\n$$_files"; false; \
else echo found 0 files with prohibited extensions; \
fi
.PHONY: lint/big-files
lint/big-files:
@echo checking big files...
@big_file_list=""; \
for f in $$(git ls-files); do \
if [ "$$(stat $$f --format %s)" -gt 5242880 ]; then big_file_list="$$big_file_list$$f\n"; fi; \
done; \
if [ ! -z "$$big_file_list" ]; then echo -e "found too big files: \n$$big_file_list"; false; \
else echo found 0 too big files; \
fi
.PHONY: lint/line-endings
lint/line-endings:
@echo checking line endings...
@_files=$$(git ls-files -z | xargs --null ${_start_args} dos2unix --info=c --) && \
if [ ! -z "$$_files" ]; then \
echo -e "found files with CRLF line endings: \n$$_files"; false; \
else echo all files have unix line endings; \
fi
.PHONY: lint/markdown-links
lint/markdown-links:
git ls-files -z | grep --null-data "\.md$$" | xargs --null --no-run-if-empty -n1 markdown-link-check
.PHONY: lint/markdown
lint/markdown:
git ls-files -z | \
grep --null-data -v "LICENSE.md" | \
grep --null-data "\.md$$" --exclude="*LICENSE.md" | \
xargs --null --no-run-if-empty markdownlint -c tools/formatter/configs/markdownlint.yml
output/docker_mlperf_formatter.stamp: tools/formatter/Dockerfile
docker build --progress=plain \
--build-arg UID=`id -u` --build-arg GID=`id -g` \
-t mlperf/formatter tools/formatter
touch $@
FORMAT_DOCKER_ARGS= \
--mount source=mlperf-formatter-pubcache,target=/home/mlperf/.pub-cache \
--mount source=mlperf-formatter-output,target=/home/mlperf/mobile_app_open/output \
-v $(CURDIR):/home/mlperf/mobile_app_open \
-w /home/mlperf/mobile_app_open \
mlperf/formatter \
.PHONY: docker/format
docker/format: output/docker_mlperf_formatter.stamp
MSYS2_ARG_CONV_EXCL="*" docker run -it --rm \
${FORMAT_DOCKER_ARGS} \
make flutter/prepare format
.PHONY: docker/lint
docker/lint: output/docker_mlperf_formatter.stamp
MSYS2_ARG_CONV_EXCL="*" docker run -it --rm \
${FORMAT_DOCKER_ARGS} \
make flutter/prepare lint
.PHONY: docker/format/--
docker/format/--: output/docker_mlperf_formatter.stamp
MSYS2_ARG_CONV_EXCL="*" docker run -it --rm \
${FORMAT_DOCKER_ARGS} \
bash