hatch-cpp 0.3.0__tar.gz → 0.3.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/PKG-INFO +1 -1
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/__init__.py +1 -1
- hatch_cpp-0.3.2/hatch_cpp/tests/test_platform_specific.py +535 -0
- hatch_cpp-0.3.2/hatch_cpp/toolchains/common.py +386 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/pyproject.toml +2 -2
- hatch_cpp-0.3.0/hatch_cpp/toolchains/common.py +0 -248
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/.gitignore +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/LICENSE +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/README.md +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/config.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/hooks.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/plugin.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_hatch_build.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_basic/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_basic/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_basic/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_basic/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake/CMakeLists.txt +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake/Makefile +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake/project/include/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake_vcpkg/CMakeLists.txt +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake_vcpkg/Makefile +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake_vcpkg/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake_vcpkg/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake_vcpkg/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake_vcpkg/project/include/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake_vcpkg/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_cmake_vcpkg/vcpkg.json +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_hatch_build/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_hatch_build/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_hatch_build/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_hatch_build/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_limited_api/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_limited_api/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_limited_api/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_limited_api/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_nanobind/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_nanobind/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_nanobind/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_override_classes/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_override_classes/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_override_classes/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_override_toolchain/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_override_toolchain/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_override_toolchain/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_pybind/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_pybind/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_pybind/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.cpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_pybind_vcpkg/cpp/project/basic.hpp +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_pybind_vcpkg/project/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_pybind_vcpkg/pyproject.toml +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_project_pybind_vcpkg/vcpkg.json +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_projects.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/tests/test_structs.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/toolchains/__init__.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/toolchains/cmake.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/toolchains/vcpkg.py +0 -0
- {hatch_cpp-0.3.0 → hatch_cpp-0.3.2}/hatch_cpp/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hatch-cpp
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Hatch plugin for C++ builds
|
|
5
5
|
Project-URL: Repository, https://github.com/python-project-templates/hatch-cpp
|
|
6
6
|
Project-URL: Homepage, https://github.com/python-project-templates/hatch-cpp
|
|
@@ -0,0 +1,535 @@
|
|
|
1
|
+
"""Tests for platform-specific library configuration fields."""
|
|
2
|
+
|
|
3
|
+
from hatch_cpp import HatchCppLibrary, HatchCppPlatform
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class TestPlatformSpecificFields:
|
|
7
|
+
"""Test suite for platform-specific field handling in HatchCppLibrary."""
|
|
8
|
+
|
|
9
|
+
def test_effective_include_dirs(self):
|
|
10
|
+
"""Test that include_dirs are properly merged with platform-specific dirs."""
|
|
11
|
+
library = HatchCppLibrary(
|
|
12
|
+
name="test",
|
|
13
|
+
sources=["test.cpp"],
|
|
14
|
+
include_dirs=["common/include"],
|
|
15
|
+
include_dirs_linux=["linux/include"],
|
|
16
|
+
include_dirs_darwin=["darwin/include"],
|
|
17
|
+
include_dirs_win32=["win32/include"],
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
linux_dirs = library.get_effective_include_dirs("linux")
|
|
21
|
+
assert "common/include" in linux_dirs
|
|
22
|
+
assert "linux/include" in linux_dirs
|
|
23
|
+
assert "darwin/include" not in linux_dirs
|
|
24
|
+
assert "win32/include" not in linux_dirs
|
|
25
|
+
|
|
26
|
+
darwin_dirs = library.get_effective_include_dirs("darwin")
|
|
27
|
+
assert "common/include" in darwin_dirs
|
|
28
|
+
assert "darwin/include" in darwin_dirs
|
|
29
|
+
assert "linux/include" not in darwin_dirs
|
|
30
|
+
|
|
31
|
+
win32_dirs = library.get_effective_include_dirs("win32")
|
|
32
|
+
assert "common/include" in win32_dirs
|
|
33
|
+
assert "win32/include" in win32_dirs
|
|
34
|
+
assert "linux/include" not in win32_dirs
|
|
35
|
+
|
|
36
|
+
def test_effective_library_dirs(self):
|
|
37
|
+
"""Test that library_dirs are properly merged with platform-specific dirs."""
|
|
38
|
+
library = HatchCppLibrary(
|
|
39
|
+
name="test",
|
|
40
|
+
sources=["test.cpp"],
|
|
41
|
+
library_dirs=["common/lib"],
|
|
42
|
+
library_dirs_linux=["linux/lib"],
|
|
43
|
+
library_dirs_darwin=["darwin/lib"],
|
|
44
|
+
library_dirs_win32=["win32/lib"],
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
linux_dirs = library.get_effective_library_dirs("linux")
|
|
48
|
+
assert "common/lib" in linux_dirs
|
|
49
|
+
assert "linux/lib" in linux_dirs
|
|
50
|
+
assert "darwin/lib" not in linux_dirs
|
|
51
|
+
|
|
52
|
+
darwin_dirs = library.get_effective_library_dirs("darwin")
|
|
53
|
+
assert "common/lib" in darwin_dirs
|
|
54
|
+
assert "darwin/lib" in darwin_dirs
|
|
55
|
+
|
|
56
|
+
win32_dirs = library.get_effective_library_dirs("win32")
|
|
57
|
+
assert "common/lib" in win32_dirs
|
|
58
|
+
assert "win32/lib" in win32_dirs
|
|
59
|
+
|
|
60
|
+
def test_effective_libraries(self):
|
|
61
|
+
"""Test that libraries are properly merged with platform-specific libraries."""
|
|
62
|
+
library = HatchCppLibrary(
|
|
63
|
+
name="test",
|
|
64
|
+
sources=["test.cpp"],
|
|
65
|
+
libraries=["common"],
|
|
66
|
+
libraries_linux=["pthread", "dl"],
|
|
67
|
+
libraries_darwin=["objc"],
|
|
68
|
+
libraries_win32=["kernel32", "user32"],
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
linux_libs = library.get_effective_libraries("linux")
|
|
72
|
+
assert "common" in linux_libs
|
|
73
|
+
assert "pthread" in linux_libs
|
|
74
|
+
assert "dl" in linux_libs
|
|
75
|
+
assert "objc" not in linux_libs
|
|
76
|
+
|
|
77
|
+
darwin_libs = library.get_effective_libraries("darwin")
|
|
78
|
+
assert "common" in darwin_libs
|
|
79
|
+
assert "objc" in darwin_libs
|
|
80
|
+
assert "pthread" not in darwin_libs
|
|
81
|
+
|
|
82
|
+
win32_libs = library.get_effective_libraries("win32")
|
|
83
|
+
assert "common" in win32_libs
|
|
84
|
+
assert "kernel32" in win32_libs
|
|
85
|
+
assert "user32" in win32_libs
|
|
86
|
+
assert "pthread" not in win32_libs
|
|
87
|
+
|
|
88
|
+
def test_effective_compile_args(self):
|
|
89
|
+
"""Test that extra_compile_args are properly merged with platform-specific args."""
|
|
90
|
+
library = HatchCppLibrary(
|
|
91
|
+
name="test",
|
|
92
|
+
sources=["test.cpp"],
|
|
93
|
+
extra_compile_args=["-O2"],
|
|
94
|
+
extra_compile_args_linux=["-march=native"],
|
|
95
|
+
extra_compile_args_darwin=["-mmacosx-version-min=11"],
|
|
96
|
+
extra_compile_args_win32=["/O2"],
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
linux_args = library.get_effective_compile_args("linux")
|
|
100
|
+
assert "-O2" in linux_args
|
|
101
|
+
assert "-march=native" in linux_args
|
|
102
|
+
assert "-mmacosx-version-min=11" not in linux_args
|
|
103
|
+
|
|
104
|
+
darwin_args = library.get_effective_compile_args("darwin")
|
|
105
|
+
assert "-O2" in darwin_args
|
|
106
|
+
assert "-mmacosx-version-min=11" in darwin_args
|
|
107
|
+
|
|
108
|
+
win32_args = library.get_effective_compile_args("win32")
|
|
109
|
+
assert "-O2" in win32_args
|
|
110
|
+
assert "/O2" in win32_args
|
|
111
|
+
|
|
112
|
+
def test_effective_link_args(self):
|
|
113
|
+
"""Test that extra_link_args are properly merged with platform-specific args."""
|
|
114
|
+
library = HatchCppLibrary(
|
|
115
|
+
name="test",
|
|
116
|
+
sources=["test.cpp"],
|
|
117
|
+
extra_link_args=["-shared"],
|
|
118
|
+
extra_link_args_linux=["-Wl,-rpath,$ORIGIN/lib"],
|
|
119
|
+
extra_link_args_darwin=["-Wl,-rpath,@loader_path/lib"],
|
|
120
|
+
extra_link_args_win32=["/NODEFAULTLIB"],
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
linux_args = library.get_effective_link_args("linux")
|
|
124
|
+
assert "-shared" in linux_args
|
|
125
|
+
assert "-Wl,-rpath,$ORIGIN/lib" in linux_args
|
|
126
|
+
assert "-Wl,-rpath,@loader_path/lib" not in linux_args
|
|
127
|
+
|
|
128
|
+
darwin_args = library.get_effective_link_args("darwin")
|
|
129
|
+
assert "-shared" in darwin_args
|
|
130
|
+
assert "-Wl,-rpath,@loader_path/lib" in darwin_args
|
|
131
|
+
|
|
132
|
+
win32_args = library.get_effective_link_args("win32")
|
|
133
|
+
assert "-shared" in win32_args
|
|
134
|
+
assert "/NODEFAULTLIB" in win32_args
|
|
135
|
+
|
|
136
|
+
def test_effective_extra_objects(self):
|
|
137
|
+
"""Test that extra_objects are properly merged with platform-specific objects."""
|
|
138
|
+
library = HatchCppLibrary(
|
|
139
|
+
name="test",
|
|
140
|
+
sources=["test.cpp"],
|
|
141
|
+
extra_objects=["common.o"],
|
|
142
|
+
extra_objects_linux=["linux.o"],
|
|
143
|
+
extra_objects_darwin=["darwin.o"],
|
|
144
|
+
extra_objects_win32=["win32.obj"],
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
linux_objs = library.get_effective_extra_objects("linux")
|
|
148
|
+
assert "common.o" in linux_objs
|
|
149
|
+
assert "linux.o" in linux_objs
|
|
150
|
+
assert "darwin.o" not in linux_objs
|
|
151
|
+
|
|
152
|
+
darwin_objs = library.get_effective_extra_objects("darwin")
|
|
153
|
+
assert "common.o" in darwin_objs
|
|
154
|
+
assert "darwin.o" in darwin_objs
|
|
155
|
+
|
|
156
|
+
win32_objs = library.get_effective_extra_objects("win32")
|
|
157
|
+
assert "common.o" in win32_objs
|
|
158
|
+
assert "win32.obj" in win32_objs
|
|
159
|
+
|
|
160
|
+
def test_effective_define_macros(self):
|
|
161
|
+
"""Test that define_macros are properly merged with platform-specific macros."""
|
|
162
|
+
library = HatchCppLibrary(
|
|
163
|
+
name="test",
|
|
164
|
+
sources=["test.cpp"],
|
|
165
|
+
define_macros=["COMMON=1"],
|
|
166
|
+
define_macros_linux=["LINUX=1", "_GNU_SOURCE"],
|
|
167
|
+
define_macros_darwin=["DARWIN=1", "__APPLE__"],
|
|
168
|
+
define_macros_win32=["WIN32=1", "_WINDOWS"],
|
|
169
|
+
)
|
|
170
|
+
|
|
171
|
+
linux_macros = library.get_effective_define_macros("linux")
|
|
172
|
+
assert "COMMON=1" in linux_macros
|
|
173
|
+
assert "LINUX=1" in linux_macros
|
|
174
|
+
assert "_GNU_SOURCE" in linux_macros
|
|
175
|
+
assert "DARWIN=1" not in linux_macros
|
|
176
|
+
|
|
177
|
+
darwin_macros = library.get_effective_define_macros("darwin")
|
|
178
|
+
assert "COMMON=1" in darwin_macros
|
|
179
|
+
assert "DARWIN=1" in darwin_macros
|
|
180
|
+
assert "__APPLE__" in darwin_macros
|
|
181
|
+
|
|
182
|
+
win32_macros = library.get_effective_define_macros("win32")
|
|
183
|
+
assert "COMMON=1" in win32_macros
|
|
184
|
+
assert "WIN32=1" in win32_macros
|
|
185
|
+
assert "_WINDOWS" in win32_macros
|
|
186
|
+
|
|
187
|
+
def test_effective_undef_macros(self):
|
|
188
|
+
"""Test that undef_macros are properly merged with platform-specific macros."""
|
|
189
|
+
library = HatchCppLibrary(
|
|
190
|
+
name="test",
|
|
191
|
+
sources=["test.cpp"],
|
|
192
|
+
undef_macros=["COMMON_UNDEF"],
|
|
193
|
+
undef_macros_linux=["LINUX_UNDEF"],
|
|
194
|
+
undef_macros_darwin=["DARWIN_UNDEF"],
|
|
195
|
+
undef_macros_win32=["WIN32_UNDEF"],
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
linux_macros = library.get_effective_undef_macros("linux")
|
|
199
|
+
assert "COMMON_UNDEF" in linux_macros
|
|
200
|
+
assert "LINUX_UNDEF" in linux_macros
|
|
201
|
+
assert "DARWIN_UNDEF" not in linux_macros
|
|
202
|
+
|
|
203
|
+
darwin_macros = library.get_effective_undef_macros("darwin")
|
|
204
|
+
assert "COMMON_UNDEF" in darwin_macros
|
|
205
|
+
assert "DARWIN_UNDEF" in darwin_macros
|
|
206
|
+
|
|
207
|
+
win32_macros = library.get_effective_undef_macros("win32")
|
|
208
|
+
assert "COMMON_UNDEF" in win32_macros
|
|
209
|
+
assert "WIN32_UNDEF" in win32_macros
|
|
210
|
+
|
|
211
|
+
def test_empty_platform_specific_fields(self):
|
|
212
|
+
"""Test that empty platform-specific fields don't cause issues."""
|
|
213
|
+
library = HatchCppLibrary(
|
|
214
|
+
name="test",
|
|
215
|
+
sources=["test.cpp"],
|
|
216
|
+
include_dirs=["common/include"],
|
|
217
|
+
# No platform-specific fields set
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
linux_dirs = library.get_effective_include_dirs("linux")
|
|
221
|
+
assert linux_dirs == ["common/include"]
|
|
222
|
+
|
|
223
|
+
darwin_dirs = library.get_effective_include_dirs("darwin")
|
|
224
|
+
assert darwin_dirs == ["common/include"]
|
|
225
|
+
|
|
226
|
+
win32_dirs = library.get_effective_include_dirs("win32")
|
|
227
|
+
assert win32_dirs == ["common/include"]
|
|
228
|
+
|
|
229
|
+
def test_only_platform_specific_fields(self):
|
|
230
|
+
"""Test that only platform-specific fields work without common fields."""
|
|
231
|
+
library = HatchCppLibrary(
|
|
232
|
+
name="test",
|
|
233
|
+
sources=["test.cpp"],
|
|
234
|
+
# No common include_dirs
|
|
235
|
+
include_dirs_linux=["linux/include"],
|
|
236
|
+
include_dirs_darwin=["darwin/include"],
|
|
237
|
+
)
|
|
238
|
+
|
|
239
|
+
linux_dirs = library.get_effective_include_dirs("linux")
|
|
240
|
+
assert linux_dirs == ["linux/include"]
|
|
241
|
+
|
|
242
|
+
darwin_dirs = library.get_effective_include_dirs("darwin")
|
|
243
|
+
assert darwin_dirs == ["darwin/include"]
|
|
244
|
+
|
|
245
|
+
win32_dirs = library.get_effective_include_dirs("win32")
|
|
246
|
+
assert win32_dirs == []
|
|
247
|
+
|
|
248
|
+
def test_alias_hyphenated_names(self):
|
|
249
|
+
"""Test that hyphenated field names work as aliases."""
|
|
250
|
+
library = HatchCppLibrary(
|
|
251
|
+
name="test",
|
|
252
|
+
sources=["test.cpp"],
|
|
253
|
+
**{
|
|
254
|
+
"include-dirs": ["common/include"],
|
|
255
|
+
"include-dirs-linux": ["linux/include"],
|
|
256
|
+
"library-dirs-darwin": ["darwin/lib"],
|
|
257
|
+
"extra-compile-args-win32": ["/O2"],
|
|
258
|
+
"extra-link-args-linux": ["-Wl,-rpath,$ORIGIN"],
|
|
259
|
+
"define-macros-darwin": ["DARWIN=1"],
|
|
260
|
+
"undef-macros-win32": ["NDEBUG"],
|
|
261
|
+
},
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
assert library.include_dirs == ["common/include"]
|
|
265
|
+
assert library.include_dirs_linux == ["linux/include"]
|
|
266
|
+
assert library.library_dirs_darwin == ["darwin/lib"]
|
|
267
|
+
assert library.extra_compile_args_win32 == ["/O2"]
|
|
268
|
+
assert library.extra_link_args_linux == ["-Wl,-rpath,$ORIGIN"]
|
|
269
|
+
assert library.define_macros_darwin == ["DARWIN=1"]
|
|
270
|
+
assert library.undef_macros_win32 == ["NDEBUG"]
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
class TestPlatformFlagsIntegration:
|
|
274
|
+
"""Integration tests for platform-specific fields in compile/link flags."""
|
|
275
|
+
|
|
276
|
+
def test_compile_flags_include_platform_specific_include_dirs(self):
|
|
277
|
+
"""Test that get_compile_flags includes platform-specific include dirs."""
|
|
278
|
+
library = HatchCppLibrary(
|
|
279
|
+
name="test",
|
|
280
|
+
sources=["test.cpp"],
|
|
281
|
+
binding="generic",
|
|
282
|
+
include_dirs=["common/include"],
|
|
283
|
+
include_dirs_linux=["linux/include"],
|
|
284
|
+
)
|
|
285
|
+
|
|
286
|
+
# Create a mock linux platform
|
|
287
|
+
platform = HatchCppPlatform(cc="gcc", cxx="g++", ld="ld", platform="linux", toolchain="gcc", disable_ccache=True)
|
|
288
|
+
|
|
289
|
+
flags = platform.get_compile_flags(library)
|
|
290
|
+
assert "-Icommon/include" in flags
|
|
291
|
+
assert "-Ilinux/include" in flags
|
|
292
|
+
|
|
293
|
+
def test_compile_flags_include_platform_specific_macros(self):
|
|
294
|
+
"""Test that get_compile_flags includes platform-specific define/undef macros."""
|
|
295
|
+
library = HatchCppLibrary(
|
|
296
|
+
name="test",
|
|
297
|
+
sources=["test.cpp"],
|
|
298
|
+
binding="generic",
|
|
299
|
+
define_macros=["COMMON=1"],
|
|
300
|
+
define_macros_linux=["LINUX_SPECIFIC=1"],
|
|
301
|
+
undef_macros=["OLD_MACRO"],
|
|
302
|
+
undef_macros_linux=["LINUX_OLD"],
|
|
303
|
+
)
|
|
304
|
+
|
|
305
|
+
platform = HatchCppPlatform(cc="gcc", cxx="g++", ld="ld", platform="linux", toolchain="gcc", disable_ccache=True)
|
|
306
|
+
|
|
307
|
+
flags = platform.get_compile_flags(library)
|
|
308
|
+
assert "-DCOMMON=1" in flags
|
|
309
|
+
assert "-DLINUX_SPECIFIC=1" in flags
|
|
310
|
+
assert "-UOLD_MACRO" in flags
|
|
311
|
+
assert "-ULINUX_OLD" in flags
|
|
312
|
+
|
|
313
|
+
def test_link_flags_include_platform_specific_libraries(self):
|
|
314
|
+
"""Test that get_link_flags includes platform-specific libraries."""
|
|
315
|
+
library = HatchCppLibrary(
|
|
316
|
+
name="test",
|
|
317
|
+
sources=["test.cpp"],
|
|
318
|
+
binding="generic",
|
|
319
|
+
libraries=["common"],
|
|
320
|
+
libraries_linux=["pthread", "dl"],
|
|
321
|
+
library_dirs=["common/lib"],
|
|
322
|
+
library_dirs_linux=["linux/lib"],
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
platform = HatchCppPlatform(cc="gcc", cxx="g++", ld="ld", platform="linux", toolchain="gcc", disable_ccache=True)
|
|
326
|
+
|
|
327
|
+
flags = platform.get_link_flags(library)
|
|
328
|
+
assert "-lcommon" in flags
|
|
329
|
+
assert "-lpthread" in flags
|
|
330
|
+
assert "-ldl" in flags
|
|
331
|
+
assert "-Lcommon/lib" in flags
|
|
332
|
+
assert "-Llinux/lib" in flags
|
|
333
|
+
|
|
334
|
+
def test_link_flags_include_platform_specific_link_args(self):
|
|
335
|
+
"""Test that get_link_flags includes platform-specific extra_link_args."""
|
|
336
|
+
library = HatchCppLibrary(
|
|
337
|
+
name="test",
|
|
338
|
+
sources=["test.cpp"],
|
|
339
|
+
binding="generic",
|
|
340
|
+
extra_link_args=["-shared"],
|
|
341
|
+
extra_link_args_linux=["-Wl,-rpath,$ORIGIN/lib"],
|
|
342
|
+
)
|
|
343
|
+
|
|
344
|
+
platform = HatchCppPlatform(cc="gcc", cxx="g++", ld="ld", platform="linux", toolchain="gcc", disable_ccache=True)
|
|
345
|
+
|
|
346
|
+
flags = platform.get_link_flags(library)
|
|
347
|
+
assert "-shared" in flags
|
|
348
|
+
assert "-Wl,-rpath,$ORIGIN/lib" in flags
|
|
349
|
+
|
|
350
|
+
def test_darwin_platform_uses_darwin_specific_fields(self):
|
|
351
|
+
"""Test that darwin platform uses darwin-specific fields."""
|
|
352
|
+
library = HatchCppLibrary(
|
|
353
|
+
name="test",
|
|
354
|
+
sources=["test.cpp"],
|
|
355
|
+
binding="generic",
|
|
356
|
+
libraries_linux=["pthread"],
|
|
357
|
+
libraries_darwin=["objc"],
|
|
358
|
+
extra_link_args_darwin=["-Wl,-rpath,@loader_path/lib"],
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
platform = HatchCppPlatform(cc="clang", cxx="clang++", ld="ld", platform="darwin", toolchain="clang", disable_ccache=True)
|
|
362
|
+
|
|
363
|
+
flags = platform.get_link_flags(library)
|
|
364
|
+
assert "-lobjc" in flags
|
|
365
|
+
assert "-lpthread" not in flags
|
|
366
|
+
assert "-Wl,-rpath,@loader_path/lib" in flags
|
|
367
|
+
|
|
368
|
+
def test_win32_platform_uses_win32_specific_fields(self):
|
|
369
|
+
"""Test that win32 platform uses win32-specific fields."""
|
|
370
|
+
library = HatchCppLibrary(
|
|
371
|
+
name="test",
|
|
372
|
+
sources=["test.cpp"],
|
|
373
|
+
binding="generic",
|
|
374
|
+
libraries=["common"],
|
|
375
|
+
libraries_win32=["kernel32"],
|
|
376
|
+
library_dirs=["common/lib"],
|
|
377
|
+
library_dirs_win32=["win32/lib"],
|
|
378
|
+
)
|
|
379
|
+
|
|
380
|
+
platform = HatchCppPlatform(cc="cl", cxx="cl", ld="link", platform="win32", toolchain="msvc", disable_ccache=True)
|
|
381
|
+
|
|
382
|
+
flags = platform.get_link_flags(library)
|
|
383
|
+
assert "common.lib" in flags
|
|
384
|
+
assert "kernel32.lib" in flags
|
|
385
|
+
assert "/LIBPATH:common/lib" in flags
|
|
386
|
+
assert "/LIBPATH:win32/lib" in flags
|
|
387
|
+
|
|
388
|
+
def test_msvc_compile_flags_use_platform_specific_fields(self):
|
|
389
|
+
"""Test that MSVC compile flags include platform-specific fields."""
|
|
390
|
+
library = HatchCppLibrary(
|
|
391
|
+
name="test",
|
|
392
|
+
sources=["test.cpp"],
|
|
393
|
+
binding="generic",
|
|
394
|
+
include_dirs=["common/include"],
|
|
395
|
+
include_dirs_win32=["win32/include"],
|
|
396
|
+
define_macros=["COMMON=1"],
|
|
397
|
+
define_macros_win32=["_WINDOWS"],
|
|
398
|
+
extra_compile_args_win32=["/W4"],
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
platform = HatchCppPlatform(cc="cl", cxx="cl", ld="link", platform="win32", toolchain="msvc", disable_ccache=True)
|
|
402
|
+
|
|
403
|
+
flags = platform.get_compile_flags(library)
|
|
404
|
+
assert "/Icommon/include" in flags
|
|
405
|
+
assert "/Iwin32/include" in flags
|
|
406
|
+
assert "/DCOMMON=1" in flags
|
|
407
|
+
assert "/D_WINDOWS" in flags
|
|
408
|
+
assert "/W4" in flags
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
class TestPlatformFieldOrdering:
|
|
412
|
+
"""Test that platform-specific fields are appended after common fields."""
|
|
413
|
+
|
|
414
|
+
def test_include_dirs_ordering(self):
|
|
415
|
+
"""Test that platform-specific include dirs come after common dirs."""
|
|
416
|
+
library = HatchCppLibrary(
|
|
417
|
+
name="test",
|
|
418
|
+
sources=["test.cpp"],
|
|
419
|
+
include_dirs=["first", "second"],
|
|
420
|
+
include_dirs_linux=["third", "fourth"],
|
|
421
|
+
)
|
|
422
|
+
|
|
423
|
+
dirs = library.get_effective_include_dirs("linux")
|
|
424
|
+
assert dirs == ["first", "second", "third", "fourth"]
|
|
425
|
+
|
|
426
|
+
def test_libraries_ordering(self):
|
|
427
|
+
"""Test that platform-specific libraries come after common libraries."""
|
|
428
|
+
library = HatchCppLibrary(
|
|
429
|
+
name="test",
|
|
430
|
+
sources=["test.cpp"],
|
|
431
|
+
libraries=["common1", "common2"],
|
|
432
|
+
libraries_linux=["linux1", "linux2"],
|
|
433
|
+
)
|
|
434
|
+
|
|
435
|
+
libs = library.get_effective_libraries("linux")
|
|
436
|
+
assert libs == ["common1", "common2", "linux1", "linux2"]
|
|
437
|
+
|
|
438
|
+
def test_base_list_not_mutated(self):
|
|
439
|
+
"""Test that the base lists are not mutated when getting effective values."""
|
|
440
|
+
library = HatchCppLibrary(
|
|
441
|
+
name="test",
|
|
442
|
+
sources=["test.cpp"],
|
|
443
|
+
include_dirs=["common"],
|
|
444
|
+
include_dirs_linux=["linux"],
|
|
445
|
+
)
|
|
446
|
+
|
|
447
|
+
# Get effective dirs multiple times
|
|
448
|
+
dirs1 = library.get_effective_include_dirs("linux")
|
|
449
|
+
dirs2 = library.get_effective_include_dirs("linux")
|
|
450
|
+
|
|
451
|
+
# Both should be equal
|
|
452
|
+
assert dirs1 == dirs2
|
|
453
|
+
|
|
454
|
+
# Base list should not be modified
|
|
455
|
+
assert library.include_dirs == ["common"]
|
|
456
|
+
assert library.include_dirs_linux == ["linux"]
|
|
457
|
+
|
|
458
|
+
|
|
459
|
+
class TestMSVCPythonLibsPath:
|
|
460
|
+
"""Tests for MSVC Python libs path discovery."""
|
|
461
|
+
|
|
462
|
+
def test_msvc_link_flags_include_libpath(self):
|
|
463
|
+
"""Test that MSVC link flags include /LIBPATH for Python libs."""
|
|
464
|
+
library = HatchCppLibrary(
|
|
465
|
+
name="test",
|
|
466
|
+
sources=["test.cpp"],
|
|
467
|
+
binding="generic", # Skip Python.h include
|
|
468
|
+
)
|
|
469
|
+
|
|
470
|
+
platform = HatchCppPlatform(
|
|
471
|
+
cc="cl",
|
|
472
|
+
cxx="cl",
|
|
473
|
+
ld="link",
|
|
474
|
+
platform="win32",
|
|
475
|
+
toolchain="msvc",
|
|
476
|
+
disable_ccache=True,
|
|
477
|
+
)
|
|
478
|
+
|
|
479
|
+
flags = platform.get_link_flags(library)
|
|
480
|
+
# Should have /link /DLL flags
|
|
481
|
+
assert "/link" in flags
|
|
482
|
+
assert "/DLL" in flags
|
|
483
|
+
# Should have output file
|
|
484
|
+
assert "/Fe:" in flags
|
|
485
|
+
|
|
486
|
+
def test_msvc_link_flags_with_libraries(self):
|
|
487
|
+
"""Test that MSVC link flags properly format library names."""
|
|
488
|
+
library = HatchCppLibrary(
|
|
489
|
+
name="test",
|
|
490
|
+
sources=["test.cpp"],
|
|
491
|
+
binding="generic",
|
|
492
|
+
libraries=["mylib"],
|
|
493
|
+
library_dirs=["path/to/libs"],
|
|
494
|
+
)
|
|
495
|
+
|
|
496
|
+
platform = HatchCppPlatform(
|
|
497
|
+
cc="cl",
|
|
498
|
+
cxx="cl",
|
|
499
|
+
ld="link",
|
|
500
|
+
platform="win32",
|
|
501
|
+
toolchain="msvc",
|
|
502
|
+
disable_ccache=True,
|
|
503
|
+
)
|
|
504
|
+
|
|
505
|
+
flags = platform.get_link_flags(library)
|
|
506
|
+
# Libraries should have .lib suffix on Windows
|
|
507
|
+
assert "mylib.lib" in flags
|
|
508
|
+
# Library dirs should use /LIBPATH:
|
|
509
|
+
assert "/LIBPATH:path/to/libs" in flags
|
|
510
|
+
|
|
511
|
+
def test_msvc_link_flags_with_platform_specific_libraries(self):
|
|
512
|
+
"""Test that MSVC uses win32-specific libraries."""
|
|
513
|
+
library = HatchCppLibrary(
|
|
514
|
+
name="test",
|
|
515
|
+
sources=["test.cpp"],
|
|
516
|
+
binding="generic",
|
|
517
|
+
libraries=["common"],
|
|
518
|
+
libraries_win32=["kernel32", "user32"],
|
|
519
|
+
library_dirs_win32=["C:/Windows/System32"],
|
|
520
|
+
)
|
|
521
|
+
|
|
522
|
+
platform = HatchCppPlatform(
|
|
523
|
+
cc="cl",
|
|
524
|
+
cxx="cl",
|
|
525
|
+
ld="link",
|
|
526
|
+
platform="win32",
|
|
527
|
+
toolchain="msvc",
|
|
528
|
+
disable_ccache=True,
|
|
529
|
+
)
|
|
530
|
+
|
|
531
|
+
flags = platform.get_link_flags(library)
|
|
532
|
+
assert "common.lib" in flags
|
|
533
|
+
assert "kernel32.lib" in flags
|
|
534
|
+
assert "user32.lib" in flags
|
|
535
|
+
assert "/LIBPATH:C:/Windows/System32" in flags
|