Skip to content

Commit

Permalink
ci: install compiledb, use files_changed for build.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
scarf005 committed Jul 24, 2023
1 parent 07a1fb1 commit 968ed4a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
47 changes: 43 additions & 4 deletions build-scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Build script intended for use in Github workflow

echo "Using bash version $BASH_VERSION"
set -exo pipefail

num_jobs=3
Expand Down Expand Up @@ -95,15 +96,52 @@ then
# And the same for clang-tidy
"$CATA_CLANG_TIDY" ../src/version.cpp -- -v

# Run clang-tidy analysis instead of regular build & test
# We could use CMake to create compile_commands.json, but that's super
# slow, so use compiledb <https://github.com/nickdiego/compiledb>
# instead.
compiledb -n make

cd ..
ln -s build/compile_commands.json
rm -f compile_commands.json && ln -s build/compile_commands.json

# TODO: first analyze all files that changed in this PR
set +x
# Check for changes to any files that would require us to run clang-tidy across everything
changed_global_files="$( ( ./build-scripts/files_changed || echo 'unknown') | \
egrep -i "clang-tidy|build-scripts|cmake|unknown" || true )"
if [ -n "$changed_global_files" ]
then
first_changed_file="$(echo "$changed_global_files" | head -n 1)"
echo "Analyzing all files because $first_changed_file was changed"
TIDY="all"
fi

all_cpp_files="$( \
grep '"file": "' build/compile_commands.json | \
sed "s+.*$PWD/++;s+\",\?$++")"
set -x
sed "s+.*$PWD/++;s+\"$++")"
if [ "$TIDY" == "all" ]
then
echo "Analyzing all files"
tidyable_cpp_files=$all_cpp_files
else
make \
-j $num_jobs \
${COMPILER:+COMPILER=$COMPILER} \
TILES=${TILES:-0} \
SOUND=${SOUND:-0} \
includes

./build-scripts/files_changed > ./files_changed
tidyable_cpp_files="$( \
( build-scripts/get_affected_files.py ./files_changed ) || \
echo unknown )"

if [ "tidyable_cpp_files" == "unknown" ]
then
echo "Unable to determine affected files, tidying all files"
tidyable_cpp_files=$all_cpp_files
fi
fi

function analyze_files_in_random_order
{
Expand All @@ -118,6 +156,7 @@ then

echo "Analyzing all files"
analyze_files_in_random_order "$all_cpp_files"
set -x
else
# Regular build
make -j$num_jobs translations_compile
Expand Down
2 changes: 1 addition & 1 deletion build-scripts/requirements.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ echo "::add-matcher::build-scripts/problem-matchers/debugmsg.json"

if [ -n "$CATA_CLANG_TIDY" ]; then
pip install --user wheel --upgrade
pip install --user 'lit==0.11.1' 'click==7.1.2'
pip install --user compiledb 'lit==0.11.1' 'click==7.1.2'
fi

if [ -n "$LANGUAGES" ]; then
Expand Down

0 comments on commit 968ed4a

Please sign in to comment.