Skip to content

Commit

Permalink
pexports: migrate to Conan v2
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Jul 19, 2023
1 parent adc2d85 commit ce5c1db
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 74 deletions.
3 changes: 0 additions & 3 deletions recipes/pexports/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ sources:
patches:
"0.47":
- patch_file: "patches/0001-add-help.patch"
base_path: "source_subfolder"
- patch_file: "patches/0002-fix-MSVC-stack-overflow.patch"
base_path: "source_subfolder"
- patch_file: "patches/0003-fix-MSVC-x86.patch"
base_path: "source_subfolder"
130 changes: 71 additions & 59 deletions recipes/pexports/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,94 +1,106 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
import contextlib
import os

required_conan_version = ">=1.33.0"
from conan import ConanFile
from conan.tools.build import cross_building
from conan.tools.env import Environment, VirtualBuildEnv, VirtualRunEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, chdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import unix_path, is_msvc

required_conan_version = ">=1.47.0"


class PExportsConan(ConanFile):
name = "pexports"
description = "pexports is a program to extract exported symbols from a PE image (executable)."
homepage = "https://sourceforge.net/projects/mingw/files/MinGW/Extension/pexports/"
license = "GPL-2.0-or-later"
topics = ("windows", "dll", "PE", "symbols", "import", "library")
url = "https://github.com/conan-io/conan-center-index"
settings = "os", "arch", "compiler", "build_type"

exports_sources = "patches/*"

_autotools = None
homepage = "https://sourceforge.net/projects/mingw/files/MinGW/Extension/pexports/"
topics = ("windows", "dll", "PE", "symbols", "import", "library")

@property
def _source_subfolder(self):
return "source_subfolder"
package_type = "application"
settings = "os", "arch", "compiler", "build_type"

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

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

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

def build_requirements(self):
self.build_requires("automake/1.16.3")
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
def layout(self):
basic_layout(self, src_folder="src")

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

def build_requirements(self):
self.tool_requires("automake/1.16.5")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")

def source(self):
filename = "pexports.tar.xz"
tools.get(**self.conan_data["sources"][self.version], filename=filename,
destination=self._source_subfolder, strip_root=True)

@property
def _user_info_build(self):
return getattr(self, "user_info_build", self.deps_user_info)

@contextlib.contextmanager
def _build_context(self):
if self.settings.compiler == "Visual Studio":
with tools.vcvars(self):
env = {
"CC": "{} cl -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
"LD": "{} link -nologo".format(tools.unix_path(self._user_info_build["automake"].compile)),
}
with tools.environment_append(env):
yield
else:
yield

def _configure_autotools(self):
if self._autotools:
return self._autotools
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
host = build = None
if self.settings.compiler == "Visual Studio":
self._autotools.defines.append("YY_NO_UNISTD_H")
host = build = False
self._autotools.configure(configure_dir=self._source_subfolder, host=host, build=build)
return self._autotools
get(self, **self.conan_data["sources"][self.version], filename=filename, strip_root=True)

def generate(self):
env = VirtualBuildEnv(self)
env.generate()
if not cross_building(self):
env = VirtualRunEnv(self)
env.generate(scope="build")

tc = AutotoolsToolchain(self)
tc.configure_args.append(f"--prefix={unix_path(self, self.package_folder)}")
if is_msvc(self):
tc.extra_defines.append("YY_NO_UNISTD_H")
tc.generate()

if is_msvc(self):
env = Environment()
automake_conf = self.dependencies.build["automake"].conf_info
compile_wrapper = unix_path(self, automake_conf.get("user.automake:compile-wrapper", check_type=str))
ar_wrapper = unix_path(self, automake_conf.get("user.automake:lib-wrapper", check_type=str))
env.define("CC", f"{compile_wrapper} cl -nologo")
env.define("CXX", f"{compile_wrapper} cl -nologo")
env.define("LD", "link -nologo")
env.define("AR", f'{ar_wrapper} "lib -nologo"')
env.define("NM", "dumpbin -symbols")
env.define("OBJDUMP", ":")
env.define("RANLIB", ":")
env.define("STRIP", ":")
env.vars(self).save_script("conanbuild_msvc")

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
with tools.chdir(self._source_subfolder):
self.run("{} -fiv".format(tools.get_env("AUTORECONF")), win_bash=tools.os_info.is_windows)
with self._build_context():
autotools = self._configure_autotools()
apply_conandata_patches(self)
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.autoreconf()
autotools.configure()
autotools.make()

def package(self):
self.copy("COPYING", src=self._source_subfolder, dst="licenses")
with self._build_context():
autotools = self._configure_autotools()
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.install()

def package_info(self):
self.cpp_info.libdirs = []
self.cpp_info.includedires = ["include"]

# TODO: to remove in conan v2
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.output.info(f"Appending PATH environment variable: {bin_path}")
self.env_info.PATH.append(bin_path)
5 changes: 1 addition & 4 deletions recipes/pexports/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
cmake_minimum_required(VERSION 3.1)
cmake_minimum_required(VERSION 3.15)
project(test_package C)

if(NOT WIN32)
message(FATAL_ERROR "pexports only supports Windows")
endif()

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

find_program(PEXPORTS_BIN "pexports")
set(EXPORTS_DEF_PATH "${CMAKE_BINARY_DIR}/exports.def")
if(MSVC)
Expand Down
30 changes: 22 additions & 8 deletions recipes/pexports/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanException
import os

from conan import ConanFile
from conan.errors import ConanException
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
from conan.tools.files import load


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "cmake"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

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

def layout(self):
cmake_layout(self)

def build(self):
if self.settings.os == "Windows":
Expand All @@ -14,13 +28,13 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self, skip_x64_x86=True):
self.run("pexports -H", run_environment=True)
if can_run(self):
self.run("pexports -H")
if self.settings.os == "Windows":
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
self.run(bin_path, env="conanrun")
exports_def_path = os.path.join(self.build_folder, "exports.def")
exports_def_contents = tools.load(exports_def_path)
self.output.info("{} contents:\n{}".format(exports_def_path, exports_def_contents))
exports_def_contents = load(self, exports_def_path)
self.output.info(f"{exports_def_path} contents:\n{exports_def_contents}")
if not "test_package_function" in exports_def_contents:
raise ConanException("pexport could not detect `test_package_function` in the dll")
8 changes: 8 additions & 0 deletions recipes/pexports/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.15)
project(test_package)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
${CMAKE_CURRENT_BINARY_DIR}/test_package/)
26 changes: 26 additions & 0 deletions recipes/pexports/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanException
import os


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

def build(self):
if self.settings.os == "Windows":
cmake = CMake(self)
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self, skip_x64_x86=True):
self.run("pexports -H", run_environment=True)
if self.settings.os == "Windows":
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
exports_def_path = os.path.join(self.build_folder, "exports.def")
exports_def_contents = tools.load(exports_def_path)
self.output.info("{} contents:\n{}".format(exports_def_path, exports_def_contents))
if not "test_package_function" in exports_def_contents:
raise ConanException("pexport could not detect `test_package_function` in the dll")

0 comments on commit ce5c1db

Please sign in to comment.