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.
This commit is contained in:
Mark Olesen
2020-05-11 10:55:23 +02:00
parent 8bd9f41efd
commit 9e3d06853e
17 changed files with 282 additions and 207 deletions

View File

@ -4,7 +4,7 @@ SUFFIXES += .Cver
# Update strings in C++ file and in META-INFO files
Cvertoo = \
wmakeBuildInfo -update -filter $< > $(@D)/$(<F).C; \
$(WM_SCRIPTS)/wmake-build-info -update -filter $< > $(@D)/$(<F).C; \
$(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
#------------------------------------------------------------------------------

View File

@ -6,11 +6,10 @@
# \\ / A nd | www.openfoam.com
# \\/ M anipulation |
#------------------------------------------------------------------------------
# Copyright (C) 2017-2018 OpenCFD Ltd.
# Copyright (C) 2017-2020 OpenCFD Ltd.
#------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
# 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<<ERROR
${0##*/}: Error incorrect top-level directory

View File

@ -12,7 +12,8 @@
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
#
# Script
# wmakeBuildInfo
# wmake/scripts/wmake-build-info
# Backend for "wmake -build-info"
#
# Description
# Print the api/version and other build information for the project.
@ -22,10 +23,19 @@
# - WM_PROJECT_VERSION
# - WM_DIR (unset defaults to WM_PROJECT_DIR/wmake)
#
# Files
# - META-INFO/{api-info,build-info}
# - wmake/rules/General/general
# - debian : implicitly disables git queries
#
# Note
# Partial logic is also implemented in the bin/foamEtcFile
# -show-api and -show-patch options.
# Make sure that changes here are also reflected there.
# When a 'debian/' directory exists, the '.git/' directory is most
# likely 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.
#
# SeeAlso
# META-INFO/README.md for other routines that also use META-INFO.
#
#------------------------------------------------------------------------------
# Locations
@ -33,11 +43,9 @@ rulesFile="${WM_DIR:-$WM_PROJECT_DIR/wmake}/rules/General/general"
META_INFO="$WM_PROJECT_DIR/META-INFO"
FOAM_GIT_DIR="$WM_PROJECT_DIR/.git"
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
printHelp() {
cat<<USAGE
Usage: ${0##*/} [OPTION]
${0##*/} [-update] -filter FILE
options:
@ -56,7 +64,7 @@ options:
-show-patch Print patch value from meta-info and exit
-help Print the usage
Query/manage status of api,branch,build information.
Query/manage status of {api,branch,build} information.
Default without any arguments is the same as '-query-make'.
USAGE
@ -85,7 +93,7 @@ while [ "$#" -gt 0 ]
do
case "$1" in
-h | -help*)
usage
printHelp
;;
-cmp | -check)
optCheck=true
@ -124,7 +132,7 @@ do
unset FOAM_GIT_DIR
;;
*)
die "unknown option/argument: '$1'"
die "Unknown option/argument: '$1'"
;;
esac
shift
@ -137,6 +145,11 @@ done
[ -d "$META_INFO" ] || \
die "No ${META_INFO##*/}/ directory for project"
# Disable git queries for debian packaging (see notes above)
if [ -d "$WM_PROJECT_DIR/debian" ]
then
unset FOAM_GIT_DIR
fi
#------------------------------------------------------------------------------
@ -146,7 +159,7 @@ then
if [ -f "$META_INFO/build-info" ]
then
echo "Removing project ${META_INFO##*/}/build-info" 1>&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

134
wmake/scripts/wmake-check-dir Executable file
View File

@ -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 <dir>
# wmake-check-dir <dir> <dir2>
#
# 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<<USAGE
Usage: ${0##*/} [OPTION] dir [dir2]
options:
-q | -quiet suppress all normal output
-h | -help display short help and exit
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
Exit status 1 on error
USAGE
exit 0 # A clean exit
}
# Report error and exit
unset optQuiet
die()
{
if [ -z "$optQuiet" ]
then
exec 1>&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
#------------------------------------------------------------------------------

View File

@ -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"

View File

@ -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<<HELP_HEAD
Usage: $Script [OPTION] [dir]
$Script [OPTION] target [dir [MakeDir]]
$Script -subcommand ...
options:
-s | -silent Silent mode (does not echo commands)
-s | -silent Silent mode (do not echo commands)
-a | -all wmake all sub-directories, running Allwmake if present
-q | -queue wmakeCollect sub-directories, running Allwmake if present
-k | -keep-going Keep going even when errors occur (-non-stop)
-j | -jN | -j N Compile using all or specified N cores/hyperthreads
-update Update lnInclude dirs, dep files, remove deprecated files/dirs
-update Update lnInclude, dep files, remove deprecated files/dirs
HELP_HEAD
if [ -n "$1" ]
@ -95,20 +97,36 @@ cat<<HELP_FULL
HELP_FULL
fi
cat<<HELP_TAIL_COMMON
cat<<TAIL_OPTIONS
-pwd Print root directory containing a Make/ directory
-version | --version Print version (same as -show-api)
-h | -help Display short help and exit
-help-full Display full help and exit
A general, easy-to-use make system for multi-platform development
with support for local and network parallel compilation.
subcommands (wmake subcommand -help for more information):
TAIL_OPTIONS
if [ -n "$1" ]
then
cat<<HELP_SUBCOMMANDS
-build-info Query/manage status of {api,branch,build} information
-check-dir Check directory equality
HELP_SUBCOMMANDS
else
cat<<HELP_SUBCOMMANDS
-build-info -check-dir
HELP_SUBCOMMANDS
fi
cat<<HELP_TAIL_COMMON
General, wrapped make system for multi-platform development.
HELP_TAIL_COMMON
if [ -n "$1" ]
then
cat<<HELP_TAIL_FULL
Makefile targets: platforms/linux64GccDPInt32Opt/.../fvMesh.o (for example)
Special targets:
all | queue Same as -all | -queue options
@ -116,8 +134,8 @@ Special targets:
lib Compile statically linked archive lib (.a)
libo Compile statically linked lib (.o)
libso Compile dynamically linked lib (.so)
dep Compile lnInclude and dependencies only
updatedep Compile dependencies only (in case of broken dependencies)
dep Create lnInclude and dependencies only
updatedep Create dependencies only (in case of broken dependencies)
objects Compile but not link
Environment
@ -126,6 +144,7 @@ Environment
HELP_TAIL_FULL
else
cat<<HELP_TAIL_BRIEF
Some special targets (see -help-full for details):
all | queue Same as -all | -queue options
exe Executables
@ -169,7 +188,12 @@ allCores()
#------------------------------------------------------------------------------
# Default to compiling the local target only
unset all update optDebug optShow optPrintRootDir
unset optAll optUpdate optDebug optQuiet optShow optPwd
# Consistency with inherited values
if [ "$WM_QUIET" = true ]
then optQuiet=true
fi
while [ "$#" -gt 0 ]
do
@ -180,7 +204,23 @@ do
-h | -help*) # Short help
printHelp
;;
# Forward to scripts/wmake-build-info
-build-info) shift
exec "$scriptsDir/wmake-build-info" "$@"
exit $?
;;
# Forward to scripts/wmake-check-dir
# Out of order options: (-quiet)
-check-dir) shift
exec "$scriptsDir/wmake-check-dir" \
${optQuiet:+-silent} "$@"
exit $?
;;
-s | -silent)
optQuiet=true
export WM_QUIET=true
;;
-debug)
@ -197,10 +237,10 @@ do
optShow=true
;;
-a | -all | all)
all=all
optAll=all
;;
-q | -queue | queue)
all=queue
optAll=queue
;;
# Parallel compilation on all cores (or specified number of cores)
-j)
@ -231,7 +271,7 @@ do
;;
# Print root directory containing a Make/ directory and exit
-pwd)
optPrintRootDir=true
optPwd=true
;;
# Meant to be used following a pull, this will:
# - remove dep files that depend on deleted files;
@ -240,8 +280,8 @@ do
# - remove empty directories, along with deprecated object directories
# and respective binaries.
-update)
update=true
: "${all:=all}" # implies 'all', unless previous set to 'queue' etc.
optUpdate=true
: "${optAll:=all}" # implies 'all', unless previously set
;;
-version | --version)
$make -f $WM_DIR/makefiles/info api
@ -311,7 +351,7 @@ MakeDir=Make
unset dir
if [ -n "$optPrintRootDir" ]
if [ -n "$optPwd" ]
then
if [ $# -ge 1 ]
then
@ -322,10 +362,7 @@ then
then
dir="${1%/*}"
: "${dir:=.}"
if [ "$dir" = "$1" ]
then
dir="."
fi
[ "$dir" != "$1" ] || dir="."
else
echo "$Script error: not a file or directory" 1>&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////_}"

View File

@ -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 <http://www.gnu.org/licenses/>.
#
# Script
# wmakeCheckPwd
#
# Usage
# wmakeCheckPwd <dir>
#
# Description
# Check that the current working directory is the directory <dir>.
# 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<<USAGE
Usage: $Script [OPTION] dirName
options:
-q | -quiet suppress all normal output
Check that the current working directory is the directory <dir>
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 <dir>
[ -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
#------------------------------------------------------------------------------

1
wmake/wmakeCheckPwd Symbolic link
View File

@ -0,0 +1 @@
scripts/wmake-check-dir

View File

@ -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