diff --git a/.github/workflows/python_tests.yml b/.github/workflows/python_tests.yml index 812d32d7..6fa92e07 100644 --- a/.github/workflows/python_tests.yml +++ b/.github/workflows/python_tests.yml @@ -1,4 +1,3 @@ -# TODO: Enable os: windows-latest # TODO: Enable pytest --doctest-modules name: Python_tests @@ -14,11 +13,15 @@ jobs: fail-fast: false max-parallel: 5 matrix: - os: [macos-15-intel, macos-latest, ubuntu-latest] # , windows-latest] + os: [macos-15-intel, macos-latest, ubuntu-latest, windows-latest] python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"] include: - os: macos-26 python-version: 3.x + - os: ubuntu-24.04-arm # Ubuntu on ARM + python-version: "3.14" + - os: windows-11-arm # Windows on ARM + python-version: "3.14" steps: - uses: actions/checkout@v6 - name: Set up Python ${{ matrix.python-version }} diff --git a/.gitignore b/.gitignore index 5f71dbd4..dcf3cb43 100644 --- a/.gitignore +++ b/.gitignore @@ -144,3 +144,7 @@ static test/fixtures/out *.actual +*.sln +*.vcproj +!test/fixtures/expected-win32/**/*.sln +!test/fixtures/expected-win32/**/*.vcproj diff --git a/pylib/gyp/generator/ninja_test.py b/pylib/gyp/generator/ninja_test.py index 616bc7aa..5b688ae7 100644 --- a/pylib/gyp/generator/ninja_test.py +++ b/pylib/gyp/generator/ninja_test.py @@ -11,26 +11,36 @@ from pathlib import Path from gyp.generator import ninja +from gyp.MSVSVersion import SelectVisualStudioVersion + + +def _has_visual_studio(): + """Check if Visual Studio can be detected by gyp's registry-based detection.""" + if not sys.platform.startswith("win"): + return False + try: + SelectVisualStudioVersion("auto", allow_fallback=False) + return True + except ValueError: + return False class TestPrefixesAndSuffixes(unittest.TestCase): + @unittest.skipUnless( + _has_visual_studio(), + "requires Windows with a Visual Studio installation detected via the registry", + ) def test_BinaryNamesWindows(self): - # These cannot run on non-Windows as they require a VS installation to - # correctly handle variable expansion. - if sys.platform.startswith("win"): - writer = ninja.NinjaWriter( - "foo", "wee", ".", ".", "build.ninja", ".", "build.ninja", "win" - ) - spec = {"target_name": "wee"} - self.assertTrue( - writer.ComputeOutputFileName(spec, "executable").endswith(".exe") - ) - self.assertTrue( - writer.ComputeOutputFileName(spec, "shared_library").endswith(".dll") - ) - self.assertTrue( - writer.ComputeOutputFileName(spec, "static_library").endswith(".lib") - ) + writer = ninja.NinjaWriter( + "foo", "wee", ".", ".", "build.ninja", ".", "build.ninja", "win" + ) + spec = {"target_name": "wee"} + for key, ext in { + "executable": ".exe", + "shared_library": ".dll", + "static_library": ".lib", + }: + self.assertTrue(writer.ComputeOutputFileName(spec, key).endswith(ext)) def test_BinaryNamesLinux(self): writer = ninja.NinjaWriter( diff --git a/test/fixtures/expected-win32/msvs/integration.sln b/test/fixtures/expected-win32/msvs/integration.sln new file mode 100644 index 00000000..276e0693 --- /dev/null +++ b/test/fixtures/expected-win32/msvs/integration.sln @@ -0,0 +1,16 @@ +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{*}") = "test", "test.vcproj", "{*}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Default|Win32 = Default|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {*}.Default|Win32.ActiveCfg = Default|Win32 + {*}.Default|Win32.Build.0 = Default|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/test/fixtures/expected-win32/msvs/test.vcproj b/test/fixtures/expected-win32/msvs/test.vcproj new file mode 100644 index 00000000..981a106c --- /dev/null +++ b/test/fixtures/expected-win32/msvs/test.vcproj @@ -0,0 +1 @@ + diff --git a/test/integration_test.py b/test/integration_test.py index b45a62ff..26d78763 100644 --- a/test/integration_test.py +++ b/test/integration_test.py @@ -5,6 +5,7 @@ import os import re import shutil +import sys import unittest import gyp @@ -12,40 +13,48 @@ fixture_dir = os.path.join(os.path.dirname(__file__), "fixtures") gyp_file = os.path.join(os.path.dirname(__file__), "fixtures/integration.gyp") -supported_sysnames = {"darwin", "linux"} -sysname = os.uname().sysname.lower() +if sys.platform == "win32": + sysname = sys.platform +else: + sysname = os.uname().sysname.lower() expected_dir = os.path.join(fixture_dir, f"expected-{sysname}") -class TestGyp(unittest.TestCase): - def setUp(self) -> None: - if sysname not in supported_sysnames: - self.skipTest(f"Unsupported system: {sysname}") - shutil.rmtree(os.path.join(fixture_dir, "out"), ignore_errors=True) +def assert_file(test, actual, expected) -> None: + actual_filepath = os.path.join(fixture_dir, actual) + expected_filepath = os.path.join(expected_dir, expected) + + with open(expected_filepath) as in_file: + in_bytes = in_file.read() + in_bytes = in_bytes.strip() + expected_bytes = re.escape(in_bytes) + expected_bytes = expected_bytes.replace("\\*", ".*") + expected_re = re.compile(expected_bytes) - def assert_file(self, actual, expected) -> None: - actual_filepath = os.path.join(fixture_dir, actual) - expected_filepath = os.path.join(expected_dir, expected) + with open(actual_filepath) as in_file: + actual_bytes = in_file.read() + actual_bytes = actual_bytes.strip() - with open(expected_filepath) as in_file: - expected_bytes = re.escape(in_file.read()) - expected_bytes = expected_bytes.replace("\\*", ".*") - expected_re = re.compile(expected_bytes) + try: + test.assertRegex(actual_bytes, expected_re) + except Exception: + shutil.copyfile(actual_filepath, f"{expected_filepath}.actual") + raise - with open(actual_filepath) as in_file: - actual_bytes = in_file.read() - try: - self.assertRegex(actual_bytes, expected_re) - except Exception: - shutil.copyfile(actual_filepath, f"{expected_filepath}.actual") - raise +class TestGypUnix(unittest.TestCase): + supported_sysnames = {"darwin", "linux"} + + def setUp(self) -> None: + if sysname not in TestGypUnix.supported_sysnames: + self.skipTest(f"Unsupported system: {sysname}") + shutil.rmtree(os.path.join(fixture_dir, "out"), ignore_errors=True) def test_ninja(self) -> None: rc = gyp.main(["-f", "ninja", "--depth", fixture_dir, gyp_file]) assert rc == 0 - self.assert_file("out/Default/obj/test.ninja", "ninja/test.ninja") + assert_file(self, "out/Default/obj/test.ninja", "ninja/test.ninja") def test_make(self) -> None: rc = gyp.main( @@ -61,10 +70,24 @@ def test_make(self) -> None: ) assert rc == 0 - self.assert_file("out/test.target.mk", "make/test.target.mk") + assert_file(self, "out/test.target.mk", "make/test.target.mk") def test_cmake(self) -> None: rc = gyp.main(["-f", "cmake", "--depth", fixture_dir, gyp_file]) assert rc == 0 - self.assert_file("out/Default/CMakeLists.txt", "cmake/CMakeLists.txt") + assert_file(self, "out/Default/CMakeLists.txt", "cmake/CMakeLists.txt") + + +class TestGypWindows(unittest.TestCase): + def setUp(self) -> None: + if sys.platform != "win32": + self.skipTest("Windows-only test") + shutil.rmtree(os.path.join(fixture_dir, "out"), ignore_errors=True) + + def test_msvs(self) -> None: + rc = gyp.main(["-f", "msvs", "--depth", fixture_dir, gyp_file]) + assert rc == 0 + + assert_file(self, "test.vcproj", "msvs/test.vcproj") + assert_file(self, "integration.sln", "msvs/integration.sln")