-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Added features to the premake cli wrapper (#17398)
* 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
1 parent
0455fd6
commit b6788ad
Showing
2 changed files
with
58 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |