Skip to content

Commit

Permalink
build: make standalone test/package targets (#101)
Browse files Browse the repository at this point in the history
* refactor: make standalone test/package targets

* fix: project_name_camel_case substitution

---------

Co-authored-by: Kyle Cochran <kyle.cochran@loftorbital.com>
  • Loading branch information
kyle-cochran and kyle-cochran authored May 11, 2023
1 parent 489a66e commit aa6f077
Showing 1 changed file with 78 additions and 39 deletions.
117 changes: 78 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ docker_release_image_jupyter_repository := $(docker_image_repository)-jupyter
jupyter_notebook_image_repository := jupyter/scipy-notebook:python-3.8.8
jupyter_notebook_port := 9005
jupyter_python_version := 3.8
jupyter_project_name_python_shared_object := OpenSpaceToolkitAstrodynamicsPy.cpython-38-x86_64-linux-gnu

project_name_camel_case := $(shell echo $(project_name) | sed -r 's/(^|-)([a-z])/\U\2/g')
jupyter_project_name_python_shared_object := $(shell echo "OpenSpaceToolkit${project_name_camel_case}.cpython-38-x86_64-linux-gnu")

clang_format_sources_path ?= $(shell find ~+ src/ include/ test/ bindings/python/src/ -name '*.cpp' -o -name '*.cxx' -o -name '*.hpp' -o -name '*.tpp')

pull: ## Pull all images

@ echo "Pulling images..."

@ make pull-development-image
@ make pull-release-images
@ $(MAKE) pull-development-image
@ $(MAKE) pull-release-images

.PHONY: pull

Expand All @@ -41,11 +43,11 @@ pull-release-images: ## Pull release images

@ echo "Pull release images..."

@ make pull-release-image-cpp
@ $(MAKE) pull-release-image-cpp

@ make pull-release-image-python
@ $(MAKE) pull-release-image-python

@ make pull-release-image-jupyter
@ $(MAKE) pull-release-image-jupyter

.PHONY: pull-release-images

Expand Down Expand Up @@ -82,8 +84,8 @@ build-images: ## Build development and release images

@ echo "Building images..."

@ make build-development-image
@ make build-release-images
@ $(MAKE) build-development-image
@ $(MAKE) build-release-images

.PHONY: build-images

Expand All @@ -92,7 +94,6 @@ build-development-image: pull-development-image ## Build development image
@ echo "Building development image..."

docker build \
--cache-from=$(docker_development_image_repository):latest \
--file="$(CURDIR)/docker/development/Dockerfile" \
--tag=$(docker_development_image_repository):$(docker_image_version) \
--tag=$(docker_development_image_repository):latest \
Expand All @@ -105,11 +106,11 @@ build-release-images: ## Build release images

@ echo "Building release images..."

@ make build-release-image-cpp
@ $(MAKE) build-release-image-cpp

@ make build-release-image-python
@ $(MAKE) build-release-image-python

@ make build-release-image-jupyter
@ $(MAKE) build-release-image-jupyter

.PHONY: build-release-images

Expand All @@ -118,7 +119,6 @@ build-release-image-cpp: build-development-image pull-release-image-cpp
@ echo "Building C++ release image..."

docker build \
--cache-from=$(docker_release_image_cpp_repository):latest \
--file="$(CURDIR)/docker/release/Dockerfile" \
--tag=$(docker_release_image_cpp_repository):$(docker_image_version) \
--tag=$(docker_release_image_cpp_repository):latest \
Expand All @@ -133,7 +133,6 @@ build-release-image-python: build-development-image pull-release-image-python
@ echo "Building Python release image..."

docker build \
--cache-from=$(docker_release_image_python_repository):latest \
--file="$(CURDIR)/docker/release/Dockerfile" \
--tag=$(docker_release_image_python_repository):$(docker_image_version) \
--tag=$(docker_release_image_python_repository):latest \
Expand All @@ -148,7 +147,6 @@ build-release-image-jupyter: pull-release-image-jupyter
@ echo "Building Jupyter Notebook release image..."

docker build \
--cache-from=$(docker_release_image_jupyter_repository):latest \
--file="$(CURDIR)/docker/jupyter/Dockerfile" \
--tag=$(docker_release_image_jupyter_repository):$(docker_image_version) \
--tag=$(docker_release_image_jupyter_repository):latest \
Expand All @@ -159,6 +157,12 @@ build-release-image-jupyter: pull-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 \
Expand All @@ -168,21 +172,27 @@ build-documentation: build-development-image ## Build documentation
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=OFF -DBUILD_PYTHON_BINDINGS=OFF -DBUILD_DOCUMENTATION=ON .. \
&& make docs"
&& $(MAKE) docs"

.PHONY: build-documentation
.PHONY: build-documentation-standalone

build-packages: ## Build packages

@ echo "Building packages..."

@ make build-packages-cpp
@ make build-packages-python
@ $(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 \
Expand All @@ -192,13 +202,19 @@ build-packages-cpp: build-development-image ## Build C++ packages
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=OFF -DBUILD_PYTHON_BINDINGS=OFF -DCPACK_GENERATOR=DEB .. \
&& make package \
&& $(MAKE) package \
&& mkdir -p /app/packages/cpp \
&& mv /app/build/*.deb /app/packages/cpp"

.PHONY: build-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..."

Expand All @@ -209,11 +225,11 @@ build-packages-python: build-development-image ## Build Python packages
--workdir=/app/build \
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_UNIT_TESTS=OFF -DBUILD_PYTHON_BINDINGS=ON .. \
&& make -j 4 \
&& $(MAKE) -j 4 \
&& mkdir -p /app/packages/python \
&& mv /app/build/bindings/python/dist/*.whl /app/packages/python"

.PHONY: build-packages-python
.PHONY: build-packages-python-standalone

start-development-no-link: build-development-image ## Start development environment

Expand Down Expand Up @@ -368,21 +384,27 @@ test: ## Run tests

@ echo "Running tests..."

@ make test-unit
@ make test-coverage
@ $(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
@ $(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..."

Expand All @@ -394,34 +416,51 @@ test-unit-cpp: build-development-image ## Run C++ unit tests
--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"
&& $(MAKE) -j 4 \
&& $(MAKE) test"

.PHONY: test-unit-cpp
.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="$(CURDIR)/share/OpenSpaceToolkit:/usr/local/share/OpenSpaceToolkit:delegated" \
--workdir=/usr/local/lib/python3.11/site-packages/ostk/$(project_name) \
--volume="/app/build" \
--workdir=/app/build \
--entrypoint="" \
$(docker_release_image_python_repository):$(docker_image_version) \
/bin/bash -c "pip install pytest && pytest -sv ."
$(docker_development_image_repository):$(docker_image_version) \
/bin/bash -c "cmake -DBUILD_PYTHON_BINDINGS=ON -DBUILD_UNIT_TESTS=OFF .. \
&& $(MAKE) -j 4 && pip install bindings/python/dist/*311*.whl \
&& cd /usr/local/lib/python3.11/site-packages/ostk/$(project_name)/ \
&& python3.11 -m pytest -sv ."

.PHONY: test-unit-python
.PHONY: test-unit-python-standalone

test-coverage: ## Run test coverage cpp

@ echo "Running coverage tests..."

@ make test-coverage-cpp
@ $(MAKE) test-coverage-cpp

.PHONY: test-coverage

test-coverage-cpp: build-development-image
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..."

Expand All @@ -433,13 +472,13 @@ test-coverage-cpp: build-development-image
--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 \
&& $(MAKE) -j 4 \
&& $(MAKE) coverage \
&& (rm -rf /app/coverage || true) \
&& mkdir /app/coverage \
&& mv /app/build/coverage* /app/coverage"

.PHONY: test-coverage-cpp
.PHONY: test-coverage-cpp-standalone

clean: ## Clean

Expand Down

0 comments on commit aa6f077

Please sign in to comment.