From 01d8a59afe53ab76a48b4b413d81577782d808f7 Mon Sep 17 00:00:00 2001 From: memsharded Date: Wed, 20 Nov 2024 01:31:26 +0100 Subject: [PATCH 1/2] fixing Premake --- conan/tools/premake/premake.py | 40 +++--------- conan/tools/premake/premakedeps.py | 6 +- test/functional/toolchains/test_premake.py | 74 ++++++++++++++++++++++ 3 files changed, 85 insertions(+), 35 deletions(-) create mode 100644 test/functional/toolchains/test_premake.py diff --git a/conan/tools/premake/premake.py b/conan/tools/premake/premake.py index f9864bf37e0..b685c77ddb9 100644 --- a/conan/tools/premake/premake.py +++ b/conan/tools/premake/premake.py @@ -1,39 +1,17 @@ -class Premake(object): +class Premake: def __init__(self, conanfile): self._conanfile = conanfile # automatically chooses premake action based on used compiler def configure(self): - if "Visual Studio" in self._conanfile.settings.compiler: - _visuals = {'8': '2005', - '9': '2008', - '10': '2010', - '11': '2012', - '12': '2013', - '14': '2015', - '15': '2017', - '16': '2019'} - premake_command = "premake5 vs%s" % _visuals.get(str(self._conanfile.settings.compiler.version)) - self._conanfile.run(premake_command) - elif "msvc" in self._conanfile.settings.compiler: - _visuals = {'14.0': '2005', - '15.0': '2008', - '16.0': '2010', - '17.0': '2012', - '18.0': '2013', - '19.0': '2015', - # add non-trailing 0 variation manually - '19.1': '2017', - '19.2': '2019'} - # generate VS2017 versions - for i in range(0,7): - ver = '19.1' + str(i) - _visuals[ver] = '2017' - # generate VS2019 versions - for i in range(0,10): - ver = '19.2' + str(i) - _visuals[ver] = '2019' - premake_command = "premake5 vs%s" % _visuals.get(str(self._conanfile.settings.compiler.version)) + if "msvc" in self._conanfile.settings.compiler: + _visuals = {'190': '2015', + '191': '2017', + '192': '2019', + '193': '2022', + '194': '2023'} + version = _visuals.get(str(self._conanfile.settings.compiler.version)) + premake_command = f"premake5 vs{version}" self._conanfile.run(premake_command) else: self._conanfile.run("premake5 gmake2") diff --git a/conan/tools/premake/premakedeps.py b/conan/tools/premake/premakedeps.py index d3eaa3e49e4..3e868eabaed 100644 --- a/conan/tools/premake/premakedeps.py +++ b/conan/tools/premake/premakedeps.py @@ -110,7 +110,7 @@ def _format_flags(flags): if dep_cpp_info.sysroot else "" -class PremakeDeps(object): +class PremakeDeps: """ PremakeDeps class generator conandeps.premake5.lua: unconditional import of all *direct* dependencies only @@ -192,9 +192,7 @@ def content(self): build_req = self._conanfile.dependencies.build # Merge into one list - full_req = list(host_req.items()) \ - + list(test_req.items()) \ - + list(build_req.items()) + full_req = list(host_req.items()) + list(test_req.items()) + list(build_req.items()) # Process dependencies and accumulate globally required data pkg_files = [] diff --git a/test/functional/toolchains/test_premake.py b/test/functional/toolchains/test_premake.py new file mode 100644 index 00000000000..8ff701979f4 --- /dev/null +++ b/test/functional/toolchains/test_premake.py @@ -0,0 +1,74 @@ +import platform +import textwrap + +import pytest + +from conan.test.assets.sources import gen_function_cpp + + +@pytest.mark.skipif(platform.system() == "Darwin", reason="Not for MacOS") +@pytest.mark.tool("premake") +def test_premake(matrix_client): + c = matrix_client + conanfile = textwrap.dedent(""" + import os + from conan import ConanFile + from conan.tools.premake import Premake + from conan.tools.microsoft import MSBuild + class Pkg(ConanFile): + settings = "os", "compiler", "build_type", "arch" + requires = "matrix/1.0" + generators = "PremakeDeps", "VCVars" + def build(self): + p = Premake(self) + p.configure() + build_type = str(self.settings.build_type) + if self.settings.os == "Windows": + msbuild = MSBuild(self) + msbuild.build("HelloWorld.sln") + else: + self.run(f"make config={build_type.lower()}_x86_64") + p = os.path.join(self.build_folder, "bin", build_type, "HelloWorld") + self.run(f'"{p}"') + """) + premake = textwrap.dedent(""" + -- premake5.lua + + include('conandeps.premake5.lua') + + workspace "HelloWorld" + conan_setup() + configurations { "Debug", "Release" } + platforms { "x86_64" } + + project "HelloWorld" + kind "ConsoleApp" + language "C++" + targetdir "bin/%{cfg.buildcfg}" + + files { "**.h", "**.cpp" } + + filter "configurations:Debug" + defines { "DEBUG" } + symbols "On" + + filter "configurations:Release" + defines { "NDEBUG" } + optimize "On" + + filter "platforms:x86_64" + architecture "x86_64" + """) + c.save({"conanfile.py": conanfile, + "premake5.lua": premake, + "main.cpp": gen_function_cpp(name="main", includes=["matrix"], calls=["matrix"])}) + c.run("build .") + assert "main: Release!" in c.out + assert "matrix/1.0: Hello World Release!" in c.out + if platform.system() == "Windows": + assert "main _M_X64 defined" in c.out + else: + assert "main __x86_64__ defined" in c.out + c.run("build . -s build_type=Debug --build=missing") + assert "main: Debug!" in c.out + assert "matrix/1.0: Hello World Debug!" in c.out From 431e5797491dde14b2dcdcadc5546c729c899164 Mon Sep 17 00:00:00 2001 From: memsharded Date: Thu, 28 Nov 2024 19:44:00 +0100 Subject: [PATCH 2/2] remove from CI --- test/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/conftest.py b/test/conftest.py index b9bc9ff5887..149b1d1dfcc 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -164,6 +164,7 @@ 'Darwin': '/Users/jenkins/bazel-7.1.2/bin'}}, }, 'premake': { + "disabled": True, "exe": "premake5", "default": "5.0.0", "5.0.0": {