Skip to content

Commit

Permalink
fixing Premake (#17350)
Browse files Browse the repository at this point in the history
* fixing Premake

* remove from CI
  • Loading branch information
memsharded authored Nov 29, 2024
1 parent 31d4c4d commit f09d596
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 35 deletions.
40 changes: 9 additions & 31 deletions conan/tools/premake/premake.py
Original file line number Diff line number Diff line change
@@ -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")
6 changes: 2 additions & 4 deletions conan/tools/premake/premakedeps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down
1 change: 1 addition & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@
'Darwin': '/Users/jenkins/bazel-7.1.2/bin'}},
},
'premake': {
"disabled": True,
"exe": "premake5",
"default": "5.0.0",
"5.0.0": {
Expand Down
74 changes: 74 additions & 0 deletions test/functional/toolchains/test_premake.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f09d596

Please sign in to comment.