浏览代码

Move the build and test scripts into the `tools/` subdir

default_compile_flags
vector-of-bool 5 年前
父节点
当前提交
8501a8c359
共有 3 个文件被更改,包括 34 次插入27 次删除
  1. +8
    -8
      azure-pipelines.yml
  2. +21
    -17
      tools/build.py
  3. +5
    -2
      tools/test.py

+ 8
- 8
azure-pipelines.yml 查看文件

@@ -9,14 +9,14 @@ jobs:
echo Loading VS environment
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\Tools\\vsdevcmd" -arch=x64 || exit 1
echo Executing build/test script
python -u build.py --cxx cl.exe --test --static || exit 1
python -u tools/build.py --cxx cl.exe --test --static || exit 1
displayName: Build and Run Unit Tests
- publish: _build/ddslim.exe
artifact: DDSLiM Executable - Windows
- script: |
echo Loading VS environment
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\Common7\\Tools\\vsdevcmd" -arch=x64 || exit 1
python -u test.py --exe _build/ddslim -T:msvc || exit 1
python -u tools/test.py --exe _build/ddslim -T:msvc || exit 1
displayName: Smoke Tests

- job: Windows_MSVC_VS2019
@@ -27,14 +27,14 @@ jobs:
echo Loading VS environment
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\Tools\\vsdevcmd" -arch=x64 || exit 1
echo Executing build/test script
python -u build.py --cxx cl.exe --test --static || exit 1
python -u tools/build.py --cxx cl.exe --test --static || exit 1
displayName: Build and Run Unit Tests
- publish: _build/ddslim.exe
artifact: DDSLiM Executable - Windows
- script: |
echo Loading VS environment
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\Tools\\vsdevcmd" -arch=x64 || exit 1
python -u test.py --exe _build/ddslim -T:msvc || exit 1
python -u tools/test.py --exe _build/ddslim -T:msvc || exit 1
displayName: Smoke Tests

- job: Linux_GCC
@@ -43,11 +43,11 @@ jobs:
steps:
- script: sudo apt install -y python3-minimal g++-8
displayName: Prepare System
- script: python3 -u build.py --cxx g++-8 --test --static
- script: python3 -u tools/build.py --cxx g++-8 --test --static
displayName: Build and Run Unit Tests
- publish: _build/ddslim
artifact: DDSLiM Executable - Linux
- script: python3 -u test.py --exe _build/ddslim -T:gcc-8
- script: python3 -u tools/test.py --exe _build/ddslim -T:gcc-8
displayName: Smoke Tests

- job: macOS
@@ -56,9 +56,9 @@ jobs:
steps:
- script: brew install gcc@8
displayName: Prepare System
- script: python3 -u build.py --cxx g++-8 --test
- script: python3 -u tools/build.py --cxx g++-8 --test
displayName: Build and Run Unit Tests
- publish: _build/ddslim
artifact: DDSLiM Executable - macOS
- script: python3 -u test.py --exe _build/ddslim -T:gcc-8
- script: python3 -u tools/test.py --exe _build/ddslim -T:gcc-8
displayName: Smoke Tests

build.py → tools/build.py 查看文件

@@ -11,7 +11,7 @@ import subprocess
import time
import sys

HERE_DIR = Path(__file__).parent.absolute()
ROOT = Path(__file__).parent.parent.absolute()

