mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: add hook for bear frontend to create json output (#1936)
Example usage,
wmake -with-bear src/OpenFOAM
src/Allwmake -with-bear -s -j
- bin/tools/vscode-settings
Emit some json content suitable for setting up Visual Studio Code
for use with OpenFOAM.
For example,
bin/tools/vscode-settings > .vscode/settings.json
Ideas from Volker Weissman
This commit is contained in:
@ -38,6 +38,13 @@
|
||||
# -l | -log | -log=FILE
|
||||
# -prefix=... same as -module-prefix=...
|
||||
#
|
||||
# Trapped options
|
||||
# -with-bear
|
||||
#
|
||||
# Note
|
||||
# Locally handled options (eg, -log) must preceeded trapped options
|
||||
# such as -with-bear. This is non-intuitive, but not easily fixed.
|
||||
#
|
||||
#------------------------------------------------------------------------------
|
||||
# Check environment
|
||||
[ -d "$WM_PROJECT_DIR" ] || {
|
||||
@ -80,6 +87,7 @@ USAGE
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
unset optDebug optLog optNonRecursive optPrefix optQueue
|
||||
unset optWmakeFrontend
|
||||
|
||||
for arg in "$@"
|
||||
do
|
||||
@ -91,6 +99,12 @@ do
|
||||
usage
|
||||
;;
|
||||
|
||||
-with-bear)
|
||||
# Everything wrapped via 'bear'
|
||||
optWmakeFrontend="-with-bear"
|
||||
break # Stop now, continue with wmake
|
||||
;;
|
||||
|
||||
-no-recurs* | -fromWmake)
|
||||
# Avoid recursion (eg, if called from wmake)
|
||||
optNonRecursive=true
|
||||
@ -183,12 +197,14 @@ if [ -z "$optNonRecursive" ]
|
||||
then
|
||||
if [ -z "$optLog" ]
|
||||
then
|
||||
exec wmake -all $optDebug $optQueue $*
|
||||
exec wmake $optWmakeFrontend -all \
|
||||
$optDebug $optQueue $*
|
||||
exit $? # Unneeded, but just in case something went wrong
|
||||
else
|
||||
echo "Logging wmake -all output to '$optLog'" 1>&2
|
||||
echo 1>&2
|
||||
exec wmake -all $optDebug $optQueue $* 2>&1 | /usr/bin/tee $optLog
|
||||
exec wmake $optWmakeFrontend -all \
|
||||
$optDebug $optQueue $* 2>&1 | /usr/bin/tee $optLog
|
||||
# Need to cleanup after the tee
|
||||
rc=$? # Error code from tee (not wmake), but not entirely important
|
||||
echo "Done logging to '$optLog'" 1>&2
|
||||
@ -211,6 +227,7 @@ fi
|
||||
# Cleanup local variables and functions
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
unset optWmakeFrontend
|
||||
unset optNonRecursive optDebug optLog optPrefix optQueue
|
||||
unset -f usage
|
||||
|
||||
|
||||
158
wmake/scripts/wmake-with-bear
Executable file
158
wmake/scripts/wmake-with-bear
Executable file
@ -0,0 +1,158 @@
|
||||
#!/bin/sh
|
||||
#------------------------------------------------------------------------------
|
||||
# ========= |
|
||||
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
# \\ / O peration |
|
||||
# \\ / A nd | www.openfoam.com
|
||||
# \\/ M anipulation |
|
||||
#-------------------------------------------------------------------------------
|
||||
# Copyright (C) 2020 OpenCFD Ltd.
|
||||
#------------------------------------------------------------------------------
|
||||
# License
|
||||
# This file is part of OpenFOAM, distributed under GPL-3.0-or-later.
|
||||
#
|
||||
# Script
|
||||
# wmake/scripts/wmake-with-bear
|
||||
# Backend for "wmake -with-bear"
|
||||
#
|
||||
# Usage
|
||||
# wmake-with-bear [wmake options and args]
|
||||
#
|
||||
# Description
|
||||
# Call wmake via 'bear' to create json output.
|
||||
#
|
||||
# Environment
|
||||
# WM_PROJECT_DIR, WM_PROJECT_USER_DIR, WM_OPTIONS
|
||||
#
|
||||
#-------------------------------------------------------------------------------
|
||||
cacheDirName="build/$WM_OPTIONS"
|
||||
|
||||
printHelp() {
|
||||
cat<<USAGE
|
||||
|
||||
Usage: ${0##*/} [wmake options and args]
|
||||
|
||||
options:
|
||||
-bear-output-dir=DIR Specify output directory
|
||||
-version Print bear version
|
||||
-h | -help Display short help and exit
|
||||
|
||||
Call wmake via 'bear' to create json output.
|
||||
Output: ${outputDir:-"${WM_PROJECT_DIR:-<project>}/$cacheDirName"}
|
||||
|
||||
USAGE
|
||||
exit 0 # A clean exit
|
||||
}
|
||||
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
unset optVersion outputDir
|
||||
|
||||
# Parse options
|
||||
while [ "$#" -gt 0 ]
|
||||
do
|
||||
case "$1" in
|
||||
'') ;;
|
||||
--) shift; break ;;
|
||||
|
||||
-h | -help*)
|
||||
printHelp
|
||||
;;
|
||||
|
||||
-version)
|
||||
optVersion=true
|
||||
break
|
||||
;;
|
||||
|
||||
-bear-output-dir=*)
|
||||
outputDir="${1#*=}"
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
# Detect version. Seems to be stderr for some versions!?
|
||||
if version="$(bear --version 2>&1)"
|
||||
then
|
||||
version="$(echo "$version" | sed -ne '1{ s/^[^0-9]*\([1-9]\)/\1/p }')"
|
||||
else
|
||||
unset version
|
||||
fi
|
||||
|
||||
if [ "$optVersion" = true ]
|
||||
then
|
||||
echo "bear=$(command -v bear)"
|
||||
echo "version=${version:-missing}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Not found? Can stop immediately
|
||||
if [ -z "$version" ]
|
||||
then
|
||||
echo "Warning: bear not found" 1>&2
|
||||
echo "Stopping" 1>&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
|
||||
unset outputFile
|
||||
setOutput()
|
||||
{
|
||||
if [ -z "$outputDir" ]
|
||||
then
|
||||
prefixDir="$WM_PROJECT_DIR"
|
||||
if ! [ -w "$prefixDir" ]
|
||||
then
|
||||
echo "Non-writable directory: $prefixDir" 1>&2
|
||||
echo "Try with user location" 1>&2
|
||||
prefixDir="$WM_PROJECT_USER_DIR"
|
||||
|
||||
if ! [ -w "$prefixDir" ]
|
||||
then
|
||||
echo "Non-writable directory: $prefixDir" 1>&2
|
||||
echo "Using home directory" 1>&2
|
||||
prefixDir="$HOME"
|
||||
fi
|
||||
fi
|
||||
outputDir="$prefixDir/$cacheDirName"
|
||||
fi
|
||||
|
||||
mkdir -p "$outputDir"
|
||||
outputFile="$outputDir/compile_commands.json"
|
||||
echo "Output = $outputFile" 1>&2
|
||||
}
|
||||
|
||||
|
||||
case "$version" in
|
||||
(2.*)
|
||||
# Version 2
|
||||
echo "Use bear $version" 1>&2
|
||||
setOutput
|
||||
exec bear --append -o "$outputFile" wmake "$@"
|
||||
;;
|
||||
|
||||
([3-9].* | [1-9][0-9].*)
|
||||
# Version 3 or newer
|
||||
echo "Use bear $version" 1>&2
|
||||
setOutput
|
||||
exec bear --append --output "$outputFile" -- wmake "$@"
|
||||
;;
|
||||
|
||||
(*)
|
||||
# Unknown version or some other error
|
||||
echo "Warning: bear $version" 1>&2
|
||||
echo "Stopping" 1>&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Should never reach here
|
||||
exit $?
|
||||
|
||||
#------------------------------------------------------------------------------
|
||||
Reference in New Issue
Block a user