Skip to content

Commit fe8a3e2

Browse files
committed
tooling: Derive package version from git describe
1 parent 32be85d commit fe8a3e2

24 files changed

+59
-145
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
VERSION
2+
13
# Standard out-of-source build
24
build/
35
compile_commands.json

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ smoketest:
7777
@${CLOE_LAUNCH} clean -P conanfile.py
7878
@\time -f "\nTotal smoketest time (real) = %e sec" bats tests
7979

80+
purge-all:
81+
$(call print_header, "Removing all cloe Conan packages...")
82+
conan remove -f 'cloe-*'
83+
conan remove -f 'cloe'
84+
conan remove -f 'fable'
8085

8186
# Development targets ---------------------------------------------------------
8287
.PHONY: format todos find-missing-eol sanitize-files

Makefile.package

+12-9
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ DATE := $(shell date +"%Y%m%d")
2222
TIMESTAMP := $(shell date -u +'%Y-%m-%dT%H:%M:%SZ')
2323

2424
HAS_GIT := $(shell [ -d ${PROJECT_ROOT}/.git ] && echo "true")
25+
ifeq (${PROJECT_VERSION},unknown)
2526
ifeq (${HAS_GIT},true)
26-
GIT_COMMIT_HASH := $(shell git log -1 --format=%h)
27-
GIT_COMMIT_DIRTY := $(shell git diff --quiet || echo "-dirty")
28-
GIT_DESCRIBE := ${GIT_COMMIT_HASH}${GIT_COMMIT_DIRTY}
27+
GIT_COMMIT_HASH := $(shell git log -1 --format=%h)
28+
GIT_COMMIT_DIRTY := $(shell git diff --quiet || echo "-dirty")
29+
GIT_DESCRIBE := $(shell git describe --dirty="-dirty" | sed -r "s/^v(.*)/\1/")
2930
else
30-
GIT_DESCRIBE := "unknown"
31+
GIT_DESCRIBE := "unknown"
32+
endif
33+
PROJECT_VERSION := ${GIT_DESCRIBE}
3134
endif
3235

3336
SOURCE_DIR := .
@@ -189,10 +192,10 @@ download:
189192
#
190193
# See: https://docs.conan.io/en/latest/mastering/policies.html
191194
#
192-
conan create . ${PACKAGE_CHANNEL} \
195+
conan create . ${PACKAGE_FQN} \
193196
--build=never \
194197
${CONAN_OPTIONS} || \
195-
conan create . ${PACKAGE_CHANNEL} \
198+
conan create . ${PACKAGE_FQN} \
196199
--build=${BUILD_POLICY} --build=${PACKAGE_NAME} \
197200
${CONAN_OPTIONS}
198201

@@ -204,7 +207,7 @@ package:
204207
#
205208
# See: https://docs.conan.io/en/latest/mastering/policies.html
206209
#
207-
conan create . ${PACKAGE_CHANNEL} \
210+
conan create . ${PACKAGE_FQN} \
208211
--build=${BUILD_POLICY} --build=${PACKAGE_NAME} \
209212
${CONAN_OPTIONS}
210213

@@ -214,7 +217,7 @@ package-all:
214217
# Conan will retrieve and build all dependencies unconditionally.
215218
# Note that this cannot be called if the package is currently in editable mode.
216219
#
217-
conan create . ${PACKAGE_CHANNEL} \
220+
conan create . ${PACKAGE_FQN} \
218221
--build \
219222
${CONAN_OPTIONS}
220223

@@ -225,7 +228,7 @@ package-outdated:
225228
# Rebuilds will occur if package info has changed or a hash of the source
226229
# code changes. Timestamps are not taken into account.
227230
#
228-
conan create . ${PACKAGE_CHANNEL} \
231+
conan create . ${PACKAGE_FQN} \
229232
--build=outdated \
230233
${CONAN_OPTIONS}
231234

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ See the Conan [documentation][6] for more information on how to do this.
8686
8787
To build all packages, you should run the following:
8888
89-
make export-vendor export
90-
make package
89+
make export-vendor
90+
make package-auto
9191
9292
This will export all Conan recipes from this repository and create the cloe
9393
package. Conan will download and build all necessary dependencies. Should

