Skip to content

Commit 7018583

Browse files
committed
Use a build matrix.
1 parent 06eef64 commit 7018583

File tree

4 files changed

+200
-2
lines changed

4 files changed

+200
-2
lines changed

build.sh

+156
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
#! /bin/bash
2+
3+
OVERRIDE_CONFIG=~/.mbs2/overrides.cfg
4+
if [ -f "$OVERRIDE_CONFIG" ]; then
5+
. $OVERRIDE_CONFIG
6+
fi
7+
8+
# FIXME: Get this from a config file.
9+
JONCHKI_VERSION=0.0.12.1
10+
JONCHKI_VERBOSE=debug
11+
JONCHKI_REPOSITORY=~/.mbs2
12+
JONCHKI_SYSCFG=jonchki/jonchkisys.cfg
13+
JONCHKI_PRJCFG=jonchki/jonchkicfg.xml
14+
JONCHKI_DEPENDENCY_LOG=dependency-log.xml
15+
JONCHKI_LOG=
16+
17+
# ---------------------------------------------------------------------------
18+
#
19+
# Get the host architecture.
20+
#
21+
22+
# Get the CPU architecture with the "lscpu" command.
23+
CPUARCH=$(lscpu | awk -F'Architecture:' '{print $2}' | xargs)
24+
# Translate a few older CPUs to a (hopefully) compatible architecture.
25+
declare -A arch2bits=(
26+
["i386"]="x86"
27+
["i486"]="x86"
28+
["i586"]="x86"
29+
["i686"]="x86"
30+
)
31+
HOST_ARCHITECTURE="${arch2bits[$CPUARCH]}"
32+
if [ -z "${HOST_ARCHITECTURE}" ]; then
33+
HOST_ARCHITECTURE=$CPUARCH
34+
fi
35+
36+
# Detect a 32 bit system running on a 64bit CPU.
37+
OSARCH=$(getconf LONG_BIT)
38+
if [ "$OSARCH" == "32" ]; then
39+
# This is an x86_64 CPU running a x86 OS.
40+
if [ "$HOST_ARCHITECTURE" == "x86_64" ]; then
41+
HOST_ARCHITECTURE="x86"
42+
fi
43+
fi
44+
45+
if [ -z "${HOST_ARCHITECTURE}" ]; then
46+
echo "Failed to detect the host architecture."
47+
exit -1
48+
fi
49+
50+
# ---------------------------------------------------------------------------
51+
#
52+
# Get the OS.
53+
#
54+
55+
if [ -f /etc/lsb-release ]; then
56+
HOST_DISTRIBUTION_ID=$(cat /etc/lsb-release | awk -F'DISTRIB_ID=' '{print $2}' | xargs | awk '{print tolower($0)}')
57+
HOST_DISTRIBUTION_VERSION=$(cat /etc/lsb-release | awk -F'DISTRIB_RELEASE=' '{print $2}' | xargs)
58+
fi
59+
60+
if [ -z "${HOST_DISTRIBUTION_ID}" ]; then
61+
echo "Failed to detect the distribution ID."
62+
exit -1
63+
fi
64+
if [ -z "${HOST_DISTRIBUTION_VERSION}" ]; then
65+
echo "Failed to detect the distribution version."
66+
exit -1
67+
fi
68+
69+
# ---------------------------------------------------------------------------
70+
#
71+
# Apply overrides.
72+
#
73+
if [ -n "$HOST_DISTRIBUTION_ID_OVERRIDE" ]; then
74+
echo "Overriding the host distribution ID for MBS from $HOST_DISTRIBUTION_ID to $HOST_DISTRIBUTION_ID_OVERRIDE ."
75+
HOST_DISTRIBUTION_ID=$HOST_DISTRIBUTION_ID_OVERRIDE
76+
fi
77+
if [ -n "$HOST_DISTRIBUTION_VERSION_OVERRIDE" ]; then
78+
echo "Overriding the host distribution version for MBS from $HOST_DISTRIBUTION_VERSION to $HOST_DISTRIBUTION_VERSION_OVERRIDE ."
79+
HOST_DISTRIBUTION_VERSION=$HOST_DISTRIBUTION_VERSION_OVERRIDE
80+
fi
81+
if [ -n "$HOST_ARCHITECTURE_OVERRIDE" ]; then
82+
echo "Overriding the host architecture for MBS from $HOST_ARCHITECTURE to $HOST_ARCHITECTURE_OVERRIDE ."
83+
HOST_ARCHITECTURE=$HOST_ARCHITECTURE_OVERRIDE
84+
fi
85+
86+
# ---------------------------------------------------------------------------
87+
#
88+
# Get the standard archive format.
89+
#
90+
91+
declare -A distribid2archformat=(
92+
["ubuntu"]="tar.gz"
93+
)
94+
STANDARD_ARCHIVE_FORMAT="${distribid2archformat[$HOST_DISTRIBUTION_ID]}"
95+
96+
if [ -z "${STANDARD_ARCHIVE_FORMAT}" ]; then
97+
echo "Failed to detect the standard archive format."
98+
exit -1
99+
fi
100+
101+
# ---------------------------------------------------------------------------
102+
103+
ARTIFACT_FILE="jonchki-${JONCHKI_VERSION}-${HOST_DISTRIBUTION_ID}${HOST_DISTRIBUTION_VERSION}_${HOST_ARCHITECTURE}.${STANDARD_ARCHIVE_FORMAT}"
104+
105+
# Get the path to the artifact download and depack folder.
106+
ARTIFACT_REPOSITORY_PATH=$(realpath ${JONCHKI_REPOSITORY})/repository/org/muhkuh/lua/jonchki/${JONCHKI_VERSION}
107+
ARTIFACT_INSTALL_PATH=$(realpath ${JONCHKI_REPOSITORY})/install/org/muhkuh/lua/jonchki
108+
JONCHKI_TOOL=${ARTIFACT_INSTALL_PATH}/jonchki-${JONCHKI_VERSION}/jonchki
109+
110+
# Create the paths if they does not exist.
111+
mkdir -p ${ARTIFACT_REPOSITORY_PATH}
112+
if [ $? -ne 0 ]; then
113+
echo "Failed to create the repository path \"${ARTIFACT_REPOSITORY_PATH}\"."
114+
exit -1
115+
fi
116+
mkdir -p ${ARTIFACT_INSTALL_PATH}
117+
if [ $? -ne 0 ]; then
118+
echo "Failed to create the install path \"${ARTIFACT_INSTALL_PATH}\"."
119+
exit -1
120+
fi
121+
122+
# Was the artifact already downloaded?
123+
if [ ! -f "${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE}" ]; then
124+
echo "Downloading the artifact..."
125+
curl --location --output ${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} https://github.com/muhkuh-sys/org.muhkuh.lua-jonchki/releases/download/v${JONCHKI_VERSION}/${ARTIFACT_FILE}
126+
if [ $? -ne 0 ]; then
127+
echo "Failed to download the artifact."
128+
exit -1
129+
fi
130+
fi
131+
132+
# Was the artifact already depacked?
133+
if [ ! -f "${JONCHKI_TOOL}" ]; then
134+
if [ "${STANDARD_ARCHIVE_FORMAT}" == "tar.gz" ]; then
135+
tar --directory=${ARTIFACT_INSTALL_PATH} --file=${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} --extract --gzip
136+
if [ $? -ne 0 ]; then
137+
echo "Failed to extract the artifact ${ARTIFACT_REPOSITORY_PATH}/${ARTIFACT_FILE} ."
138+
exit -1
139+
fi
140+
else
141+
echo "Unknown archive format: ${STANDARD_ARCHIVE_FORMAT}"
142+
exit -1
143+
fi
144+
fi
145+
146+
# Get the version of the installed tool.
147+
INSTALLED_JONCHKI_VERSION=$(${JONCHKI_TOOL} --version | cut --delimiter=" " --fields=2 | awk '{print tolower($0)}')
148+
if [ "${INSTALLED_JONCHKI_VERSION}" != "v${JONCHKI_VERSION}" ]; then
149+
echo "Unexpected jonchki version in \"${JONCHKI_TOOL}\", expected \"v${JONCHKI_VERSION}\", found \"${INSTALLED_JONCHKI_VERSION}\"."
150+
fi
151+
152+
# Run jonchki.
153+
${JONCHKI_TOOL} build
154+
if [ $? -ne 0 ]; then
155+
exit -1
156+
fi

