|
1 |
| -from conans import ConanFile, AutoToolsBuildEnvironment, tools |
2 |
| -from conans.errors import ConanInvalidConfiguration |
| 1 | +from conan import ConanFile |
| 2 | +from conan.errors import ConanInvalidConfiguration |
| 3 | +from conan.tools.apple import fix_apple_shared_install_name |
| 4 | +from conan.tools.env import VirtualBuildEnv |
| 5 | +from conan.tools.files import copy, get, rm, rmdir |
| 6 | +from conan.tools.gnu import Autotools, AutotoolsToolchain |
| 7 | +from conan.tools.layout import basic_layout |
| 8 | +from conan.tools.microsoft import is_msvc, unix_path |
3 | 9 | import os
|
4 | 10 |
|
| 11 | +required_conan_version = ">=1.53.0" |
| 12 | + |
5 | 13 |
|
6 | 14 | class GumboParserConan(ConanFile):
|
7 | 15 | name = "gumbo-parser"
|
8 | 16 | description = "An HTML5 parsing library in pure C99"
|
9 |
| - topics = ("conan", "parser") |
| 17 | + topics = ("parser", "html") |
10 | 18 | url = "https://github.com/conan-io/conan-center-index"
|
11 | 19 | homepage = "https://github.com/google/gumbo-parser"
|
12 | 20 | license = "Apache-2.0"
|
13 |
| - settings = "os", "arch", "compiler", "build_type" |
14 |
| - options = {"shared": [True, False], "fPIC": [True, False]} |
15 |
| - default_options = {"shared": False, "fPIC": True} |
16 | 21 |
|
17 |
| - _autotools = None |
| 22 | + settings = "os", "arch", "compiler", "build_type" |
| 23 | + options = { |
| 24 | + "shared": [True, False], |
| 25 | + "fPIC": [True, False], |
| 26 | + } |
| 27 | + default_options = { |
| 28 | + "shared": False, |
| 29 | + "fPIC": True, |
| 30 | + } |
18 | 31 |
|
19 | 32 | @property
|
20 |
| - def _source_subfolder(self): |
21 |
| - return "source_subfolder" |
| 33 | + def _settings_build(self): |
| 34 | + return getattr(self, "settings_build", self.settings) |
22 | 35 |
|
23 | 36 | def config_options(self):
|
24 | 37 | if self.settings.os == "Windows":
|
25 | 38 | del self.options.fPIC
|
26 | 39 |
|
27 | 40 | def configure(self):
|
28 |
| - del self.settings.compiler.libcxx |
29 |
| - del self.settings.compiler.cppstd |
30 |
| - if self.settings.compiler == "Visual Studio": |
31 |
| - raise ConanInvalidConfiguration("This recipe does not support Visual Studio") |
| 41 | + if self.options.shared: |
| 42 | + self.options.rm_safe("fPIC") |
| 43 | + self.settings.rm_safe("compiler.cppstd") |
| 44 | + self.settings.rm_safe("compiler.libcxx") |
| 45 | + |
| 46 | + def layout(self): |
| 47 | + basic_layout(self, src_folder="src") |
| 48 | + |
| 49 | + def validate(self): |
| 50 | + if is_msvc(self): |
| 51 | + raise ConanInvalidConfiguration("gumbo-parser recipe does not support Visual Studio yet") |
32 | 52 |
|
33 | 53 | def build_requirements(self):
|
34 |
| - self.build_requires("libtool/2.4.6") |
| 54 | + self.tool_requires("libtool/2.4.7") |
| 55 | + if self._settings_build.os == "Windows": |
| 56 | + self.win_bash = True |
| 57 | + if not self.conf.get("tools.microsoft.bash:path", check_type=str): |
| 58 | + self.tool_requires("msys2/cci.latest") |
35 | 59 |
|
36 | 60 | def source(self):
|
37 |
| - tools.get(**self.conan_data["sources"][self.version]) |
38 |
| - extracted_folder = "gumbo-parser-{0}".format(self.version) |
39 |
| - os.rename(extracted_folder, self._source_subfolder) |
| 61 | + get(self, **self.conan_data["sources"][self.version], |
| 62 | + destination=self.source_folder, strip_root=True) |
40 | 63 |
|
41 |
| - def _configure_autotools(self): |
42 |
| - if not self._autotools: |
43 |
| - with tools.chdir(self._source_subfolder): |
44 |
| - self.run("./autogen.sh", win_bash=tools.os_info.is_windows) |
45 |
| - self._autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows) |
46 |
| - args = [] |
47 |
| - if self.options.shared: |
48 |
| - args.extend(['--disable-static', '--enable-shared']) |
49 |
| - else: |
50 |
| - args.extend(['--disable-shared', '--enable-static']) |
51 |
| - self._autotools.configure(configure_dir=self._source_subfolder, args=args) |
52 |
| - return self._autotools |
| 64 | + def generate(self): |
| 65 | + env = VirtualBuildEnv(self) |
| 66 | + env.generate() |
| 67 | + tc = AutotoolsToolchain(self) |
| 68 | + tc.generate() |
53 | 69 |
|
54 | 70 | def build(self):
|
55 |
| - autotools = self._configure_autotools() |
| 71 | + autotools = Autotools(self) |
| 72 | + autotools.autoreconf() |
| 73 | + autotools.configure() |
56 | 74 | autotools.make()
|
57 | 75 |
|
58 | 76 | def package(self):
|
59 |
| - self.copy(pattern="COPYING", dst="licenses", src=self._source_subfolder) |
60 |
| - autotools = self._configure_autotools() |
61 |
| - autotools.install() |
62 |
| - tools.rmdir(os.path.join(self.package_folder, 'lib', 'pkgconfig')) |
63 |
| - os.unlink(os.path.join(self.package_folder, 'lib', 'libgumbo.la')) |
| 77 | + copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses")) |
| 78 | + autotools = Autotools(self) |
| 79 | + # TODO: replace by autotools.install() once https://github.com/conan-io/conan/issues/12153 fixed |
| 80 | + autotools.install(args=[f"DESTDIR={unix_path(self, self.package_folder)}"]) |
| 81 | + rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig")) |
| 82 | + rm(self, "*.la", os.path.join(self.package_folder, "lib")) |
| 83 | + fix_apple_shared_install_name(self) |
64 | 84 |
|
65 | 85 | def package_info(self):
|
66 |
| - self.cpp_info.names["pkg_config"] = "gumbo" |
| 86 | + self.cpp_info.set_property("pkg_config_name", "gumbo") |
67 | 87 | self.cpp_info.libs = ["gumbo"]
|
68 |
| - if self.settings.os == "Linux": |
| 88 | + if self.settings.os in ["Linux", "FreeBSD"]: |
69 | 89 | self.cpp_info.system_libs.append("m")
|
0 commit comments