From d92777a3ff14085c8f4d866c86983b235cbe650c Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Wed, 24 Apr 2024 11:27:10 +1200 Subject: [PATCH] Packaging: Cleanup Windows Build Scripts. Do some housekeeping and cleanup on the build scripts for Windows: - remove Windows 32bit builds as support for this has been removed from the mxe container; - fix some warnings in the smtk2ssrf installer configuration; - sanitise the output colour of the smtk2ssrf build script; - add a docker based build script for the Windows installers; - remove outdated and deprecated documentation and scripts. Signed-off-by: Michael Keller --- .github/workflows/windows.yml | 5 +- .gitignore | 1 + packaging/windows/README.md | 9 ++- .../windows/container-prep.sh | 0 packaging/windows/create-win-installer.sh | 45 -------------- packaging/windows/docker-build.sh | 58 +++++++++++++++++++ .../windows/in-container-build.sh | 8 +-- packaging/windows/smtk-import.nsi.in | 16 ++--- packaging/windows/smtk2ssrf-mxe-build.sh | 2 +- .../mxe-build-container/instructions.md | 36 ------------ 10 files changed, 81 insertions(+), 99 deletions(-) rename .github/workflows/scripts/windows-container-prep.sh => packaging/windows/container-prep.sh (100%) delete mode 100644 packaging/windows/create-win-installer.sh create mode 100755 packaging/windows/docker-build.sh rename .github/workflows/scripts/windows-in-container-build.sh => packaging/windows/in-container-build.sh (78%) delete mode 100644 scripts/docker/mxe-build-container/instructions.md diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 465730058..0e2716535 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -44,12 +44,13 @@ jobs: git config --global --add safe.directory ${SUBSURFACE_REPO_PATH}/libdivecomputer cd /win ln -s /__w/subsurface/subsurface . - bash -x subsurface/.github/workflows/scripts/windows-container-prep.sh 2>&1 | tee pre-build.log + bash -x subsurface/packaging/windows/container-prep.sh 2>&1 | tee pre-build.log - name: run build run: | + export OUTPUT_DIR="$GITHUB_WORKSPACE" cd /win - bash -x subsurface/.github/workflows/scripts/windows-in-container-build.sh 2>&1 | tee build.log + bash -x subsurface/packaging/windows/in-container-build.sh 2>&1 | tee build.log grep "Built target installer" build.log # only publish a 'release' on push events (those include merging a PR) diff --git a/.gitignore b/.gitignore index 3074508a9..8603cc7b7 100644 --- a/.gitignore +++ b/.gitignore @@ -49,3 +49,4 @@ appdata/subsurface.appdata.xml android-mobile/Roboto-Regular.ttf gh_release_notes.md release_content_title.txt +/output/ diff --git a/packaging/windows/README.md b/packaging/windows/README.md index fccb518d0..ccc4e6e6a 100644 --- a/packaging/windows/README.md +++ b/packaging/windows/README.md @@ -7,12 +7,15 @@ image that has all the build components pre-assembled. All it takes is this: ``` -cd /some/path/windows +export GIT_AUTHOR_NAME= +export GIT_AUTHOR_EMAIL= + +cd /some/path git clone https://github.com/subsurface/subsurface cd subsurface git submodule init git submodule update -docker run -v /some/path/windows:/__w subsurface/mxe-build:3.1.0 /bin/bash /__w/subsurface/packaging/windows/create-win-installer.sh +./packaging/windows/docker-build.sh ``` -This will result in subsurface-VERSION.exe and smtk2ssrf-VERSION.exe to be created. +This will result in subsurface-VERSION.exe and smtk2ssrf-VERSION.exe to be created in /some/path/subsurface/output/windows/. diff --git a/.github/workflows/scripts/windows-container-prep.sh b/packaging/windows/container-prep.sh similarity index 100% rename from .github/workflows/scripts/windows-container-prep.sh rename to packaging/windows/container-prep.sh diff --git a/packaging/windows/create-win-installer.sh b/packaging/windows/create-win-installer.sh deleted file mode 100644 index f75d16836..000000000 --- a/packaging/windows/create-win-installer.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# this is run inside the docker container -cd /__w - -[ -d mxe ] || ln -s /win/mxe . - -# grab the version number -cd subsurface -VERSION=$(./scripts/get-version) -cd .. - -# prep the container -bash subsurface/.github/workflows/scripts/windows-container-prep.sh - -# remove artifact from prior builds -rm -f mdbtools/include/mdbver.h - -# build the 64bit installer -rm -rf win64 -mkdir win64 -cd win64 - -# build Subsurface and then smtk2ssrf -export MXEBUILDTYPE=x86_64-w64-mingw32.shared -export PATH=/win/mxe/usr/bin:$PATH -bash -ex ../subsurface/packaging/windows/mxe-based-build.sh installer -mv subsurface/subsurface-$VERSION.exe /__w - -bash -ex ../subsurface/packaging/windows/smtk2ssrf-mxe-build.sh -a -i - -mv smtk-import/smtk2ssrf-$VERSION.exe /__w - -if [ "$1" != "-64only" ] ; then - # build the 32bit installer - cd /__w - rm -rf win32 - mkdir win32 - cd win32 - - # build Subsurface and then smtk2ssrf - export MXEBUILDTYPE=i686-w64-mingw32.shared - bash -ex ../subsurface/packaging/windows/mxe-based-build.sh installer - mv subsurface/subsurface-$VERSION.exe /__w/subsurface-32bit-$VERSION.exe -fi diff --git a/packaging/windows/docker-build.sh b/packaging/windows/docker-build.sh new file mode 100755 index 000000000..e86c7cd39 --- /dev/null +++ b/packaging/windows/docker-build.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# +# Build the Subsurface Windows installer and the Smtk2ssrf Windows installer in a Docker container +# + +# Needs the following environment variables to be set +# GIT_AUTHOR_NAME= +# GIT_AUTHOR_EMAIL= + +CONTAINER_NAME=windows-builder-docker + +pushd . +cd "$(dirname "$0")/../.." +SUBSURFACE_ROOT="${PWD}" +popd + +OUTPUT_DIR=output/windows +CONTAINER_ROOT_DIR=/win +CONTAINER_SUBSURFACE_DIR=${CONTAINER_ROOT_DIR}/subsurface + +LOGIN_USER=$(id -u) +LOGIN_GROUP=$(id -g) +FULL_USER=${LOGIN_USER}:${LOGIN_GROUP} + +# Check if our container exists +CONTAINER_ID=$(docker container ls -a -q -f name=${CONTAINER_NAME}) + +# Create the container if it does not exist +if [[ -z "${CONTAINER_ID}" ]]; then + docker create -v ${SUBSURFACE_ROOT}:${CONTAINER_SUBSURFACE_DIR} --name=${CONTAINER_NAME} subsurface/mxe-build:3.1.0 sleep infinity +fi + +docker start ${CONTAINER_NAME} + +BUILD_PARAMETERS="" +if [[ -z "${CONTAINER_ID}" ]]; then + # Prepare the image for first use + docker exec -t ${CONTAINER_NAME} groupadd $(id -g -n) -o -g ${LOGIN_GROUP} + docker exec -t ${CONTAINER_NAME} useradd $(id -u -n) -o -u ${LOGIN_USER} -g ${LOGIN_GROUP} -d ${CONTAINER_ROOT_DIR} + docker exec -t ${CONTAINER_NAME} find ${CONTAINER_ROOT_DIR} -type d -exec chown ${FULL_USER} {} \; + + docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global --add safe.directory ${CONTAINER_SUBSURFACE_DIR} + docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global --add safe.directory ${CONTAINER_SUBSURFACE_DIR}/libdivecomputer + docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global --add safe.directory ${CONTAINER_SUBSURFACE_DIR}/nightly-builds + + docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global user.name "${GIT_AUTHOR_NAME}" + docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} git config --global user.email "${GIT_AUTHOR_EMAIL}" + + docker exec -u ${FULL_USER} -t ${CONTAINER_NAME} bash -x subsurface/packaging/windows/container-prep.sh +fi + +# Build +mkdir -p "${SUBSURFACE_ROOT}/${OUTPUT_DIR}" +docker exec -u ${FULL_USER} -e OUTPUT_DIR=${CONTAINER_SUBSURFACE_DIR}/${OUTPUT_DIR} -t ${CONTAINER_NAME} bash -x subsurface/packaging/windows/in-container-build.sh + +# Stop the container +docker stop ${CONTAINER_NAME} diff --git a/.github/workflows/scripts/windows-in-container-build.sh b/packaging/windows/in-container-build.sh similarity index 78% rename from .github/workflows/scripts/windows-in-container-build.sh rename to packaging/windows/in-container-build.sh index 5cec6a2ee..f11c2a582 100644 --- a/.github/workflows/scripts/windows-in-container-build.sh +++ b/packaging/windows/in-container-build.sh @@ -19,14 +19,14 @@ bash -ex ../subsurface/packaging/windows/mxe-based-build.sh installer # the strange two step move is in order to get predictable names to use # in the publish step of the GitHub Action -mv subsurface/subsurface.exe* ${GITHUB_WORKSPACE}/ +mv subsurface/subsurface.exe* ${OUTPUT_DIR}/ fullname=$(cd subsurface ; ls subsurface-*.exe) -mv subsurface/"$fullname" ${GITHUB_WORKSPACE}/"${fullname%.exe}-installer.exe" +mv subsurface/"$fullname" ${OUTPUT_DIR}/"${fullname%.exe}-installer.exe" bash -ex ../subsurface/packaging/windows/smtk2ssrf-mxe-build.sh -a -i # the strange two step move is in order to get predictable names to use # in the publish step of the GitHub Action -mv smtk-import/smtk2ssrf.exe ${GITHUB_WORKSPACE}/ +mv smtk-import/smtk2ssrf.exe ${OUTPUT_DIR}/ fullname=$(cd smtk-import ; ls smtk2ssrf*.exe) -mv smtk-import/smtk2ssrf*.exe ${GITHUB_WORKSPACE}/"${fullname%.exe}-installer.exe" +mv smtk-import/smtk2ssrf*.exe ${OUTPUT_DIR}/"${fullname%.exe}-installer.exe" diff --git a/packaging/windows/smtk-import.nsi.in b/packaging/windows/smtk-import.nsi.in index eaa835670..52f3d89f9 100644 --- a/packaging/windows/smtk-import.nsi.in +++ b/packaging/windows/smtk-import.nsi.in @@ -215,16 +215,16 @@ Section "Uninstall" Delete "$DESKTOP\Smtk2ssrf.lnk" # remove the registry entires - ${If} $Checkbox_Reg_State == 1 - DeleteRegKey HKCU "Software\Smtk2ssrf" - ${EndIf} +# ${If} $Checkbox_Reg_State == 1 +# DeleteRegKey HKCU "Software\Smtk2ssrf" +# ${EndIf} # remove the user directory - ${If} $Checkbox_UserDir_State == 1 - ${AndIf} $UserDir != "" - ${AndIf} ${FileExists} "$UserDir\*.*" - RMDir /r $UserDir - ${EndIf} +# ${If} $Checkbox_UserDir_State == 1 +# ${AndIf} $UserDir != "" +# ${AndIf} ${FileExists} "$UserDir\*.*" +# RMDir /r $UserDir +# ${EndIf} # remove the uninstaller entry DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Smtk2ssrf" diff --git a/packaging/windows/smtk2ssrf-mxe-build.sh b/packaging/windows/smtk2ssrf-mxe-build.sh index f8048dffb..2edf6b45e 100755 --- a/packaging/windows/smtk2ssrf-mxe-build.sh +++ b/packaging/windows/smtk2ssrf-mxe-build.sh @@ -216,4 +216,4 @@ if [ ! -z "$DATADIR" ]; then cp -vf "$BUILDDIR"/smtk-import/smtk2ssrf-*.exe "$DATADIR" fi -echo -e "$RED---> Building smtk2ssrf done$DEFAULT" +echo -e "$BLUE---> Building smtk2ssrf done$DEFAULT" diff --git a/scripts/docker/mxe-build-container/instructions.md b/scripts/docker/mxe-build-container/instructions.md deleted file mode 100644 index 9a456bc91..000000000 --- a/scripts/docker/mxe-build-container/instructions.md +++ /dev/null @@ -1,36 +0,0 @@ -# Instructions for building the container environment and using it to build/package subsurface. - -This document assumes you have alreay installed docker and have checked out subsurface according to the instructions in the INSTALL document. - -If you just want to build with the current mxe build container then starting from the folder above subsurface run - -```bash -docker run -v $PWD/win32:/win/win32 -v $PWD/subsurface:/win/subsurface --name=mybuilder -w /win -d subsurface/mxe-build:x.y /bin/sleep 60m -``` - -replacing the x.y in the mxe-build tag with the current version e.g. 3.1.0 - -Next you need to prep the container by installing some prerequisites - -```bash -docker exec -t mybuilder bash subsurface/.github/workflows/scripts/windows-container-prep.sh 2>&1 | tee pre-build.log -``` - -Finaly the actual build is done with -```bash -docker exec -t mybuilder bash subsurface/.github/workflows/scripts/windows-in-container-build.sh 2>&1 | tee build.log -``` - -To get the built binary out of the container -``` -docker exec -t mybuilder bash -c "cp /subsurface-*-installer.exe /win/win32" -``` -Which will copy the installer into the win32 folder which will be a sibling of the subsurface folder. - -## Modifying the container -If you want to make changes to the build environment used in the conatiner -The script scripts/docker/mxe-build-container/build-container.sh will build the Docker image itself. -The sha of the version of MXE we are using is built into this, so you can update that to whatever version is required, and modify dockerfiles and settings-stage1.mk and settings-stage2.mk to pull in any other prerequisites as required. - -If you are working on updating the container then you should incrment the minor version of the variable VERSION in the script as otherwise it will clash with the version used in production -