Skip to content

Commit

Permalink
[Feature] Added features to the premake cli wrapper (#17398)
Browse files Browse the repository at this point in the history
* Added features to the premake cli wrapper
- Modifiable premake action (autodetected in constructor)
- Modifiable lua file location
- Custom user actions (defined within the premake5.lua file) exposed as 'arguments'

* adding to CI and new test

* only Linux premake5

* fix docker

* merged develop2 with CI support

---------

Co-authored-by: memsharded <[email protected]>
  • Loading branch information
Ohjurot and memsharded authored Feb 13, 2025
1 parent 0455fd6 commit b6788ad
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 11 deletions.
45 changes: 34 additions & 11 deletions conan/tools/premake/premake.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
# Source: https://learn.microsoft.com/en-us/cpp/overview/compiler-versions?view=msvc-170
PREMAKE_VS_VERSION = {
'190': '2015',
'191': '2017',
'192': '2019',
'193': '2022',
'194': '2022', # still 2022
}


class Premake:
"""
Premake cli wrapper
"""

def __init__(self, conanfile):
self._conanfile = conanfile

# automatically chooses premake action based on used compiler
def configure(self):
self.action = None # premake5 action to use (Autogenerated)
self.luafile = 'premake5.lua' # Path to the root (premake5) lua file
# (key value pairs. Will translate to "--{key}={value}")
self.arguments = {} # https://premake.github.io/docs/Command-Line-Arguments/

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)
msvc_version = PREMAKE_VS_VERSION.get(str(self._conanfile.settings.compiler.version))
self.action = f'vs{msvc_version}'
else:
self._conanfile.run("premake5 gmake2")
self.action = 'gmake2'

@staticmethod
def _expand_args(args):
return ' '.join([f'--{key}={value}' for key, value in args.items()])

def configure(self):
premake_options = dict()
premake_options["file"] = self.luafile

premake_command = f'premake5 {self._expand_args(premake_options)} {self.action} ' \
f'{self._expand_args(self.arguments)}'
self._conanfile.run(premake_command)
24 changes: 24 additions & 0 deletions test/integration/toolchains/premake/test_premake.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import textwrap

from conan.test.utils.tools import TestClient


def test_premake_args():
c = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.premake import Premake
class Pkg(ConanFile):
settings = "os", "compiler", "build_type", "arch"
def run(self, cmd, *args, **kwargs):
self.output.info(f"Running {cmd}!!")
def build(self):
premake = Premake(self)
premake.luafile = "myproject.lua"
premake.arguments = {"myarg": "myvalue"}
premake.configure()
""")
c.save({"conanfile.py": conanfile})
c.run("build . -s compiler=msvc -s compiler.version=193 -s compiler.runtime=dynamic")
assert "conanfile.py: Running premake5 --file=myproject.lua vs2022 --myarg=myvalue!!" in c.out

0 comments on commit b6788ad

Please sign in to comment.