From 9e3d06853e9db42202ce7249d3564ad6478c893f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 11 May 2020 10:55:23 +0200 Subject: [PATCH] ENH: add 'subcommand' handling to wmake (#1693) - initial split of wmake-related commands into "plumbing" and "porcelain" akin to how git handles things. - wmakeBuildInfo (very low-level), now relocated to the wmake/scripts and accessible for the user as "wmake -build-info". This satisfies a long-standing desire to access build information in a fashion similar to the api/patch information. CONFIG: avoid git information when building with a debian/ directory - when a 'debian/' directory exists, there is a high probability that the '.git/' directory is from debian and not from OpenFOAM (ie, useless here). This corresponds to an implicit '-no-git', which has no effect when building from pristine sources. ENH: wmakeCheckPwd becomes scripts/wmake-check-dir - accessible for the user as "wmake -check-dir" and with 1 or 2 directory names. A wmakeCheckPwd symlink left for compatibility. --- Allwmake | 2 +- META-INFO/README.md | 53 +++---- README.md | 6 +- applications/Allwmake | 2 +- bin/foamEtcFile | 8 +- bin/tools/foamPackRelease | 2 +- etc/openfoam | 3 + src/Allwmake | 2 +- src/OpenFOAM/Alltouch | 4 +- wmake/rules/General/version | 2 +- wmake/scripts/wcleanObjects | 9 +- .../wmake-build-info} | 37 +++-- wmake/scripts/wmake-check-dir | 134 ++++++++++++++++++ wmake/wclean | 8 +- wmake/wmake | 98 +++++++++---- wmake/wmakeCheckPwd | 115 +-------------- wmake/wmakeLnIncludeAll | 4 +- 17 files changed, 282 insertions(+), 207 deletions(-) rename wmake/{wmakeBuildInfo => scripts/wmake-build-info} (94%) create mode 100755 wmake/scripts/wmake-check-dir mode change 100755 => 120000 wmake/wmakeCheckPwd diff --git a/Allwmake b/Allwmake index c5ba88c93b..8a42e1341a 100755 --- a/Allwmake +++ b/Allwmake @@ -1,7 +1,7 @@ #!/bin/sh # Run from OPENFOAM top-level directory only cd "${0%/*}" || exit -wmakeCheckPwd "$WM_PROJECT_DIR" 2>/dev/null || { +wmake -check-dir "$WM_PROJECT_DIR" 2>/dev/null || { echo "Error (${0##*/}) : not located in \$WM_PROJECT_DIR" echo " Check your OpenFOAM environment and installation" exit 1 diff --git a/META-INFO/README.md b/META-INFO/README.md index 87db61f163..f1152b5aea 100644 --- a/META-INFO/README.md +++ b/META-INFO/README.md @@ -1,59 +1,60 @@ # META-INFO -Meta-information is for OpenFOAM internal use only. - -Do not rely on any files or any file contents in this directory, -or even the existence of this directory. +Meta-information is generally for OpenFOAM internal use only. The format, content and meaning may be changed at anytime without -notice. +notice. If any of these are changed, these are some of places that +will need to be updated accordingly: -The information is provided here for internal documentation purposes. + - bin/foamEtcFile + - bin/tools/foamConfigurePaths + - bin/tools/foamPackRelease + - etc/openfoam + - wmake/scripts/wmake-build-info ## api-info This file and its contents are to be tracked by git. -- File content (api) generated by wmakeBuildInfo from OPENFOAM define - in `wmake/rules/General/general` - +- File content (api) generated by `wmake -build-info` from the + `OPENFOAM` define in `wmake/rules/General/general` - File content (patch) is manually generated content. ## build-info -This file is *never* to be tracked by git, but may be present in shipped -source archives. +This file is ***never*** to be tracked by git, but may be present in +shipped source archives. -- File content (branch, build) generated by wmakeBuildInfo from git - information and cached from previous wmake (api) +- File content (branch, build) generated by `wmake -build-info` from + git information and cached from previous wmake (api) ## Content types ### api +Format: `date +%y%m` + - 4-digit year-month (YYMM) integer corresponding to the major release or in unusual cases an intermediate release. - -- Format is year-month, as per `date +%y%m`. - Eg, `1712` for the Dec-2017 release. + Example, `1712` for the Dec-2017 release. ### patch +Format: `date +%y%m%d` + - 6-digit year-month-day (YYMMDD) integer corresponding to a patch-level for the given **released** API. - -- Format is year-month-day, as per `date +%y%m%d`. - -- The first release can have a patch value of `0` (unpatched = just - released) or a patch value corresponding to the release date. +- The first release can have a patch value of `0` or `1` which + indicates that it is unpatched or just released. Alternatively + it can have a patch value corresponding to the release date. The patch value is only meaningful together with the api value. However, for *development* branches, the patch level should not be -ascribed much meaning -- it can be `0` or have a value corresponding -to the last merge with a *maintenance* (*eg*, `master`) branch. +ascribed too much meaning, but will often correspond to the last +merge with a *maintenance* (*eg*, `master`) branch. ## Flow of information @@ -70,9 +71,9 @@ distributions to have a record of the same information. | build | git | build-info | -The command `wmakeBuildInfo -check` is used to determine if +The command `wmake -build-info -check` is used to determine if the saved information needs synchronization. The command -`wmakeBuildInfo -update` preforms the synchronitzation. +`wmake -build-info -update` performs the synchronization. ## Notes @@ -82,4 +83,4 @@ contains more permanent information, whereas the `build-info` is more transient in nature. ---- -2019-01-23 +2020-05-05 diff --git a/README.md b/README.md index abbc8a95ea..da379686a7 100644 --- a/README.md +++ b/README.md @@ -85,10 +85,10 @@ As can be seen in this example, the git build information is supplemented by the date when the last change was authored, which can be helpful when the repository contains local changes. If you simply wish to know the current API and patch levels directly, the -`wmakeBuildInfo` script provides the relevant information even +`wmake -build-info` provides the relevant information even when OpenFOAM has not yet been compiled: ``` -$ wmakeBuildInfo +$ wmake -build-info make api = 1812 patch = 190531 @@ -207,4 +207,4 @@ ThirdParty directory will contain either an `Allwmake` file or a - [Community](http://www.openfoam.com/community/), [Governance](http://www.openfoam.com/governance/) - [Contacting OpenCFD](http://www.openfoam.com/contact/) -Copyright 2016-2019 OpenCFD Ltd +Copyright 2016-2020 OpenCFD Ltd diff --git a/applications/Allwmake b/applications/Allwmake index 005fec2570..286abf1974 100755 --- a/applications/Allwmake +++ b/applications/Allwmake @@ -1,7 +1,7 @@ #!/bin/sh # Run from OPENFOAM applications/ directory only cd "${0%/*}" || exit -wmakeCheckPwd "$WM_PROJECT_DIR/applications" 2>/dev/null || { +wmake -check-dir "$WM_PROJECT_DIR/applications" 2>/dev/null || { echo "Error (${0##*/}) : not located in \$WM_PROJECT_DIR/applications" echo " Check your OpenFOAM environment and installation" exit 1 diff --git a/bin/foamEtcFile b/bin/foamEtcFile index fc8cc57bf5..0a31ed9c48 100755 --- a/bin/foamEtcFile +++ b/bin/foamEtcFile @@ -43,9 +43,11 @@ # Note # This script must exist in the project 'bin' directory # -# The '-show-api' and '-show-patch' options implement partial logic -# from wmake/wmakeBuildInfo. -# Make sure that any changes there are also reflected here. +# The '-show-api' and '-show-patch' options extract values from +# the "META-INFO/api-info" file +# +# SeeAlso +# META-INFO/README.md for other routines that also use META-INFO. # #------------------------------------------------------------------------------- printHelp() { diff --git a/bin/tools/foamPackRelease b/bin/tools/foamPackRelease index 54370b8b00..49b7bfe003 100755 --- a/bin/tools/foamPackRelease +++ b/bin/tools/foamPackRelease @@ -264,7 +264,7 @@ patch="$(git --git-dir="$gitbase/.git" show "$sha1" | sed -ne s/patch=//p)" [ -n "$api" ] || die "Could resolve api value" -# Determine the BUILD information from git, as per wmakeBuildInfo. +# Determine the BUILD information from git, as per `wmake -build-info` build="$(git --git-dir="$gitbase/.git" log -1 --date=short --format='%h=%ad' 2>/dev/null|sed 's/-//g;s/=/-/')" echo "Detected api, patch, build as '$api', '$patch', '$build'" 1>&2 diff --git a/etc/openfoam b/etc/openfoam index 2bb13cbe32..e53f253504 100755 --- a/etc/openfoam +++ b/etc/openfoam @@ -34,6 +34,9 @@ # However, the '-D' options grant more flexibility. For example, # etc/openfoam -DWM_COMPILER=Clang # +# SeeAlso +# META-INFO/README.md for other routines that also use META-INFO. +# #------------------------------------------------------------------------------ # Auto-detect from location. Do not call from within the etc/directory itself! projectDir="$(\cd "$(dirname "${0%/*}")" && \pwd -L)" diff --git a/src/Allwmake b/src/Allwmake index 7f42ca5cbb..812b206ecb 100755 --- a/src/Allwmake +++ b/src/Allwmake @@ -1,7 +1,7 @@ #!/bin/sh # Run from OPENFOAM src/ directory only cd "${0%/*}" || exit -wmakeCheckPwd "$WM_PROJECT_DIR/src" 2>/dev/null || { +wmake -check-dir "$WM_PROJECT_DIR/src" 2>/dev/null || { echo "Error (${0##*/}) : not located in \$WM_PROJECT_DIR/src" echo " Check your OpenFOAM environment and installation" exit 1 diff --git a/src/OpenFOAM/Alltouch b/src/OpenFOAM/Alltouch index ca1d3ac8bb..063ba7027e 100755 --- a/src/OpenFOAM/Alltouch +++ b/src/OpenFOAM/Alltouch @@ -6,11 +6,11 @@ touch=true case "$1" in -check) - if wmakeBuildInfo -check + if wmake -build-info -check then unset touch fi -;; + ;; esac if [ -n "$touch" ] diff --git a/wmake/rules/General/version b/wmake/rules/General/version index 08400d12cc..7dc486969f 100644 --- a/wmake/rules/General/version +++ b/wmake/rules/General/version @@ -4,7 +4,7 @@ SUFFIXES += .Cver # Update strings in C++ file and in META-INFO files Cvertoo = \ - wmakeBuildInfo -update -filter $< > $(@D)/$( $(@D)/$(. +# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. # # Script # wcleanBuild, wcleanPlatform @@ -88,8 +87,8 @@ done #------------------------------------------------------------------------------ # Run from OPENFOAM or THIRDPARTY top-level directory only -wmakeCheckPwd -q "$WM_PROJECT_DIR" 2>/dev/null || \ -wmakeCheckPwd -q "$WM_THIRD_PARTY_DIR" 2>/dev/null || \ +wmake -check-dir -quiet "$WM_PROJECT_DIR" 2>/dev/null || \ +wmake -check-dir -quiet "$WM_THIRD_PARTY_DIR" 2>/dev/null || \ { cat<&2 - - while [ "$#" -ge 1 ]; do echo "$1"; shift; done +printHelp() { cat<&2 - rm -f "$META_INFO/build-info" 2>/dev/null + rm -f "$META_INFO/build-info" else echo "Already removed project ${META_INFO##*/}/build-info" 1>&2 fi diff --git a/wmake/scripts/wmake-check-dir b/wmake/scripts/wmake-check-dir new file mode 100755 index 0000000000..be333717c7 --- /dev/null +++ b/wmake/scripts/wmake-check-dir @@ -0,0 +1,134 @@ +#!/bin/sh +#------------------------------------------------------------------------------ +# ========= | +# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox +# \\ / O peration | +# \\ / A nd | www.openfoam.com +# \\/ M anipulation | +#------------------------------------------------------------------------------- +# Copyright (C) 2011-2015 OpenFOAM Foundation +# Copyright (C) 2020 OpenCFD Ltd. +#------------------------------------------------------------------------------ +# License +# This file is part of OpenFOAM, distributed under GPL-3.0-or-later. +# +# Script +# wmake/scripts/wmake-check-dir +# Backend for "wmake -check-dir" +# +# wmake/wmakeCheckPwd (1912 and earlier) +# +# Usage +# wmake-check-dir +# wmake-check-dir +# +# Description +# Check that two directories are identical after resolving the absolute +# paths. If only a single directory is specified, check against the +# working directory. +# +# Exit status 0 when directories are identical. +# +#------------------------------------------------------------------------------- +printHelp() { + cat<&2 + echo "${0##*/}: $1" + shift + while [ "$#" -ge 1 ]; do echo " $1"; shift; done + fi + exit 1 +} + +#------------------------------------------------------------------------------ + +# Parse options +while [ "$#" -gt 0 ] +do + case "$1" in + -h | -help*) + printHelp + ;; + -q | -quiet | -s | -silent) + optQuiet=true + ;; + --) + shift + break + ;; + -*) + die "Unknown option: '$1'" "See '${0##*/} -help' for usage" + ;; + *) + break + ;; + esac + shift +done + +dirName1="${1%/}" +dirName2="${2%/}" + +: "${dirName1:=/}" +: "${dirName2:=$PWD}" + +[ "$#" -eq 1 ] || \ +[ "$#" -eq 2 ] || \ + die "Expected 1 or 2 arguments, was given $#" + + +# Simple lexical check +[ "$dirName1" = "$dirName2" ] && exit 0 + +# Check existence +[ -d "$dirName1" ] || die "Directory does not exist '$dirName1'" + +resolved1="$(cd "$dirName1" 2>/dev/null && pwd -P)" +if [ "$#" -eq 1 ] +then + resolved2="$(pwd -P)" +else + # Check existence + [ -d "$dirName2" ] || die "Directory does not exist '$dirName2'" + + resolved2="$(cd "$dirName2" 2>/dev/null && pwd -P)" +fi + + +# Compare absolute paths, without symlinks +if [ "$resolved1" = "$resolved2" ] +then + exit 0 +fi + +if [ "$#" -eq 1 ] +then + die "Current directory is not '$dirName1'" +else + die "Directories are different" +fi + +#------------------------------------------------------------------------------ diff --git a/wmake/wclean b/wmake/wclean index 1d771fcabb..180dc89b8b 100755 --- a/wmake/wclean +++ b/wmake/wclean @@ -175,15 +175,15 @@ then -name .git -prune -o -type d -print) do echo " searching: ${d#./}" - find $d -depth -empty -type d -delete -print + find "$d" -depth -empty -type d -delete -print done # Second pass: clean up object directories with WM_PROJECT_DIR that don't # have respective source code folders, along with the respective binaries - if [ "$(expandPath $PWD)" = "$(expandPath $WM_PROJECT_DIR)" ] - then - objectsDir=$(findObjectDir $PWD 2>/dev/null) || exit 1 # Fatal + if "$scriptsDir"/wmake-check-dir "$WM_PROJECT_DIR" && \ + objectsDir=$(findObjectDir . 2>/dev/null) + then if [ -d "$objectsDir" ] then echo " Removing redundant object directories in $objectsDir" diff --git a/wmake/wmake b/wmake/wmake index 920e71d1ff..9cd0c380c3 100755 --- a/wmake/wmake +++ b/wmake/wmake @@ -29,8 +29,7 @@ # wmake # # Description -# General, wrapped make system for multi-platform development with -# support for local and network parallel compilation. +# General, wrapped make system for multi-platform development. # # Intermediate object and dependency files retain the tree structure # of the original source files, with its location depending on the @@ -55,24 +54,27 @@ # # See also # wmakeLnInclude, wmakeLnIncludeAll, wmakeCollect, wdep, wrmdep, wrmo, -# wclean, wcleanPlatform, wcleanLnIncludeAll +# wclean, wcleanLnIncludeAll # #------------------------------------------------------------------------------ -Script="${0##*/}" # Use 'Script' for error messages in wmakeFunctions -. "${0%/*}"/scripts/wmakeFunctions # Source wmake functions +Script="${0##*/}" # Need 'Script' for wmakeFunctions messages +scriptsDir="${0%/*}"/scripts # wmake/scripts directory +. "$scriptsDir"/wmakeFunctions # Source wmake functions printHelp() { cat<&2 exit 1 @@ -395,7 +432,7 @@ unset dir # Recurse the source tree to update all #------------------------------------------------------------------------------ -if [ "$update" = true ] +if [ "$optUpdate" = true ] then wrmdep -update wrmdep -old @@ -405,13 +442,13 @@ then fi +unset exitCode + #------------------------------------------------------------------------------ # Recurse the source tree to compile "all" targets #------------------------------------------------------------------------------ -unset exitCode - -if [ "$all" = all ] +if [ "$optAll" = all ] then if [ -e Allwmake.override ] then @@ -467,12 +504,11 @@ fi #------------------------------------------------------------------------------ -# Recurse the source tree to compile "all" targets using wmakeCollect +# Recurse source tree to compile "all" targets using wmakeCollect #------------------------------------------------------------------------------ - -if [ "$all" = queue ] +if [ "$optAll" = queue ] then - [ "$update" = true ] || wmakeLnIncludeAll $parOpt + [ "$optUpdate" = true ] || wmakeLnIncludeAll $parOpt ( export WM_COLLECT_DIR="$WM_PROJECT_DIR/build/${WM_OPTIONS}/${PWD////_}" diff --git a/wmake/wmakeCheckPwd b/wmake/wmakeCheckPwd deleted file mode 100755 index 0a792bee0c..0000000000 --- a/wmake/wmakeCheckPwd +++ /dev/null @@ -1,114 +0,0 @@ -#!/bin/sh -#------------------------------------------------------------------------------ -# ========= | -# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox -# \\ / O peration | -# \\ / A nd | www.openfoam.com -# \\/ M anipulation | -#------------------------------------------------------------------------------- -# Copyright (C) 2011-2015 OpenFOAM Foundation -#------------------------------------------------------------------------------ -# License -# This file is part of OpenFOAM. -# -# OpenFOAM is free software: you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# OpenFOAM is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# You should have received a copy of the GNU General Public License -# along with OpenFOAM. If not, see . -# -# Script -# wmakeCheckPwd -# -# Usage -# wmakeCheckPwd -# -# Description -# Check that the current working directory is the directory . -# Exit status 0 when the directories are identical -# -#------------------------------------------------------------------------------- -Script=${0##*/} - -unset optQuiet -exec 1>&2 # No stdout, stderr only - -usage() { - [ "$optQuiet" = true ] && exit 1 - while [ "$#" -ge 1 ]; do echo "$1"; shift; done - cat< - - Exit status 0 when the directories are identical - Exit status 1 on error - -USAGE - exit 1 -} - - -error() -{ - if [ "$optQuiet" != true ] - then - echo "$Script error: $1" - shift - while [ "$#" -ge 1 ]; do echo " $1"; shift; done - fi - exit 1 -} - -#------------------------------------------------------------------------------ -# Parse arguments and options -#------------------------------------------------------------------------------ - -while [ "$#" -gt 0 ] -do - case "$1" in - -h | -help*) - usage - ;; - -q | -quiet) - optQuiet=true - shift - ;; - -*) - usage "Unknown option: '$1'" - ;; - *) - break - ;; - esac -done - -[ "$#" -eq 1 ] || usage "Incorrect number of arguments" - -dirName="$1" - -# Simple lexical check against PWD -[ "$PWD" = "$dirName" ] && exit 0 - -# Check existence of -[ -d "$dirName" ] || error "Directory does not exist '$dirName'" - -# Compare absolute paths, without symlinks -[ "$(cd $dirName 2>/dev/null && pwd -P)" = "$(pwd -P)" ] || \ - error "Current directory is not '$dirName'" - - -exit 0 # clean exit - -#------------------------------------------------------------------------------ diff --git a/wmake/wmakeCheckPwd b/wmake/wmakeCheckPwd new file mode 120000 index 0000000000..19d5c59516 --- /dev/null +++ b/wmake/wmakeCheckPwd @@ -0,0 +1 @@ +scripts/wmake-check-dir \ No newline at end of file diff --git a/wmake/wmakeLnIncludeAll b/wmake/wmakeLnIncludeAll index 6b44652514..e69f1a66a8 100755 --- a/wmake/wmakeLnIncludeAll +++ b/wmake/wmakeLnIncludeAll @@ -7,7 +7,7 @@ # \\/ M anipulation | #------------------------------------------------------------------------------ # Copyright (C) 2011-2016 OpenFOAM Foundation -# Copyright (C) 2018 OpenCFD Ltd. +# Copyright (C) 2018-2020 OpenCFD Ltd. #------------------------------------------------------------------------------ # License # This file is part of OpenFOAM. @@ -102,7 +102,7 @@ done # project directory: {applications,src} directories if [ "$#" -eq 0 ] then - if wmakeCheckPwd "$WM_PROJECT_DIR" 2>/dev/null + if wmake -check-dir "$WM_PROJECT_DIR" 2>/dev/null then set -- applications src else