build_matrix.lua

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
local t = ...
2+
3+
-- The artifact configuration and the finalizer are in the project root folder.
4+
t:setVar(nil, 'jonchki_artifact_configuration', '${prj_root}/jonchki.xml')
5+
t:setVar(nil, 'define_finalizer', '${prj_root}/finalizer.lua')
6+
7+
t:createArtifacts{
8+
'jonchki'
9+
}
10+
11+
-- Build for ARM64 and x86_64 on Ubuntu 20.04 .
12+
t:addBuildToAllArtifacts({
13+
platform_distribution_id = 'ubuntu',
14+
platform_distribution_version = '20.04',
15+
platform_cpu_architecture = 'arm64'
16+
}, true)
17+
t:addBuildToAllArtifacts({
18+
platform_distribution_id = 'ubuntu',
19+
platform_distribution_version = '20.04',
20+
platform_cpu_architecture = 'x86_64'
21+
}, true)
22+
23+
-- Build for ARM64, RISCV64 and x86_64 on Ubuntu 22.04 .
24+
t:addBuildToAllArtifacts({
25+
platform_distribution_id = 'ubuntu',
26+
platform_distribution_version = '22.04',
27+
platform_cpu_architecture = 'arm64'
28+
}, true)
29+
t:addBuildToAllArtifacts({
30+
platform_distribution_id = 'ubuntu',
31+
platform_distribution_version = '22.04',
32+
platform_cpu_architecture = 'riscv64'
33+
}, true)
34+
t:addBuildToAllArtifacts({
35+
platform_distribution_id = 'ubuntu',
36+
platform_distribution_version = '22.04',
37+
platform_cpu_architecture = 'x86_64'
38+
}, true)
39+
40+
t:build()
41+
42+
return true
File renamed without changes.

jonchki/jonchkisys.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
work = jonchki
2-
cache = ../cache
1+
work = targets
2+
cache = ~/.mbs2/cache
33
cache_max_size = 512M

0 commit comments

Comments
 (0)