mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
MISC: extend foamGrep...Targets tools
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
# \\ / A nd | www.openfoam.com
|
||||
# \\/ M anipulation |
|
||||
#------------------------------------------------------------------------------
|
||||
# Copyright (C) 2016 OpenCFD Ltd.
|
||||
# Copyright (C) 2016-2025 OpenCFD Ltd.
|
||||
#------------------------------------------------------------------------------
|
||||
# License
|
||||
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||
@ -22,22 +22,25 @@
|
||||
# Confirm that all available EXE targets have actually been created:
|
||||
#
|
||||
# foamGrepExeTargets > targets-available
|
||||
# foamGrepExeTargets -appbin > targets-created
|
||||
# foamGrepExeTargets -bin > targets-created
|
||||
# diff -uw targets-available targets-created
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
usage() {
|
||||
exec 1>&2
|
||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||
cat<<USAGE
|
||||
usage: ${0##*/}
|
||||
-appbin list contents of \$FOAM_APPBIN (no git required)
|
||||
-help
|
||||
# Locations
|
||||
FOAM_GIT_DIR="$WM_PROJECT_DIR/.git"
|
||||
|
||||
List available EXE= targets. Requires git.
|
||||
printHelp() {
|
||||
cat<<USAGE
|
||||
|
||||
usage: ${0##*/}
|
||||
-bin List contents of \$FOAM_APPBIN (no git required)
|
||||
-no-git Disable use of git for obtaining information
|
||||
-help Print the usage
|
||||
|
||||
List exe targets (contains EXE). Uses git when possible
|
||||
|
||||
USAGE
|
||||
exit 1
|
||||
exit 0 # clean exit
|
||||
}
|
||||
|
||||
# Report error and exit
|
||||
@ -55,54 +58,63 @@ die()
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
unset projectdir
|
||||
for i in "./.git" "$WM_PROJECT_DIR/.git"
|
||||
do
|
||||
if [ -d "$i" ]
|
||||
then
|
||||
projectdir="${i%/*}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
# Parse options
|
||||
while [ "$#" -gt 0 ]
|
||||
do
|
||||
case "$1" in
|
||||
-h | -help*)
|
||||
usage
|
||||
-h | -help* | --help*)
|
||||
printHelp
|
||||
;;
|
||||
|
||||
-appbin)
|
||||
test -n "$FOAM_APPBIN" && cd "$FOAM_APPBIN" || \
|
||||
-bin)
|
||||
if [ -n "$FOAM_APPBIN" ] && cd "$FOAM_APPBIN"
|
||||
then
|
||||
/bin/ls -1
|
||||
exit 0
|
||||
else
|
||||
die "FOAM_APPBIN is not valid"
|
||||
|
||||
/bin/ls -1
|
||||
exit 0
|
||||
fi
|
||||
;;
|
||||
-no-git)
|
||||
unset FOAM_GIT_DIR
|
||||
;;
|
||||
*)
|
||||
die "unknown option/argument: '$1'"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Default is grep (via git)
|
||||
|
||||
[ -d "$projectdir" ] || \
|
||||
die "Cannot locate OpenFOAM project, or it does not have a git directory"
|
||||
# Check environment variables
|
||||
[ -d "$WM_PROJECT_DIR" ] || \
|
||||
die "Bad or unset environment variable: \$WM_PROJECT_DIR"
|
||||
|
||||
cd "$WM_PROJECT_DIR" || die "No project directory: $WM_PROJECT_DIR"
|
||||
|
||||
# Run from top-level directory - otherwise the grep is quite difficult
|
||||
# A version with 'find' is likewise possible, but not as fast.
|
||||
|
||||
# Check 'src' too, in case somehow something is there as well.
|
||||
(
|
||||
cd "$projectdir" && \
|
||||
git grep --cached -P '^\s*EXE\s*=' \
|
||||
applications/solvers \
|
||||
applications/utilities \
|
||||
src
|
||||
) | sed -e 's@.*/@@' | sort | uniq
|
||||
for dir in applications/solvers applications/utilities src
|
||||
do
|
||||
if [ -d "$dir" ]
|
||||
then
|
||||
echo "Checking: $dir" 1>&2
|
||||
else
|
||||
echo "No directory: $dir" 1>&2
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ -d "$FOAM_GIT_DIR" ]
|
||||
then
|
||||
git grep --cached -H -P '^\s*EXE\s*=' "$dir" 2>/dev/null
|
||||
else
|
||||
# Filesystem find (not quite as fast)
|
||||
for i in $(find "$dir" -name files)
|
||||
do
|
||||
grep -H -P '^\s*EXE\s*=' "$i" 2>/dev/null
|
||||
done
|
||||
fi
|
||||
done | sed -ne 's@/Make/files:.*$@@p' | sed -e 's@.*/@@' | sort | uniq
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
125
bin/tools/foamGrepLibTargets
Executable file
125
bin/tools/foamGrepLibTargets
Executable file
@ -0,0 +1,125 @@
|
||||
#!/bin/sh
|
||||
#------------------------------------------------------------------------------
|
||||
# ========= |
|
||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
# \\ / O peration |
|
||||
# \\ / A nd | www.openfoam.com
|
||||
# \\/ M anipulation |
|
||||
#------------------------------------------------------------------------------
|
||||
# Copyright (C) 2025 OpenCFD Ltd.
|
||||
#------------------------------------------------------------------------------
|
||||
# License
|
||||
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||
#
|
||||
# Script
|
||||
# foamGrepLibTargets
|
||||
#
|
||||
# Description
|
||||
# List library targets (contain "LIB_LIBS =")
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
# Locations
|
||||
FOAM_GIT_DIR="$WM_PROJECT_DIR/.git"
|
||||
|
||||
printHelp() {
|
||||
cat<<USAGE
|
||||
|
||||
usage: ${0##*/}
|
||||
-no-git Disable use of git for obtaining information
|
||||
-app Search applications/solvers/ applications/utilities/
|
||||
-src Search src/
|
||||
-no-git Disable use of git for obtaining information
|
||||
-help Print the usage
|
||||
|
||||
List library targets (contains LIB_LIBS). Uses git when possible
|
||||
|
||||
USAGE
|
||||
exit 0 # clean exit
|
||||
}
|
||||
|
||||
# Report error and exit
|
||||
die()
|
||||
{
|
||||
exec 1>&2
|
||||
echo
|
||||
echo "Error encountered:"
|
||||
while [ "$#" -ge 1 ]; do echo " $1"; shift; done
|
||||
echo
|
||||
echo "See '${0##*/} -help' for usage"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
unset locations
|
||||
|
||||
# Parse options
|
||||
while [ "$#" -gt 0 ]
|
||||
do
|
||||
case "$1" in
|
||||
-h | -help* | --help*)
|
||||
printHelp
|
||||
;;
|
||||
|
||||
-app)
|
||||
locations="$locations applications/solvers applications/utilities"
|
||||
;;
|
||||
|
||||
-src)
|
||||
locations="$locations src"
|
||||
;;
|
||||
|
||||
-no-git)
|
||||
unset FOAM_GIT_DIR
|
||||
;;
|
||||
*)
|
||||
die "unknown option/argument: '$1'"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Check environment variables
|
||||
[ -d "$WM_PROJECT_DIR" ] || \
|
||||
die "Bad or unset environment variable: \$WM_PROJECT_DIR"
|
||||
|
||||
# Fallback to all locations
|
||||
if [ -z "$locations" ]
|
||||
then
|
||||
locations="applications/solvers applications/utilities src"
|
||||
fi
|
||||
|
||||
set -- $locations
|
||||
|
||||
if [ "$#" -eq 0 ]
|
||||
then
|
||||
die "No search locations"
|
||||
fi
|
||||
|
||||
# Run from top-level directory - otherwise the grep is quite difficult
|
||||
|
||||
cd "$WM_PROJECT_DIR" || die "No project directory: $WM_PROJECT_DIR"
|
||||
|
||||
for dir in "$@"
|
||||
do
|
||||
if [ -d "$dir" ]
|
||||
then
|
||||
echo "Checking: $dir" 1>&2
|
||||
else
|
||||
echo "No directory: $dir" 1>&2
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ -d "$FOAM_GIT_DIR" ]
|
||||
then
|
||||
git grep --cached -H -P '^\s*LIB_LIBS\s*=' "$dir" 2>/dev/null
|
||||
else
|
||||
# Filesystem find (not quite as fast)
|
||||
for i in $(find "$dir" -name options)
|
||||
do
|
||||
grep -H -P '^\s*LIB_LIBS\s*=' "$i" 2>/dev/null
|
||||
done
|
||||
fi
|
||||
done | sed -ne 's@/Make/options:.*$@@p' | sort | uniq
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user