gamemode/scripts/static-analyser-check.sh
Sam Gleske b8fa857b35 Fix GitHub Actions Static Analyzer Check
Dockerfile
----------

This dockerfile was used to emulate GitHub actions.

<details><summary>Dockerfile source (click to expand)</summary>

```dockerfile
FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN set -ex; \
apt-get update; \
apt-get install -y build-essential meson appstream clang clang-format clang-tools libdbus-1-dev libinih-dev libsystemd-dev git

RUN set -ex; \
yes | adduser ci-user

USER ci-user
```

</details>

Commands to reproduce
---------------------

I simulated GitHub actions with a local docker environment.

    docker build -t ci .

I ran the following commands to reproduce the issue so that I could bugfix the static analyzer script.

```bash
docker run -e CI=true --rm -v "$PWD:$PWD" -w "$PWD" --init ci ./scripts/static-analyser-check.sh
docker run -e CI=true --rm -v "$PWD:$PWD" -w "$PWD" --init ci ./bootstrap.sh -Dwith-examples=true
docker run --rm -v "$PWD:$PWD" -w "$PWD" --init ci meson test -C builddir
docker run --rm -v "$PWD:$PWD" -w "$PWD" --init ci dbus-run-session -- gamemode-simulate-game
docker run --rm -v "$PWD:$PWD" -w "$PWD" --init ci ./scripts/static-analyser-check.sh
```

All commands reuse the same workspace which is how it works in GH actions.

Legitimate bugs
---------------

Now the error displayed in build failure appears to be a legitimate bug.  Four were found related to null pointer dereference.  I'm not fixing the bug but the check should work properly for those who do.

If you following my docker setup in this description you can view the bug report by starting the report server.

```bash
docker run -p 127.0.0.1:8181:8181 -it --rm -v "$PWD:$PWD" -w "$PWD" --init ci scan-view --host 0.0.0.0 --allow-all-hosts builddir/meson-logs/scanbuild/*
```

After the report server is started you can visit `http://127.0.0.1:8181/` to view the bugs.

Screenshot of report
--------------------

![Screenshot of bug report](https://user-images.githubusercontent.com/875669/155830028-473db1ea-7c98-4a82-bc3a-290d5c155108.png)
2022-03-10 10:40:45 +00:00

13 lines
313 B
Bash
Executable File

#!/bin/bash
set -exo pipefail
# Ensure we are at the project root
cd "$(dirname $0)"/..
# Collect scan-build output
ninja scan-build -C builddir | tee builddir/meson-logs/scan-build.txt
# Invert the output - if this string exists it's a fail
! grep -E '[0-9]+ bugs? found.' builddir/meson-logs/scan-build.txt