VERSION

-1
This file was deleted.

conanfile.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import os.path
2-
1+
from pathlib import Path
32
from conans import CMake, ConanFile, tools
43

54

@@ -27,15 +26,13 @@ class Cloe(ConanFile):
2726

2827
_cmake = None
2928

30-
def _project_version(self):
31-
version_file = os.path.join(self.recipe_folder, "VERSION")
32-
return tools.load(version_file).strip()
33-
3429
def set_version(self):
35-
self.version = self._project_version()
36-
37-
def _requires(self, name):
38-
self.requires(f"{name}/{self.version}@cloe/develop")
30+
version_file = Path(self.recipe_folder) / "VERSION"
31+
if version_file.exists():
32+
self.version = tools.load(version_file).strip()
33+
else:
34+
git = tools.Git(folder=self.recipe_folder)
35+
self.version = git.run("describe --dirty=-dirty")[1:]
3936

4037
def requirements(self):
4138
self.requires("boost/[<1.70]", override=True)
@@ -58,7 +55,7 @@ def requirements(self):
5855
requires.append("cloe-engine")
5956

6057
for dep in requires:
61-
self._requires(dep)
58+
self.requires(f"{dep}/{self.version}@cloe/develop")
6259

6360
def _configure_cmake(self):
6461
if self._cmake:

dist/docker/Dockerfile.archlinux

+2
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ RUN --mount=type=cache,target=/ccache \
5454

5555
# Build Cloe.
5656
COPY . /cloe
57+
ARG PROJECT_VERSION=unknown
5758
ARG PACKAGE_TARGET=package-auto
5859
RUN --mount=type=cache,target=/ccache \
5960
--mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
6061
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
62+
echo "${PROJECT_VERSION}" > /cloe/VERSION && \
6163
make WITH_VTD=${WITH_VTD} ${PACKAGE_TARGET} && \
6264
# Clean up:
6365
find /root/.conan/data -name dl -type d -maxdepth 5 -exec rm -r {} + && \

dist/docker/Dockerfile.bionic

+2
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ RUN --mount=type=cache,target=/ccache \
5858

5959
# Build Cloe.
6060
COPY . /cloe
61+
ARG PROJECT_VERSION=unknown
6162
ARG PACKAGE_TARGET=package-auto
6263
RUN --mount=type=cache,target=/ccache \
6364
--mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
6465
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
66+
echo "${PROJECT_VERSION}" > /cloe/VERSION && \
6567
make WITH_VTD=${WITH_VTD} ${PACKAGE_TARGET} && \
6668
# Clean up:
6769
find /root/.conan/data -name dl -type d -maxdepth 5 -exec rm -r {} + && \

dist/docker/Dockerfile.focal

+2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ RUN --mount=type=cache,target=/ccache \
7171

7272
# Build Cloe.
7373
COPY . /cloe
74+
ARG PROJECT_VERSION=unknown
7475
ARG PACKAGE_TARGET=package-auto
7576
RUN --mount=type=cache,target=/ccache \
7677
--mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
7778
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
79+
echo "${PROJECT_VERSION}" > /cloe/VERSION && \
7880
make WITH_VTD=${WITH_VTD} ${PACKAGE_TARGET} && \
7981
# Clean up:
8082
find /root/.conan/data -name dl -type d -maxdepth 5 -exec rm -r {} + && \

dist/docker/Dockerfile.xenial

+2
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ RUN --mount=type=cache,target=/ccache \
110110

111111
# Build Cloe.
112112
COPY . /cloe
113+
ARG PROJECT_VERSION=unknown
113114
ARG PACKAGE_TARGET=package-auto
114115
RUN --mount=type=cache,target=/ccache \
115116
--mount=type=secret,target=/root/setup.sh,id=setup,mode=0400 \
116117
if [ -r /root/setup.sh ]; then . /root/setup.sh; fi && \
118+
echo "${PROJECT_VERSION}" > /cloe/VERSION && \
117119
make WITH_VTD=${WITH_VTD} ${PACKAGE_TARGET} && \
118120
# Clean up:
119121
find /root/.conan/data -name dl -type d -maxdepth 5 -exec rm -r {} + && \

