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
|
# \\ / A nd | www.openfoam.com
|
||||||
# \\/ M anipulation |
|
# \\/ M anipulation |
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# Copyright (C) 2016 OpenCFD Ltd.
|
# Copyright (C) 2016-2025 OpenCFD Ltd.
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
# License
|
# License
|
||||||
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
# 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:
|
# Confirm that all available EXE targets have actually been created:
|
||||||
#
|
#
|
||||||
# foamGrepExeTargets > targets-available
|
# foamGrepExeTargets > targets-available
|
||||||
# foamGrepExeTargets -appbin > targets-created
|
# foamGrepExeTargets -bin > targets-created
|
||||||
# diff -uw targets-available targets-created
|
# diff -uw targets-available targets-created
|
||||||
#
|
#
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
usage() {
|
# Locations
|
||||||
exec 1>&2
|
FOAM_GIT_DIR="$WM_PROJECT_DIR/.git"
|
||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
|
||||||
cat<<USAGE
|
|
||||||
usage: ${0##*/}
|
|
||||||
-appbin list contents of \$FOAM_APPBIN (no git required)
|
|
||||||
-help
|
|
||||||
|
|
||||||
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
|
USAGE
|
||||||
exit 1
|
exit 0 # clean exit
|
||||||
}
|
}
|
||||||
|
|
||||||
# Report error and 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
|
# Parse options
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-h | -help*)
|
-h | -help* | --help*)
|
||||||
usage
|
printHelp
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-appbin)
|
-bin)
|
||||||
test -n "$FOAM_APPBIN" && cd "$FOAM_APPBIN" || \
|
if [ -n "$FOAM_APPBIN" ] && cd "$FOAM_APPBIN"
|
||||||
|
then
|
||||||
|
/bin/ls -1
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
die "FOAM_APPBIN is not valid"
|
die "FOAM_APPBIN is not valid"
|
||||||
|
fi
|
||||||
/bin/ls -1
|
;;
|
||||||
exit 0
|
-no-git)
|
||||||
|
unset FOAM_GIT_DIR
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
die "unknown option/argument: '$1'"
|
die "unknown option/argument: '$1'"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
# Default is grep (via git)
|
# Check environment variables
|
||||||
|
[ -d "$WM_PROJECT_DIR" ] || \
|
||||||
[ -d "$projectdir" ] || \
|
die "Bad or unset environment variable: \$WM_PROJECT_DIR"
|
||||||
die "Cannot locate OpenFOAM project, or it does not have a git directory"
|
|
||||||
|
|
||||||
|
cd "$WM_PROJECT_DIR" || die "No project directory: $WM_PROJECT_DIR"
|
||||||
|
|
||||||
# Run from top-level directory - otherwise the grep is quite difficult
|
# Run from top-level directory - otherwise the grep is quite difficult
|
||||||
# A version with 'find' is likewise possible, but not as fast.
|
# A version with 'find' is likewise possible, but not as fast.
|
||||||
|
|
||||||
# Check 'src' too, in case somehow something is there as well.
|
# Check 'src' too, in case somehow something is there as well.
|
||||||
(
|
for dir in applications/solvers applications/utilities src
|
||||||
cd "$projectdir" && \
|
do
|
||||||
git grep --cached -P '^\s*EXE\s*=' \
|
if [ -d "$dir" ]
|
||||||
applications/solvers \
|
then
|
||||||
applications/utilities \
|
echo "Checking: $dir" 1>&2
|
||||||
src
|
else
|
||||||
) | sed -e 's@.*/@@' | sort | uniq
|
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