{ | |||||
"compiler_id": 'gnu', | |||||
"cxx_version": 'c++17', | |||||
"cxx_compiler": 'g++-9', | |||||
} |
{ | |||||
"compiler_id": 'msvc', | |||||
"cxx_version": "c++17" | |||||
} |
import pytest | |||||
from subprocess import CalledProcessError | from subprocess import CalledProcessError | ||||
import time | |||||
import pytest | |||||
from dds_ci import paths | from dds_ci import paths | ||||
from dds_ci.testing import Project, PackageJSON | from dds_ci.testing import Project, PackageJSON | ||||
tmp_project.write('src/f.cpp', r'void f() {}') | tmp_project.write('src/f.cpp', r'void f() {}') | ||||
tmp_project.build() | tmp_project.build() | ||||
# Writing again will build again: | # Writing again will build again: | ||||
time.sleep(0.2) # Sleep long enough to register a file change | |||||
tmp_project.write('src/f.cpp', r'bad again') | tmp_project.write('src/f.cpp', r'bad again') | ||||
with pytest.raises(CalledProcessError): | with pytest.raises(CalledProcessError): | ||||
tmp_project.build() | tmp_project.build() |
with pytest.raises(subprocess.CalledProcessError): | with pytest.raises(subprocess.CalledProcessError): | ||||
test_project.build() | test_project.build() | ||||
# Pause long enough for timestamps to change | |||||
test_project.write('src/2.cpp', ''' | test_project.write('src/2.cpp', ''' | ||||
#include "./values.hpp" | #include "./values.hpp" | ||||
:param build_root: The root directory where the output will be written. | :param build_root: The root directory where the output will be written. | ||||
:param jobs: The number of jobs to use. Default is CPU-count + 2 | :param jobs: The number of jobs to use. Default is CPU-count + 2 | ||||
""" | """ | ||||
toolchain = toolchain or tc_mod.get_default_test_toolchain() | |||||
toolchain = toolchain or tc_mod.get_default_audit_toolchain() | |||||
jobs = jobs or multiprocessing.cpu_count() + 2 | jobs = jobs or multiprocessing.cpu_count() + 2 | ||||
self.run([ | self.run([ | ||||
'build', | 'build', | ||||
]) | ]) | ||||
def build_deps(self, args: proc.CommandLine, *, toolchain: Optional[Path] = None) -> None: | def build_deps(self, args: proc.CommandLine, *, toolchain: Optional[Path] = None) -> None: | ||||
toolchain = toolchain or tc_mod.get_default_test_toolchain() | |||||
toolchain = toolchain or tc_mod.get_default_audit_toolchain() | |||||
self.run([ | self.run([ | ||||
'build-deps', | 'build-deps', | ||||
f'--toolchain={toolchain}', | f'--toolchain={toolchain}', |
Execute the build that generates the test-mode executable. Uses the given 'dds' | Execute the build that generates the test-mode executable. Uses the given 'dds' | ||||
to build the new dds. Returns a DDSWrapper around the generated test executable. | to build the new dds. Returns a DDSWrapper around the generated test executable. | ||||
""" | """ | ||||
test_tc = args.test_toolchain or toolchain.get_default_test_toolchain() | |||||
test_tc = args.test_toolchain or toolchain.get_default_audit_toolchain() | |||||
build_dir = paths.BUILD_DIR | build_dir = paths.BUILD_DIR | ||||
with toolchain.fixup_toolchain(test_tc) as new_tc: | with toolchain.fixup_toolchain(test_tc) as new_tc: | ||||
dds.build(toolchain=new_tc, root=paths.PROJECT_ROOT, build_root=build_dir, jobs=args.jobs) | dds.build(toolchain=new_tc, root=paths.PROJECT_ROOT, build_root=build_dir, jobs=args.jobs) | ||||
""" | """ | ||||
main_tc = args.toolchain or ( | main_tc = args.toolchain or ( | ||||
# If we are in rapid-dev mode, use the test toolchain, which had audit/debug enabled | # If we are in rapid-dev mode, use the test toolchain, which had audit/debug enabled | ||||
toolchain.get_default_toolchain() if not args.rapid else toolchain.get_default_test_toolchain()) | |||||
toolchain.get_default_toolchain() if not args.rapid else toolchain.get_default_audit_toolchain()) | |||||
with toolchain.fixup_toolchain(main_tc) as new_tc: | with toolchain.fixup_toolchain(main_tc) as new_tc: | ||||
try: | try: | ||||
dds.build(toolchain=new_tc, root=paths.PROJECT_ROOT, build_root=paths.BUILD_DIR, jobs=args.jobs) | dds.build(toolchain=new_tc, root=paths.PROJECT_ROOT, build_root=paths.BUILD_DIR, jobs=args.jobs) |
PROJECT_ROOT = Path(__file__).absolute().parent.parent.parent | PROJECT_ROOT = Path(__file__).absolute().parent.parent.parent | ||||
#: The <repo>/tools directory | #: The <repo>/tools directory | ||||
TOOLS_DIR = PROJECT_ROOT / 'tools' | TOOLS_DIR = PROJECT_ROOT / 'tools' | ||||
#: The <repo>/tests directory | |||||
TESTS_DIR = PROJECT_ROOT / 'tests' | |||||
#: The default build directory | #: The default build directory | ||||
BUILD_DIR = PROJECT_ROOT / '_build' | BUILD_DIR = PROJECT_ROOT / '_build' | ||||
#: The directory were w prebuild/bootstrapped results will go, and scratch space for the build | #: The directory were w prebuild/bootstrapped results will go, and scratch space for the build |
yield new_json | yield new_json | ||||
def get_default_test_toolchain() -> Path: | |||||
def get_default_audit_toolchain() -> Path: | |||||
""" | """ | ||||
Get the default toolchain that should be used for dev and test based on the | Get the default toolchain that should be used for dev and test based on the | ||||
host platform. | host platform. | ||||
return paths.TOOLS_DIR / 'gcc-9-test.jsonc' | return paths.TOOLS_DIR / 'gcc-9-test.jsonc' | ||||
if sys.platform == 'win32': | if sys.platform == 'win32': | ||||
return paths.TOOLS_DIR / 'msvc-audit.jsonc' | return paths.TOOLS_DIR / 'msvc-audit.jsonc' | ||||
if sys.platform in 'linux': | |||||
if sys.platform == 'linux': | |||||
return paths.TOOLS_DIR / 'gcc-9-audit.jsonc' | return paths.TOOLS_DIR / 'gcc-9-audit.jsonc' | ||||
if sys.platform == 'darwin': | if sys.platform == 'darwin': | ||||
return paths.TOOLS_DIR / 'gcc-9-audit-macos.jsonc' | return paths.TOOLS_DIR / 'gcc-9-audit-macos.jsonc' | ||||
raise RuntimeError(f'Unable to determine the default toolchain (sys.platform is {sys.platform!r})') | raise RuntimeError(f'Unable to determine the default toolchain (sys.platform is {sys.platform!r})') | ||||
def get_default_test_toolchain() -> Path: | |||||
""" | |||||
Get the default toolchain that should be used by tests that need a toolchain | |||||
to use for executing dds. | |||||
""" | |||||
if sys.platform == 'win32': | |||||
return paths.TESTS_DIR / 'msvc.tc.jsonc' | |||||
if sys.platform in ('linux', 'darwin'): | |||||
return paths.TESTS_DIR / 'gcc-9.tc.jsonc' | |||||
raise RuntimeError(f'Unable to determine the default toolchain (sys.platform is {sys.platform!r})') | |||||
def get_default_toolchain() -> Path: | def get_default_toolchain() -> Path: | ||||
""" | """ | ||||
Get the default toolchain that should be used to generate the release executable | Get the default toolchain that should be used to generate the release executable |