Skip to content

Commit 8ecce87

Browse files
author
Martin Valgur
authored
(#18844) premake: migrate to Conan v2
* premake: migrate to Conan v2 * premake: add VS 2022 support, fix package_type * premake: fix Linux package() * premake: fix package() * premake: get rid of vs_ide_version use * premake: add 5.0.0-beta2 * premake: add libuuid dependency * premake: add layout to test_package * premake: disable beta2 Fails with premake5: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by premake5) premake5: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.25' not found (required by premake5) premake5: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.28' not found (required by premake5) for v1 in CI during test_package. * premake: workaround for Conan v1 debug build failure * premake: tweak comments
1 parent 3f347fe commit 8ecce87

File tree

6 files changed

+125
-135
lines changed

6 files changed

+125
-135
lines changed

recipes/premake/5.x/conandata.yml

-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@ sources:
22
"5.0.0-alpha15":
33
url: "https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-src.zip"
44
sha256: "880f56e7cb9f4945d1cb879f059189462c1b7bf62ef43ac7d25842dfb177dd53"
5-
"5.0.0-alpha14":
6-
url: "https://github.com/premake/premake-core/releases/download/v5.0.0-alpha14/premake-5.0.0-alpha14-src.zip"
7-
sha256: "7c9fa4488156625c819dd03f2b48bfd4712fbfabdc2b5768e8c7f52dd7d16608"
85
patches:
96
"5.0.0-alpha15":
107
- patch_file: "patches/0001-5.0.0-alpha15-mingw.patch"
11-
base_path: "source_subfolder"
12-
"5.0.0-alpha14":
13-
- patch_file: "patches/0001-5.0.0-alpha14-mingw.patch"
14-
base_path: "source_subfolder"

recipes/premake/5.x/conanfile.py

+103-51
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,87 @@
1-
from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild
2-
from conans.errors import ConanInvalidConfiguration
31
import glob
42
import os
53
import re
4+
import shutil
5+
6+
from conan import ConanFile, conan_version
7+
from conan.errors import ConanInvalidConfiguration
8+
from conan.tools.build import cross_building
9+
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, replace_in_file
10+
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
11+
from conan.tools.layout import basic_layout
12+
from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, check_min_vs
13+
14+
required_conan_version = ">=1.53.0"
615

716

817
class PremakeConan(ConanFile):
918
name = "premake"
10-
topics = ("conan", "premake", "build", "build-systems")
11-
description = "Describe your software project just once, using Premake's simple and easy to read syntax, and build it everywhere"
19+
description = (
20+
"Describe your software project just once, "
21+
"using Premake's simple and easy to read syntax, "
22+
"and build it everywhere"
23+
)
24+
license = "BSD-3-Clause"
1225
url = "https://github.com/conan-io/conan-center-index"
1326
homepage = "https://premake.github.io"
14-
license = "BSD-3-Clause"
27+
topics = ("build", "build-systems")
28+
29+
package_type = "application"
1530
settings = "os", "arch", "compiler", "build_type"
16-
exports_sources = "patches/**"
1731
options = {
1832
"lto": [True, False],
1933
}
2034
default_options = {
2135
"lto": False,
2236
}
2337

24-
@property
25-
def _source_subfolder(self):
26-
return "source_subfolder"
27-
28-
def source(self):
29-
tools.get(**self.conan_data["sources"][self.version])
30-
extracted_dir = self.name + "-" + self.version
31-
os.rename(extracted_dir, self._source_subfolder)
38+
def export_sources(self):
39+
export_conandata_patches(self)
3240

3341
def config_options(self):
34-
if self.settings.os != "Windows" or self.settings.compiler == "Visual Studio":
35-
del self.options.lto
42+
if self.settings.os != "Windows" or is_msvc(self):
43+
self.options.rm_safe("lto")
44+
45+
def layout(self):
46+
basic_layout(self, src_folder="src")
47+
48+
def package_id(self):
49+
del self.info.settings.compiler
50+
51+
def requirements(self):
52+
if self.settings.os != "Windows":
53+
self.requires("util-linux-libuuid/2.39")
3654

