Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Meson support #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: docker://lpenz/omnilint:v0.2
pytest:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v3
- name: Install pytest
run: python -m pip install pytest
- run: pytest
test:
strategy:
matrix:
Expand All @@ -19,6 +27,7 @@ jobs:
- clang-sanitize-undefined
- clang-sanitize-dataflow
- clang-sanitize-safe-stack
- gcc-sanitize-address
- valgrind
- cpack
- coverage
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ RUN set -e -x; \
# infra
ca-certificates python3-yaml \
# build
cmake pkg-config make gcc g++ \
cmake pkg-config make gcc g++ meson ninja-build \
# coverage report
curl lcov \
# clang
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ The available presets are:
[clang sanitizers](https://clang.llvm.org/docs/index.html) and
run the tests.
- *cmake*: append `-DCMAKE_C/CXX_COMPILER=clang/clang++ -DCMAKE_C/CXX_FLAGS=-fno-omit-frame-pointer -fsanitize=<sanitizer>` to `cmakeflags`.
- *gcc-sanitize-&lt;sanitizer&gt;*: compile with one of the
[gcc sanitizers](https://devdocs.io/gcc~10/instrumentation-options) and
run the tests.
- *cmake*: append `-DCMAKE_C/CXX_COMPILER=gcc/g++ -DCMAKE_C/CXX_FLAGS=-fno-omit-frame-pointer -fsanitize=<sanitizer>` to `cmakeflags`.
- *valgrind*: run the tests with [valgrind](https://valgrind.org/).
- *test*: set default test phase to `ctest -DExperimentalMemCheck --output-on-failure .`
- *cpack*: runs [cpack](https://cmake.org/cmake/help/latest/module/CPack.html)
Expand Down
1 change: 1 addition & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ inputs:
- iwyu
- clang-tidy
- clang-sanitize-*
- gcc-sanitize-*
- valgrind
- coverage
- install
Expand Down
67 changes: 50 additions & 17 deletions entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import sys
import os
import subprocess
from contextlib import contextmanager
from enum import Enum


@contextmanager
Expand All @@ -21,6 +22,11 @@ def error(title, msg):
sys.stderr.write("> {}\n".format(msg))


class CompilerGroup(Enum):
gcc = ('gcc', 'g++')
clang = ('clang', 'clang++')


class Entrypoint(object):
def __init__(self, extenv):
self.extenv = extenv
Expand Down Expand Up @@ -89,7 +95,7 @@ class Entrypoint(object):
return False
return True

def main(self):
def parse(self):
# Setup phase can be executed immediately, it ignores presets:
with ghgroup("Setup"):
# Directory:
Expand All @@ -105,27 +111,53 @@ class Entrypoint(object):
if not self.dependencies():
return False

if os.path.exists("meson.build"):
build_system = "meson"
else:
build_system = "cmake"

# Defaults, affected by presets:
self.cmd_cmake = "cmake . "
self.cmd_cmake += self.extenv.get("INPUT_CMAKEFLAGS", "")
self.cmd_build = "make VERBOSE=1"
self.cmd_test = "ctest --output-on-failure ."
if build_system == "meson":
self.cmd_cmake = "meson build -Dtests=enabled"
self.cmd_build = "ninja -C build"
self.cmd_test = "ninja test -C build"
else: # build_system "cmake":
self.cmd_cmake = "cmake . "
self.cmd_cmake += self.extenv.get("INPUT_CMAKEFLAGS", "")
self.cmd_build = "make VERBOSE=1"
self.cmd_test = "ctest --output-on-failure build"

# Presets, overriding or complementing defaults:
preset = self.extenv.get("INPUT_PRESET")
if preset:
if preset.startswith("clang-sanitize-"):
sanitizer = re.match("clang-sanitize-(.*)", preset).group(1)
self.cmd_cmake += " -DCMAKE_C_COMPILER=clang"
self.cmd_cmake += " -DCMAKE_CXX_COMPILER=clang++"
for lang in ["C", "CXX"]:
self.cmd_cmake += (
' -DCMAKE_{}_FLAGS="-fno-omit-frame-pointer'
' -fsanitize={}"'.format(lang, sanitizer)
)
if preset.split("-")[:2] in [["clang", "sanitize"], ["gcc", "sanitize"]]:
match = re.match("(.*)-sanitize-(.*)", preset)
compilers = dict(CompilerGroup.__members__.items())[match.group(1)]
sanitizer = match.group(2)
if build_system == "cmake":
self.cmd_cmake += " -DCMAKE_C_COMPILER={}".format(compilers.value[0])
self.cmd_cmake += " -DCMAKE_CXX_COMPILER={}".format(compilers.value[1])
for lang in ["C", "CXX"]:
self.cmd_cmake += (
' -DCMAKE_{}_FLAGS="-fno-omit-frame-pointer'
' -fsanitize={}"'.format(lang, sanitizer)
)
else:
self.cmd_cmake = "CC={} {}".format(compilers.value[0], self.cmd_cmake)
self.cmd_cmake = "CXX={} {}".format(compilers.value[1], self.cmd_cmake)
for lang in ["C", "CXX"]:
self.cmd_cmake = (
'{}FLAGS="-fno-omit-frame-pointer'
' -fsanitize={}" {}'.format(lang, sanitizer, self.cmd_cmake)
)

elif preset == "install":
self.cmd_cmake += " -DCMAKE_INSTALL_PREFIX=/tmp/_install"
self.cmd_test = "make install"
if build_system == "cmake":
self.cmd_cmake += " -DCMAKE_INSTALL_PREFIX=/tmp/_install"
self.cmd_test = "make install"
elif build_system == "meson":
self.cmd_cmake += " --destdir=/tmp/_install"
self.cmd_test = "ninja install -C build"
self.cmd_post = "find /tmp/_install -type f"
elif preset == "cpack":
self.cmd_test = "cpack"
Expand Down Expand Up @@ -179,7 +211,8 @@ class Entrypoint(object):
if cmd_post_override:
self.cmd_post = cmd_post_override

# Run
def main(self):
self.parse()
return self.run()


Expand Down
31 changes: 31 additions & 0 deletions tests/test_sanitize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import imp
import unittest

entrypoint = imp.load_source("entrypoint", "./entrypoint")


class SanitizeTests(unittest.TestCase):

def test_clang(self):
uut = entrypoint.Entrypoint({
"INPUT_PRESET": "clang-sanitize-address",
})
uut.parse()
self.assertEqual(
uut.cmd_cmake,
'cmake . -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ '
'-DCMAKE_C_FLAGS="-fno-omit-frame-pointer -fsanitize=address" '
'-DCMAKE_CXX_FLAGS="-fno-omit-frame-pointer -fsanitize=address"'
)

def test_gcc(self):
uut = entrypoint.Entrypoint({
"INPUT_PRESET": "gcc-sanitize-address",
})
uut.parse()
self.assertEqual(
uut.cmd_cmake,
'cmake . -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ '
'-DCMAKE_C_FLAGS="-fno-omit-frame-pointer -fsanitize=address" '
'-DCMAKE_CXX_FLAGS="-fno-omit-frame-pointer -fsanitize=address"'
)