-
-
Notifications
You must be signed in to change notification settings - Fork 344
Expand file tree
/
Copy pathjustfile
More file actions
executable file
·645 lines (545 loc) · 24.4 KB
/
justfile
File metadata and controls
executable file
·645 lines (545 loc) · 24.4 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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
#!/usr/bin/env just --justfile
set shell := ['bash', '-c']
# Import demo sub-justfile as a module
mod demo 'demo/justfile'
# Import martin-ui sub-justfile as a module
mod ui 'martin/martin-ui/justfile'
# How to call the current just executable.
# Note that just_executable() may have `\` in Windows paths, so we need to quote it.
just := quote(just_executable())
# if running in CI, treat warnings as errors by setting RUSTFLAGS and RUSTDOCFLAGS to '-D warnings' unless they are already set
# Use `CI=true just ci-test` to run the same tests as in GitHub CI.
# Use `just env-info` to see the current values of RUSTFLAGS and RUSTDOCFLAGS
ci_mode := if env('CI', '') != '' {'1'} else {''}
# Build in release mode by default. Set RELEASE_MODE='' to build in debug mode (used for PRs in CI to reduce build time).
# Use `RELEASE_MODE= just build-release <target>` to build in debug mode locally.
release_mode := if env('RELEASE_MODE', '1') != '' {'1'} else {''}
# cargo-binstall needs a workaround due to caching
# ci_mode might be manually set by user, so re-check the env var
binstall_args := if env('CI', '') != '' {'--no-confirm --no-track --disable-telemetry'} else {''}
export RUSTFLAGS := env('RUSTFLAGS', if ci_mode == '1' {'-D warnings'} else {''})
export RUSTDOCFLAGS := env('RUSTDOCFLAGS', if ci_mode == '1' {'-D warnings'} else {''})
export RUST_BACKTRACE := env('RUST_BACKTRACE', if ci_mode == '1' {'1'} else {'0'})
#export RUST_LOG := 'debug'
#export RUST_LOG := 'sqlx::query=info,trace'
#export DATABASE_URL='postgres://postgres:postgres@localhost:5411/db'
# Set additional database connection parameters, e.g. just PGPARAMS='keepalives=0&keepalives_idle=15' psql
PGPARAMS := ''
PGPORT := '5411'
export DATABASE_URL := ('postgres://postgres:postgres@localhost:' + PGPORT + '/db' + (if PGPARAMS != '' { '?' + PGPARAMS } else { '' }))
export CARGO_TERM_COLOR := 'always'
# Set AWS variables for testing pmtiles from S3
export AWS_SKIP_CREDENTIALS := '1'
export AWS_REGION := 'eu-central-1'
@_default:
{{just}} --list
# Run benchmark tests
bench:
cargo bench --bench sources
open target/criterion/report/index.html
# Run HTTP requests benchmark using OHA tool. Use with `just bench-server`
bench-http: (cargo-install 'oha')
@echo "ATTENTION: Make sure Martin was started with just bench-server"
@echo "Warming up..."
oha --latency-correction -z 5s --no-tui http://localhost:3000/function_zxy_query/18/235085/122323 > /dev/null
oha --latency-correction -z 60s http://localhost:3000/function_zxy_query/18/235085/122323
oha --latency-correction -z 5s --no-tui http://localhost:3000/png/0/0/0 > /dev/null
oha --latency-correction -z 60s http://localhost:3000/png/0/0/0
oha --latency-correction -z 5s --no-tui http://localhost:3000/stamen_toner__raster_CC-BY-ODbL_z3/0/0/0 > /dev/null
oha --latency-correction -z 60s http://localhost:3000/stamen_toner__raster_CC-BY-ODbL_z3/0/0/0
# Start release-compiled Martin server and a test database
bench-server: start
cargo run --release -- tests/fixtures/mbtiles tests/fixtures/pmtiles
# Run integration tests and save its output as the new expected output (ordering is important)
bless:
#!/usr/bin/env bash
set -euo pipefail
echo "Blessing unit tests"
for target in restart clean-test bless-insta ui::bless bless-pg; do
echo "::group::just $target"
{{quote(just_executable())}} $target
echo "::endgroup::"
done
echo "Blessing integration tests"
{{quote(just_executable())}} bless-int
# Run integration tests and save its output as the new expected output
bless-insta *args: (cargo-install 'cargo-insta')
cargo insta test --accept --all-targets --workspace {{args}}
# Bless integration tests
bless-int:
rm -rf tests/temp
tests/test.sh
rm -rf tests/expected && mv tests/output tests/expected
bless-pg: start (cargo-install 'cargo-insta')
cargo insta test --accept --features test-pg --no-default-features --test pg_function_source_test --test pg_server_test --test pg_table_source_test
cargo insta test --accept --features test-pg --no-default-features --package martin --lib
cargo insta test --accept --features test-pg --package martin-core --no-default-features --lib
# Build binaries for a target. In release mode (default), strips debug info.
# Set RELEASE_MODE='' to build in debug mode (used for PRs in CI to reduce build time).
build-release target:
#!/usr/bin/env bash
set -euo pipefail
# on debian we need to build a deb package
if [[ "{{target}}" == "debian-x86_64" ]]; then
{{quote(just_executable())}} build-deb target/debian/debian-x86_64.deb
else
rustup target add {{target}}
if [[ "{{release_mode}}" == "1" ]]; then
export CARGO_TARGET_{{shoutysnakecase(target)}}_RUSTFLAGS='-C strip=debuginfo'
fi
cargo build {{if release_mode == '1' {'--release'} else {''} }} --target {{target}} --package mbtiles --locked
cargo build {{if release_mode == '1' {'--release'} else {''} }} --target {{target}} --package martin --locked
fi
# Build debian package
build-deb output: (cargo-install 'cargo-deb')
#!/usr/bin/env bash
set -euo pipefail
sudo apt-get install -y dpkg dpkg-dev liblzma-dev
if [[ "{{release_mode}}" == "1" ]]; then
cargo deb -v -p martin --output {{output}}
else
cargo deb -v -p martin --profile dev --output {{output}}
fi
# Build for musl target using zigbuild
# Set RELEASE_MODE='' to build in debug mode (used for PRs in CI to reduce build time).
build-release-musl target:
#!/usr/bin/env bash
set -euo pipefail
rustup target add {{target}}
if [[ "{{release_mode}}" == "1" ]]; then
export CARGO_TARGET_{{shoutysnakecase(target)}}_RUSTFLAGS='-C strip=debuginfo'
fi
cargo zigbuild {{if release_mode == '1' {'--release'} else {''} }} --target {{target}} --package mbtiles --locked
cargo zigbuild {{if release_mode == '1' {'--release'} else {''} }} --target {{target}} --package martin --locked
# Move build artifacts to target_releases directory
move-artifacts target:
#!/usr/bin/env bash
set -euo pipefail
mkdir -p target_releases
build_dir={{if release_mode == '1' {'release'} else {'debug'} }}
if [[ "{{target}}" == "debian-x86_64" ]]; then
mv target/debian/*.deb target_releases/
else
if [[ "{{target}}" == "x86_64-pc-windows-msvc" ]]; then
mv target/{{target}}/"$build_dir"/martin.exe target_releases/
mv target/{{target}}/"$build_dir"/martin-cp.exe target_releases/
mv target/{{target}}/"$build_dir"/mbtiles.exe target_releases/
else
mv target/{{target}}/"$build_dir"/martin target_releases/
mv target/{{target}}/"$build_dir"/martin-cp target_releases/
mv target/{{target}}/"$build_dir"/mbtiles target_releases/
fi
fi
# Quick compile without building a binary
check: (cargo-install 'cargo-hack')
cargo hack --exclude-features _tiles,_catalog check --all-targets --each-feature --workspace
# Test documentation generation
check-doc: (docs-build)
# Run all tests as expected by CI
ci-test: env-info restart test-fmt clippy check-doc test check && assert-git-is-clean
# Perform cargo clean to delete all build files
clean: clean-test stop ui::clean
cargo clean -p static-files
cargo clean
# Run cargo clippy to lint the code
clippy *args:
cargo clippy --workspace --all-targets {{args}}
# Validate markdown URLs with markdown-link-check
clippy-md:
docker run --rm -v ${PWD}:/workdir --entrypoint sh ghcr.io/tcort/markdown-link-check -c \
'echo -e "/workdir/README.md\n$(find /workdir/docs/content -name "*.md")" | tr "\n" "\0" | xargs -0 -P 5 -n1 -I{} markdown-link-check --config /workdir/.github/files/markdown.links.config.json {}'
# Generate code coverage report. Will install `cargo llvm-cov` if missing.
coverage *args='--no-clean --open': (cargo-install 'cargo-llvm-cov') clean start
#!/usr/bin/env bash
set -euo pipefail
if ! rustup component list | grep llvm-tools-preview > /dev/null; then \
echo "llvm-tools-preview could not be found. Installing..." ;\
rustup component add llvm-tools-preview ;\
fi
source <(cargo llvm-cov show-env --export-prefix)
cargo llvm-cov clean --workspace
echo "::group::Unit tests"
{{just}} test-cargo --all-targets
{{just}} test-pg
echo "::endgroup::"
# echo "::group::Documentation tests"
# {{just}} test-doc <- deliberately disabled until --doctest for cargo-llvm-cov does not hang indefinitely
# echo "::endgroup::"
{{just}} test-int
cargo llvm-cov report {{args}}
# Start Martin server
cp *args:
cargo run --bin martin-cp -- {{args}}
# Start Martin server and open a test page (not the integrated UI)
debug-page *args: start
open tests/debug.html # run will not exit, so open debug page first
{{just}} run {{args}}
# Build and run martin docker image
docker-run *args:
docker run -it --rm --net host -e DATABASE_URL -v $PWD/tests:/tests ghcr.io/maplibre/martin:1.4.0 {{args}}
# Build and run martin documentation
docs:
docker run --rm -it -p 8000:8000 -v ${PWD}:/docs zensical/zensical:latest
# Build martin documentation
docs-build:
docker run --rm -v ${PWD}:/docs zensical/zensical:latest build
# Print environment info
env-info:
@echo "Running {{if ci_mode == '1' {'in CI mode'} else {'in dev mode'} }} / {{if release_mode == '1' {'release mode'} else {'debug mode'} }} on {{os()}} / {{arch()}}"
@echo "PWD {{justfile_directory()}}"
{{just}} --version
rustc --version
cargo --version
rustup --version
@echo "RUSTFLAGS='$RUSTFLAGS'"
@echo "RUSTDOCFLAGS='$RUSTDOCFLAGS'"
@echo "RUST_BACKTRACE='$RUST_BACKTRACE'"
npm --version
node --version
# Reformat all code `cargo fmt`. If nightly is available, use it for better results
fmt:
#!/usr/bin/env bash
set -euo pipefail
if (rustup toolchain list | grep nightly && rustup component list --toolchain nightly | grep rustfmt) &> /dev/null; then
echo 'Reformatting Rust code using nightly Rust fmt to sort imports'
cargo +nightly fmt --all -- --config imports_granularity=Module,group_imports=StdExternalCrate
else
echo 'Reformatting Rust with the stable cargo fmt. Install nightly with `rustup install nightly` for better results'
cargo fmt --all
fi
# Reformat markdown files using markdownlint-cli2
fmt-md:
docker run --rm -v $PWD:/workdir davidanson/markdownlint-cli2 --config /workdir/.github/files/config.markdownlint-cli2.jsonc --fix
# Reformat all SQL files using docker
fmt-sql:
docker run -it --rm -v $PWD:/sql sqlfluff/sqlfluff:latest fix --dialect=postgres --exclude-rules=AL07,LT05,LT12 --exclude '^tests/fixtures/(mbtiles|files)/.*\.sql$'
docker run -it --rm -v $PWD:/sql sqlfluff/sqlfluff:latest fix --dialect=sqlite --exclude-rules=LT01,LT05 --files '^tests/fixtures/(mbtiles|files)/.*\.sql$'
# Reformat all Cargo.toml files using cargo-sort
fmt-toml *args: (cargo-install 'cargo-sort')
cargo sort --workspace --order package,lib,bin,bench,features,dependencies,build-dependencies,dev-dependencies {{args}}
# Do any git command, ensuring that the testing environment is set up. Accepts the same arguments as git.
[no-exit-message]
git *args: start
git {{args}}
# Show help for new contributors
help:
@echo "Common commands:"
@echo " just validate-tools # Check required tools"
@echo " just start # Start test database"
@echo " just run # Start Martin server"
@echo " just test # Run all tests"
@echo " just fmt # Format code"
@echo " just book # Build documentation"
@echo ""
@echo "Full list: just --list"
# Install Linux dependencies (Ubuntu/Debian). Supports 'vulkan' and 'opengl' backends.
[linux]
install-dependencies backend='vulkan':
sudo apt-get update
sudo apt-get install -y \
{{if backend == 'opengl' {'libgl1-mesa-dev libglu1-mesa-dev'} else {''} }} \
{{if backend == 'vulkan' {'mesa-vulkan-drivers glslang-dev'} else {''} }} \
build-essential \
libcurl4-openssl-dev \
libglfw3-dev \
libuv1-dev \
libz-dev
# Install macOS dependencies via Homebrew
[macos]
install-dependencies backend='vulkan':
brew install \
{{if backend == 'vulkan' {'molten-vk vulkan-headers'} else {''} }} \
curl \
glfw \
libuv \
zlib
# Install Windows dependencies
[windows]
install-dependencies backend='vulkan':
@echo "rendering styles is not currently supported on windows"
# Run cargo fmt and cargo clippy
lint: fmt clippy ui::biome ui::type-check
# Run mbtiles command
mbtiles *args:
cargo run -p mbtiles -- {{args}}
# Create assets package
package-assets target:
#!/usr/bin/env bash
set -euo pipefail
mkdir -p target/files
cd target/{{target}}
if [[ '{{target}}' == 'x86_64-pc-windows-msvc' ]]; then
7z a ../files/martin-{{target}}.zip martin.exe martin-cp.exe mbtiles.exe
elif [[ '{{target}}' == 'debian-x86_64' ]]; then
mv *.deb ../files/
else
chmod +x martin martin-cp mbtiles
tar czvf ../files/martin-{{target}}.tar.gz martin martin-cp mbtiles
fi
cd ../..
# Run pg_dump utility against the test database
pg_dump *args:
pg_dump {{args}} {{quote(DATABASE_URL)}}
# Update sqlite database schema.
prepare-sqlite: install-sqlx
mkdir -p mbtiles/.sqlx
cd mbtiles && cargo sqlx prepare --database-url sqlite://$PWD/../tests/fixtures/mbtiles/world_cities.mbtiles -- --lib --tests
# Print the connection string for the test database
print-conn-str:
@echo {{quote(DATABASE_URL)}}
# Run PSQL utility against the test database
psql *args:
psql {{args}} {{quote(DATABASE_URL)}}
# Restart the test database
restart:
# sometimes Just optimizes targets, so here we force stop & start by using external just executable
{{just}} stop
{{just}} start
# Start Martin server
run *args='--webui enable-for-all':
cargo run -p martin -- {{args}}
# Start release-compiled Martin server and a test database
run-release *args='--webui enable-for-all': start
cargo run -p martin --release -- {{args}}
# Check semver compatibility with prior published version. Install it with `cargo install cargo-semver-checks`
semver *args: (cargo-install 'cargo-semver-checks')
cargo semver-checks {{args}}
# Start a test database
start: (docker-up 'db') docker-is-ready
# Start a legacy test database
start-legacy: (docker-up 'db-legacy') docker-is-ready
# Start test server for testing HTTP pmtiles
start-pmtiles-server: (docker-up 'fileserver') fileserver-is-ready
# Start an ssl-enabled test database
start-ssl: (docker-up 'db-ssl') docker-is-ready
# Start an ssl-enabled test database that requires a client certificate
start-ssl-cert: (docker-up 'db-ssl-cert') docker-is-ready
# Stop the test database
stop:
docker compose down --remove-orphans
# runs cargo-shear to lint Rust dependencies
shear:
cargo shear --expand
# in the future: add --deny-warnings
# https://github.com/Boshen/cargo-shear/pull/386
# Run all tests using a test database
test: start (test-cargo "--all-targets") test-pg test-doc ui::test test-int
# Run PostgreSQL-requiring tests only
test-pg: start
cargo test --features test-pg --no-default-features --test pg_function_source_test --test pg_server_test --test pg_table_source_test
cargo test --features test-pg --no-default-features --package martin --lib
cargo test --features test-pg --package martin-core --no-default-features --lib
# Run Rust unit tests (cargo test)
test-cargo *args:
cargo test {{args}}
# Run Rust doc tests
test-doc *args:
cargo test --doc {{args}}
# Test code formatting
test-fmt: (cargo-install 'cargo-sort') && (fmt-toml '--check' '--check-format')
cargo fmt --all -- --check
# Run integration tests
test-int: clean-test install-sqlx start-pmtiles-server
#!/usr/bin/env bash
set -euo pipefail
tests/test.sh
if [ "{{os()}}" != "linux" ]; then
echo "** Integration tests are only supported on Linux"
echo "** Skipping diffing with the expected output"
else
echo "** Comparing actual output with expected output..."
if ! diff --brief --recursive --new-file --exclude='*.pbf' tests/output tests/expected; then
echo "** Expected output does not match actual output"
echo "** If this is expected, run 'just bless' to update expected output"
echo ""
echo "::group::Resulting diff (max 100 lines)"
diff --recursive --new-file --exclude='*.pbf' tests/output tests/expected | head -n 100 | cat --show-nonprinting
echo "::endgroup::"
exit 1
else
echo "** Expected output matches actual output"
fi
fi
# Run AWS Lambda smoke test against SAM local
test-lambda martin_bin='target/debug/martin':
#!/usr/bin/env bash
set -euo pipefail
echo "::group::Build Lambda Function"
if ! command -v sam >/dev/null 2>&1; then
echo "The AWS Serverless Application Model Command Line Interface (AWS SAM CLI) is missing."
echo " https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html"
exit 1
fi
# `sam build` will copy the _entire_ context to a temporary directory, so just give it the files we need
mkdir -p .github/files/lambda-layer/bin/
if ! install {{quote(martin_bin)}} .github/files/lambda-layer/bin/; then
echo "Specify the binary, e.g. 'just test-lambda target/x86_64-linux-unknown-musl/release/martin'"
echo "Alternatively, build the binary with 'cargo build -p martin' and it will be used by default"
exit 1
fi
cp ./tests/fixtures/pmtiles2/webp2.pmtiles .github/files/lambda-function/
# build without touching real credentials
export AWS_PROFILE=dummy
export AWS_CONFIG_FILE=.github/files/dummy-aws-config
sam build --template-file .github/files/lambda.yaml
echo "::endgroup::"
# Just send a single request using `sam local invoke` to verify that
# the server boots, finds a source to serve, and can handle a request.
# TODO Run the fuller integration suite against this.
# In doing so, switch from `sam local invoke`, which starts and stops the
# server, to `sam local start-api`, which keeps it running.
echo "::group::Generate Event"
event=$(
sam local generate-event apigateway http-api-proxy \
| jq '.rawPath = "/" | .requestContext.http.method = "GET"'
)
echo "event:"
echo "$event" | jq .
echo "::endgroup::"
echo "::group::Invoke Lambda Function"
response=$(sam local invoke -e <(echo "$event"))
echo "::endgroup::"
jq -ne 'input.statusCode == 200' <<<"$response"
# Run all tests using the oldest supported version of the database
test-legacy: start-legacy (test-cargo "--all-targets") test-pg test-doc test-int
# Run all tests using an SSL connection to a test database. Expected output won't match.
test-ssl: start-ssl (test-cargo "--all-targets") test-pg test-doc clean-test
tests/test.sh
# Run all tests using an SSL connection with client cert to a test database. Expected output won't match.
test-ssl-cert: start-ssl-cert
#!/usr/bin/env bash
set -euxo pipefail
# copy client cert to the tests folder from the docker container
KEY_DIR=target/certs
mkdir -p $KEY_DIR
docker cp martin-db-ssl-cert-1:/etc/ssl/certs/ssl-cert-snakeoil.pem $KEY_DIR/ssl-cert-snakeoil.pem
docker cp martin-db-ssl-cert-1:/etc/ssl/private/ssl-cert-snakeoil.key $KEY_DIR/ssl-cert-snakeoil.key
# export DATABASE_URL="$DATABASE_URL?sslmode=verify-full&sslrootcert=$KEY_DIR/ssl-cert-snakeoil.pem&sslcert=$KEY_DIR/ssl-cert-snakeoil.pem&sslkey=$KEY_DIR/ssl-cert-snakeoil.key"
export PGSSLROOTCERT="$KEY_DIR/ssl-cert-snakeoil.pem"
export PGSSLCERT="$KEY_DIR/ssl-cert-snakeoil.pem"
export PGSSLKEY="$KEY_DIR/ssl-cert-snakeoil.key"
{{just}} test-cargo --all-targets
{{just}} clean-test
{{just}} test-doc
tests/test.sh
# Update all dependencies, including breaking changes. Requires nightly toolchain (install with `rustup install nightly`)
update:
cargo +nightly -Z unstable-options update --breaking
cargo update
# Make sure that 'evil' dependencies are at the last compatible version
# below needs to be synced with deny.toml
cargo update --precise 1.44.3 insta
cargo update --precise 1.24.0 libdeflater
cargo update --precise 1.24.0 libdeflate-sys
# Validate that all required development tools are installed
validate-tools:
#!/usr/bin/env bash
set -euo pipefail
echo "Validating development tools..."
# Check essential tools
missing_tools=()
if ! command -v jq >/dev/null 2>&1; then
missing_tools+=("jq")
fi
if ! command -v file >/dev/null 2>&1; then
missing_tools+=("file")
fi
if ! command -v curl >/dev/null 2>&1; then
missing_tools+=("curl")
fi
if ! command -v grep >/dev/null 2>&1; then
missing_tools+=("grep")
fi
if ! command -v sqlite3 >/dev/null 2>&1; then
missing_tools+=("sqlite3")
fi
if ! command -v sqldiff >/dev/null 2>&1; then
missing_tools+=("sqldiff")
fi
# Check Darwin-specific tools
if [[ "$OSTYPE" == "darwin"* ]]; then
if ! command -v gsed >/dev/null 2>&1; then
missing_tools+=("gsed")
fi
fi
# Check Linux-specific tools
if [[ "$OSTYPE" == "linux"* ]]; then
if ! command -v ogrmerge.py >/dev/null 2>&1; then
missing_tools+=("ogrmerge.py")
fi
fi
# Check FreeBSD-specific tools
if [[ "$OSTYPE" == "freebsd"* ]]; then
# This should eventually go away if the upstream pbf_glyph_tools can vendor the source artifacts
# (no more need for protoc). Other platforms automatically install a vendored binary.
if ! command -v protoc >/dev/null 2>&1; then
missing_tools+=("protoc")
fi
fi
# Report results
if [[ ${#missing_tools[@]} -eq 0 ]]; then
echo "✓ All required tools are installed"
else
echo "✗ Missing tools: ${missing_tools[*]}"
echo " Ubuntu/Debian: sudo apt install -y jq file curl grep sqlite3-tools gdal-bin"
echo " macOS: brew install jq file curl grep sqlite gdal gsed"
echo " FreeBSD: pkg install jq curl sqlite3 gdal protobuf"
echo ""
exit 1
fi
# Make sure the git repo has no uncommitted changes
[private]
assert-git-is-clean:
@if [ -n "$(git status --untracked-files --porcelain)" ]; then \
>&2 echo "ERROR: git repo is no longer clean. Make sure compilation and tests artifacts are in the .gitignore, and no repo files are modified." ;\
>&2 echo "######### git status ##########" ;\
git status ;\
git --no-pager diff ;\
exit 1 ;\
fi
# Check if a certain Cargo command is installed, and install it if needed
[private]
cargo-install $COMMAND $INSTALL_CMD='' *args='':
#!/usr/bin/env bash
set -euo pipefail
if ! command -v $COMMAND > /dev/null; then
if ! command -v cargo-binstall > /dev/null; then
echo "$COMMAND could not be found. Installing it with cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}"
cargo install ${INSTALL_CMD:-$COMMAND} --locked {{args}}
else
echo "$COMMAND could not be found. Installing it with cargo binstall ${INSTALL_CMD:-$COMMAND} {{binstall_args}} --locked"
cargo binstall ${INSTALL_CMD:-$COMMAND} {{binstall_args}} --locked
fi
fi
# Delete test output files
[private]
clean-test:
rm -rf tests/output
# Wait for the test database to be ready
[private]
docker-is-ready:
docker compose run -T --rm db-is-ready
# Wait for the fileserver to be ready
[private]
fileserver-is-ready:
#!/usr/bin/env bash
set -euo pipefail
FILESERVER_URL="${STATICS_URL:-http://localhost:5412}"
echo "Waiting for fileserver to be ready at ${FILESERVER_URL}..."
for i in {1..30}; do
if curl --silent --fail --head --connect-timeout 2 --max-time 5 "${FILESERVER_URL}/webp2.pmtiles" >/dev/null 2>&1; then
echo "Fileserver is ready!"
exit 0
fi
echo "Waiting for fileserver... (attempt $i/30)"
sleep 1
done
echo "Fileserver did not start in time"
exit 1
# Start a specific test database, e.g. db or db-legacy
[private]
docker-up name:
docker compose up -d {{name}}
# Install SQLX cli if not already installed.
[private]
install-sqlx: (cargo-install 'cargo-sqlx' 'sqlx-cli' '--no-default-features' '--features' 'sqlite,native-tls')