Skip to content

Commit 882f4d0

Browse files
authored
Add test for ignore recipe (#120)
1 parent 50690ae commit 882f4d0

7 files changed

Lines changed: 139 additions & 2 deletions

File tree

.github/workflows/tox.yml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,17 @@ jobs:
3131
container: python:3.7-slim
3232
- platform: macos-15
3333
python-version: '3.12'
34+
# Cover both cmake generator styles on windows: MSBuild and NMake.
35+
# VS 2026 needs cmake >= 4.2, which needs a policy minimum for the
36+
# cmake_minimum_required(VERSION 2.8) test packages.
3437
- platform: windows-2025
3538
python-version: '3.12'
39+
cmake-generator: 'Visual Studio 18 2026'
40+
cmake-version: '4.2.0'
41+
cmake-policy-min: '3.5'
42+
- platform: windows-2025
43+
python-version: '3.12'
44+
cmake-generator: 'NMake Makefiles'
3645

3746
steps:
3847
- uses: actions/checkout@v6
@@ -48,7 +57,7 @@ jobs:
4857
- name: Setup cmake
4958
uses: jwlawson/actions-setup-cmake@v1.9
5059
with:
51-
cmake-version: 3.31.0
60+
cmake-version: ${{ matrix.cmake-version || '3.31.0' }}
5261
- name: Install build tools
5362
if: matrix.container
5463
run: |
@@ -65,3 +74,5 @@ jobs:
6574
run: tox -e py,lint
6675
env:
6776
CGET_VERBOSE: 1
77+
CGET_DEFAULT_GENERATOR: ${{ matrix.cmake-generator }}
78+
CMAKE_POLICY_VERSION_MINIMUM: ${{ matrix.cmake-policy-min }}

cget/builder.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,20 @@ def get_path(self, *args):
1717
def get_build_path(self, *args):
1818
return self.get_path('build', *args)
1919

20+
def get_generator(self):
21+
cache_file = self.get_build_path('CMakeCache.txt')
22+
if os.path.exists(cache_file):
23+
with open(cache_file) as f:
24+
for line in f:
25+
if line.startswith('CMAKE_GENERATOR:'):
26+
return line.split('=', 1)[1].strip()
27+
return None
28+
2029
def is_make_generator(self):
30+
# NMake also writes a Makefile, but nmake has no -j option
31+
generator = self.get_generator()
32+
if generator is not None:
33+
return 'Makefiles' in generator and 'NMake' not in generator
2134
return os.path.exists(self.get_build_path('Makefile'))
2235

2336
def cmake(self, options=None, use_toolchain=False, **kwargs):
@@ -61,7 +74,8 @@ def configure(self, src_dir, defines=None, generator=None, install_prefix=None,
6174
]
6275
for d in defines or []:
6376
args.append('-D{0}'.format(d))
64-
if generator is not None: args = ['-G', generator] + args
77+
if generator is None: generator = os.environ.get('CGET_DEFAULT_GENERATOR')
78+
if generator: args = ['-G', generator] + args
6579
if self.prefix.verbose: args.extend(['-DCMAKE_VERBOSE_MAKEFILE=On'])
6680
if test: args.extend(['-DBUILD_TESTING=On'])
6781
else: args.extend(['-DBUILD_TESTING=Off'])

test/basicrecipes/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cmake_minimum_required(VERSION 2.8)
12

23
file(GLOB_RECURSE RECIPES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} recipes/*.txt recipes/*.cget recipes/*.cmake)
34

test/symlinkdir/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
cmake_minimum_required(VERSION 2.8)
12

23
install(SCRIPT install.cmake)
34

test/test_builder.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,49 @@ def test_false_when_no_makefile(self, tmp_path):
8282
b = Builder(prefix, top)
8383
assert b.is_make_generator() is False
8484

85+
def write_cache(self, build_dir, generator):
86+
with open(os.path.join(build_dir, "CMakeCache.txt"), "w") as f:
87+
f.write("CMAKE_GENERATOR:INTERNAL={}\n".format(generator))
88+
f.write("CMAKE_GENERATOR_INSTANCE:INTERNAL=\n")
89+
90+
def test_true_for_unix_makefiles_cache(self, tmp_path):
91+
prefix = MockPrefix(str(tmp_path))
92+
top = str(tmp_path / "top")
93+
build_dir = os.path.join(top, "build")
94+
os.makedirs(build_dir)
95+
self.write_cache(build_dir, "Unix Makefiles")
96+
with open(os.path.join(build_dir, "Makefile"), "w") as f:
97+
f.write("")
98+
b = Builder(prefix, top)
99+
assert b.is_make_generator() is True
100+
101+
def test_false_for_nmake_cache(self, tmp_path):
102+
prefix = MockPrefix(str(tmp_path))
103+
top = str(tmp_path / "top")
104+
build_dir = os.path.join(top, "build")
105+
os.makedirs(build_dir)
106+
self.write_cache(build_dir, "NMake Makefiles")
107+
with open(os.path.join(build_dir, "Makefile"), "w") as f:
108+
f.write("")
109+
b = Builder(prefix, top)
110+
assert b.is_make_generator() is False
111+
112+
def test_false_for_ninja_cache(self, tmp_path):
113+
prefix = MockPrefix(str(tmp_path))
114+
top = str(tmp_path / "top")
115+
build_dir = os.path.join(top, "build")
116+
os.makedirs(build_dir)
117+
self.write_cache(build_dir, "Ninja")
118+
b = Builder(prefix, top)
119+
assert b.is_make_generator() is False
120+
121+
def test_get_generator_no_cache(self, tmp_path):
122+
prefix = MockPrefix(str(tmp_path))
123+
top = str(tmp_path / "top")
124+
os.makedirs(top)
125+
b = Builder(prefix, top)
126+
assert b.get_generator() is None
127+
85128

86129
# ── show_log / show_logs ─────────────────────────────────────────────────────
87130

@@ -214,6 +257,52 @@ def test_configure_with_generator(self, tmp_path):
214257
idx = args.index('-G')
215258
assert args[idx + 1] == "Ninja"
216259

260+
def test_configure_default_generator_env(self, tmp_path, monkeypatch):
261+
monkeypatch.setenv("CGET_DEFAULT_GENERATOR", "NMake Makefiles")
262+
prefix = MockPrefix(str(tmp_path))
263+
top = str(tmp_path / "top")
264+
os.makedirs(top)
265+
b = Builder(prefix, top)
266+
src_dir = str(tmp_path / "src")
267+
os.makedirs(src_dir)
268+
269+
with mock.patch.object(b, 'cmake') as mock_cmake:
270+
b.configure(src_dir)
271+
args = mock_cmake.call_args[1]['args']
272+
assert '-G' in args
273+
idx = args.index('-G')
274+
assert args[idx + 1] == "NMake Makefiles"
275+
276+
def test_configure_generator_overrides_env(self, tmp_path, monkeypatch):
277+
monkeypatch.setenv("CGET_DEFAULT_GENERATOR", "NMake Makefiles")
278+
prefix = MockPrefix(str(tmp_path))
279+
top = str(tmp_path / "top")
280+
os.makedirs(top)
281+
b = Builder(prefix, top)
282+
src_dir = str(tmp_path / "src")
283+
os.makedirs(src_dir)
284+
285+
with mock.patch.object(b, 'cmake') as mock_cmake:
286+
b.configure(src_dir, generator="Ninja")
287+
args = mock_cmake.call_args[1]['args']
288+
idx = args.index('-G')
289+
assert args[idx + 1] == "Ninja"
290+
assert "NMake Makefiles" not in args
291+
292+
def test_configure_empty_generator_env_ignored(self, tmp_path, monkeypatch):
293+
monkeypatch.setenv("CGET_DEFAULT_GENERATOR", "")
294+
prefix = MockPrefix(str(tmp_path))
295+
top = str(tmp_path / "top")
296+
os.makedirs(top)
297+
b = Builder(prefix, top)
298+
src_dir = str(tmp_path / "src")
299+
os.makedirs(src_dir)
300+
301+
with mock.patch.object(b, 'cmake') as mock_cmake:
302+
b.configure(src_dir)
303+
args = mock_cmake.call_args[1]['args']
304+
assert '-G' not in args
305+
217306
def test_configure_with_install_prefix(self, tmp_path):
218307
prefix = MockPrefix(str(tmp_path))
219308
top = str(tmp_path / "top")

test/test_cget.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,20 @@ def test_ignore_dep(d):
994994
cget_cmd('install', '--verbose', get_exists_path('basicapp'))
995995
])
996996

997+
def test_ignore_recipe_ignore(d):
998+
d.cmds([
999+
cget_cmd('ignore', '--verbose', 'simple'),
1000+
cget_cmd('size', '1'),
1001+
cget_cmd('install', '--verbose --test --update', 'recipes,'+get_exists_path('basicrecipes')),
1002+
cget_cmd('size', '2'),
1003+
cget_cmd('rm', '--verbose -y', 'simple'),
1004+
cget_cmd('size', '1'),
1005+
cget_cmd('rm', '--verbose -y', 'recipes'),
1006+
cget_cmd('size', '0'),
1007+
cget_cmd('ignore', '--verbose', 'simple'),
1008+
cget_cmd('size', '1')
1009+
])
1010+
9971011
@appveyor_skip
9981012
def test_symlink_dir(d):
9991013
d.cmds([

tox.ini

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
envlist = py,lint
33

44
[testenv]
5+
# LIB/INCLUDE/LIBPATH: MSVC vcvars environment, needed when cmake uses NMake/Ninja on Windows
56
passenv =
67
APPVEYOR
78
GITHUB_WORKFLOW
89
CGET_VERBOSE
10+
LIB
11+
INCLUDE
12+
LIBPATH
13+
CGET_USE_SYMLINKS
14+
CGET_DEFAULT_GENERATOR
15+
CMAKE_POLICY_VERSION_MINIMUM
916
deps =
1017
-r{toxinidir}/requirements.txt
1118
coverage

0 commit comments

Comments
 (0)