Skip to content

Commit 47cf71c

Browse files
committed
Fix path handling and tests on Windows hosts
A vcpkg root in a subdirectory was compared with its .gitmodules path using backslashes on Windows, so the configured branch was ignored. POSIX vcpkg commands and Emscripten object paths were also built with backslashes when the host was Windows. The vcpkg tests that assert POSIX commands pin a Linux host, the gcc toolchain fixture is skipped on Windows, and the build matrix no longer cancels the other jobs when one fails. Signed-off-by: Tim Paine <3105306+timkpaine@users.noreply.github.com>
1 parent eef1481 commit 47cf71c

5 files changed

Lines changed: 21 additions & 5 deletions

File tree

‎.github/workflows/build.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
runs-on: ${{ matrix.os }}
2929

3030
strategy:
31+
fail-fast: false
3132
matrix:
3233
os: [ubuntu-24.04]
3334
python-version: ["3.11", "3.12", "3.13"]

‎hatch_cpp/config.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def generate(self):
197197
if self.platform.platform == "emscripten":
198198
objects = []
199199
for source_index, source in enumerate(library.sources):
200-
obj = Path("build/hatch-cpp") / f"{library_index}-{source_index}-{Path(source).stem}.o"
201-
objects.append(str(obj))
200+
obj = f"build/hatch-cpp/{library_index}-{source_index}-{Path(source).stem}.o"
201+
objects.append(obj)
202202
self.commands.append(f"{compiler} -c {source} {compile_flags} -o {obj}")
203203
self.commands.append(f"{compiler} {' '.join(objects)} {link_flags}")
204204
else:

‎hatch_cpp/tests/test_projects.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ class TestProject:
1515
[
1616
"test_project_basic",
1717
"test_project_override_classes",
18-
"test_project_override_toolchain",
18+
pytest.param(
19+
"test_project_override_toolchain",
20+
marks=pytest.mark.skipif(
21+
platform == "win32", reason="the fixture selects the gcc toolchain, whose flags clang rejects for MSVC targets"
22+
),
23+
),
1924
"test_project_pybind",
2025
"test_project_pybind_vcpkg",
2126
"test_project_nanobind",

‎hatch_cpp/tests/test_vcpkg_ref.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ def _make_vcpkg_env(self, tmp_path):
125125
"""Create a minimal vcpkg.json so generate() produces commands."""
126126
(tmp_path / "vcpkg.json").write_text("{}")
127127

128+
def _pin_linux_host(self, monkeypatch):
129+
"""Make generate() behave as on an x86_64 Linux host, whatever host runs the test."""
130+
monkeypatch.setattr("hatch_cpp.toolchains.vcpkg.sys_platform", "linux")
131+
monkeypatch.setattr("hatch_cpp.toolchains.vcpkg.platform_machine", lambda: "x86_64")
132+
128133
def test_generate_with_explicit_ref(self, tmp_path, monkeypatch):
129134
monkeypatch.chdir(tmp_path)
130135
self._make_vcpkg_env(tmp_path)
@@ -164,6 +169,7 @@ def test_generate_without_ref(self, tmp_path, monkeypatch):
164169

165170
def test_generate_uses_posix_command_paths(self, tmp_path, monkeypatch):
166171
monkeypatch.chdir(tmp_path)
172+
self._pin_linux_host(monkeypatch)
167173
self._make_vcpkg_env(tmp_path)
168174

169175
cfg = HatchCppVcpkgConfiguration(vcpkg_triplet="x64-linux")
@@ -185,6 +191,7 @@ def test_generate_detects_linux_arm64_triplet(self, tmp_path, monkeypatch):
185191

186192
def test_generate_detects_emscripten_triplet(self, tmp_path, monkeypatch):
187193
monkeypatch.chdir(tmp_path)
194+
self._pin_linux_host(monkeypatch)
188195
self._make_vcpkg_env(tmp_path)
189196
build_plan = SimpleNamespace(platform=SimpleNamespace(platform="emscripten"))
190197

@@ -206,6 +213,7 @@ def test_generate_uses_windows_command_paths(self, tmp_path, monkeypatch):
206213

207214
def test_generate_skips_clone_when_vcpkg_root_exists(self, tmp_path, monkeypatch):
208215
monkeypatch.chdir(tmp_path)
216+
self._pin_linux_host(monkeypatch)
209217
self._make_vcpkg_env(tmp_path)
210218
vcpkg_root = tmp_path / "vcpkg"
211219
vcpkg_root.mkdir()
@@ -225,6 +233,7 @@ def test_generate_skips_clone_when_vcpkg_root_exists(self, tmp_path, monkeypatch
225233

226234
def test_generate_reclones_when_vcpkg_root_exists_but_empty(self, tmp_path, monkeypatch):
227235
monkeypatch.chdir(tmp_path)
236+
self._pin_linux_host(monkeypatch)
228237
self._make_vcpkg_env(tmp_path)
229238
(tmp_path / "vcpkg").mkdir()
230239

@@ -253,6 +262,7 @@ def test_generate_bootstraps_when_vcpkg_executable_missing(self, tmp_path, monke
253262

254263
def test_generate_reclones_when_vcpkg_exists_but_not_working(self, tmp_path, monkeypatch):
255264
monkeypatch.chdir(tmp_path)
265+
self._pin_linux_host(monkeypatch)
256266
self._make_vcpkg_env(tmp_path)
257267
vcpkg_root = tmp_path / "vcpkg"
258268
vcpkg_root.mkdir()

‎hatch_cpp/toolchains/vcpkg.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _read_vcpkg_ref_from_gitmodules(vcpkg_root: Path) -> str | None:
5757
parser.read(str(gitmodules_path))
5858

5959
for section in parser.sections():
60-
if parser.get(section, "path", fallback=None) == str(vcpkg_root):
60+
if parser.get(section, "path", fallback=None) == vcpkg_root.as_posix():
6161
return parser.get(section, "branch", fallback=None)
6262

6363
return None
@@ -93,7 +93,7 @@ def _vcpkg_executable_path(self) -> Path:
9393
def _command_path(self, path: Path) -> str:
9494
if sys_platform == "win32":
9595
return str(path).replace("/", "\\")
96-
return f"./{path}"
96+
return f"./{path.as_posix()}"
9797

9898
def _delete_dir_command(self, path: Path) -> str:
9999
if sys_platform == "win32":

0 commit comments

Comments
 (0)