okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
538acd098
main
1"""sycl/tools/build.sh exits with the build's own status (#2990): 0 after a good build, nonzero after a failed one. 2 3It once ended with a grep pipeline, so a good build exited 1 (nothing to find) and a failed compile exited 0, and a `build.sh && next-step` chain ran 4the wrong way round. The test runs the real script with a stub cmake on PATH; no compiler, no oneAPI, no docker. 5""" 6from __future__import annotations 7 8import os 9import shutil 10import subprocess 11import tempfile 12import unittest 13from pathlib import Path 14 15ROOT = Path (__file__ ).resolve ().parents [2 ] 16SCRIPT = ROOT / "sycl" / "tools" / "build.sh" 17BASH = shutil .which ("bash" )# the full path: on Windows a bare "bash" can start the WSL launcher in System32 instead of Git bash 18CYGPATH = shutil .which ("cygpath" ) 19 20 21def sh_path (p )-> str : 22if CYGPATH is None : 23return str (p ) 24return subprocess .run ([CYGPATH ,"-u" ,str (p )],capture_output = True ,text = True ,check = True ).stdout .strip () 25 26 27STUB = """#!/bin/sh 28# a stand-in for cmake: `cmake --build DIR ...` prints what ninja prints and exits with STUB_RC; any other call does nothing 29case "$1" in 30--build) 31echo "[1/2] Building CXX object CMakeFiles/strata.dir/main.cpp.o" 32if [ "${STUB_RC:-0}" != 0 ]; then 33echo "FAILED: [code=1] CMakeFiles/strata.dir/main.cpp.o" 34echo "main.cpp:1:21: error: 'x' was not declared in this scope" 35echo "ninja: build stopped: cannot make progress due to previous errors." 36else 37echo "[2/2] Linking CXX executable strata" 38fi 39exit "${STUB_RC:-0}" ;; 40esac 41exit 0 42""" 43 44 45@ unittest . skipIf ( BASH is None , "needs bash" ) 46class BuildScriptStatus (unittest .TestCase ): 47def run_script (self ,rc :int ): 48with tempfile .TemporaryDirectory ()as tmp : 49bindir ,build = Path (tmp )/ "bin" ,Path (tmp )/ "build" 50bindir .mkdir () 51build .mkdir () 52 (build / "build.ninja" ).write_text ("" ,encoding = "utf-8" )# an existing build folder: the script does not configure it 53 (bindir / "cmake" ).write_text (STUB ,encoding = "utf-8" ,newline = "\n" ) 54 (bindir / "cmake" ).chmod (0o755 ) 55env = dict (os .environ ,PATH = sh_path (bindir )+ os .pathsep + os .environ ["PATH" ],STUB_RC = str (rc ),REPO = sh_path (ROOT ), 56BUILD_DIR = sh_path (build ),AOT = "" ,I8_ESIMD = "OFF" ) 57done = subprocess .run ([BASH ,sh_path (SCRIPT ),"strata" ],capture_output = True ,text = True ,env = env ,timeout = 120 ) 58return done 59 60def test_a_good_build_exits_zero (self ): 61done = self .run_script (0 ) 62self .assertIn ("BUILD EXIT 0" ,done .stdout ) 63self .assertIn ("errors: 0" ,done .stdout ) 64self .assertEqual (done .returncode ,0 ,done .stdout + done .stderr ) 65 66def test_a_failed_compile_exits_nonzero_with_the_builds_status (self ): 67done = self .run_script (1 ) 68self .assertIn ("BUILD EXIT 1" ,done .stdout ) 69self .assertIn ("errors: 1" ,done .stdout ) 70self .assertEqual (done .returncode ,1 ,done .stdout + done .stderr ) 71 72 73if __name__ == "__main__" : 74unittest .main ()