-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
128 additions
and
74 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
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,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) |
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
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
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,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/) |
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,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") |