Skip to content

Commit

Permalink
ci: use files_changed for build.sh
Browse files Browse the repository at this point in the history
originally added compiledb but removed them on rebase as it was unnecessary.

see: cataclysmbnteam#3028 (comment)
see: cataclysmbnteam#3028 (comment)

Co-authored-by: Olanti <[email protected]>
  • Loading branch information
scarf005 and olanti-p committed Aug 6, 2023
1 parent ad23045 commit f402b6c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
37 changes: 35 additions & 2 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 @@ -98,12 +99,43 @@ then
cd ..
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
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 +150,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
9 changes: 1 addition & 8 deletions build-scripts/clang-tidy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,7 @@ ${COMPILER:-clang++} -v -x c++ /dev/null -c
# 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 ..
rm -f compile_commands.json && ln -s build/compile_commands.json
ln -s build/compile_commands.json

# We want to first analyze all files that changed in this PR, then as
# many others as possible, in a random order.
Expand Down

0 comments on commit f402b6c

Please sign in to comment.