Skip to content

Commit 6e37b6f

Browse files
committed
create-deb-deploy: always-double deb creation added
1 parent 4e77778 commit 6e37b6f

1 file changed

Lines changed: 109 additions & 81 deletions

File tree

scripts/create-deb-deploy.sh

Lines changed: 109 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,19 @@ BUILD_LOG="${ART_DIR}/build.log"
1919

2020
usage() {
2121
cat <<'EOF'
22-
Usage: create-deb-deploy.sh [--with-headers | --without-headers]
22+
Usage: create-deb-deploy.sh
2323
2424
Options:
25-
--with-headers Keep installed header files in the generated .deb.
26-
--without-headers Exclude installed *.h, *.hpp, and *.tpp files from the .deb.
2725
-h, --help Show this help message.
2826
2927
Environment:
30-
INCLUDE_HEADERS=1|0 Default header inclusion mode when no CLI flag is passed.
3128
REUSE_BUILD=auto|1|0 Reuse an existing build directory when possible. Defaults to auto.
3229
EOF
3330
}
3431

35-
INCLUDE_HEADERS="${INCLUDE_HEADERS:-1}"
3632
REUSE_BUILD="${REUSE_BUILD:-auto}"
3733
while [[ $# -gt 0 ]]; do
3834
case "$1" in
39-
--with-headers)
40-
INCLUDE_HEADERS="1"
41-
shift
42-
;;
43-
--without-headers)
44-
INCLUDE_HEADERS="0"
45-
shift
46-
;;
4735
-h|--help)
4836
usage
4937
exit 0
@@ -56,15 +44,6 @@ while [[ $# -gt 0 ]]; do
5644
esac
5745
done
5846

59-
case "${INCLUDE_HEADERS}" in
60-
0|1)
61-
;;
62-
*)
63-
echo "ERROR: INCLUDE_HEADERS must be 0 or 1, got '${INCLUDE_HEADERS}'"
64-
exit 1
65-
;;
66-
esac
67-
6847
case "${REUSE_BUILD}" in
6948
auto|0|1)
7049
;;
@@ -83,11 +62,16 @@ fi
8362

8463
PACKAGE_NAME="${PACKAGE_NAME:-dls2}"
8564
MAINTAINER="${DEB_MAINTAINER:-Michele Pestarino <michele.pestarino@iit.it>}"
86-
PACKAGE_DESCRIPTION="${DEB_DESCRIPTION:-DLS2 runtime package}"
65+
RUNTIME_PACKAGE_NAME="${PACKAGE_NAME}-runtime"
66+
FRAMEWORK_PACKAGE_NAME="${PACKAGE_NAME}-framework"
67+
RUNTIME_PACKAGE_DESCRIPTION="${DEB_RUNTIME_DESCRIPTION:-DLS2 runtime package}"
68+
FRAMEWORK_PACKAGE_DESCRIPTION="${DEB_FRAMEWORK_DESCRIPTION:-DLS2 framework package}"
8769
DEB_DEPENDS="${DEB_DEPENDS:-python3, python3-psutil, libyaml-cpp0.8, libtinyxml2-10, libgtk-3-0t64 | libgtk-3-0, libcairo2, libglib2.0-0t64 | libglib2.0-0, libboost-filesystem1.83.0, libconsole-bridge1.0, libcap2-bin}"
8870

89-
DEB_NAME="${PACKAGE_NAME}_${VERSION}_amd64.deb"
90-
DEB_PATH="${ROOT_DIR}/${DEB_NAME}"
71+
RUNTIME_DEB_NAME="${RUNTIME_PACKAGE_NAME}_${VERSION}_amd64.deb"
72+
FRAMEWORK_DEB_NAME="${FRAMEWORK_PACKAGE_NAME}_${VERSION}_amd64.deb"
73+
RUNTIME_DEB_PATH="${ROOT_DIR}/${RUNTIME_DEB_NAME}"
74+
FRAMEWORK_DEB_PATH="${ROOT_DIR}/${FRAMEWORK_DEB_NAME}"
9175
JOBS="${JOBS:-4}"
9276
LIVE_BUILD_OUTPUT="${LIVE_BUILD_OUTPUT:-0}"
9377
BUILD_VERBOSE="${BUILD_VERBOSE:-0}"
@@ -96,7 +80,12 @@ CMAKE_ARGS="${CMAKE_ARGS:-}"
9680
BUILD_ARGS="${BUILD_ARGS:--j${JOBS}}"
9781