INCLUDE_DIRS = [
'external/taywee-args/include',
@@ -44,7 +44,7 @@ def _create_compile_command(opts: BuildOptions, cpp_file: Path,
if not opts.is_msvc:
cmd = [
str(opts.cxx),
f'-I{HERE_DIR / "src"}',
f'-I{ROOT / "src"}',
'-std=c++17',
'-Wall',
'-Wextra',
@@ -65,7 +65,7 @@ def _create_compile_command(opts: BuildOptions, cpp_file: Path,
else:
cmd.append('-O2')
cmd.extend(
itertools.chain.from_iterable(('-isystem', str(HERE_DIR / subdir))
itertools.chain.from_iterable(('-isystem', str(ROOT / subdir))
for subdir in INCLUDE_DIRS))
return cmd
else:
@@ -77,7 +77,7 @@ def _create_compile_command(opts: BuildOptions, cpp_file: Path,
'/EHsc',
'/std:c++latest',
'/DFMT_HEADER_ONLY=1',
f'/I{HERE_DIR / "src"}',
f'/I{ROOT / "src"}',
str(cpp_file),
'/c',
f'/Fo{obj_file}',
@@ -90,18 +90,18 @@ def _create_compile_command(opts: BuildOptions, cpp_file: Path,
cmd.append('/MT')
else:
cmd.append('/MD')
cmd.extend(f'/I{HERE_DIR / subdir}' for subdir in INCLUDE_DIRS)
cmd.extend(f'/I{ROOT / subdir}' for subdir in INCLUDE_DIRS)
return cmd


def _compile_src(opts: BuildOptions, cpp_file: Path) -> Tuple[Path, Path]:
build_dir = HERE_DIR / '_build'
src_dir = HERE_DIR / 'src'
build_dir = ROOT / '_build'
src_dir = ROOT / 'src'
relpath = cpp_file.relative_to(src_dir)
obj_path = build_dir / relpath.with_name(relpath.name + opts.obj_suffix)
obj_path.parent.mkdir(exist_ok=True, parents=True)
cmd = _create_compile_command(opts, cpp_file, obj_path)
msg = f'Compile C++ file: {cpp_file}'
msg = f'Compile C++ file: {cpp_file.relative_to(ROOT)}'
print(msg)
start = time.time()
res = subprocess.run(
@@ -113,8 +113,12 @@ def _compile_src(opts: BuildOptions, cpp_file: Path) -> Tuple[Path, Path]:
raise RuntimeError(
f'Compile command ({cmd}) failed for {cpp_file}:\n{res.stdout.decode()}'
)
if res.stdout:
print(res.stdout.decode())
stdout: str = res.stdout.decode()
fname_head = f'{cpp_file.name}\r\n'
if stdout.startswith(fname_head):
stdout = stdout[len(fname_head):]
if stdout:
print(stdout, end='')
end = time.time()
print(f'{msg} - Done: {end - start:.2}s')
return cpp_file, obj_path
@@ -132,11 +136,11 @@ def compile_sources(opts: BuildOptions,
def _create_archive_command(opts: BuildOptions,
objects: Iterable[Path]) -> Tuple[Path, List[str]]:
if opts.is_msvc:
lib_file = HERE_DIR / '_build/libddslim.lib'
lib_file = ROOT / '_build/libddslim.lib'
cmd = ['lib', '/nologo', f'/OUT:{lib_file}', *map(str, objects)]
return lib_file, cmd
else:
lib_file = HERE_DIR / '_build/libddslim.a'
lib_file = ROOT / '_build/libddslim.a'
cmd = ['ar', 'rsc', str(lib_file), *map(str, objects)]
return lib_file, cmd

@@ -196,7 +200,7 @@ def link_exe(opts: BuildOptions, obj: Path, lib: Path, *,
out: Path = None) -> Path:
if out is None:
basename = obj.stem
out = HERE_DIR / '_build/test' / (basename + '.exe')
out = ROOT / '_build/test' / (basename + '.exe')
out.parent.mkdir(exist_ok=True, parents=True)

print(f'Linking executable {out}')
@@ -230,9 +234,9 @@ def main(argv: Sequence[str]) -> int:
'--static', action='store_true', help='Build a static executable')
args = parser.parse_args(argv)

all_sources = set(HERE_DIR.glob('src/**/*.cpp'))
test_sources = set(HERE_DIR.glob('src/**/*.test.cpp'))
main_sources = set(HERE_DIR.glob('src/**/*.main.cpp'))
all_sources = set(ROOT.glob('src/**/*.cpp'))
test_sources = set(ROOT.glob('src/**/*.test.cpp'))
main_sources = set(ROOT.glob('src/**/*.main.cpp'))

lib_sources = (all_sources - test_sources) - main_sources

@@ -255,7 +259,7 @@ def main(argv: Sequence[str]) -> int:
build_opts,
objects[next(iter(main_sources))],
lib,
out=HERE_DIR / '_build/ddslim')
out=ROOT / '_build/ddslim')

if args.test:
list(pool.map(run_test, test_exes))

test.py → tools/test.py 查看文件

@@ -7,13 +7,16 @@ import subprocess
import sys


ROOT = Path(__file__).parent.parent.absolute()


class TestOptions(NamedTuple):
exe: Path
toolchain: str


def run_test_dir(dir: Path, opts: TestOptions) -> bool:
print(f'Running test: {dir.name} ', end='')
print(f'Running test: {dir.stem} ', end='')
out_dir = dir / '_build'
if out_dir.exists():
shutil.rmtree(out_dir)
@@ -43,7 +46,7 @@ def run_test_dir(dir: Path, opts: TestOptions) -> bool:
def run_tests(opts: TestOptions) -> int:
print('Sanity check...')
subprocess.check_output([str(opts.exe), '--help'])
tests_subdir = Path(__file__).parent.absolute() / 'tests'
tests_subdir = ROOT / 'tests'

test_dirs = tests_subdir.glob('*.test')
ret = 0

正在加载...
取消
保存