87 lines
1.8 KiB
Bash
Executable File
87 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
scriptName=$(basename $0)
|
|
version=0.1
|
|
original=""
|
|
sources=""
|
|
verbose=0
|
|
tmpFilename='.tmp.compile_commands.json'
|
|
srcOriginalPath="../../git/src"
|
|
|
|
function print {
|
|
verbose=$1
|
|
message=$2
|
|
if [[ $verbose -eq 1 ]]; then
|
|
echo "[V] $message"
|
|
fi
|
|
}
|
|
|
|
function usage {
|
|
echo "
|
|
Usage: $scriptName [OPTIONS]
|
|
Options:
|
|
[-o|--original] - location of a original compile_commands.json (e.g. -o /tmp/test/compile_commands.json)
|
|
[-s|--sources] - location of your sources directory (e.g. /external_chr/src/)
|
|
[-g|--gitsrc] - location of an original src directory; default ../../git/src/ (relative to build/Release)
|
|
"
|
|
}
|
|
|
|
function about {
|
|
echo "
|
|
${scriptName} ver.${version}
|
|
This script's purpose to deal with external sources of a project for which compile commands
|
|
are generated.
|
|
for usage examples call
|
|
${scriptName} [-h|--help]
|
|
"
|
|
}
|
|
|
|
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
|
|
case $1 in
|
|
-a | --about)
|
|
about
|
|
exit
|
|
;;
|
|
-h | --help)
|
|
usage
|
|
exit
|
|
;;
|
|
-o | --original)
|
|
shift
|
|
original=$1
|
|
;;
|
|
-s | --sources)
|
|
shift
|
|
sources=$1
|
|
;;
|
|
-g | --gitsrc)
|
|
shift
|
|
srcOriginalPath=$1
|
|
;;
|
|
-v | --verbose)
|
|
verbose=1
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
print $verbose "original=$original && sources=$sources"
|
|
|
|
cp $original $tmpFilename
|
|
|
|
buildDirectory=$(grep directory $original | head -n 1 | cut -d ':' -f 2 | cut -d '"' -f 2)
|
|
|
|
print $verbose "buildDirectory=$buildDirectory"
|
|
|
|
if command -v pv &>/dev/null; then
|
|
pv $tmpFilename | sed "s|${srcOriginalPath}|${sources}|g" >${sources}/compile_commands.json
|
|
else
|
|
echo "pv was not found on PATH so just wait..."
|
|
sed -i "s|${srcOriginalPath}|${sources}|g" $tmpFilename
|
|
cp $tmpFilename ${sources}/compile_commands.json
|
|
fi
|
|
|
|
print $verbose "original compile_commands src path ($srcOriginalPath) was changed to $sources"
|
|
|
|
rm $tmpFilename
|