From 583b3aa5f8b167b2dcee72956287de5cd18e3eec Mon Sep 17 00:00:00 2001 From: Gabriel Gerlero Date: Fri, 7 Jul 2023 16:14:57 -0300 Subject: [PATCH] Improve Makefile --- .github/workflows/build-test.yml | 47 ++++++-------- Makefile | 103 ++++++++++++++++++------------- configure.sh | 7 +++ 3 files changed, 84 insertions(+), 73 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 13831e8..c6c4623 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -68,40 +68,29 @@ jobs: - name: Generate cache restore keys id: caching run: | - DEPS_RESTORE_KEY="deps-${{ env.OPENFOAM }}-${{ env.BUILD_OS }}-${{ hashFiles('make_deps.txt', 'Brewfile') }}-" - BUILD_RESTORE_KEY="build-${{ env.OPENFOAM }}-${{ env.BUILD_OS }}-${{ hashFiles('make_build.txt', 'Brewfile', format('OpenFOAM-v${0}.tgz.sha256', inputs.openfoam-version), 'configure.sh') }}-" + DEPS_RESTORE_KEY="build-${{ env.OPENFOAM }}-${{ env.BUILD_OS }}-${{ hashFiles('make_deps.txt', 'Brewfile') }}" + BUILD_RESTORE_KEY="$DEPS_RESTORE_KEY-${{ hashFiles('make_build.txt', 'configure.sh') }}" echo "DEPS_RESTORE_KEY=$DEPS_RESTORE_KEY" >> "$GITHUB_OUTPUT" echo "BUILD_RESTORE_KEY=$BUILD_RESTORE_KEY" >> "$GITHUB_OUTPUT" - - name: Look up cached build - if: inputs.use-cached - id: cache_build - uses: actions/cache/restore@v3 - with: - path: build/*-build.sparsebundle - key: ignore - restore-keys: - ${{ steps.caching.outputs.BUILD_RESTORE_KEY }} - lookup-only: true - name: Look up cached deps - if: inputs.use-cached && steps.cache_build.outputs.cache-matched-key == '' id: cache_deps uses: actions/cache/restore@v3 with: - path: build/*-deps.sparsebundle + path: build/*.sparsebundle key: ignore - restore-keys: + restore-keys: | ${{ steps.caching.outputs.DEPS_RESTORE_KEY }} lookup-only: true - name: Make deps - if: steps.cache_build.outputs.cache-matched-key == '' && steps.cache_deps.outputs.cache-matched-key == '' + if: ${{ !inputs.use-cached || steps.cache_deps.outputs.cache-matched-key == '' }} run: | make deps ${{ env.MAKE_VARS }} - name: Save deps to cache - if: steps.cache_build.outputs.cache-matched-key == '' && steps.cache_deps.outputs.cache-matched-key == '' + if: ${{ !inputs.use-cached || steps.cache_deps.outputs.cache-matched-key == '' }} uses: actions/cache/save@v3 with: - path: build/*-deps.sparsebundle - key: ${{ steps.caching.outputs.DEPS_RESTORE_KEY }}${{ github.run_id }} + path: build/*.sparsebundle + key: ${{ steps.caching.outputs.DEPS_RESTORE_KEY }}-${{ github.run_id }} build: needs: deps @@ -114,36 +103,36 @@ jobs: id: cache_build uses: actions/cache/restore@v3 with: - path: build/*-build.sparsebundle + path: build/*.sparsebundle key: ignore - restore-keys: + restore-keys: | ${{ needs.deps.outputs.build-restore-key }} - name: Restore cached deps if: steps.cache_build.outputs.cache-matched-key == '' id: cache_deps uses: actions/cache/restore@v3 with: - path: build/*-deps.sparsebundle + path: build/*.sparsebundle key: ignore - restore-keys: + restore-keys: | ${{ needs.deps.outputs.deps-restore-key }} fail-on-cache-miss: true - - name: Reuse cached build or deps - run: | - touch -c build/*-deps.sparsebundle - touch -c build/*-build.sparsebundle - name: Build if: steps.cache_build.outputs.cache-matched-key == '' run: | + touch * + make touch-deps ${{ env.MAKE_VARS }} make build ${{ env.MAKE_VARS }} - name: Save build to cache if: steps.cache_build.outputs.cache-matched-key == '' && inputs.cache-build uses: actions/cache/save@v3 with: - path: build/*-build.sparsebundle - key: ${{ needs.deps.outputs.build-restore-key }}${{ github.run_id }} + path: build/*.sparsebundle + key: ${{ needs.deps.outputs.build-restore-key }}-${{ github.run_id }} - name: Make app run: | + touch * + make touch-build ${{ env.MAKE_VARS }} make zip ${{ env.MAKE_VARS }} - name: Upload app artifact uses: actions/upload-artifact@v3 diff --git a/Makefile b/Makefile index e40e8e2..04bdaec 100644 --- a/Makefile +++ b/Makefile @@ -34,11 +34,15 @@ ifndef OPENFOAM_GIT_BRANCH OPENFOAM_TARBALL = $(shell basename $(OPENFOAM_TARBALL_URL)) endif +VOLUME = /Volumes/$(APP_NAME) + # Build targets app: build/$(APP_NAME).app -build: build/$(APP_NAME)-build.sparsebundle -deps: build/$(APP_NAME)-deps.sparsebundle +build: $(VOLUME)/build/log.txt + hdiutil detach $(VOLUME) +deps: $(VOLUME)/Brewfile.lock.json + hdiutil detach $(VOLUME) fetch-source: $(OPENFOAM_TARBALL) ifeq ($(DEPENDENCIES_KIND),both) @@ -55,7 +59,6 @@ install: $(INSTALL_DIR)/$(APP_NAME).app # Build rules -VOLUME = /Volumes/$(APP_NAME) VOLUME_ID_FILE = $(VOLUME)/.vol_id APP_CONTENTS = \ @@ -111,13 +114,12 @@ build/$(APP_NAME).app/Contents/%: Contents/% mkdir -p $(@D) cp -a $< $@ -build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg: build/$(APP_NAME)-build.sparsebundle build/$(APP_NAME).app/Contents/Resources/icon.icns fix_install_names.sh +build/$(APP_NAME).app/Contents/Resources/$(APP_NAME).dmg: $(VOLUME)/build/log.txt build/$(APP_NAME).app/Contents/Resources/icon.icns fix_install_names.sh [ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME) hdiutil attach \ build/$(APP_NAME)-build.sparsebundle \ -shadow - cd $(VOLUME) \ - && "$(CURDIR)/fix_install_names.sh" + cd $(VOLUME) && "$(CURDIR)/fix_install_names.sh" cp build/$(APP_NAME).app/Contents/Resources/icon.icns $(VOLUME)/.VolumeIcon.icns SetFile -c icnC $(VOLUME)/.VolumeIcon.icns SetFile -a C $(VOLUME) @@ -138,7 +140,7 @@ else ifeq ($(DEPENDENCIES_KIND),homebrew) else $(error Invalid value for DEPENDENCIES_KIND) endif - rm -rf $(VOLUME)/.fseventsd || true + rm -rf $(VOLUME)/.fseventsd mkdir -p build/$(APP_NAME).app/Contents/Resources hdiutil create \ -format $(DMG_FORMAT) \ @@ -150,10 +152,14 @@ endif hdiutil detach $(VOLUME) rm build/$(APP_NAME)-build.sparsebundle.shadow -build/$(APP_NAME)-build.sparsebundle: build/$(APP_NAME)-deps.sparsebundle $(OPENFOAM_TARBALL) configure.sh - [ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME) - mv build/$(APP_NAME)-deps.sparsebundle build/$(APP_NAME)-build.sparsebundle - hdiutil attach build/$(APP_NAME)-build.sparsebundle +$(VOLUME)/build/log.txt: $(VOLUME)/Brewfile.lock.json $(VOLUME)/etc/prefs.sh + cd $(VOLUME) \ + && source etc/bashrc \ + && foamSystemCheck \ + && ( ./Allwmake -j $(WMAKE_NJOBS) -s -q -k || true ) \ + && ./Allwmake -j $(WMAKE_NJOBS) -s -l build/log.txt + +$(VOLUME)/etc/prefs.sh: $(OPENFOAM_TARBALL) configure.sh | $(VOLUME) ifdef OPENFOAM_TARBALL tar -xzf $(OPENFOAM_TARBALL) --strip-components 1 -C $(VOLUME) else ifdef OPENFOAM_GIT_BRANCH @@ -162,47 +168,50 @@ else ifdef OPENFOAM_GIT_BRANCH git -C $(VOLUME) pull origin $(OPENFOAM_GIT_BRANCH) git -C $(VOLUME) submodule update --init --recursive endif - cd $(VOLUME) \ - && "$(CURDIR)/configure.sh" \ - && source etc/bashrc \ - && foamSystemCheck \ - && ( ./Allwmake -j $(WMAKE_NJOBS) -s -q -k || true ) \ - && ./Allwmake -j $(WMAKE_NJOBS) -s - hdiutil detach $(VOLUME) + cd $(VOLUME) && "$(CURDIR)/configure.sh" -build/$(APP_NAME)-deps.sparsebundle: Brewfile $(if $(filter homebrew,$(DEPENDENCIES_KIND)),Brewfile.lock.json) - [ ! -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)/ +$(VOLUME)/Brewfile.lock.json: $(VOLUME)/Brewfile | $(VOLUME)/usr +ifeq ($(DEPENDENCIES_KIND),standalone) + $(VOLUME)/usr/bin/brew bundle --file $(VOLUME)/Brewfile --cleanup --verbose + $(VOLUME)/usr/bin/brew list --versions +else ifeq ($(DEPENDENCIES_KIND),homebrew) + brew bundle --file $(VOLUME)/Brewfile --no-upgrade +else + $(error Invalid value for DEPENDENCIES_KIND) +endif + +$(VOLUME)/usr: | $(VOLUME) ifeq ($(DEPENDENCIES_KIND),standalone) git clone https://github.com/Homebrew/brew $(VOLUME)/homebrew mkdir -p $(VOLUME)/usr/bin ln -s ../../homebrew/bin/brew $(VOLUME)/usr/bin/ - $(VOLUME)/usr/bin/brew bundle --file $(VOLUME)/Brewfile --verbose - $(VOLUME)/usr/bin/brew autoremove - $(VOLUME)/usr/bin/brew list --versions else ifeq ($(DEPENDENCIES_KIND),homebrew) - brew bundle check --verbose --no-upgrade - cp Brewfile.lock.json $(VOLUME)/ ln -s $(shell brew --prefix) $(VOLUME)/usr else $(error Invalid value for DEPENDENCIES_KIND) endif - hdiutil detach $(VOLUME) -$(OPENFOAM_TARBALL): $(or $(wildcard $(OPENFOAM_TARBALL).sha256), \ - $(warning No checksum file found for $(OPENFOAM_TARBALL); will skip verification)) +$(VOLUME)/Brewfile: Brewfile | $(VOLUME) + cp Brewfile $(VOLUME)/ + +$(VOLUME): | build/$(APP_NAME)-build.sparsebundle + hdiutil attach build/$(APP_NAME)-build.sparsebundle + +build/$(APP_NAME)-build.sparsebundle: + mkdir -p build + hdiutil create \ + -size 50g \ + -fs $(VOLUME_FILESYSTEM) \ + -volname $(APP_NAME) \ + build/$(APP_NAME)-build.sparsebundle \ + -ov + +$(OPENFOAM_TARBALL): | $(OPENFOAM_TARBALL).sha256 curl -L -o $(OPENFOAM_TARBALL) $(OPENFOAM_TARBALL_URL) - [ -z $< ] || shasum -a 256 -c $< + [ ! -f $(OPENFOAM_TARBALL).sha256 ] || shasum -a 256 --check $(OPENFOAM_TARBALL).sha256 -Brewfile.lock.json: Brewfile - brew bundle +$(OPENFOAM_TARBALL).sha256: + $(warning No checksum file found for $(OPENFOAM_TARBALL); will skip verification) # Non-build targets and rules @@ -254,11 +263,11 @@ test-dmg: clean-app: [ ! -d $(VOLUME) ] || hdiutil detach $(VOLUME) - rm -rf build/$(APP_NAME).app + rm -rf build/$(APP_NAME).app build/$(APP_NAME)-build.sparsebundle.shadow clean-build: clean-app rm -f build/$(DIST_NAME).zip - rm -rf build/$(APP_NAME)-build.sparsebundle build/$(APP_NAME)-deps.sparsebundle $(TEST_DIR)/test-openfoam $(TEST_DIR)/test-bash $(TEST_DIR)/test-zsh $(TEST_DIR)/test-dmg + rm -rf build/$(APP_NAME)-build.sparsebundle $(TEST_DIR)/test-openfoam $(TEST_DIR)/test-bash $(TEST_DIR)/test-zsh $(TEST_DIR)/test-dmg rmdir $(TEST_DIR) || true rmdir build || true @@ -268,9 +277,15 @@ clean: clean-build uninstall: rm -rf $(INSTALL_DIR)/$(APP_NAME).app +touch-deps: | $(VOLUME) + $(MAKE) --touch deps + hdiutil detach $(VOLUME) + +touch-build: | $(VOLUME) + $(MAKE) --touch build + hdiutil detach $(VOLUME) # Set special targets -.PHONY: app build deps fetch-source zip install test test-openfoam test-bash test-zsh test-dmg clean-app clean-build clean uninstall -.PRECIOUS: build/$(APP_NAME)-build.sparsebundle -.SECONDARY: $(OPENFOAM_TARBALL) Brewfile.lock.json build/$(APP_NAME)-deps.sparsebundle build/$(APP_NAME)-build.sparsebundle +.PHONY: app build deps fetch-source zip install test test-openfoam test-bash test-zsh test-dmg clean-app clean-build clean uninstall touch-deps touch-build +.SECONDARY: $(OPENFOAM_TARBALL) .DELETE_ON_ERROR: diff --git a/configure.sh b/configure.sh index d328af2..3293dbc 100755 --- a/configure.sh +++ b/configure.sh @@ -3,6 +3,13 @@ # Configure OpenFOAM for compilation and use within OpenFOAM.app on macOS # ----------------------------------------------------------------------------- +# Delete previous configuration files +rm -f etc/config.sh/prefs.openmpi +rm -f etc/config.csh/prefs.openmpi + +rm -f etc/prefs.sh +rm -f etc/prefs.csh + # Do as much as possible with foamConfigurePaths bin/tools/foamConfigurePaths \ -system-compiler Clang \