dist/docker/Makefile

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Usage: make [options] <target>
22
#
33

4-
CLOE_ROOT := ../..
5-
CLOE_VERSION := $(shell cat ${CLOE_ROOT}/VERSION)
4+
PROJECT_ROOT := ../..
5+
PROJECT_VERSION := $(shell make --no-print-directory -C ${PROJECT_ROOT} -f Makefile.package info-version)
66

77
DOCKER := DOCKER_BUILDKIT=1 docker
88

@@ -17,9 +17,9 @@ DOCKER_NETWORK := \
1717
)
1818

1919
IMAGE_BASE := cloe/cloe-engine
20-
IMAGE_VERSION := ${CLOE_VERSION}
20+
IMAGE_VERSION := ${PROJECT_VERSION}
2121
DOCKER_IMAGE := ${IMAGE_BASE}:${IMAGE_VERSION}
22-
DOCKER_CONTEXT := ${CLOE_ROOT}
22+
DOCKER_CONTEXT := ${PROJECT_ROOT}
2323

2424
# Default build arguments
2525
VENDOR_TARGET :=
@@ -29,6 +29,7 @@ WITH_VTD :=
2929

3030
DOCKER_BUILD_ARGS += ${DOCKER_NETWORK}
3131
DOCKER_BUILD_ARGS += --progress=plain
32+
DOCKER_BUILD_ARGS += --build-arg PROJECT_VERSION=${PROJECT_VERSION}
3233

3334
ifeq ($(shell [ -f setup.sh ] && echo "true"),true)
3435
DOCKER_BUILD_ARGS += --secret id=setup,src=setup.sh
@@ -49,7 +50,6 @@ endif
4950
ifeq (${WITH_VTD},1)
5051
DOCKER_IMAGE := ${DOCKER_IMAGE}-vtd
5152
DOCKER_BUILD_ARGS += --build-arg WITH_VTD=${WITH_VTD}
52-
DOCKER_BUILD_ARGS += --build-arg VTD_SRCS=cloe/vires:2.2.0
5353
endif
5454

5555
DOCKER_ARGS := ${DOCKER_BUILD_ARGS}
@@ -96,9 +96,9 @@ archlinux: Dockerfile.archlinux
9696

9797
# The VTD image is required for the other builds, but can be empty if you don't
9898
# have access to actual VTD sources.
99-
VTD_VERSION := $(shell make --no-print-directory -C ${CLOE_ROOT}/vendor/vtd info-version)
99+
VTD_VERSION := $(shell make --no-print-directory -C ${PROJECT_ROOT}/vendor/vtd info-version 2>/dev/null)
100100
VTD_IMAGE := cloe/vtd-sources:${VTD_VERSION}
101-
VTD_CONTEXT := ${CLOE_ROOT}/vendor/vtd/vires
101+
VTD_CONTEXT := ${PROJECT_ROOT}/vendor/vtd/vires
102102
vires: Dockerfile.vires
103103
@echo ===================================================================================
104104
[ -d ${VTD_CONTEXT} ] || mkdir ${VTD_CONTEXT}

engine/conanfile.py

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import os.path
2-
1+
import os
2+
from pathlib import Path
33
from conans import CMake, ConanFile, tools
44

55

@@ -27,13 +27,6 @@ class CloeEngine(ConanFile):
2727

2828
_cmake = None
2929

30-
def _project_version(self):
31-
version_file = os.path.join(self.recipe_folder, "..", "VERSION")
32-
return tools.load(version_file).strip()
33-
34-
def set_version(self):
35-
self.version = self._project_version()
36-
3730
def requirements(self):
3831
self.requires("boost/[>=1.65.1]"),
3932
self.requires(f"cloe-runtime/{self.version}@cloe/develop")

fable/conanfile.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import os.path
2-
1+
from pathlib import Path
32
from conans import CMake, ConanFile, tools
43

54

@@ -34,13 +33,6 @@ class Fable(ConanFile):
3433

