Skip to content

Commit

Permalink
(#13860) make: conan v2 support
Browse files Browse the repository at this point in the history
* conan v2 support

* use self.settings.rm_safe
  • Loading branch information
SpaceIm authored Nov 7, 2022
1 parent cc9c468 commit 53ef068
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 48 deletions.
2 changes: 0 additions & 2 deletions recipes/make/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ sources:
patches:
"4.3":
- patch_file: "patches/4.3-0001-clang.patch"
base_path: "source_subfolder"
"4.2.1":
- patch_file: "patches/4.2.1-0001-clang.patch"
base_path: "source_subfolder"
74 changes: 46 additions & 28 deletions recipes/make/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,64 +1,82 @@
from conans import ConanFile, tools, AutoToolsBuildEnvironment
from conan import ConanFile
from conan.tools.files import apply_conandata_patches, chdir, copy, export_conandata_patches, get
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, VCVars
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.53.0"


class MakeConan(ConanFile):
name = "make"
description = "GNU Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files"
topics = ("conan", "make", "build", "makefile")
description = (
"GNU Make is a tool which controls the generation of executables and "
"other non-source files of a program from the program's source files"
)
topics = ("make", "build", "makefile")
homepage = "https://www.gnu.org/software/make/"
url = "https://github.com/conan-io/conan-center-index"
license = "GPL-3.0-or-later"
settings = "os", "arch", "compiler", "build_type"

exports_sources = "patches/*"

@property
def _source_subfolder(self):
return "source_subfolder"
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

def export_sources(self):
export_conandata_patches(self)

def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def source(self):
tools.get(**self.conan_data["sources"][self.version],
destination=self._source_subfolder, strip_root=True)
def layout(self):
basic_layout(self, src_folder="src")

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

def build(self):
for patch in self.conan_data.get("patches").get(self.version, []):
tools.patch(**patch)
def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
if is_msvc(self):
vcvars = VCVars(self)
vcvars.generate()
if self._settings_build.os != "Windows":
tc = AutotoolsToolchain(self)
tc.generate()

with tools.chdir(self._source_subfolder):
def build(self):
apply_conandata_patches(self)
with chdir(self, self.source_folder):
# README.W32
if tools.os_info.is_windows:
if self.settings.compiler == "Visual Studio":
if self._settings_build.os == "Windows":
if is_msvc(self):
command = "build_w32.bat --without-guile"
else:
command = "build_w32.bat --without-guile gcc"
else:
env_build = AutoToolsBuildEnvironment(self)
env_build.configure()
autotools = Autotools(self)
autotools.configure()
command = "./build.sh"
with tools.vcvars(self.settings) if self.settings.compiler == "Visual Studio" else tools.no_op():
self.run(command)
self.run(command)

def package(self):
self.copy(pattern="COPYING", src=self._source_subfolder, dst="licenses")
self.copy(pattern="make", src=self._source_subfolder, dst="bin", keep_path=False)
self.copy(pattern="*gnumake.exe", src=self._source_subfolder, dst="bin", keep_path=False)
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
for make_exe in ("make", "*gnumake.exe"):
copy(self, make_exe, src=self.source_folder, dst=os.path.join(self.package_folder, "bin"), keep_path=False)

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

make = os.path.join(self.package_folder, "bin", "gnumake.exe" if self.settings.os == "Windows" else "make")
self.conf_info.define("tools.gnu:make_program", make)

# TODO: to remove in conan v2
self.user_info.make = make

self.output.info('Creating CONAN_MAKE_PROGRAM environment variable: %s' % make)
self.env_info.CONAN_MAKE_PROGRAM = make
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
2 changes: 0 additions & 2 deletions recipes/make/all/test_package/.gitattributes

This file was deleted.

24 changes: 8 additions & 16 deletions recipes/make/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
from conans import ConanFile, AutoToolsBuildEnvironment, tools
import contextlib
from conan import ConanFile


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

@contextlib.contextmanager
def _build_context(self):
if hasattr(self, "settings_build"):
# Environments are not inherited when cross building, so manually set the `CONANMAKE_PROGRAM' environment variable
with tools.environment_append({"CONAN_MAKE_PROGRAM": self.deps_user_info["make"].make}):
yield
else:
yield
def build_requirements(self):
self.tool_requires(self.tested_reference_str)

def test(self):
if not tools.cross_building(self):
with tools.chdir(self.source_folder):
with self._build_context():
env_build = AutoToolsBuildEnvironment(self)
env_build.make(args=["love"])
make = self.conf.get("tools.gnu:make_program", check_type=str)
self.run(f"{make} -C {self.source_folder} love")
13 changes: 13 additions & 0 deletions recipes/make/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from conans import ConanFile, tools
import os


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

def test(self):
if not tools.cross_building(self):
with tools.run_environment(self):
make = self.deps_user_info["make"].make
makefile_dir = os.path.join(self.source_folder, os.pardir, "test_package")
self.run(f"{make} -C {makefile_dir} love")

0 comments on commit 53ef068

Please sign in to comment.