3755
def validate(self):
38-
if hasattr(self, 'settings_build') and tools.cross_building(self, skip_x64_x86=True):
56+
if hasattr(self, "settings_build") and cross_building(self, skip_x64_x86=True):
3957
raise ConanInvalidConfiguration("Cross-building not implemented")
58+
if conan_version.major == 1 and self.settings.build_type == "Debug":
59+
# This configuration fails without any error messages in C3I.
60+
# https://c3i.jfrog.io/artifactory/misc/logs/pr/18844/15-linux-clang/premake/5.0.0-alpha15/
61+
raise ConanInvalidConfiguration("Debug build not supported with Conan 1.x")
62+
63+
def source(self):
64+
get(self, **self.conan_data["sources"][self.version], strip_root=True)
4065

4166
@property
42-
def _msvc_version(self):
43-
return {
44-
"12": "2013",
45-
"14": "2015",
46-
"15": "2017",
47-
"16": "2019",
48-
}.get(str(self.settings.compiler.version), "2017")
67+
def _ide_version(self):
68+
compiler_version = str(self.settings.compiler.version)
69+
if str(self.settings.compiler) == "Visual Studio":
70+
return {"17": "2022",
71+
"16": "2019",
72+
"15": "2017",
73+
"14": "2015",
74+
"12": "2013"}.get(compiler_version)
75+
else:
76+
return {"193": "2022",
77+
"192": "2019",
78+
"191": "2017",
79+
"190": "2015",
80+
"180": "2013"}.get(compiler_version)
4981

5082
@property
51-
def _msvc_build_dirname(self):
52-
return "vs{}".format(self._msvc_version)
83+
def _msvc_build_dir(self):
84+
return os.path.join(self.source_folder, "build", f"vs{self._ide_version}")
5385

5486
def _version_info(self, version):
5587
res = []
@@ -63,13 +95,6 @@ def _version_info(self, version):
6395
res.append(p)
6496
return tuple(res)
6597

66-
@property
67-
def _gmake_directory_name_prefix(self):
68-
if self._version_info(self.version) <= self._version_info("5.0.0-alpha14"):
69-
return "gmake"
70-
else:
71-
return "gmake2"
72-
7398
@property
7499
def _gmake_platform(self):
75100
return {
@@ -80,8 +105,8 @@ def _gmake_platform(self):
80105
}[str(self.settings.os)]
81106

82107
@property
83-
def _gmake_build_dirname(self):
84-
return "{}.{}".format(self._gmake_directory_name_prefix, self._gmake_platform)
108+
def _gmake_build_dir(self):
109+
return os.path.join(self.source_folder, "build", f"gmake2.{self._gmake_platform}")
85110

86111
@property
87112
def _gmake_config(self):
@@ -91,35 +116,62 @@ def _gmake_config(self):
91116
"x86": "x86",
92117
"x86_64": "x64",
93118
}[str(self.settings.arch)]
94-
config = "{}_{}".format(build_type, arch)
119+
config = f"{build_type}_{arch}"
95120
else:
96121
config = build_type
97122
return config
98123

124+
def generate(self):
125+
if is_msvc(self):
126+
tc = MSBuildToolchain(self)
127+
tc.generate()
128+
else:
129+
tc = AutotoolsToolchain(self)
130+
tc.make_args = ["verbose=1", f"config={self._gmake_config}"]
131+
tc.generate()
132+
deps = AutotoolsDeps(self)
133+
deps.generate()
134+
99135
def _patch_sources(self):
100-
for patch in self.conan_data.get("patches", {}).get(self.version, []):
101-
tools.patch(**patch)
102-
if self.options.get_safe("lto", None) == False:
103-
for fn in glob.glob(os.path.join(self._source_subfolder, "build", self._gmake_build_dirname, "*.make")):
104-
tools.replace_in_file(fn, "-flto", "", strict=False)
136+
apply_conandata_patches(self)
137+
if self.options.get_safe("lto", None) is False:
138+
for fn in glob.glob(os.path.join(self._gmake_build_dir, "*.make")):
139+
replace_in_file(self, fn, "-flto", "", strict=False)
140+
if check_min_vs(self, 193, raise_invalid=False):
141+
# Create VS 2022 project directory based on VS 2019 one
142+
if "alpha" in str(self.version):
143+
shutil.move(os.path.join(self.source_folder, "build", "vs2019"),
144+
os.path.join(self.source_folder, "build", "vs2022"))
145+
for vcxproj in glob.glob(os.path.join(self.source_folder, "build", "vs2022", "*.vcxproj")):
146+
replace_in_file(self, vcxproj, "v142", "v143")
105147

106148
def build(self):
107149
self._patch_sources()
108-
if self.settings.compiler == "Visual Studio":
109-
with tools.chdir(os.path.join(self._source_subfolder, "build", self._msvc_build_dirname)):
150+
if is_msvc(self):
151+
with chdir(self, self._msvc_build_dir):
110152
msbuild = MSBuild(self)
111-
msbuild.build("Premake5.sln", platforms={"x86": "Win32", "x86_64": "x64"})
153+
msbuild.build(sln="Premake5.sln")
112154
else:
113-
with tools.chdir(os.path.join(self._source_subfolder, "build", self._gmake_build_dirname)):
114-
env_build = AutoToolsBuildEnvironment(self)
115-
env_build.make(target="Premake5", args=["verbose=1", "config={}".format(self._gmake_config)])
155+
with chdir(self, self._gmake_build_dir):
156+
autotools = Autotools(self)
157+
autotools.make(target="Premake5")
116158

117159
def package(self):
118-
self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
119-
self.copy(pattern="*premake5.exe", dst="bin", keep_path=False)
120-
self.copy(pattern="*premake5", dst="bin", keep_path=False)
160+
copy(self, "LICENSE.txt",
161+
dst=os.path.join(self.package_folder, "licenses"),
162+
src=self.source_folder)
163+
suffix = ".exe" if self.settings.os == "Windows" else ""
164+
copy(self, f"*/premake5{suffix}",
165+
dst=os.path.join(self.package_folder, "bin"),
166+
src=os.path.join(self.source_folder, "bin"),
167+
keep_path=False)
121168

122169
def package_info(self):
170+
self.cpp_info.frameworkdirs = []
171+
self.cpp_info.libdirs = []
172+
self.cpp_info.resdirs = []
173+
self.cpp_info.includedirs = []
174+
175+
# TODO: Legacy, to be removed on Conan 2.0
123176
bindir = os.path.join(self.package_folder, "bin")
124-
self.output.info("Appending PATH environment variable: {}".format(bindir))
125177
self.env_info.PATH.append(bindir)

recipes/premake/5.x/patches/0001-5.0.0-alpha14-mingw.patch

-72
This file was deleted.
+11-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
1-
from conans import ConanFile, tools
1+
from conan import ConanFile
2+
from conan.tools.cmake import cmake_layout
23

34

45
class TestPackageConan(ConanFile):
56
settings = "os", "arch", "compiler", "build_type"
7+
generators = "VirtualBuildEnv"
8+
test_type = "explicit"
9+
10+
def build_requirements(self):
11+
self.tool_requires(self.tested_reference_str)
12+
13+
def layout(self):
14+
cmake_layout(self)
615

716
def test(self):
8-
if not tools.cross_building(self.settings):
9-
self.run("premake5 --version", run_environment=True)
17+
self.run("premake5 --version")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from conans import ConanFile, tools
2+
3+
4+
class TestPackageConan(ConanFile):
5+
settings = "os", "arch", "compiler", "build_type"
6+
7+
def test(self):
8+
if not tools.cross_building(self.settings):
9+
self.run("premake5 --version", run_environment=True)

recipes/premake/config.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
versions:
2-
"5.0.0-alpha14":
3-
folder: "5.x"
2+
# "5.0.0-beta2":
3+
# folder: "5.x"
44
"5.0.0-alpha15":
55
folder: "5.x"

0 commit comments

Comments
 (0)