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:
148
bin/tools/vscode-settings
Executable file
148
bin/tools/vscode-settings
Executable file
@ -0,0 +1,148 @@
|
|||||||
|
#!/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
|
||||||
|
# bin/tools/vscode-settings
|
||||||
|
#
|
||||||
|
# Description
|
||||||
|
# Emit some settings for Visual Studio Code + OpenFOAM
|
||||||
|
#
|
||||||
|
# Example
|
||||||
|
# bin/tools/vscode-settings > .vscode/settings.json
|
||||||
|
# etc/openfoam -spdp -int64 bin/tools/vscode-settings
|
||||||
|
#
|
||||||
|
# Environment
|
||||||
|
# WM_PROJECT_DIR, WM_PROJECT_USER_DIR, WM_OPTIONS
|
||||||
|
#
|
||||||
|
# More information:
|
||||||
|
# https://openfoamwiki.net/index.php/HowTo_Use_OpenFOAM_with_Visual_Studio_Code
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# Values consistent with wmake-with-bear
|
||||||
|
cacheDirName="build/$WM_OPTIONS"
|
||||||
|
|
||||||
|
printHelp() {
|
||||||
|
cat<<USAGE
|
||||||
|
|
||||||
|
Usage: ${0##*/} [OPTIONS]
|
||||||
|
|
||||||
|
options:
|
||||||
|
-help Print the usage
|
||||||
|
|
||||||
|
Emit some settings for Visual Studio Code + OpenFOAM
|
||||||
|
|
||||||
|
For example,
|
||||||
|
bin/tools/vscode-settings > .vscode/settings.json
|
||||||
|
etc/openfoam -spdp -int64 bin/tools/vscode-settings
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
exit 0 # clean exit
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
unset outputDir
|
||||||
|
|
||||||
|
# Parse options
|
||||||
|
while [ "$#" -gt 0 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
-h | -help*)
|
||||||
|
printHelp
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Unknown option/argument: '$1'" 1>&2
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# Report settings and flag errors
|
||||||
|
projectDir="$WM_PROJECT_DIR"
|
||||||
|
session="$projectDir"/etc/openfoam
|
||||||
|
|
||||||
|
echo "project: ${WM_PROJECT_DIR:?OpenFOAM environment not set?}" 1>&2
|
||||||
|
echo "options: ${WM_OPTIONS:?not set}" 1>&2
|
||||||
|
if [ -x "$session" ]
|
||||||
|
then
|
||||||
|
echo "session: $session" 1>&2
|
||||||
|
else
|
||||||
|
echo "No session: $session" 1>&2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -z "$outputDir" ]
|
||||||
|
then
|
||||||
|
prefixDir="$projectDir"
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
## echo "Output = $outputDir" 1>&2
|
||||||
|
|
||||||
|
# JSON output. Long entries are outdented.
|
||||||
|
cat << INFO 1>&2
|
||||||
|
# -------------------------
|
||||||
|
# Some settings for Visual Studio Code + OpenFOAM
|
||||||
|
# -------------------------
|
||||||
|
INFO
|
||||||
|
|
||||||
|
echo '{' # BEGIN_LIST
|
||||||
|
|
||||||
|
# ccls integration
|
||||||
|
cat << JSON_CONTENT
|
||||||
|
"ccls.cache.directory":
|
||||||
|
"$outputDir/ccls-cache",
|
||||||
|
|
||||||
|
"ccls.misc.compilationDatabaseDirectory":
|
||||||
|
"$outputDir",
|
||||||
|
|
||||||
|
JSON_CONTENT
|
||||||
|
|
||||||
|
|
||||||
|
# Compilation via openfoam session
|
||||||
|
if [ -x "$session" ]
|
||||||
|
then
|
||||||
|
cat << JSON_CONTENT
|
||||||
|
"C_Cpp.default.compileCommands":
|
||||||
|
"$session wmake -with-bear -s -j",
|
||||||
|
JSON_CONTENT
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat << JSON_CONTENT
|
||||||
|
|
||||||
|
"C_Cpp.autocomplete": "Disabled",
|
||||||
|
"C_Cpp.errorSquiggles": "Disabled",
|
||||||
|
"C_Cpp.formatting": "Disabled",
|
||||||
|
"C_Cpp.intelliSenseEngine": "Disabled"
|
||||||
|
JSON_CONTENT
|
||||||
|
|
||||||
|
echo '}' # END_LIST
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
@ -38,6 +38,13 @@
|
|||||||
# -l | -log | -log=FILE
|
# -l | -log | -log=FILE
|
||||||
# -prefix=... same as -module-prefix=...
|
# -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
|
# Check environment
|
||||||
[ -d "$WM_PROJECT_DIR" ] || {
|
[ -d "$WM_PROJECT_DIR" ] || {
|
||||||
@ -80,6 +87,7 @@ USAGE
|
|||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
unset optDebug optLog optNonRecursive optPrefix optQueue
|
unset optDebug optLog optNonRecursive optPrefix optQueue
|
||||||
|
unset optWmakeFrontend
|
||||||
|
|
||||||
for arg in "$@"
|
for arg in "$@"
|
||||||
do
|
do
|
||||||
@ -91,6 +99,12 @@ do
|
|||||||
usage
|
usage
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
-with-bear)
|
||||||
|
# Everything wrapped via 'bear'
|
||||||
|
optWmakeFrontend="-with-bear"
|
||||||
|
break # Stop now, continue with wmake
|
||||||
|
;;
|
||||||
|
|
||||||
-no-recurs* | -fromWmake)
|
-no-recurs* | -fromWmake)
|
||||||
# Avoid recursion (eg, if called from wmake)
|
# Avoid recursion (eg, if called from wmake)
|
||||||
optNonRecursive=true
|
optNonRecursive=true
|
||||||
@ -183,12 +197,14 @@ if [ -z "$optNonRecursive" ]
|
|||||||
then
|
then
|
||||||
if [ -z "$optLog" ]
|
if [ -z "$optLog" ]
|
||||||
then
|
then
|
||||||
exec wmake -all $optDebug $optQueue $*
|
exec wmake $optWmakeFrontend -all \
|
||||||
|
$optDebug $optQueue $*
|
||||||
exit $? # Unneeded, but just in case something went wrong
|
exit $? # Unneeded, but just in case something went wrong
|
||||||
else
|
else
|
||||||
echo "Logging wmake -all output to '$optLog'" 1>&2
|
echo "Logging wmake -all output to '$optLog'" 1>&2
|
||||||
echo 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
|
# Need to cleanup after the tee
|
||||||
rc=$? # Error code from tee (not wmake), but not entirely important
|
rc=$? # Error code from tee (not wmake), but not entirely important
|
||||||
echo "Done logging to '$optLog'" 1>&2
|
echo "Done logging to '$optLog'" 1>&2
|
||||||
@ -211,6 +227,7 @@ fi
|
|||||||
# Cleanup local variables and functions
|
# Cleanup local variables and functions
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
unset optWmakeFrontend
|
||||||
unset optNonRecursive optDebug optLog optPrefix optQueue
|
unset optNonRecursive optDebug optLog optPrefix optQueue
|
||||||
unset -f usage
|
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 $?
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
16
wmake/wmake
16
wmake/wmake
@ -115,10 +115,11 @@ then
|
|||||||
cat<<HELP_SUBCOMMANDS
|
cat<<HELP_SUBCOMMANDS
|
||||||
-build-info Query/manage status of {api,branch,build} information
|
-build-info Query/manage status of {api,branch,build} information
|
||||||
-check-dir Check directory equality
|
-check-dir Check directory equality
|
||||||
|
-with-bear Call wmake via 'bear' to create json output
|
||||||
HELP_SUBCOMMANDS
|
HELP_SUBCOMMANDS
|
||||||
else
|
else
|
||||||
cat<<HELP_SUBCOMMANDS
|
cat<<HELP_SUBCOMMANDS
|
||||||
-build-info -check-dir
|
-build-info -check-dir -with-bear
|
||||||
HELP_SUBCOMMANDS
|
HELP_SUBCOMMANDS
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -205,6 +206,9 @@ fi
|
|||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
'') ;;
|
||||||
|
--) shift; break ;;
|
||||||
|
|
||||||
-help-f*) # Full help
|
-help-f*) # Full help
|
||||||
printHelp -full
|
printHelp -full
|
||||||
;;
|
;;
|
||||||
@ -226,6 +230,12 @@ do
|
|||||||
exit $?
|
exit $?
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
# Forward to scripts/wmake-with-bear
|
||||||
|
-with-bear) shift
|
||||||
|
exec "$scriptsDir/wmake-with-bear" "$@"
|
||||||
|
exit $?
|
||||||
|
;;
|
||||||
|
|
||||||
-s | -silent | -quiet)
|
-s | -silent | -quiet)
|
||||||
optQuiet=true
|
optQuiet=true
|
||||||
export WM_QUIET=true
|
export WM_QUIET=true
|
||||||
@ -329,10 +339,6 @@ do
|
|||||||
optShow=true
|
optShow=true
|
||||||
break;
|
break;
|
||||||
;;
|
;;
|
||||||
--)
|
|
||||||
shift
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
-*)
|
-*)
|
||||||
die "unknown option: '$1'"
|
die "unknown option: '$1'"
|
||||||
;;
|
;;
|
||||||
|
|||||||
Reference in New Issue
Block a user