forked from conan-io/conan-center-index
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(conan-io#18636) asn1c: migrate to Conan v2
* asn1c: migrate to Conan v2 * asn1c: add support for non-MSVC Windows builds * asn1c: bump deps * asn1c: fix test_package * asn1c: skip printing of PATH
- Loading branch information
Showing
3 changed files
with
83 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,82 +1,101 @@ | ||
from conans import AutoToolsBuildEnvironment, tools | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.errors import ConanInvalidConfiguration | ||
from conan.tools.files import get, rmdir, chdir | ||
import os | ||
from conan.tools.build import cross_building | ||
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv | ||
from conan.tools.files import copy, get, rmdir, chdir | ||
from conan.tools.gnu import Autotools, AutotoolsToolchain | ||
from conan.tools.layout import basic_layout | ||
from conan.tools.microsoft import is_msvc | ||
|
||
required_conan_version = ">=1.47.0" | ||
required_conan_version = ">=1.53.0" | ||
|
||
|
||
class Asn1cConan(ConanFile): | ||
name = "asn1c" | ||
description = "The ASN.1 Compiler" | ||
license = "BSD-2-Clause" | ||
topics = ("asn.1", "compiler") | ||
homepage = "https://lionet.info/asn1c" | ||
url = "https://github.com/conan-io/conan-center-index" | ||
homepage = "https://lionet.info/asn1c" | ||
topics = ("asn.1", "compiler") | ||
|
||
package_type = "application" | ||
settings = "os", "arch", "compiler", "build_type" | ||
|
||
_autotools = None | ||
|
||
@property | ||
def _source_subfolder(self): | ||
return "source_subfolder" | ||
|
||
@property | ||
def _datarootdir(self): | ||
return os.path.join(self.package_folder, "res") | ||
def _settings_build(self): | ||
return getattr(self, "settings_build", self.settings) | ||
|
||
def configure(self): | ||
del self.settings.compiler.libcxx | ||
del self.settings.compiler.cppstd | ||
self.settings.rm_safe("compiler.libcxx") | ||
self.settings.rm_safe("compiler.cppstd") | ||
|
||
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("bison/3.7.6") | ||
self.tool_requires("flex/2.6.4") | ||
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") | ||
if is_msvc(self): | ||
self.tool_requires("automake/1.16.5") | ||
self.tool_requires("winflexbison/2.5.24") | ||
else: | ||
self.tool_requires("bison/3.8.2") | ||
self.tool_requires("flex/2.6.4") | ||
self.tool_requires("libtool/2.4.7") | ||
|
||
def validate(self): | ||
if self.settings.compiler == "Visual Studio": | ||
if is_msvc(self): | ||
raise ConanInvalidConfiguration("Visual Studio is not supported") | ||
|
||
def package_id(self): | ||
del self.info.settings.compiler | ||
|
||
def source(self): | ||
get(self, **self.conan_data["sources"][self.version], | ||
destination=self._source_subfolder, strip_root=True) | ||
|
||
def _configure_autotools(self): | ||
if self._autotools: | ||
return self._autotools | ||
self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) | ||
conf_args = [ | ||
"--datarootdir={}".format(tools.unix_path(self._datarootdir)), | ||
] | ||
self._autotools.configure(args=conf_args, configure_dir=self._source_subfolder) | ||
return self._autotools | ||
get(self, **self.conan_data["sources"][self.version], 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 += ["--datarootdir=${prefix}/res"] | ||
tc.generate() | ||
|
||
def build(self): | ||
with chdir(self, self._source_subfolder): | ||
self.run("{} -fiv".format(tools.get_env("AUTORECONF")), win_bash=tools.os_info.is_windows) | ||
autotools = self._configure_autotools() | ||
autotools.make() | ||
with chdir(self, self.source_folder): | ||
autotools = Autotools(self) | ||
autotools.autoreconf() | ||
autotools.configure() | ||
autotools.make() | ||
|
||
def package(self): | ||
self.copy("LICENSE", dst="licenses", src=self._source_subfolder) | ||
autotools = self._configure_autotools() | ||
autotools.install() | ||
copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder) | ||
with chdir(self, self.source_folder): | ||
autotools = Autotools(self) | ||
autotools.install() | ||
rmdir(self, os.path.join(self.package_folder, "res", "doc")) | ||
rmdir(self, os.path.join(self.package_folder, "res", "man")) | ||
|
||
def package_info(self): | ||
bin_path = os.path.join(self.package_folder, "bin") | ||
self.output.info("Appending PATH environment variable: {}".format(bin_path)) | ||
self.env_info.PATH.append(bin_path) | ||
self.cpp_info.includedirs = [] | ||
self.cpp_info.libdirs = [] | ||
self.cpp_info.frameworkdirs = [] | ||
self.cpp_info.resdirs = ["res"] | ||
|
||
# asn1c cannot use environment variables to specify support files path | ||
# so `SUPPORT_PATH` should be propagated to command line invocation to `-S` argument | ||
self.env_info.SUPPORT_PATH = os.path.join(self.package_folder, "res/asn1c") | ||
support_path = os.path.join(self.package_folder, "res", "asn1c") | ||
self.buildenv_info.define_path("SUPPORT_PATH", support_path) | ||
|
||
self.cpp_info.includedirs = [] | ||
# TODO: to remove in conan v2 | ||
bin_path = os.path.join(self.package_folder, "bin") | ||
self.env_info.PATH.append(bin_path) | ||
self.env_info.SUPPORT_PATH = support_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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,30 @@ | ||
from conans import CMake | ||
import os | ||
|
||
from conan import ConanFile | ||
from conan.tools.build import can_run, cross_building | ||
from conan.tools.cmake import cmake_layout, CMake | ||
from conan.tools.files import copy | ||
from conan.tools.build import cross_building | ||
import os | ||
|
||
|
||
class TestPackageConan(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
|
||
generators = "cmake" | ||
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv", "VirtualBuildEnv" | ||
test_type = "explicit" | ||
|
||
def build_requirements(self): | ||
self.tool_requires(str(self.requires["asn1c"])) | ||
self.tool_requires(self.tested_reference_str) | ||
|
||
def layout(self): | ||
cmake_layout(self) | ||
|
||
def build(self): | ||
if not cross_building(self): | ||
copy(self, "MyModule.asn1", src=self.source_folder, dst=self.build_folder) | ||
cmake = CMake(self) | ||
cmake.definitions["SUPPORT_PATH"] = self.deps_env_info["asn1c"].SUPPORT_PATH | ||
cmake.configure() | ||
cmake.build() | ||
|
||
def test(self): | ||
if not cross_building(self): | ||
bin_path = os.path.join("bin", "test_package") | ||
self.run(bin_path, run_environment=True) | ||
if can_run(self): | ||
bin_path = os.path.join(self.cpp.build.bindir, "test_package") | ||
self.run(bin_path, env="conanrun") |