9882
mkdir -p "${ART_DIR}"
99-
rm -f "${DEB_PATH}" "${ART_DIR}/pkg_files.txt" "${BUILD_LOG}"
83+
rm -f \
84+
"${RUNTIME_DEB_PATH}" \
85+
"${FRAMEWORK_DEB_PATH}" \
86+
"${ART_DIR}/pkg_files_runtime.txt" \
87+
"${ART_DIR}/pkg_files_framework.txt" \
88+
"${BUILD_LOG}"
10089

10190
for required_dir in dls2 robotlib gluecode; do
10291
if [[ ! -f "${ROOT_DIR}/${required_dir}/CMakeLists.txt" ]]; then
@@ -108,13 +97,13 @@ done
10897

10998
run_pipeline() {
11099
local build_dir="${ROOT_DIR}/build"
111-
local stage_dir="${ROOT_DIR}/.deb_stage"
100+
local base_stage_dir="${ROOT_DIR}/.deb_stage"
112101
local reuse_existing_build="0"
113102

114103
if [[ "${CLEAN_BUILD}" == "1" ]]; then
115104
rm -rf "${build_dir}"
116105
fi
117-
rm -rf "${stage_dir}"
106+
rm -rf "${base_stage_dir}" "${ROOT_DIR}/.deb_stage_runtime" "${ROOT_DIR}/.deb_stage_framework"
118107

119108
# shellcheck disable=SC2206
120109
local cmake_user_args=(${CMAKE_ARGS})
@@ -152,20 +141,13 @@ run_pipeline() {
152141
fi
153142
fi
154143

155-
DESTDIR="${stage_dir}" cmake --install "${build_dir}"
144+
DESTDIR="${base_stage_dir}" cmake --install "${build_dir}"
156145

157-
if [[ "${INCLUDE_HEADERS}" == "0" && -d "${stage_dir}/usr/include" ]]; then
158-
find "${stage_dir}/usr/include" -type f \
159-
\( -name '*.h' -o -name '*.hpp' -o -name '*.tpp' \) \
160-
-delete
161-
find "${stage_dir}/usr/include" -depth -type d -empty -delete
162-
fi
163-
164-
strip "${stage_dir}/usr/bin/dls2/dynamic_legged_systems_framework" || true
165-
strip "${stage_dir}/usr/bin/dls2/child_process_launcher" || true
166-
strip "${stage_dir}/usr/lib/librobotlib.so" || true
146+
strip "${base_stage_dir}/usr/bin/dls2/dynamic_legged_systems_framework" || true
147+
strip "${base_stage_dir}/usr/bin/dls2/child_process_launcher" || true
148+
strip "${base_stage_dir}/usr/lib/librobotlib.so" || true
167149

168-
if [[ -f "${stage_dir}/usr/bin/dls" ]]; then
150+
if [[ -f "${base_stage_dir}/usr/bin/dls" ]]; then
169151
awk '
170152
NR == 1 {
171153
print
@@ -186,33 +168,38 @@ run_pipeline() {
186168
next
187169
}
188170
{ print }
189-
' "${stage_dir}/usr/bin/dls" > "${stage_dir}/usr/bin/dls.tmp"
190-
mv "${stage_dir}/usr/bin/dls.tmp" "${stage_dir}/usr/bin/dls"
191-
chmod +x "${stage_dir}/usr/bin/dls"
171+
' "${base_stage_dir}/usr/bin/dls" > "${base_stage_dir}/usr/bin/dls.tmp"
172+
mv "${base_stage_dir}/usr/bin/dls.tmp" "${base_stage_dir}/usr/bin/dls"
173+
chmod +x "${base_stage_dir}/usr/bin/dls"
192174
fi
193175

194-
mkdir -p "${stage_dir}/etc/profile.d" "${stage_dir}/DEBIAN"
195-
cat > "${stage_dir}/etc/profile.d/dls2.sh" << "EOPROFILE"
176+
mkdir -p "${base_stage_dir}/etc/profile.d"
177+
cat > "${base_stage_dir}/etc/profile.d/dls2.sh" << "EOPROFILE"
196178
#!/bin/sh
197179
export GZ_SIM_RESOURCE_PATH="/usr/local/share/dls-gazebo/worlds"
198180
export DLS_SERVERS_PATH="/usr/include/dls2/util/messaging/servers.yaml"
199181
export DLS_SAFETY_LAYER_PATH="/usr/include/dls2/supervisor/data/safety_layer.yaml"
200182
export DLS_SCHEDULER_PATH="/usr/include/dls2/schedulers"
201183
EOPROFILE
202-
chmod +x "${stage_dir}/etc/profile.d/dls2.sh"
203-
204-
cat > "${stage_dir}/DEBIAN/control" << EOCONTROL
205-
Package: ${PACKAGE_NAME}
184+
chmod +x "${base_stage_dir}/etc/profile.d/dls2.sh"
185+
186+
write_package_metadata() {
187+
local stage_dir="$1"
188+
local package_name="$2"
189+
local package_description="$3"
190+
mkdir -p "${stage_dir}/DEBIAN"
191+
cat > "${stage_dir}/DEBIAN/control" << EOCONTROL
192+
Package: ${package_name}
206193
Version: ${DEB_CONTROL_VERSION}
207194
Section: base
208195
Priority: optional
209196
Architecture: amd64
210197
Maintainer: ${MAINTAINER}
211198
Depends: ${DEB_DEPENDS}
212-
Description: ${PACKAGE_DESCRIPTION}
199+
Description: ${package_description}
213200
EOCONTROL
214201

215-
cat > "${stage_dir}/DEBIAN/postinst" << 'EOPOSTINST'
202+
cat > "${stage_dir}/DEBIAN/postinst" << 'EOPOSTINST'
216203
#!/bin/sh
217204
set -e
218205
@@ -231,39 +218,76 @@ fi
231218
232219
exit 0
233220
EOPOSTINST
234-
chmod 0755 "${stage_dir}/DEBIAN/postinst"
235-
236-
if ! find "${stage_dir}" -mindepth 1 \
237-
! -path "${stage_dir}/DEBIAN" \
238-
! -path "${stage_dir}/DEBIAN/*" \
239-
! -path "${stage_dir}/etc" \
240-
! -path "${stage_dir}/etc/profile.d" \
241-
! -path "${stage_dir}/etc/profile.d/dls2.sh" \
242-
-print -quit | grep -q .; then
243-
echo "ERROR: staged package payload is empty."
244-
echo "Hint: cmake configure/build/install likely failed earlier, or the build cache points to a different source tree."
245-
return 1
246-
fi
221+
chmod 0755 "${stage_dir}/DEBIAN/postinst"
222+
}
223+
224+
package_variant() {
225+
local variant="$1"
226+
local include_headers="$2"
227+
local package_name="$3"
228+
local package_description="$4"
229+
local deb_name="$5"
230+
local pkg_list_path="$6"
231+
local stage_dir="${ROOT_DIR}/.deb_stage_${variant}"
232+
233+
cp -a "${base_stage_dir}" "${stage_dir}"
234+
235+
if [[ "${include_headers}" == "0" && -d "${stage_dir}/usr/include" ]]; then
236+
find "${stage_dir}/usr/include" -type f \
237+
\( -name '*.h' -o -name '*.hpp' -o -name '*.tpp' \) \
238+
-delete
239+
find "${stage_dir}/usr/include" -depth -type d -empty -delete
240+
fi
241+
242+
write_package_metadata "${stage_dir}" "${package_name}" "${package_description}"
243+
244+
if ! find "${stage_dir}" -mindepth 1 \
245+
! -path "${stage_dir}/DEBIAN" \
246+
! -path "${stage_dir}/DEBIAN/*" \
247+
! -path "${stage_dir}/etc" \
248+
! -path "${stage_dir}/etc/profile.d" \
249+
! -path "${stage_dir}/etc/profile.d/dls2.sh" \
250+
-print -quit | grep -q .; then
251+
echo "ERROR: staged package payload is empty for ${variant}."
252+
echo "Hint: cmake configure/build/install likely failed earlier, or the build cache points to a different source tree."
253+
return 1
254+
fi
247255

248-
dpkg-deb --build "${stage_dir}" "${DEB_NAME}"
256+
dpkg-deb --build "${stage_dir}" "${deb_name}"
249257

250-
dpkg-deb -c "${DEB_NAME}" \
251-
| awk '
252-
$1 !~ /^d/ {
253-
for (i = 1; i <= NF; i++) {
254-
if ($i ~ /^\.\//) {
255-
print $i
256-
break
258+
dpkg-deb -c "${deb_name}" \
259+
| awk '
260+
$1 !~ /^d/ {
261+
for (i = 1; i <= NF; i++) {
262+
if ($i ~ /^\.\//) {
263+
print $i
264+
break
265+
}
257266
}
258267
}
259-
}
260-
' \
261-
| sed -E 's#^\./#/#; s#/$##; s#//+#/#g' \
262-
| sort -u > "${ART_DIR}/pkg_files.txt"
268+
' \
269+
| sed -E 's#^\./#/#; s#/$##; s#//+#/#g' \
270+
| sort -u > "${pkg_list_path}"
271+
}
272+
273+
package_variant \
274+
"runtime" \
275+
"0" \
276+
"${RUNTIME_PACKAGE_NAME}" \
277+
"${RUNTIME_PACKAGE_DESCRIPTION}" \
278+
"${RUNTIME_DEB_NAME}" \
279+
"${ART_DIR}/pkg_files_runtime.txt"
280+
281+
package_variant \
282+
"framework" \
283+
"1" \
284+
"${FRAMEWORK_PACKAGE_NAME}" \
285+
"${FRAMEWORK_PACKAGE_DESCRIPTION}" \
286+
"${FRAMEWORK_DEB_NAME}" \
287+
"${ART_DIR}/pkg_files_framework.txt"
263288
}
264289

265290
echo "[build] building and packaging on host in ${ROOT_DIR}"
266-
echo "[build] include headers: ${INCLUDE_HEADERS}"
267291
echo "[build] reuse build: ${REUSE_BUILD}"
268292
if [[ "${LIVE_BUILD_OUTPUT}" == "1" ]]; then
269293
if run_pipeline > >(tee "${BUILD_LOG}") 2>&1; then
@@ -285,12 +309,16 @@ if [[ ${rc} -ne 0 ]]; then
285309
exit ${rc}
286310
fi
287311

288-
if [[ ! -f "${DEB_PATH}" ]]; then
289-
echo "ERROR: .deb not created at ${DEB_PATH}"
312+
if [[ ! -f "${RUNTIME_DEB_PATH}" || ! -f "${FRAMEWORK_DEB_PATH}" ]]; then
313+
echo "ERROR: expected .deb files were not created:"
314+
echo " - ${RUNTIME_DEB_PATH}"
315+
echo " - ${FRAMEWORK_DEB_PATH}"
290316
echo "See ${BUILD_LOG}"
291317
tail -n 120 "${BUILD_LOG}" || true
292318
exit 1
293319
fi
294320

295-
echo "[build] OK: ${DEB_PATH}"
296-
echo "${DEB_PATH}"
321+
echo "[build] OK: ${RUNTIME_DEB_PATH}"
322+
echo "[build] OK: ${FRAMEWORK_DEB_PATH}"
323+
echo "${RUNTIME_DEB_PATH}"
324+
echo "${FRAMEWORK_DEB_PATH}"

0 commit comments

Comments
 (0)