-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a stage to static analysis to check cmake rules
Add a small script to the static analysis stage of the CI to check that CMake rules are respected. Specifically it checks if `DISCOVERY_MODE PRE_TEST` is set (without this compilation breaks on Adastra). Missing `DISCOVERY_MODE PRE_TEST` are added. Fixes #384 See merge request gysela-developpers/gyselalibxx!742 --------------------------------------------
- Loading branch information
1 parent
72e13f5
commit 201cb4b
Showing
4 changed files
with
69 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
A script to ensure that any rules about CMake contents are respected. | ||
""" | ||
import glob | ||
from pathlib import Path | ||
import sys | ||
|
||
HOME_DIR = Path(__file__).parent.parent.absolute() | ||
|
||
if __name__ == '__main__': | ||
cmake_files = glob.glob(str(HOME_DIR / '**' / 'CMakeLists.txt'), recursive=True) | ||
|
||
success = True | ||
|
||
for f_name in cmake_files: | ||
with open(f_name, encoding='utf-8') as f: | ||
code = f.read() | ||
|
||
# Check that all tests are discovered in PRE_TEST mode | ||
while 'gtest_discover_tests' in code: | ||
code = code.split('gtest_discover_tests', 1)[1].split('(', 1)[1] | ||
gtest_arg_str, code = code.split(')', 1) | ||
gtest_args = gtest_arg_str.split() | ||
try: | ||
discovery_index = gtest_args.index('DISCOVERY_MODE') | ||
except ValueError: | ||
discovery_index = None | ||
if discovery_index is None or gtest_args[discovery_index+1] != 'PRE_TEST': | ||
success = False | ||
print(f"Tests for target {gtest_args[0]} should be discovered before running the test (not during build). Please add 'DISCOVERY_MODE PRE_TEST' to the arguments of gtest_discover_tests in {f_name}") | ||
|
||
if not success: | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters