Skip to content

Commit

Permalink
(#18844) premake: migrate to Conan v2
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
valgur authored Dec 14, 2023
1 parent 3f347fe commit 8ecce87
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 135 deletions.
7 changes: 0 additions & 7 deletions recipes/premake/5.x/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@ sources:
"5.0.0-alpha15":
url: "https://github.com/premake/premake-core/releases/download/v5.0.0-alpha15/premake-5.0.0-alpha15-src.zip"
sha256: "880f56e7cb9f4945d1cb879f059189462c1b7bf62ef43ac7d25842dfb177dd53"
"5.0.0-alpha14":
url: "https://github.com/premake/premake-core/releases/download/v5.0.0-alpha14/premake-5.0.0-alpha14-src.zip"
sha256: "7c9fa4488156625c819dd03f2b48bfd4712fbfabdc2b5768e8c7f52dd7d16608"
patches:
"5.0.0-alpha15":
- patch_file: "patches/0001-5.0.0-alpha15-mingw.patch"
base_path: "source_subfolder"
"5.0.0-alpha14":
- patch_file: "patches/0001-5.0.0-alpha14-mingw.patch"
base_path: "source_subfolder"
154 changes: 103 additions & 51 deletions recipes/premake/5.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,87 @@
from conans import ConanFile, tools, AutoToolsBuildEnvironment, MSBuild
from conans.errors import ConanInvalidConfiguration
import glob
import os
import re
import shutil

from conan import ConanFile, conan_version
from conan.errors import ConanInvalidConfiguration
from conan.tools.build import cross_building
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get, replace_in_file
from conan.tools.gnu import Autotools, AutotoolsToolchain, AutotoolsDeps
from conan.tools.layout import basic_layout
from conan.tools.microsoft import MSBuild, MSBuildToolchain, is_msvc, check_min_vs

required_conan_version = ">=1.53.0"


class PremakeConan(ConanFile):
name = "premake"
topics = ("conan", "premake", "build", "build-systems")
description = "Describe your software project just once, using Premake's simple and easy to read syntax, and build it everywhere"
description = (
"Describe your software project just once, "
"using Premake's simple and easy to read syntax, "
"and build it everywhere"
)
license = "BSD-3-Clause"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://premake.github.io"
license = "BSD-3-Clause"
topics = ("build", "build-systems")

package_type = "application"
settings = "os", "arch", "compiler", "build_type"
exports_sources = "patches/**"
options = {
"lto": [True, False],
}
default_options = {
"lto": False,
}

@property
def _source_subfolder(self):
return "source_subfolder"

def source(self):
tools.get(**self.conan_data["sources"][self.version])
extracted_dir = self.name + "-" + self.version
os.rename(extracted_dir, self._source_subfolder)
def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os != "Windows" or self.settings.compiler == "Visual Studio":
del self.options.lto
if self.settings.os != "Windows" or is_msvc(self):
self.options.rm_safe("lto")

def layout(self):
basic_layout(self, src_folder="src")

def package_id(self):
del self.info.settings.compiler

def requirements(self):
if self.settings.os != "Windows":
self.requires("util-linux-libuuid/2.39")

def validate(self):
if hasattr(self, 'settings_build') and tools.cross_building(self, skip_x64_x86=True):
if hasattr(self, "settings_build") and cross_building(self, skip_x64_x86=True):
raise ConanInvalidConfiguration("Cross-building not implemented")
if conan_version.major == 1 and self.settings.build_type == "Debug":
# This configuration fails without any error messages in C3I.
# https://c3i.jfrog.io/artifactory/misc/logs/pr/18844/15-linux-clang/premake/5.0.0-alpha15/
raise ConanInvalidConfiguration("Debug build not supported with Conan 1.x")

def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)

@property
def _msvc_version(self):
return {
"12": "2013",
"14": "2015",
"15": "2017",
"16": "2019",
}.get(str(self.settings.compiler.version), "2017")
def _ide_version(self):
compiler_version = str(self.settings.compiler.version)
if str(self.settings.compiler) == "Visual Studio":
return {"17": "2022",
"16": "2019",
"15": "2017",
"14": "2015",
"12": "2013"}.get(compiler_version)
else:
return {"193": "2022",
"192": "2019",
"191": "2017",
"190": "2015",
"180": "2013"}.get(compiler_version)

@property
def _msvc_build_dirname(self):
return "vs{}".format(self._msvc_version)
def _msvc_build_dir(self):
return os.path.join(self.source_folder, "build", f"vs{self._ide_version}")

def _version_info(self, version):
res = []
Expand All @@ -63,13 +95,6 @@ def _version_info(self, version):
res.append(p)
return tuple(res)

