feat: start abaqus input parser
This commit is contained in:
@@ -30,14 +30,15 @@ class ValidateWorkspaceTests(unittest.TestCase):
|
||||
(root / "CMakeLists.txt").write_text("cmake_minimum_required(VERSION 3.20)\n", encoding="utf-8")
|
||||
build_dir = root / "build" / "msvc-debug"
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
self.assertEqual(
|
||||
validate_workspace.discover_commands(root),
|
||||
[
|
||||
f'cmake -S "{root}" -B "{build_dir}" -G "Visual Studio 17 2022" -A x64',
|
||||
f'cmake --build "{build_dir}" --config Debug',
|
||||
f'ctest --test-dir "{build_dir}" --output-on-failure -C Debug',
|
||||
],
|
||||
)
|
||||
with patch.object(validate_workspace.shutil, "which", return_value="C:\\tools\\cmake.exe"):
|
||||
self.assertEqual(
|
||||
validate_workspace.discover_commands(root),
|
||||
[
|
||||
f'cmake -S "{root}" -B "{build_dir}" -G "Visual Studio 17 2022" -A x64',
|
||||
f'cmake --build "{build_dir}" --config Debug',
|
||||
f'ctest --test-dir "{build_dir}" --output-on-failure -C Debug',
|
||||
],
|
||||
)
|
||||
|
||||
def test_msvc_debug_configure_preset_is_preferred_when_present(self):
|
||||
validate_workspace = load_validate_workspace()
|
||||
@@ -60,14 +61,39 @@ class ValidateWorkspaceTests(unittest.TestCase):
|
||||
encoding="utf-8",
|
||||
)
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
self.assertEqual(
|
||||
validate_workspace.discover_commands(root),
|
||||
[
|
||||
"cmake --preset msvc-debug",
|
||||
f'cmake --build "{root / "out" / "msvc-debug"}" --config Debug',
|
||||
f'ctest --test-dir "{root / "out" / "msvc-debug"}" --output-on-failure -C Debug',
|
||||
],
|
||||
)
|
||||
with patch.object(validate_workspace.shutil, "which", return_value="C:\\tools\\cmake.exe"):
|
||||
self.assertEqual(
|
||||
validate_workspace.discover_commands(root),
|
||||
[
|
||||
"cmake --preset msvc-debug",
|
||||
f'cmake --build "{root / "out" / "msvc-debug"}" --config Debug',
|
||||
f'ctest --test-dir "{root / "out" / "msvc-debug"}" --output-on-failure -C Debug',
|
||||
],
|
||||
)
|
||||
|
||||
def test_cmake_commands_use_common_install_path_when_tools_are_not_on_path(self):
|
||||
validate_workspace = load_validate_workspace()
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
root = Path(tmp) / "project"
|
||||
root.mkdir()
|
||||
(root / "CMakeLists.txt").write_text("cmake_minimum_required(VERSION 3.20)\n", encoding="utf-8")
|
||||
common_bin = Path(tmp) / "CMake" / "bin"
|
||||
common_bin.mkdir(parents=True)
|
||||
(common_bin / "cmake.exe").write_text("", encoding="utf-8")
|
||||
(common_bin / "ctest.exe").write_text("", encoding="utf-8")
|
||||
build_dir = root / "build" / "msvc-debug"
|
||||
|
||||
with patch.dict(os.environ, {}, clear=True):
|
||||
with patch.object(validate_workspace, "COMMON_CMAKE_BIN", common_bin):
|
||||
with patch.object(validate_workspace.shutil, "which", return_value=None):
|
||||
self.assertEqual(
|
||||
validate_workspace.discover_commands(root),
|
||||
[
|
||||
f'"{common_bin / "cmake.exe"}" -S "{root}" -B "{build_dir}" -G "Visual Studio 17 2022" -A x64',
|
||||
f'"{common_bin / "cmake.exe"}" --build "{build_dir}" --config Debug',
|
||||
f'"{common_bin / "ctest.exe"}" --test-dir "{build_dir}" --output-on-failure -C Debug',
|
||||
],
|
||||
)
|
||||
|
||||
def test_no_cmake_project_has_no_validation_commands(self):
|
||||
validate_workspace = load_validate_workspace()
|
||||
|
||||
@@ -32,6 +32,17 @@ def _cmake_config() -> tuple[str, str, str, Path]:
|
||||
return generator, platform, config, build_dir
|
||||
|
||||
|
||||
def _tool_command(tool_name: str) -> str:
|
||||
if shutil.which(tool_name) is not None:
|
||||
return tool_name
|
||||
|
||||
exe = COMMON_CMAKE_BIN / f"{tool_name}.exe"
|
||||
if exe.exists():
|
||||
return f'"{exe}"'
|
||||
|
||||
return tool_name
|
||||
|
||||
|
||||
def _read_presets(root: Path) -> dict:
|
||||
presets_file = root / "CMakePresets.json"
|
||||
if not presets_file.exists():
|
||||
@@ -53,13 +64,15 @@ def _preset_binary_dir(root: Path, preset: dict) -> Path:
|
||||
def load_preset_commands(root: Path) -> list[str]:
|
||||
payload = _read_presets(root)
|
||||
config = os.environ.get("HARNESS_CMAKE_CONFIG", DEFAULT_CONFIG)
|
||||
cmake = _tool_command("cmake")
|
||||
ctest = _tool_command("ctest")
|
||||
for preset in payload.get("configurePresets", []):
|
||||
if isinstance(preset, dict) and preset.get("name") == PRESET_NAME:
|
||||
build_dir = _preset_binary_dir(root, preset)
|
||||
return [
|
||||
f"cmake --preset {PRESET_NAME}",
|
||||
f'cmake --build "{build_dir}" --config {config}',
|
||||
f'ctest --test-dir "{build_dir}" --output-on-failure -C {config}',
|
||||
f"{cmake} --preset {PRESET_NAME}",
|
||||
f'{cmake} --build "{build_dir}" --config {config}',
|
||||
f'{ctest} --test-dir "{build_dir}" --output-on-failure -C {config}',
|
||||
]
|
||||
return []
|
||||
|
||||
@@ -71,10 +84,12 @@ def load_cmake_commands(root: Path) -> list[str]:
|
||||
generator, platform, config, build_dir = _cmake_config()
|
||||
if not build_dir.is_absolute():
|
||||
build_dir = root / build_dir
|
||||
cmake = _tool_command("cmake")
|
||||
ctest = _tool_command("ctest")
|
||||
return [
|
||||
f'cmake -S "{root}" -B "{build_dir}" -G "{generator}" -A {platform}',
|
||||
f'cmake --build "{build_dir}" --config {config}',
|
||||
f'ctest --test-dir "{build_dir}" --output-on-failure -C {config}',
|
||||
f'{cmake} -S "{root}" -B "{build_dir}" -G "{generator}" -A {platform}',
|
||||
f'{cmake} --build "{build_dir}" --config {config}',
|
||||
f'{ctest} --test-dir "{build_dir}" --output-on-failure -C {config}',
|
||||
]
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user