-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
642 lines (425 loc) · 18.4 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
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
# Apache License 2.0
project_name := astrodynamics
project_name_camel_case := $(shell echo $(project_name) | sed -r 's/(^|-)([a-z])/\U\2/g')
project_version := $(shell git describe --tags --always)
docker_registry_path := openspacecollective
docker_image_repository := $(docker_registry_path)/open-space-toolkit-$(project_name)
docker_image_version := $(project_version)
docker_development_image_repository := $(docker_image_repository)-development
docker_release_image_cpp_repository := $(docker_image_repository)-cpp
docker_release_image_python_repository := $(docker_image_repository)-python
docker_release_image_jupyter_repository := $(docker_image_repository)-jupyter
jupyter_notebook_port := 9005
jupyter_python_version := 3.11
jupyter_python_version_without_dot := $(shell echo $(jupyter_python_version) | sed 's/\.//')
jupyter_notebook_image_repository := jupyter/scipy-notebook:x86_64-python-$(jupyter_python_version).3
extract_python_package_version := $(shell echo $(project_version) | sed 's/-/./' | sed 's/-.*//')
dev_username := developer
pull: ## Pull all images
@ echo "Pulling images..."
@ $(MAKE) pull-development-image
@ $(MAKE) pull-release-images
.PHONY: pull
pull-development-image: ## Pull development image
@ echo "Pulling development image..."
docker pull $(docker_development_image_repository):$(docker_image_version) || true
docker pull $(docker_development_image_repository):latest || true
.PHONY: pull-development-image
pull-release-images: ## Pull release images
@ echo "Pull release images..."
@ $(MAKE) pull-release-image-cpp
@ $(MAKE) pull-release-image-python
@ $(MAKE) pull-release-image-jupyter
.PHONY: pull-release-images
pull-release-image-cpp: ## Pull release image cpp
@ echo "Pull C++ release image..."
docker pull $(docker_release_image_cpp_repository):$(docker_image_version) || true
docker pull $(docker_release_image_cpp_repository):latest || true
.PHONY: pull-release-image-cpp
pull-release-image-python: ## Pull release image python
@ echo "Pulling Python release image..."
docker pull $(docker_release_image_python_repository):$(docker_image_version) || true
docker pull $(docker_release_image_python_repository):latest || true
.PHONY: pull-release-image-python
pull-release-image-jupyter: ## Pull release image jupyter
@ echo "Pulling Jupyter Notebook release image..."
docker pull $(docker_release_image_jupyter_repository):$(docker_image_version) || true
docker pull $(docker_release_image_jupyter_repository):latest || true
.PHONY: pull-release-image-jupyter
build: build-images ## Build all images
build-images: ## Build development and release images
@ echo "Building images..."
@ $(MAKE) build-development-image
@ $(MAKE) build-release-images
.PHONY: build-images
build-development-image: pull-development-image ## Build development image
@ echo "Building development image with root user..."
docker build \
--file="$(CURDIR)/docker/development/Dockerfile" \
--tag=$(docker_development_image_repository):$(docker_image_version) \
--tag=$(docker_development_image_repository):latest \
--build-arg="VERSION=$(docker_image_version)" \
--target=root-user \
"$(CURDIR)"
.PHONY: build-development-image
build-development-image-non-root: pull-development-image ## Build development image for humans
@ echo "Building development image for humans with non-root user..."
docker build \
--file="$(CURDIR)/docker/development/Dockerfile" \
--tag=$(docker_development_image_repository)-non-root:$(docker_image_version) \
--tag=$(docker_development_image_repository)-non-root:latest \
--build-arg="VERSION=$(docker_image_version)" \
--build-arg="USER_UID=$(shell id -u)" \
--build-arg="USER_GID=$(shell id -g)" \
--target=non-root-user \
"$(CURDIR)"
.PHONY: build-development-image-non-root
build-release-images: ## Build release images
@ echo "Building release images..."
@ $(MAKE) build-release-image-cpp
@ $(MAKE) build-release-image-python
@ $(MAKE) build-release-image-jupyter
.PHONY: build-release-images
build-release-image-cpp: build-development-image pull-release-image-cpp ## Build release image cpp
@ echo "Building C++ release image..."
docker build \
--file="$(CURDIR)/docker/release/Dockerfile" \
--tag=$(docker_release_image_cpp_repository):$(docker_image_version) \
--tag=$(docker_release_image_cpp_repository):latest \
--build-arg="VERSION=$(docker_image_version)" \
--target=cpp-release \
"$(CURDIR)"
.PHONY: build-release-image-cpp
build-release-image-python: build-development-image pull-release-image-python ## Build release image python
@ echo "Building Python release image..."
docker build \
--file="$(CURDIR)/docker/release/Dockerfile" \
--tag=$(docker_release_image_python_repository):$(docker_image_version) \
--tag=$(docker_release_image_python_repository):latest \
--build-arg="VERSION=$(docker_image_version)" \
--target=python-release \
"$(CURDIR)"
.PHONY: build-release-image-python
build-release-image-jupyter: pull-release-image-jupyter ## Build release image jupyter
@ echo "Building Jupyter Notebook release image..."
docker build \
--file="$(CURDIR)/docker/jupyter/Dockerfile" \
--tag=$(docker_release_image_jupyter_repository):$(docker_image_version) \
--tag=$(docker_release_image_jupyter_repository):latest \
--build-arg="JUPYTER_NOTEBOOK_IMAGE_REPOSITORY=$(jupyter_notebook_image_repository)" \
"$(CURDIR)/docker/jupyter"
.PHONY: build-release-image-jupyter
build-documentation: build-development-image ## Build documentation
@ $(MAKE) build-documentation-standalone
.PHONY: build-documentation
build-documentation-standalone: ## Build documentation (standalone)
@ echo "Building documentation..."
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=OFF -DBUILD_BENCHMARK=OFF -DBUILD_VALIDATION_TESTS=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_DOCUMENTATION=ON .. \
&& $(MAKE) docs"
.PHONY: build-documentation-standalone
build-packages: ## Build packages
@ echo "Building packages..."
@ $(MAKE) build-packages-cpp
@ $(MAKE) build-packages-python
.PHONY: build-packages
build-packages-cpp: build-development-image ## Build C++ packages
@ $(MAKE) build-packages-cpp-standalone
.PHONY: build-packages-cpp
build-packages-cpp-standalone: ## Build C++ packages (standalone)
@ echo "Building C++ packages..."
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=OFF -DBUILD_BENCHMARK=OFF -DBUILD_VALIDATION_TESTS=OFF -DBUILD_PYTHON_BINDINGS=OFF -DCPACK_GENERATOR=DEB .. \
&& $(MAKE) package \
&& mkdir -p /app/packages/cpp \
&& mv /app/build/*.deb /app/packages/cpp"
.PHONY: build-packages-cpp-standalone
build-packages-python: build-development-image ## Build Python packages
@ $(MAKE) build-packages-python-standalone
.PHONY: build-packages-python
build-packages-python-standalone: ## Build Python packages (standalone)
@ echo "Building Python packages..."
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=OFF -DBUILD_VALIDATION_TESTS=OFF -DBUILD_BENCHMARK=OFF -DBUILD_PYTHON_BINDINGS=ON .. \
&& $(MAKE) -j 4 \
&& mkdir -p /app/packages/python \
&& mv /app/build/bindings/python/dist/*.whl /app/packages/python"
.PHONY: build-packages-python-standalone
start-development-no-link: build-development-image-non-root ## Start development environment
@ echo "Starting development environment..."
@ mkdir -p "$(CURDIR)/build"
docker run \
--name=open-space-toolkit-$(project_name)-dev-non-root \
-it \
--rm \
--volume="$(CURDIR):/app:delegated" \
--volume="$(HOME)/.ssh:/home/$(dev_username)/.ssh:ro" \
--volume="$(HOME)/.gitconfig:/home/$(dev_username)/.gitconfig:ro" \
--workdir=/app/build \
$(docker_development_image_repository)-non-root:$(docker_image_version) \
/bin/zsh
.PHONY: start-development-no-link
start-development-link: build-development-image ## Start linked development environment
$(if $(links), , $(error "You need to provide the links to the C++ dependency repositories you want to link with, separated by white spaces. For example: make start-development-link links="/home/OSTk/open-space-toolkit-io /home/OSTk/open-space-toolkit-core"))
@ echo "Starting development environment (linked)..."
@ mkdir -p "$(CURDIR)/build"
@ docker_development_image_repository=$(docker_development_image_repository) docker_image_version=$(docker_image_version) "$(CURDIR)/tools/development/start.sh" --link $(links)
@ sudo chown -R $(shell id -u):$(shell id -g) $(CURDIR)
.PHONY: start-development-link
ifndef links
start-development dev: start-development-no-link
else
start-development dev: start-development-link
endif
.PHONY: start-development
start-python: build-release-image-python ## Start Python runtime environment
@ echo "Starting Python runtime environment..."
docker run \
-it \
--rm \
$(docker_release_image_python_repository):$(docker_image_version)
.PHONY: start-python
start-jupyter: build-release-image-jupyter ## Start Jupyter Notebook environment
@ echo "Starting Jupyter Notebook environment..."
docker run \
-it \
--rm \
--publish="$(jupyter_notebook_port):8888" \
--volume="$(CURDIR)/bindings/python/docs:/home/jovyan/docs" \
--volume="$(CURDIR)/tutorials/python/notebooks:/home/jovyan/tutorials" \
--workdir="/home/jovyan" \
$(docker_release_image_jupyter_repository):$(docker_image_version) \
/bin/bash -c "start-notebook.sh --ServerApp.token=''"
.PHONY: start-jupyter-notebook
debug-jupyter-rebuild: build-development-image ## Debug jupyter notebook using the ostk-astro package built from current source code
@ echo "Building Python$(jupyter_python_version) packages..."
docker run \
-it \
--rm \
--volume="$(CURDIR):/app:delegated" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=OFF -DBUILD_BENCHMARK=OFF -DBUILD_VALIDATION_TESTS=OFF -DBUILD_PYTHON_BINDINGS=ON -DPYTHON_SEARCH_VERSIONS="$(jupyter_python_version)" .. \
&& $(MAKE) -j $(shell nproc)"
@ $(MAKE) debug-jupyter
.PHONY: debug-jupyter-rebuild
debug-jupyter: build-release-image-jupyter ## Debug jupyter notebook using the ostk-astro package from pre-built wheels
@ echo "Debugging Jupyter Notebook environment..."
docker run \
-it \
--rm \
--user=root \
--publish="$(jupyter_notebook_port):8888" \
--volume="$(CURDIR)/bindings/python/docs:/home/jovyan/docs:delegated" \
--volume="$(CURDIR)/tutorials/python/notebooks:/home/jovyan/tutorials:delegated" \
--volume="$(CURDIR)/build/bindings/python/OpenSpaceToolkit${project_name_camel_case}Py-python-package-$(jupyter_python_version):/opt/conda/lib/python$(jupyter_python_version)/site-packages/ostk/$(project_name)" \
--workdir="/home/jovyan" \
$(docker_release_image_jupyter_repository):$(docker_image_version) \
/bin/bash -c "chown -R jovyan:users /home/jovyan ; python$(jupyter_python_version) -m pip install /opt/conda/lib/python$(jupyter_python_version)/site-packages/ostk/$(project_name)/ --force-reinstall ; start-notebook.sh --ServerApp.token=''"
@ sudo chown -R $(shell id -u):$(shell id -g) $(CURDIR)
.PHONY: debug-jupyter
debug-development: build-development-image ## Debug development environment
@ echo "Debugging development environment..."
docker run \
-it \
--rm \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash
.PHONY: debug-development
debug-cpp-release: build-release-image-cpp ## Debug C++ release environment
@ echo "Debugging C++ release environment..."
docker run \
-it \
--rm \
--entrypoint=/bin/bash \
$(docker_release_image_cpp_repository):$(docker_image_version)
.PHONY: debug-cpp-release
debug-python-release: build-release-image-python ## Debug Python release environment
@ echo "Debugging Python release environment..."
docker run \
-it \
--rm \
--entrypoint=/bin/bash \
$(docker_release_image_python_repository):$(docker_image_version)
.PHONY: debug-python-release
format: ## Run formatting
@ echo "Formatting..."
@ $(MAKE) format-cpp
@ $(MAKE) format-python
.PHONY: format
format-cpp: build-development-image ## Format all of the source code with the rules in .clang-format
docker run \
--rm \
--volume="$(CURDIR):/app" \
--workdir=/app \
$(docker_development_image_repository):$(docker_image_version) \
ostk-format-cpp
.PHONY: format-cpp
format-python: build-development-image ## Run the black format tool against python code
docker run \
--rm \
--volume="$(CURDIR):/app" \
--workdir=/app \
$(docker_development_image_repository):$(docker_image_version) \
ostk-format-python
.PHONY: format-python
format-check: ## Run format checking
@ echo "Checking format..."
@ $(MAKE) format-check-cpp
@ $(MAKE) format-check-python
.PHONY: format-check
format-check-cpp: build-development-image ## Run the clang-format tool to check the code against rules and formatting
@ $(MAKE) format-check-cpp-standalone
.PHONY: format-check-cpp
format-check-cpp-standalone:
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--workdir=/app \
$(docker_development_image_repository):$(docker_image_version) \
ostk-check-format-cpp
.PHONY: format-check-cpp-standalone
format-check-python: build-development-image ## Run the black format tool against python code
@ $(MAKE) format-check-python-standalone
.PHONY: format-check-python
format-check-python-standalone:
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--workdir=/app \
$(docker_development_image_repository):$(docker_image_version) \
ostk-check-format-python
.PHONY: format-check-python-standalone
test: ## Run tests
@ echo "Running tests..."
@ $(MAKE) test-unit
@ $(MAKE) test-coverage
.PHONY: test
test-unit: ## Run unit tests
@ echo "Running unit tests..."
@ $(MAKE) test-unit-cpp
@ $(MAKE) test-unit-python
.PHONY: test-unit
test-unit-cpp: build-development-image ## Run C++ unit tests
@ $(MAKE) test-unit-cpp-standalone
.PHONY: test-unit-cpp
test-unit-cpp-standalone: ## Run C++ unit tests (standalone)
@ echo "Running C++ unit tests..."
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_UNIT_TESTS=ON .. \
&& $(MAKE) -j 4 \
&& $(MAKE) test"
.PHONY: test-unit-cpp-standalone
test-unit-python: build-release-image-python ## Run Python unit tests
@ $(MAKE) test-unit-python-standalone
.PHONY: test-unit-python
test-unit-python-standalone: ## Run Python unit tests (standalone)
@ echo "Running Python unit tests..."
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_PYTHON_BINDINGS=ON -DBUILD_UNIT_TESTS=OFF -DBUILD_VALIDATION_TESTS=OFF -DBUILD_BENCHMARK=OFF .. \
&& $(MAKE) -j 4 && python3.11 -m pip install --root-user-action=ignore bindings/python/OpenSpaceToolkit*Py-python-package-3.11 \
&& python3.11 -m pip install plotly pandas \
&& python3.11 -m pip install git+https://github.com/lucas-bremond/cesiumpy.git#egg=cesiumpy \
&& cd /usr/local/lib/python3.11/site-packages/ostk/$(project_name)/ \
&& python3.11 -m pytest -sv ."
.PHONY: test-unit-python-standalone
test-coverage: ## Run test coverage cpp
@ echo "Running coverage tests..."
@ $(MAKE) test-coverage-cpp
.PHONY: test-coverage
test-coverage-cpp: build-development-image ## Run C++ tests with coverage
@ $(MAKE) test-coverage-cpp-standalone
.PHONY: test-coverage-cpp
test-coverage-cpp-standalone: ## Run C++ tests with coverage (standalone)
@ echo "Running C++ coverage tests..."
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=ON -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_CODE_COVERAGE=ON .. \
&& $(MAKE) -j 4 \
&& $(MAKE) coverage \
&& (rm -rf /app/coverage || true) \
&& mkdir /app/coverage \
&& mv /app/build/coverage* /app/coverage"
.PHONY: test-coverage-cpp-standalone
benchmark: ## Run benchmarks
@ echo "Running benchmarks..."
@ $(MAKE) benchmark-cpp
.PHONY: benchmark
benchmark-cpp: build-development-image ## Run C++ benchmarks
@ $(MAKE) benchmark-cpp-standalone
.PHONY: benchmark-cpp
benchmark-cpp-standalone: ## Run C++ benchmarks (standalone)
@ echo "Running C++ benchmark..."
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_UNIT_TESTS=OFF -DBUILD_VALIDATION_TESTS=OFF -DBUILD_BENCHMARK=ON .. \
&& $(MAKE) -j 4 \
&& ./../bin/open-space-toolkit-$(project_name).benchmark --benchmark_out_format=json --benchmark_out=./../bin/benchmark_result.json"
.PHONY: benchmark-cpp-standalone
validation: ## Run validation tests
@ echo "Running validation tests..."
@ $(MAKE) validation-cpp
.PHONY: validation
validation-cpp: build-development-image ## Run C++ validation tests
@ $(MAKE) validation-cpp-standalone
.PHONY: validation-cpp
validation-cpp-standalone: ## Run C++ validation tests (standalone)
@ echo "Running C++ validation..."
docker run \
--rm \
--volume="$(CURDIR):/app:delegated" \
--volume="/app/build" \
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_UNIT_TESTS=OFF -DBUILD_BENCHMARK=OFF -DBUILD_VALIDATION_TESTS=ON .. \
&& $(MAKE) -j 4 \
&& ./../bin/open-space-toolkit-$(project_name).validation"
.PHONY: validation-cpp-standalone
clean: ## Clean
@ echo "Cleaning up..."
rm -rf "$(CURDIR)/build"
rm -rf "$(CURDIR)/bin"
rm -rf "$(CURDIR)/docs/html"
rm -rf "$(CURDIR)/docs/latex"
rm -rf "$(CURDIR)/lib"
rm -rf "$(CURDIR)/coverage"
rm -rf "$(CURDIR)/packages"
rm -rf "$(CURDIR)/.open-space-toolkit"
.PHONY: clean
help:
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
export DOCKER_BUILDKIT = 1
.DEFAULT_GOAL := help