Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing Premake #17350

Merged
merged 3 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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