diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 06f0f86..61690f6 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -24,39 +24,104 @@ on: required: false jobs: + deps: + runs-on: macos-10.15 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Cache deps + if: inputs.cache + uses: actions/cache@v3 + with: + path: build/*-deps.sparsebundle + key: deps-${{ inputs.openfoam-version }}-${{ runner.arch }}-${{ hashFiles('Brewfile', 'Makefile') }} + - name: Reuse cached deps if possible + run: | + touch -c build/*-deps.sparsebundle + - name: Make deps + run: > + make deps + OPENFOAM_VERSION=${{ inputs.openfoam-version }} + - name: Upload deps artifact + uses: actions/upload-artifact@v3 + with: + name: deps-${{ inputs.openfoam-version }}-${{ runner.arch }} + path: build/*-deps.sparsebundle + if-no-files-found: error + build: + needs: deps runs-on: macos-10.15 steps: - name: Checkout uses: actions/checkout@v2 - - name: Cache DMG file + - name: Download deps artifact + uses: actions/download-artifact@v3 + with: + name: deps-${{ inputs.openfoam-version }}-${{ runner.arch }} + path: build + - name: Use deps artifact + run: | + touch -c build/*-deps.sparsebundle + - name: Cache build if: inputs.cache uses: actions/cache@v3 with: - path: | - build/*.dmg - key: dmg-${{ inputs.openfoam-version }}-${{ runner.arch }}-${{ hashFiles('Brewfile', 'configure.sh', 'icon.icns', 'Makefile', format('OpenFOAM-v${0}.tgz.sha256', inputs.openfoam-version)) }} - - name: Reuse cached DMG if possible + path: build/*-build.sparsebundle + key: build-${{ inputs.openfoam-version }}-${{ runner.arch }}-${{ hashFiles('build/*-deps.sparsebundle', 'configure.sh', 'Makefile', format('OpenFOAM-v${0}.tgz.sha256', inputs.openfoam-version)) }} + - name: Reuse cached build if possible run: | - touch -c build/*.dmg + touch -c build/*-build.sparsebundle - name: Build run: > - make zip + make build OPENFOAM_VERSION=${{ inputs.openfoam-version }} + ${{ inputs.source-tarball-url != '' && format('SOURCE_TARBALL_URL={0}', inputs.source-tarball-url) || '' }} + - name: Upload build artifact + uses: actions/upload-artifact@v3 + with: + name: build-${{ inputs.openfoam-version }}-${{ runner.arch }} + path: build/*-build.sparsebundle + if-no-files-found: error + + app: + needs: build + strategy: + matrix: + dependencies-kind: [standalone, homebrew] + fail-fast: false + runs-on: macos-10.15 + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Download build artifact + uses: actions/download-artifact@v3 + with: + name: build-${{ inputs.openfoam-version }}-${{ runner.arch }} + path: build + - name: Use build artifact + run: | + touch -c build/*-build.sparsebundle + - name: Build zipped app + run: > + make zip APP_VERSION=${{ inputs.app-version }} + DEPENDENCIES_KIND=${{ matrix.dependencies-kind }} + OPENFOAM_VERSION=${{ inputs.openfoam-version }} ${{ inputs.source-tarball-url != '' && format('SOURCE_TARBALL_URL={0}', inputs.source-tarball-url) || '' }} - - name: Upload ZIP artifact + - name: Upload zip artifact uses: actions/upload-artifact@v3 with: - name: zip-${{ inputs.openfoam-version }} + name: zip-${{ inputs.openfoam-version }}-${{ matrix.dependencies-kind }}-${{ runner.arch }} path: build/*-app-*.zip if-no-files-found: error test: - needs: build + needs: app strategy: matrix: os: [macos-10.15, macos-11, macos-12] + dependencies-kind: [standalone, homebrew] fail-fast: false runs-on: ${{ matrix.os }} steps: @@ -65,31 +130,41 @@ jobs: - name: Download ZIP artifact uses: actions/download-artifact@v3 with: - name: zip-${{ inputs.openfoam-version }} + name: zip-${{ inputs.openfoam-version }}-${{ matrix.dependencies-kind }}-${{ runner.arch }} path: build - name: Unzip app run: | - unzip *-app-homebrew-$(uname -m).zip + unzip *-app-*.zip working-directory: build - - name: Test + - name: Install Homebrew dependencies + if: matrix.dependencies-kind == 'homebrew' run: | - make install-dependencies OPENFOAM_VERSION=${{ inputs.openfoam-version }} - make test OPENFOAM_VERSION=${{ inputs.openfoam-version }} + brew bundle --verbose + - name: Test + run: > + make test + APP_VERSION=${{ inputs.app-version }} + OPENFOAM_VERSION=${{ inputs.openfoam-version }} + DEPENDENCIES_KIND=${{ matrix.dependencies-kind }} release: - if: ${{ inputs.release }} needs: test + if: inputs.release runs-on: ubuntu-latest + strategy: + matrix: + dependencies-kind: [standalone, homebrew] + fail-fast: false steps: - - name: Download ZIP artifact + - name: Download zip artifact uses: actions/download-artifact@v3 with: - name: zip-${{ inputs.openfoam-version }} - - name: Upload ZIP to release + name: zip-${{ inputs.openfoam-version }}-${{ matrix.dependencies-kind }}-${{ runner.arch }} + - name: Upload zip to release uses: svenstaro/upload-release-action@v2 with: repo_token: ${{ secrets.GITHUB_TOKEN }} - file: '*.zip' + file: '*-app-*.zip' tag: ${{ github.ref }} file_glob: true overwrite: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ead3797..5190837 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: openfoam2206: needs: get-version - name: OpenFOAM-v2206.app + name: OpenFOAM v2206 uses: ./.github/workflows/build-test.yml with: openfoam-version: 2206 @@ -27,7 +27,7 @@ jobs: openfoam2112: needs: get-version - name: OpenFOAM-v2112.app + name: OpenFOAM v2112 uses: ./.github/workflows/build-test.yml with: openfoam-version: 2112 diff --git a/Contents/Info.plist b/Contents/Info.plist index 59763b4..6768396 100644 --- a/Contents/Info.plist +++ b/Contents/Info.plist @@ -7,8 +7,8 @@ CFBundleIconFile icon.icns CFBundleVersion - {{APP_VERSION}}-homebrew-{{ARCH}} + {{APP_VERSION}}-{{DEPENDENCIES_KIND}}-{{ARCH}} CFBundleShortVersionString {{APP_VERSION}} - \ No newline at end of file + diff --git a/Contents/MacOS/bashrc b/Contents/MacOS/bashrc index 53f791c..81fd393 100644 --- a/Contents/MacOS/bashrc +++ b/Contents/MacOS/bashrc @@ -4,7 +4,9 @@ SCRIPT_DIR="$(\cd $(dirname ${BASH_SOURCE:-${ZSH_NAME:+$0}}) && \pwd -L)" VOLUME=`"$SCRIPT_DIR/volume" -show-prefix` -# Keep the volume directory open in this process (prevents accidental ejection) -exec {fd}<"$VOLUME" +if [ ${BASH_VERSINFO:-4} -ge 4 ]; then + # Keep the volume directory open in this process (prevents accidental ejection) + exec {fd}<"$VOLUME" +fi . "$VOLUME/etc/bashrc" diff --git a/Contents/MacOS/openfoam b/Contents/MacOS/openfoam index 703563a..41d1fa6 100755 --- a/Contents/MacOS/openfoam +++ b/Contents/MacOS/openfoam @@ -19,4 +19,4 @@ VOLUME=$("$APP_BUNDLE/Contents/MacOS/volume" -show-prefix) exec {fd}<"$VOLUME" echo "Activating the OpenFOAM environment..." -exec bash "$VOLUME/etc/openfoam" "$@" +PATH="$VOLUME/usr/bin:$PATH" exec bash "$VOLUME/etc/openfoam" "$@" diff --git a/Contents/MacOS/volume b/Contents/MacOS/volume index d90ba1b..26bcc82 100755 --- a/Contents/MacOS/volume +++ b/Contents/MacOS/volume @@ -88,7 +88,7 @@ case "$1" in $QUIET || echo "The $APP_NAME volume is already mounted." else $QUIET || echo "Mounting the $APP_NAME volume..." - if ! hdiutil attach -quiet "$DMG_FILE"; then + if ! hdiutil attach -quiet -noverify "$DMG_FILE"; then echo "ERROR: Failed to mount the $APP_NAME volume" 1>&2 exit 1 fi diff --git a/Makefile b/Makefile index 5284c4b..ae264fa 100644 --- a/Makefile +++ b/Makefile @@ -8,17 +8,17 @@ SOURCE_TARBALL_URL = https://dl.openfoam.com/source/v$(OPENFOAM_VERSION)/OpenFOA SOURCE_TARBALL = $(shell basename $(SOURCE_TARBALL_URL)) VOLUME_FILESYSTEM = 'Case-sensitive APFS' WMAKE_NJOBS = '' +DEPENDENCIES_KIND = standalone DMG_FORMAT = UDRO -DIST_NAME = openfoam$(OPENFOAM_VERSION)-app-homebrew-$(shell uname -m) +DIST_NAME = openfoam$(OPENFOAM_VERSION)-app-$(DEPENDENCIES_KIND)-$(shell uname -m) INSTALL_DIR = /Applications # Build targets app: build/$(APP_NAME).app -dmg: build/$(APP_NAME).dmg build: build/$(APP_NAME)-build.sparsebundle +deps: build/$(APP_NAME)-deps.sparsebundle fetch-source: $(SOURCE_TARBALL) -install-dependencies: Brewfile.lock.json zip: build/$(DIST_NAME).zip install: $(INSTALL_DIR)/$(APP_NAME).app @@ -51,6 +51,7 @@ build/$(APP_NAME).app/Contents/Info.plist: Contents/Info.plist | build/$(APP_NAM mkdir -p build/$(APP_NAME).app/Contents cp Contents/Info.plist build/$(APP_NAME).app/Contents/ sed -i '' "s|{{APP_VERSION}}|$(APP_VERSION)|g" build/$(APP_NAME).app/Contents/Info.plist + sed -i '' "s|{{DEPENDENCIES_KIND}}|$(DEPENDENCIES_KIND)|g" build/$(APP_NAME).app/Contents/Info.plist sed -i '' "s|{{ARCH}}|$(shell uname -m)|g" build/$(APP_NAME).app/Contents/Info.plist build/$(APP_NAME).app/Contents/MacOS/openfoam: Contents/MacOS/openfoam | build/$(APP_NAME).app/Contents/MacOS/volume @@ -83,54 +84,48 @@ build/$(APP_NAME).app/Contents/Resources/icon.icns: icon.icns mkdir -p build/$(APP_NAME).app/Contents/Resources cp icon.icns build/$(APP_NAME).app/Contents/Resources/ -build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg: build/$(APP_NAME).dmg +build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg: build/$(APP_NAME).sparsebundle mkdir -p build/$(APP_NAME).app/Contents/Resources - cp build/$(APP_NAME).dmg build/$(APP_NAME).app/Contents/Resources/ + hdiutil convert \ + build/$(APP_NAME).sparsebundle \ + -format UDRW \ + -o build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg -ov + hdiutil resize \ + -sectors min \ + build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg + hdiutil convert \ + build/$(APP_NAME).sparsebundle \ + -format $(DMG_FORMAT) \ + -o build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg -ov -build/$(APP_NAME).dmg: build/$(APP_NAME)-build.sparsebundle +build/$(APP_NAME).sparsebundle: build/$(APP_NAME)-build.sparsebundle icon.icns [ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME) - cp -r build/$(APP_NAME)-build.sparsebundle build/$(APP_NAME)-temp.sparsebundle - hdiutil attach build/$(APP_NAME)-temp.sparsebundle + cp -r build/$(APP_NAME)-build.sparsebundle build/$(APP_NAME).sparsebundle + hdiutil attach build/$(APP_NAME).sparsebundle + cp icon.icns $(VOLUME)/.VolumeIcon.icns + SetFile -c icnC $(VOLUME)/.VolumeIcon.icns + SetFile -a C $(VOLUME) uuidgen > $(VOLUME_ID_FILE) cat $(VOLUME_ID_FILE) + [ $(DEPENDENCIES_KIND) != standalone ] || rm -rf $(VOLUME)/usr/bin/brew + [ $(DEPENDENCIES_KIND) != standalone ] || rm -rf $(VOLUME)/usr/Library + [ $(DEPENDENCIES_KIND) != standalone ] || rm -rf $(VOLUME)/usr/.git + [ $(DEPENDENCIES_KIND) != homebrew ] || rm -rf $(VOLUME)/usr + [ $(DEPENDENCIES_KIND) != homebrew ] || ln -s $(shell brew --prefix) $(VOLUME)/usr rm -rf $(VOLUME)/build rm -f $(VOLUME)/**/.DS_Store rm -rf $(VOLUME)/.fseventsd || true hdiutil detach $(VOLUME) hdiutil resize \ -sectors min \ - build/$(APP_NAME)-temp.sparsebundle - hdiutil compact build/$(APP_NAME)-temp.sparsebundle - hdiutil convert \ - build/$(APP_NAME)-temp.sparsebundle \ - -format UDRW \ - -o build/$(APP_NAME).dmg -ov - rm -rf build/$(APP_NAME)-temp.sparsebundle - hdiutil resize \ - -sectors min \ - build/$(APP_NAME).dmg - hdiutil convert \ - build/$(APP_NAME).dmg \ - -format $(DMG_FORMAT) \ - -o build/$(APP_NAME).dmg -ov + build/$(APP_NAME).sparsebundle + hdiutil compact build/$(APP_NAME).sparsebundle -build/$(APP_NAME)-build.sparsebundle: $(SOURCE_TARBALL) Brewfile.lock.json configure.sh Brewfile icon.icns - brew bundle check --verbose --no-upgrade - cat Brewfile.lock.json +build/$(APP_NAME)-build.sparsebundle: build/$(APP_NAME)-deps.sparsebundle $(SOURCE_TARBALL) configure.sh [ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME) - mkdir -p build - hdiutil create \ - -size 50g \ - -fs $(VOLUME_FILESYSTEM) \ - -volname $(APP_NAME) \ - build/$(APP_NAME)-build.sparsebundle \ - -ov -attach + cp -r build/$(APP_NAME)-deps.sparsebundle build/$(APP_NAME)-build.sparsebundle + hdiutil attach build/$(APP_NAME)-build.sparsebundle tar -xzf $(SOURCE_TARBALL) --strip-components 1 -C $(VOLUME) - cp icon.icns $(VOLUME)/.VolumeIcon.icns - SetFile -c icnC $(VOLUME)/.VolumeIcon.icns - SetFile -a C $(VOLUME) - cp Brewfile $(VOLUME)/ - cp Brewfile.lock.json $(VOLUME)/ cd $(VOLUME) \ && $(SHELL) -ex "$(CURDIR)/configure.sh" \ && source etc/bashrc \ @@ -139,14 +134,27 @@ build/$(APP_NAME)-build.sparsebundle: $(SOURCE_TARBALL) Brewfile.lock.json confi && ./Allwmake -j $(WMAKE_NJOBS) -s hdiutil detach $(VOLUME) +build/$(APP_NAME)-deps.sparsebundle: Brewfile + [ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME) + mkdir -p build + hdiutil create \ + -size 50g \ + -fs $(VOLUME_FILESYSTEM) \ + -volname $(APP_NAME) \ + build/$(APP_NAME)-deps.sparsebundle \ + -ov -attach + cp Brewfile $(VOLUME)/ + git clone https://github.com/Homebrew/brew $(VOLUME)/usr + $(VOLUME)/usr/bin/brew bundle --file $(VOLUME)/Brewfile --verbose + $(VOLUME)/usr/bin/brew autoremove + cat $(VOLUME)/Brewfile.lock.json + hdiutil detach $(VOLUME) + $(SOURCE_TARBALL): $(or $(wildcard $(SOURCE_TARBALL).sha256), \ $(warning No checksum file found for $(SOURCE_TARBALL); will skip verification)) curl -L -o $(SOURCE_TARBALL) $(SOURCE_TARBALL_URL) [ -z $< ] || shasum -a 256 -c $< -Brewfile.lock.json: Brewfile - brew bundle -f - # Non-build targets and rules test: test-openfoam test-bash test-zsh @@ -164,7 +172,7 @@ test-bash: [ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME) rm -rf build/test/test-bash mkdir -p build/test/test-bash - bash -c \ + PATH=$(VOLUME)/usr/bin:$$PATH bash -c \ 'source build/$(APP_NAME).app/Contents/MacOS/bashrc; \ set -ex; \ foamInstallationTest; \ @@ -184,12 +192,12 @@ test-zsh: source "$(CURDIR)/test.sh"' build/$(APP_NAME).app/Contents/MacOS/volume eject && [ ! -d $(VOLUME) ] -test-dmg: +test-image: [ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME) - hdiutil attach build/$(APP_NAME).dmg - rm -rf build/test/test-dmg - mkdir -p build/test/test-dmg - cd build/test/test-dmg \ + hdiutil attach build/$(APP_NAME).sparsebundle + rm -rf build/test/test-image + mkdir -p build/test/test-image + cd build/test/test-image \ && source $(VOLUME)/etc/bashrc \ && foamInstallationTest \ && $(SHELL) -ex "$(CURDIR)/test.sh" @@ -197,20 +205,20 @@ test-dmg: clean-build: [ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME) - rm -f build/$(APP_NAME).dmg build/$(DIST_NAME).zip - rm -rf build/$(APP_NAME).app build/$(APP_NAME)-build.sparsebundle build/test/test-openfoam build/test/test-bash build/test/test-zsh build/test/test-dmg + rm -f build/$(DIST_NAME).zip + rm -rf build/$(APP_NAME).app build/$(APP_NAME).sparsebundle build/$(APP_NAME)-build.sparsebundle build/$(APP_NAME)-deps.sparsebundle build/test/test-openfoam build/test/test-bash build/test/test-zsh build/test/test-dmg rmdir build/test || true rmdir build || true clean: clean-build - rm -f $(SOURCE_TARBALL) Brewfile.lock.json + rm -f $(SOURCE_TARBALL) uninstall: rm -rf $(INSTALL_DIR)/$(APP_NAME).app # Set special targets -.PHONY: app dmg build fetch-source install-dependencies zip install test test-openfoam test-bash test-zsh test-dmg clean-build clean uninstall +.PHONY: app build deps fetch-source zip install test test-openfoam test-bash test-zsh test-image clean-build clean uninstall .PRECIOUS: build/$(APP_NAME)-build.sparsebundle -.SECONDARY: $(SOURCE_TARBALL) Brewfile.lock.json build/$(APP_NAME)-build.sparsebundle build/$(APP_NAME).dmg +.SECONDARY: $(SOURCE_TARBALL) build/$(APP_NAME)-deps.sparsebundle build/$(APP_NAME)-build.sparsebundle build/$(APP_NAME).sparsebundle .DELETE_ON_ERROR: diff --git a/configure.sh b/configure.sh index fede296..c8b625d 100755 --- a/configure.sh +++ b/configure.sh @@ -1,29 +1,23 @@ #!/bin/bash -e -SYSTEM_COMPILER="Clang" +bin/tools/foamConfigurePaths \ + -system-compiler 'Clang' \ + -adios-path $PWD/usr/opt/adios2 \ + -boost-path $PWD/usr/opt/boost \ + -cgal-path $PWD/usr/opt/cgal\\\@4 \ + -fftw-path $PWD/usr/opt/fftw \ + -kahip-path $PWD/usr/opt/kahip \ + -metis-path $PWD/usr/opt/metis \ + -scotch-path $PWD/usr/opt/scotch-no-pthread -ADIOS_PATH='`brew --prefix adios2`' -BOOST_PATH='`brew --prefix boost`' -CGAL_PATH='`brew --prefix cgal\@4`' -FFTW_PATH='`brew --prefix fftw`' -KAHIP_PATH='`brew --prefix kahip`' -METIS_PATH='`brew --prefix metis`' -SCOTCH_PATH='`brew --prefix scotch-no-pthread`' -LIBOMP_PATH='`brew --prefix libomp`' -GMP_PATH='`brew --prefix gmp`' -MPFR_PATH='`brew --prefix mpfr`' +echo "export PATH=\"$PWD/usr/bin:\${PATH+:\$PATH}\"" >> etc/prefs.sh +echo "setenv PATH $PWD/usr/bin:\$PATH;" >> etc/prefs.csh -bin/tools/foamConfigurePaths \ - -system-compiler "$SYSTEM_COMPILER" \ - -adios-path "$ADIOS_PATH" \ - -boost-path "$BOOST_PATH" \ - -cgal-path "$CGAL_PATH" \ - -fftw-path "$FFTW_PATH" \ - -kahip-path "$KAHIP_PATH" \ - -metis-path "$METIS_PATH" \ - -scotch-path "$SCOTCH_PATH" +LIBOMP_PATH="$PWD/usr/opt/libomp" +GMP_PATH="$PWD/usr/opt/gmp" +MPFR_PATH="$PWD/usr/opt/mpfr" CPATH="$LIBOMP_PATH/include:$GMP_PATH/include:$MPFR_PATH/include" LIBRARY_PATH="$LIBOMP_PATH/lib:$GMP_PATH/lib:$MPFR_PATH/lib" @@ -33,5 +27,6 @@ echo "setenv CPATH \"$CPATH\"" >> etc/prefs.csh echo "export LIBRARY_PATH=\"$LIBRARY_PATH\"" >> etc/prefs.sh echo "setenv LIBRARY_PATH \"$LIBRARY_PATH\"" >> etc/prefs.csh + echo 'export FOAM_DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH"' >> etc/bashrc echo 'setenv FOAM_DYLD_LIBRARY_PATH "$DYLD_LIBRARY_PATH"' >> etc/cshrc