3534
_cmake = None
3635

37-
def _project_version(self):
38-
version_file = os.path.join(self.recipe_folder, "..", "VERSION")
39-
return tools.load(version_file).strip()
40-
41-
def set_version(self):
42-
self.version = self._project_version()
43-
4436
def build_requirements(self):
4537
if self.options.test:
4638
self.build_requires("gtest/[~1.10]")

models/conanfile.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import os.path
2-
1+
from pathlib import Path
32
from conans import CMake, ConanFile, tools
43

54

@@ -35,13 +34,6 @@ class CloeModels(ConanFile):
3534

3635
_cmake = None
3736

38-
def _project_version(self):
39-
version_file = os.path.join(self.recipe_folder, "..", "VERSION")
40-
return tools.load(version_file).strip()
41-
42-
def set_version(self):
43-
self.version = self._project_version()
44-
4537
def requirements(self):
4638
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
4739

oak/conanfile.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import os.path
2-
1+
from pathlib import Path
32
from conans import CMake, ConanFile, tools
43

54

@@ -34,13 +33,6 @@ class CloeOak(ConanFile):
3433

3534
_cmake = None
3635

37-
def _project_version(self):
38-
version_file = os.path.join(self.recipe_folder, "..", "VERSION")
39-
return tools.load(version_file).strip()
40-
41-
def set_version(self):
42-
self.version = self._project_version()
43-
4436
def requirements(self):
4537
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
4638

plugins/basic/conanfile.py

+1-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os.path
1+
from pathlib import Path
22
from shutil import which
33

44
from conans import CMake, ConanFile, tools
@@ -29,13 +29,6 @@ class CloeControllerBasic(ConanFile):
2929

3030
_cmake = None
3131

32-
def _project_version(self):
33-
version_file = os.path.join(self.recipe_folder, "..", "..", "VERSION")
34-
return tools.load(version_file).strip()
35-
36-
def set_version(self):
37-
self.version = self._project_version()
38-
3932
def requirements(self):
4033
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
4134
self.requires(f"cloe-models/{self.version}@cloe/develop")

plugins/gndtruth_extractor/conanfile.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import os.path
2-
1+
from pathlib import Path
32
from conans import CMake, ConanFile, tools
43

54

@@ -24,13 +23,6 @@ class CloeControllerGndtruthExtractor(ConanFile):
2423

2524
_cmake = None
2625

27-
def _project_version(self):
28-
version_file = os.path.join(self.recipe_folder, "..", "..", "VERSION")
29-
return tools.load(version_file).strip()
30-
31-
def set_version(self):
32-
self.version = self._project_version()
33-
3426
def requirements(self):
3527
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
3628
self.requires(f"cloe-models/{self.version}@cloe/develop")

plugins/minimator/conanfile.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import os.path
2-
1+
from pathlib import Path
32
from conans import CMake, ConanFile, tools
43

54

@@ -24,13 +23,6 @@ class CloeSimulatorMinimator(ConanFile):
2423

2524
_cmake = None
2625

27-
def _project_version(self):
28-
version_file = os.path.join(self.recipe_folder, "..", "..", "VERSION")
29-
return tools.load(version_file).strip()
30-
31-
def set_version(self):
32-
self.version = self._project_version()
33-
3426
def requirements(self):
3527
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
3628
self.requires(f"cloe-models/{self.version}@cloe/develop")

plugins/mocks/conanfile.py

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import os.path
2-
1+
from pathlib import Path
32
from conans import CMake, ConanFile, tools
43

54

@@ -24,13 +23,6 @@ class CloeControllerMocks(ConanFile):
2423

2524
_cmake = None
2625

27-
def _project_version(self):
28-
version_file = os.path.join(self.recipe_folder, "..", "..", "VERSION")
29-
return tools.load(version_file).strip()
30-
31-
def set_version(self):
32-
self.version = self._project_version()
33-
3426
def requirements(self):
3527
self.requires(f"cloe-runtime/{self.version}@cloe/develop")
3628
self.requires(f"cloe-models/{self.version}@cloe/develop")

0 commit comments

Comments
 (0)