mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
CONFIG: remove bash dependency from wmakeBuildInfo (fixes #1152)
- looks slightly messier without associative arrays, but improves portability. Should now also work with dash. STYLE: support wmakeBuildInfo -cmp and -check options as equivalent
This commit is contained in:
@ -1,9 +1,9 @@
|
|||||||
#!/bin/bash
|
#!/bin/sh
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# ========= |
|
# ========= |
|
||||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||||
# \\ / O peration |
|
# \\ / O peration |
|
||||||
# \\ / A nd | Copyright (C) 2018 OpenCFD Ltd.
|
# \\ / A nd | Copyright (C) 2018-2019 OpenCFD Ltd.
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
@ -26,7 +26,7 @@
|
|||||||
# wmakeBuildInfo
|
# wmakeBuildInfo
|
||||||
#
|
#
|
||||||
# Description
|
# Description
|
||||||
# Print the version used when building the project
|
# Print the api/version and other build information for the project.
|
||||||
#
|
#
|
||||||
# Environment
|
# Environment
|
||||||
# - WM_PROJECT_DIR
|
# - WM_PROJECT_DIR
|
||||||
@ -51,7 +51,7 @@ usage() {
|
|||||||
Usage: ${0##*/} [OPTION]
|
Usage: ${0##*/} [OPTION]
|
||||||
${0##*/} [-update] -filter FILE
|
${0##*/} [-update] -filter FILE
|
||||||
options:
|
options:
|
||||||
-check Compare make and meta information (exit 0 for no changes)
|
-cmp, -check Compare make and meta information (exit 0 for no changes)
|
||||||
-diff Display differences between make and meta information
|
-diff Display differences between make and meta information
|
||||||
(exit code 0 for no changes)
|
(exit code 0 for no changes)
|
||||||
-dry-run In combination with -update
|
-dry-run In combination with -update
|
||||||
@ -96,7 +96,7 @@ do
|
|||||||
-h | -help*)
|
-h | -help*)
|
||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
-check)
|
-cmp | -check)
|
||||||
optCheck=true
|
optCheck=true
|
||||||
;;
|
;;
|
||||||
-diff)
|
-diff)
|
||||||
@ -156,12 +156,11 @@ fi
|
|||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Variables
|
# Variables - for portability, avoiding bash associative arrays
|
||||||
declare -A makeInfo
|
unset make_info meta_info
|
||||||
declare -A metaInfo
|
|
||||||
|
|
||||||
#
|
|
||||||
# Populate makeInfo array
|
# Populate make_* variables
|
||||||
#
|
#
|
||||||
# - api : from rules/General/general
|
# - api : from rules/General/general
|
||||||
# - patch : cached value from previous make
|
# - patch : cached value from previous make
|
||||||
@ -177,10 +176,9 @@ declare -A metaInfo
|
|||||||
#
|
#
|
||||||
# - Working on detached head.
|
# - Working on detached head.
|
||||||
# -> branch has value "HEAD" instead of something more readable.
|
# -> branch has value "HEAD" instead of something more readable.
|
||||||
#
|
|
||||||
getMakeInfo()
|
getMakeInfo()
|
||||||
{
|
{
|
||||||
if [ "${#makeInfo[*]}" -eq 4 ]
|
if [ -n "$make_info" ]
|
||||||
then
|
then
|
||||||
##echo "use cached value for make info" 1>&2
|
##echo "use cached value for make info" 1>&2
|
||||||
return 0
|
return 0
|
||||||
@ -188,7 +186,7 @@ getMakeInfo()
|
|||||||
##echo "get make info" 1>&2
|
##echo "get make info" 1>&2
|
||||||
|
|
||||||
local api patch build branch
|
local api patch build branch
|
||||||
makeInfo=()
|
unset make_api make_patch make_branch make_build
|
||||||
|
|
||||||
# (api) from WM_DIR/rules/General/general
|
# (api) from WM_DIR/rules/General/general
|
||||||
# - extract WM_VERSION = OPENFOAM=<digits>
|
# - extract WM_VERSION = OPENFOAM=<digits>
|
||||||
@ -211,15 +209,15 @@ getMakeInfo()
|
|||||||
branch="$(git --git-dir=$WM_PROJECT_DIR/.git rev-parse --abbrev-ref HEAD 2>/dev/null)"
|
branch="$(git --git-dir=$WM_PROJECT_DIR/.git rev-parse --abbrev-ref HEAD 2>/dev/null)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
makeInfo[api]="$api"
|
make_api="$api"
|
||||||
makeInfo[patch]="${patch:-0}" # default is 0
|
make_patch="${patch:-0}" # Default is 0 (unpatched)
|
||||||
makeInfo[branch]="$branch"
|
make_branch="$branch"
|
||||||
makeInfo[build]="$build"
|
make_build="$build"
|
||||||
|
make_info=true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
# Populate meta_* variables
|
||||||
# Populate metaInfo array
|
|
||||||
#
|
#
|
||||||
# - api : from META-INFO/api-info
|
# - api : from META-INFO/api-info
|
||||||
# - patch : from META-INFO/api-info
|
# - patch : from META-INFO/api-info
|
||||||
@ -229,10 +227,9 @@ getMakeInfo()
|
|||||||
# Failure modes:
|
# Failure modes:
|
||||||
# - Directory, file or entry not found.
|
# - Directory, file or entry not found.
|
||||||
# -> corresponding entries are empty strings
|
# -> corresponding entries are empty strings
|
||||||
#
|
|
||||||
getMetaInfo()
|
getMetaInfo()
|
||||||
{
|
{
|
||||||
if [ "${#metaInfo[*]}" -eq 4 ]
|
if [ -n "$meta_info" ]
|
||||||
then
|
then
|
||||||
##echo "use cached value for meta info" 1>&2
|
##echo "use cached value for meta info" 1>&2
|
||||||
return 0
|
return 0
|
||||||
@ -240,7 +237,7 @@ getMetaInfo()
|
|||||||
##echo "get meta info" 1>&2
|
##echo "get meta info" 1>&2
|
||||||
|
|
||||||
local api patch build branch
|
local api patch build branch
|
||||||
metaInfo=()
|
unset meta_api meta_patch meta_branch meta_build
|
||||||
|
|
||||||
if [ -d "$metaInfoDir" ]
|
if [ -d "$metaInfoDir" ]
|
||||||
then
|
then
|
||||||
@ -253,14 +250,14 @@ getMetaInfo()
|
|||||||
build="$(sed -ne 's@^build *= *\([^ ]*\).*@\1@p' $metaInfoDir/build-info 2>/dev/null)"
|
build="$(sed -ne 's@^build *= *\([^ ]*\).*@\1@p' $metaInfoDir/build-info 2>/dev/null)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
metaInfo[api]="$api"
|
meta_api="$api"
|
||||||
metaInfo[patch]="${patch:-0}" # default is 0
|
meta_patch="${patch:-0}" # Default is 0 (unpatched)
|
||||||
metaInfo[branch]="$branch"
|
meta_branch="$branch"
|
||||||
metaInfo[build]="$build"
|
meta_build="$build"
|
||||||
|
meta_info=true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
|
||||||
# Get api from rules/General/general
|
# Get api from rules/General/general
|
||||||
#
|
#
|
||||||
# Failure modes:
|
# Failure modes:
|
||||||
@ -268,18 +265,17 @@ getMetaInfo()
|
|||||||
# -> Fatal for building, but could be OK for a stripped down version
|
# -> Fatal for building, but could be OK for a stripped down version
|
||||||
#
|
#
|
||||||
# Fallback. Get from api-info
|
# Fallback. Get from api-info
|
||||||
#
|
|
||||||
getApi()
|
getApi()
|
||||||
{
|
{
|
||||||
getMakeInfo
|
getMakeInfo
|
||||||
|
|
||||||
# Local copy
|
# Local copy
|
||||||
local api="${makeInfo[api]}"
|
local api="${make_api}"
|
||||||
|
|
||||||
if [ -z "$api" ]
|
if [ -z "$api" ]
|
||||||
then
|
then
|
||||||
getMetaInfo
|
getMetaInfo
|
||||||
api="${metaInfo[api]}"
|
api="${meta_api}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -n "$api" ]
|
if [ -n "$api" ]
|
||||||
@ -295,53 +291,69 @@ getApi()
|
|||||||
#
|
#
|
||||||
# Failure modes:
|
# Failure modes:
|
||||||
# - No patch information (can't find file etc).
|
# - No patch information (can't find file etc).
|
||||||
#
|
|
||||||
getPatchLevel()
|
getPatchLevel()
|
||||||
{
|
{
|
||||||
getMetaInfo
|
getMetaInfo
|
||||||
|
|
||||||
# Local copy
|
# Local copy
|
||||||
local value="${metaInfo[patch]}"
|
local patch="${meta_patch}"
|
||||||
|
|
||||||
if [ -n "$value" ]
|
if [ -n "$patch" ]
|
||||||
then
|
then
|
||||||
echo "$value"
|
echo "$patch"
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
# Report make info
|
# Report make info
|
||||||
|
#
|
||||||
reportMakeInfo()
|
reportMakeInfo()
|
||||||
{
|
{
|
||||||
getMakeInfo
|
getMakeInfo
|
||||||
getMetaInfo
|
getMetaInfo
|
||||||
|
|
||||||
local patch="${metaInfo[patch]}" # <- From meta-info only
|
|
||||||
makeInfo[patch]="${patch:=0}" # Extra safety
|
|
||||||
|
|
||||||
echo "make"
|
echo "make"
|
||||||
for key in api patch branch build
|
echo " api = ${make_api}"
|
||||||
do
|
echo " patch = ${meta_patch:-0}" # <- From meta-info only
|
||||||
echo " $key = ${makeInfo[$key]}"
|
echo " branch = ${make_branch}"
|
||||||
done
|
echo " build = ${make_build}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
# Report meta info
|
# Report meta info
|
||||||
|
#
|
||||||
reportMetaInfo()
|
reportMetaInfo()
|
||||||
{
|
{
|
||||||
getMetaInfo
|
getMetaInfo
|
||||||
|
|
||||||
local patch="${metaInfo[patch]}" # <- From meta-info only
|
|
||||||
metaInfo[patch]="${patch:=0}" # Extra safety
|
|
||||||
|
|
||||||
echo "meta"
|
echo "meta"
|
||||||
for key in api patch branch build
|
echo " api = ${meta_api}"
|
||||||
do
|
echo " patch = ${meta_patch:-0}" # <- From meta-info only
|
||||||
echo " $key = ${metaInfo[$key]}"
|
echo " branch = ${meta_branch}"
|
||||||
done
|
echo " build = ${meta_build}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# Report diff between make and meta info (single key).
|
||||||
|
# Set diff_header prior to the first call.
|
||||||
|
# $1 == key
|
||||||
|
# $2 == make value
|
||||||
|
# $3 == meta value
|
||||||
|
unset diff_header
|
||||||
|
_reportDiff()
|
||||||
|
{
|
||||||
|
if [ -n "$diff_header" ]
|
||||||
|
then
|
||||||
|
echo "$diff_header"
|
||||||
|
unset diff_header
|
||||||
|
fi
|
||||||
|
echo "$1:"
|
||||||
|
echo " make $2"
|
||||||
|
echo " meta $3"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -350,50 +362,68 @@ reportMetaInfo()
|
|||||||
# $1 == verbose, print as diff. Silent otherwise
|
# $1 == verbose, print as diff. Silent otherwise
|
||||||
checkDiff()
|
checkDiff()
|
||||||
{
|
{
|
||||||
local verbose="$1"
|
local diff verbose
|
||||||
local key diff
|
|
||||||
|
if [ "$1" = "verbose" ]
|
||||||
|
then
|
||||||
|
diff_header="Differences"
|
||||||
|
verbose=true
|
||||||
|
fi
|
||||||
|
|
||||||
getMakeInfo
|
getMakeInfo
|
||||||
getMetaInfo
|
getMetaInfo
|
||||||
|
|
||||||
for key in api patch branch build
|
# api
|
||||||
do
|
if [ "${make_api}" != "${meta_api}" ]
|
||||||
if [ "${makeInfo[$key]}" != "${metaInfo[$key]}" ]
|
|
||||||
then
|
|
||||||
case "$key" in
|
|
||||||
(branch | build)
|
|
||||||
# Only trigger when make info (branch, build) are non-empty
|
|
||||||
if [ -n "${makeInfo[$key]}" ]
|
|
||||||
then
|
|
||||||
diff="$diff $key"
|
|
||||||
fi
|
|
||||||
|
|
||||||
;;
|
|
||||||
(*)
|
|
||||||
diff="$diff $key"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if [ "$verbose" = verbose ] && [ -n "$diff" ]
|
|
||||||
then
|
then
|
||||||
echo "Differences"
|
diff=true
|
||||||
for key in $diff
|
|
||||||
do
|
if [ -n "$verbose" ]
|
||||||
echo "$key:"
|
then
|
||||||
echo " make ${makeInfo[$key]}"
|
_reportDiff "api" "${make_api}" "${meta_api}"
|
||||||
echo " meta ${metaInfo[$key]}"
|
fi
|
||||||
done
|
fi
|
||||||
|
|
||||||
|
# patch
|
||||||
|
if [ "${make_patch}" != "${meta_patch}" ]
|
||||||
|
then
|
||||||
|
diff=true
|
||||||
|
|
||||||
|
if [ -n "$verbose" ]
|
||||||
|
then
|
||||||
|
_reportDiff "patch" "${make_patch}" "${meta_patch}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# branch - only test when make info is non-empty
|
||||||
|
if [ -n "${make_branch}" ] && [ "${make_branch}" != "${meta_branch}" ]
|
||||||
|
then
|
||||||
|
diff=true
|
||||||
|
|
||||||
|
if [ -n "$verbose" ]
|
||||||
|
then
|
||||||
|
_reportDiff "branch" "${make_branch}" "${meta_branch}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# build - only test when make info is non-empty
|
||||||
|
if [ -n "${make_build}" ] && [ "${make_build}" != "${meta_build}" ]
|
||||||
|
then
|
||||||
|
diff=true
|
||||||
|
|
||||||
|
if [ -n "$verbose" ]
|
||||||
|
then
|
||||||
|
_reportDiff "build" "${make_build}" "${meta_build}"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# No diffs, but never permit entirely empty values for build.
|
# No diffs, but never permit entirely empty values for build.
|
||||||
test -z "$diff" || test -z "${makeInfo[build]}${metaInfo[build]}"
|
test -z "$diff" || test -z "${make_build}${meta_build}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Update metaInfo (on disk) based on the makeInfo
|
# Update meta info (on disk) based on the make info
|
||||||
#
|
#
|
||||||
performUpdate()
|
performUpdate()
|
||||||
{
|
{
|
||||||
@ -401,16 +431,16 @@ performUpdate()
|
|||||||
getMetaInfo
|
getMetaInfo
|
||||||
|
|
||||||
# Local copies of the make info
|
# Local copies of the make info
|
||||||
local api="${makeInfo[api]}"
|
local api="${make_api}"
|
||||||
local branch="${makeInfo[branch]}"
|
local branch="${make_branch}"
|
||||||
local build="${makeInfo[build]}"
|
local build="${make_build}"
|
||||||
local patch="${makeInfo[patch]}"
|
local patch="${make_patch}"
|
||||||
|
|
||||||
# If any of the make-info are empty (bad),
|
# If any of the make-info are empty (bad),
|
||||||
# use the meta-info to avoid spurious changes
|
# use the meta-info to avoid spurious changes
|
||||||
[ -n "$api" ] || api="${metaInfo[api]}"
|
[ -n "$api" ] || api="${meta_api}"
|
||||||
[ -n "$branch" ] || branch="${metaInfo[branch]}"
|
[ -n "$branch" ] || branch="${meta_branch}"
|
||||||
[ -n "$build" ] || build="${metaInfo[build]}"
|
[ -n "$build" ] || build="${meta_build}"
|
||||||
|
|
||||||
# Fallback to WM_PROJECT_VERSION alone
|
# Fallback to WM_PROJECT_VERSION alone
|
||||||
[ -n "$build" ] || build="${WM_PROJECT_VERSION:-unknown}"
|
[ -n "$build" ] || build="${WM_PROJECT_VERSION:-unknown}"
|
||||||
@ -419,12 +449,11 @@ performUpdate()
|
|||||||
|
|
||||||
# build-info
|
# build-info
|
||||||
outputFile="$metaInfoDir/build-info"
|
outputFile="$metaInfoDir/build-info"
|
||||||
if [ "$branch" != "${metaInfo[branch]}" ] || \
|
if [ "$branch" != "${meta_branch}" ] || \
|
||||||
[ "$build" != "${metaInfo[build]}" ] || \
|
[ "$build" != "${meta_build}" ] || \
|
||||||
[ "$patch" != "${metaInfo[patch]}" ]
|
[ "$patch" != "${meta_patch}" ]
|
||||||
then
|
then
|
||||||
patch="${metaInfo[patch]}" # <- From meta-info only
|
patch="${meta_patch:-0}" # <- From meta-info only
|
||||||
: "${patch:=0}" # Extra safety
|
|
||||||
|
|
||||||
if [ -n "$optDryRun" ]
|
if [ -n "$optDryRun" ]
|
||||||
then
|
then
|
||||||
@ -441,10 +470,9 @@ performUpdate()
|
|||||||
|
|
||||||
# api-info
|
# api-info
|
||||||
outputFile="$metaInfoDir/api-info"
|
outputFile="$metaInfoDir/api-info"
|
||||||
if [ "$api" != "${metaInfo[api]}" ]
|
if [ "$api" != "${meta_api}" ]
|
||||||
then
|
then
|
||||||
patch="${metaInfo[patch]}" # <- From meta-info only
|
patch="${meta_patch:-0}" # <- From meta-info only
|
||||||
: "${patch:=0}" # Extra safety
|
|
||||||
|
|
||||||
if [ -n "$optDryRun" ]
|
if [ -n "$optDryRun" ]
|
||||||
then
|
then
|
||||||
@ -461,8 +489,7 @@ performUpdate()
|
|||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Update metaInfo (on disk) based on the makeInfo
|
# Update meta info (on disk) based on the make info
|
||||||
# This is the
|
|
||||||
#
|
#
|
||||||
performFiltering()
|
performFiltering()
|
||||||
{
|
{
|
||||||
@ -477,11 +504,10 @@ performFiltering()
|
|||||||
getMetaInfo
|
getMetaInfo
|
||||||
|
|
||||||
# Local copies of the make info
|
# Local copies of the make info
|
||||||
local api="${makeInfo[api]}"
|
local api="${make_api}"
|
||||||
local branch="${makeInfo[branch]}"
|
local branch="${make_branch}"
|
||||||
local build="${makeInfo[build]}"
|
local build="${make_build}"
|
||||||
local patch="${metaInfo[patch]}" # <- From meta-info only
|
local patch="${meta_patch:-0}" # <- From meta-info only
|
||||||
: "${patch:=0}" # Extra safety
|
|
||||||
|
|
||||||
|
|
||||||
# If any of the make-info are empty (bad),
|
# If any of the make-info are empty (bad),
|
||||||
@ -492,19 +518,20 @@ performFiltering()
|
|||||||
|
|
||||||
if [ -z "$api" ]
|
if [ -z "$api" ]
|
||||||
then
|
then
|
||||||
api="${metaInfo[api]}"
|
api="${meta_api}"
|
||||||
api="${api:-0}" # integer value
|
api="${api:-0}" # integer value
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# branch/build could be missing for non-git
|
# branch/build could be missing for non-git
|
||||||
if [ -z "$branch" ]
|
if [ -z "$branch" ]
|
||||||
then
|
then
|
||||||
branch="${metaInfo[branch]}"
|
branch="${meta_branch}"
|
||||||
branch="${branch:-unknown}"
|
branch="${branch:-unknown}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$build" ]
|
if [ -z "$build" ]
|
||||||
then
|
then
|
||||||
build="${metaInfo[build]}"
|
build="${meta_build}"
|
||||||
# Fallback to WM_PROJECT_VERSION
|
# Fallback to WM_PROJECT_VERSION
|
||||||
build="${build:-${WM_PROJECT_VERSION:-unknown}}"
|
build="${build:-${WM_PROJECT_VERSION:-unknown}}"
|
||||||
fi
|
fi
|
||||||
@ -523,7 +550,7 @@ performFiltering()
|
|||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Dispatching
|
# Dispatch
|
||||||
|
|
||||||
if [ -n "$optCheck" ]
|
if [ -n "$optCheck" ]
|
||||||
then
|
then
|
||||||
|
|||||||
Reference in New Issue
Block a user