@property
def _gmake_directory_name_prefix(self):
if self._version_info(self.version) <= self._version_info("5.0.0-alpha14"):
return "gmake"
else:
return "gmake2"

@property
def _gmake_platform(self):
return {
Expand All @@ -80,8 +105,8 @@ def _gmake_platform(self):
}[str(self.settings.os)]

@property
def _gmake_build_dirname(self):
return "{}.{}".format(self._gmake_directory_name_prefix, self._gmake_platform)
def _gmake_build_dir(self):
return os.path.join(self.source_folder, "build", f"gmake2.{self._gmake_platform}")

@property
def _gmake_config(self):
Expand All @@ -91,35 +116,62 @@ def _gmake_config(self):
"x86": "x86",
"x86_64": "x64",
}[str(self.settings.arch)]
config = "{}_{}".format(build_type, arch)
config = f"{build_type}_{arch}"
else:
config = build_type
return config

def generate(self):
if is_msvc(self):
tc = MSBuildToolchain(self)
tc.generate()
else:
tc = AutotoolsToolchain(self)
tc.make_args = ["verbose=1", f"config={self._gmake_config}"]
tc.generate()
deps = AutotoolsDeps(self)
deps.generate()

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
if self.options.get_safe("lto", None) == False:
for fn in glob.glob(os.path.join(self._source_subfolder, "build", self._gmake_build_dirname, "*.make")):
tools.replace_in_file(fn, "-flto", "", strict=False)
apply_conandata_patches(self)
if self.options.get_safe("lto", None) is False:
for fn in glob.glob(os.path.join(self._gmake_build_dir, "*.make")):
replace_in_file(self, fn, "-flto", "", strict=False)
if check_min_vs(self, 193, raise_invalid=False):
# Create VS 2022 project directory based on VS 2019 one
if "alpha" in str(self.version):
shutil.move(os.path.join(self.source_folder, "build", "vs2019"),
os.path.join(self.source_folder, "build", "vs2022"))
for vcxproj in glob.glob(os.path.join(self.source_folder, "build", "vs2022", "*.vcxproj")):
replace_in_file(self, vcxproj, "v142", "v143")

def build(self):
self._patch_sources()
if self.settings.compiler == "Visual Studio":
with tools.chdir(os.path.join(self._source_subfolder, "build", self._msvc_build_dirname)):
if is_msvc(self):
with chdir(self, self._msvc_build_dir):
msbuild = MSBuild(self)
msbuild.build("Premake5.sln", platforms={"x86": "Win32", "x86_64": "x64"})
msbuild.build(sln="Premake5.sln")
else:
with tools.chdir(os.path.join(self._source_subfolder, "build", self._gmake_build_dirname)):
env_build = AutoToolsBuildEnvironment(self)
env_build.make(target="Premake5", args=["verbose=1", "config={}".format(self._gmake_config)])
with chdir(self, self._gmake_build_dir):
autotools = Autotools(self)
autotools.make(target="Premake5")

def package(self):
self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
self.copy(pattern="*premake5.exe", dst="bin", keep_path=False)
self.copy(pattern="*premake5", dst="bin", keep_path=False)
copy(self, "LICENSE.txt",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder)
suffix = ".exe" if self.settings.os == "Windows" else ""
copy(self, f"*/premake5{suffix}",
dst=os.path.join(self.package_folder, "bin"),
src=os.path.join(self.source_folder, "bin"),
keep_path=False)

def package_info(self):
self.cpp_info.frameworkdirs = []
self.cpp_info.libdirs = []
self.cpp_info.resdirs = []
self.cpp_info.includedirs = []

# TODO: Legacy, to be removed on Conan 2.0
bindir = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bindir))
self.env_info.PATH.append(bindir)
72 changes: 0 additions & 72 deletions recipes/premake/5.x/patches/0001-5.0.0-alpha14-mingw.patch

This file was deleted.

14 changes: 11 additions & 3 deletions recipes/premake/5.x/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from conans import ConanFile, tools
from conan import ConanFile
from conan.tools.cmake import cmake_layout


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "VirtualBuildEnv"
test_type = "explicit"

def build_requirements(self):
self.tool_requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def test(self):
if not tools.cross_building(self.settings):
self.run("premake5 --version", run_environment=True)
self.run("premake5 --version")
9 changes: 9 additions & 0 deletions recipes/premake/5.x/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from conans import ConanFile, tools


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"

def test(self):
if not tools.cross_building(self.settings):
self.run("premake5 --version", run_environment=True)
4 changes: 2 additions & 2 deletions recipes/premake/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
versions:
"5.0.0-alpha14":
folder: "5.x"
# "5.0.0-beta2":
# folder: "5.x"
"5.0.0-alpha15":
folder: "5.x"

0 comments on commit 8ecce87

Please sign in to comment.