-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathMakefile
More file actions
222 lines (165 loc) · 7.37 KB
/
Makefile
File metadata and controls
222 lines (165 loc) · 7.37 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
.PHONY: help
help:
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | \
sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
GLEAN_PYENV := $(abspath $(shell python3 -c "import sys; print('.venv' + '.'.join(str(x) for x in sys.version_info[:2]))"))
# Read the `GLEAN_BUILD_VARIANT` variable, default to debug.
# If set it is passed as a flag to cargo, so we prefix it with `--`
ifeq ($(GLEAN_BUILD_VARIANT),)
GLEAN_BUILD_PROFILE :=
else ifeq ($(GLEAN_BUILD_VARIANT),debug)
# `--debug` is invalid and `--profile debug` is unstable.
GLEAN_BUILD_PROFILE :=
else
GLEAN_BUILD_PROFILE := --$(GLEAN_BUILD_VARIANT)
endif
# Setup environments
setup-python: $(GLEAN_PYENV)/bin/python3 ## Setup a Python virtual environment
@:
$(GLEAN_PYENV)/bin/python3:
python3 -m venv $(GLEAN_PYENV)
$(GLEAN_PYENV)/bin/pip install --upgrade pip wheel setuptools
$(GLEAN_PYENV)/bin/pip install -r glean-core/python/requirements_dev.txt
# All builds
build: build-rust
build-rust: ## Build all Rust code
cargo build --all $(GLEAN_BUILD_PROFILE) $(addprefix --target ,$(GLEAN_BUILD_TARGET))
build-kotlin: ## Build all Kotlin code
./gradlew build -x test
build-swift: ## Build all Swift code
bin/iosbuild build sdk
build-apk: build-kotlin ## Build an apk of the Glean sample app
./gradlew glean-sample-app:build glean-sample-app:assembleAndroidTest
build-python: setup-python ## Build the Python bindings
VIRTUAL_ENV=$(GLEAN_PYENV) \
$(GLEAN_PYENV)/bin/maturin develop
build-python-wheel: setup-python ## Build a Python wheel
VIRTUAL_ENV=$(GLEAN_PYENV) \
$(GLEAN_PYENV)/bin/maturin build --release $(addprefix --target ,$(GLEAN_BUILD_TARGET)) $(GLEAN_BUILD_EXTRA)
build-python-sdist: setup-python ## Build a Python source distribution
VIRTUAL_ENV=$(GLEAN_PYENV) \
$(GLEAN_PYENV)/bin/maturin build --release --sdist
build-xcframework:
./bin/build-xcframework.sh
.PHONY: build build-rust build-kotlin build-swift build-apk build-python build-python-wheel build-python-sdist build-xcframework glean-core/python/glean/_uniffi/__init__.py
# All tests
test: test-rust
test-rust: ## Run Rust tests for glean-core and glean-ffi
ifeq (, $(shell command -v cargo-nextest))
cargo test --all $(addprefix --target ,$(GLEAN_BUILD_TARGET))
else
cargo nextest run --all $(addprefix --target ,$(GLEAN_BUILD_TARGET))
endif
test-rust-examples: glean-core/rlb/tests/*.sh ## Run Rust example tests
@for file in $^; do \
echo "=== $${file} ==="; \
./$$file || exit 1; \
done
test-rust-with-logs: ## Run all Rust tests with debug logging and single-threaded
RUST_LOG=glean,glean_core cargo test --all -- --nocapture --test-threads=1 $(addprefix --target ,$(GLEAN_BUILD_TARGET))
test-kotlin: ## Run all Kotlin tests
./gradlew :glean:testDebugUnitTest
test-swift: ## Run all Swift tests
bin/iosbuild test sdk
test-android-sample: build-apk ## Run the Android UI tests on the sample app
./gradlew :glean-sample-app:connectedAndroidTest
test-ios-sample: ## Run the iOS UI tests on the sample app
bin/iosbuild test sample
test-python: build-python ## Run all Python tests
$(GLEAN_PYENV)/bin/py.test -v glean-core/python/tests $(PYTEST_ARGS)
.PHONY: test test-rust test-rust-with-logs test-kotlin test-swift test-ios-sample
# Linting
lint: lint-rust lint-kotlin lint-swift lint-yaml lint-python
lint-rust: ## Run cargo-clippy to lint Rust code
cargo clippy --all --all-targets --all-features -- -D warnings -A unknown-lints
lint-kotlin: ## Run ktlint to lint Kotlin code
./gradlew lint ktlint detekt
lint-swift: ## Run swiftlint to lint Swift code
swiftlint --strict
lint-yaml: ## Run yamllint to lint YAML files
yamllint glean-core .circleci
shellcheck: ## Run shellcheck against important shell scripts
shellcheck glean-core/ios/sdk_generator.sh
shellcheck bin/check-artifact.sh
lint-python: build-python ## Run ruff and mypy to lint Python code
$(GLEAN_PYENV)/bin/python3 -m ruff format --diff glean-core/python/glean glean-core/python/tests
$(GLEAN_PYENV)/bin/python3 -m ruff check glean-core/python/glean glean-core/python/tests
$(GLEAN_PYENV)/bin/python3 -m mypy glean-core/python/glean
lint-python-fix: setup-python ## Run ruff and mypy to lint Python code
$(GLEAN_PYENV)/bin/python3 -m ruff check --fix glean-core/python/glean glean-core/python/tests
.PHONY: lint-rust lint-kotlin lint-swift lint-yaml
# Formatting
fmt-rust: ## Format all Rust code
cargo fmt --all
fmt-python: setup-python ## Run ruff to format Python code
$(GLEAN_PYENV)/bin/python3 -m ruff format glean-core/python/glean glean-core/python/tests
fmt-kotlin: ## Run ktlint to format KOtlin code
./gradlew ktlintFormat
.PHONY: fmt-rust fmt-python fmt-kotlin
# Docs
docs: docs-rust ## Build the Rust API documentation
docs-rust: ## Build the Rust documentation
bin/build-rust-docs.sh
docs-swift: ## Build the Swift documentation
bin/iosbuild build docs
docs-python: build-python ## Build the Python documentation
$(GLEAN_PYENV)/bin/python3 -m pdoc --html glean --force -o build/docs/python --config show_type_annotations=True
.PHONY: docs docs-rust docs-swift
docs-metrics: setup-python ## Build the internal metrics documentation
$(GLEAN_PYENV)/bin/pip install glean_parser~=18.2
$(GLEAN_PYENV)/bin/glean_parser translate --allow-reserved \
-f markdown \
-o ./docs/user/user/collected-metrics \
glean-core/metrics.yaml glean-core/pings.yaml glean-core/android/metrics.yaml
cat ./docs/user/_includes/glean-js-redirect-collected-metrics.md ./docs/user/user/collected-metrics/metrics.md > ./docs/user/user/collected-metrics/metrics.tmp.md
mv ./docs/user/user/collected-metrics/metrics.tmp.md ./docs/user/user/collected-metrics/metrics.md
linkcheck: docs linkcheck-raw ## Run link-checker on the generated docs
linkcheck-raw:
# Requires https://www.npmjs.com/package/link-checker
npx link-checker \
build/docs \
--disable-external true \
--allow-hash-href true \
--file-ignore "swift/.*" \
--file-ignore "python/.*" \
--file-ignore "javadoc/.*" \
--file-ignore "docs/.*" \
--url-ignore ".*/python/.*" \
--url-ignore ".*/javadoc/.*" \
--url-ignore ".*/docs/glean_.*" \
--url-ignore ".*/docs/glean/.*"
.PHONY: linkcheck linkcheck-raw
spellcheck: ## Spellcheck the docs
# Requires http://aspell.net/
bin/spellcheck.sh
# Utilities
android-emulator: ## Start the Android emulator with a predefined image
$(ANDROID_HOME)/emulator/emulator -avd Nexus_5X_API_P -netdelay none -netspeed full
.PHONY: android-emulator
coverage-python: build-python ## Generate a code coverage report for Python
GLEAN_COVERAGE=1 $(GLEAN_PYENV)/bin/python3 -m coverage run --parallel-mode -m pytest
$(GLEAN_PYENV)/bin/python3 -m coverage combine
$(GLEAN_PYENV)/bin/python3 -m coverage html
.PHONY: coverage-python
upload-wheels: setup-python
VIRTUAL_ENV=$(GLEAN_PYENV) \
$(GLEAN_PYENV)/bin/python3 -m twine upload target/wheels/*
.PHONY: upload-wheels
clean: clobber ## Clean up the object directories and build artifacts (alias for clobber)
clobber: ## Clean up the object directories and build artifacts
# Rust
cargo clean
cargo clean --manifest-path glean-core/benchmark/Cargo.toml
cargo clean --manifest-path tools/devhub/Cargo.toml
# General build folder
rm -rf build
# Swift artifacts
rm -f Glean.xcframework.zip raw_*.log
# Kotlin artifacts
./gradlew --no-daemon clean
# Python artifacts
rm -rf glean-core/python/glean/_uniffi
# Python enviromnent
[ -n "$(GLEAN_PYENV)" ] && rm -rf ./$(GLEAN_PYENV)
.PHONY: clobber clean