Skip to content

Commit bba092e

Browse files
authored
(#14321) gumbo-parser: conan v2 support
1 parent 421f4fa commit bba092e

File tree

6 files changed

+101
-48
lines changed

6 files changed

+101
-48
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
sources:
22
"0.10.1":
3-
sha256: 28463053d44a5dfbc4b77bcf49c8cee119338ffa636cc17fc3378421d714efad
43
url: "https://github.com/google/gumbo-parser/archive/v0.10.1.tar.gz"
4+
sha256: "28463053d44a5dfbc4b77bcf49c8cee119338ffa636cc17fc3378421d714efad"

recipes/gumbo-parser/all/conanfile.py

Lines changed: 57 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,89 @@
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
39
import os
410

11+
required_conan_version = ">=1.53.0"
12+
513

614
class GumboParserConan(ConanFile):
715
name = "gumbo-parser"
816
description = "An HTML5 parsing library in pure C99"
9-
topics = ("conan", "parser")
17+
topics = ("parser", "html")
1018
url = "https://github.com/conan-io/conan-center-index"
1119
homepage = "https://github.com/google/gumbo-parser"
1220
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}
1621

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+
}
1831

1932
@property
20-
def _source_subfolder(self):
21-
return "source_subfolder"
33+
def _settings_build(self):
34+
return getattr(self, "settings_build", self.settings)
2235

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

2740
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")
3252

3353
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")
3559

3660
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)
4063

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()
5369

5470
def build(self):
55-
autotools = self._configure_autotools()
71+
autotools = Autotools(self)
72+
autotools.autoreconf()
73+
autotools.configure()
5674
autotools.make()
5775

5876
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)
6484

6585
def package_info(self):
66-
self.cpp_info.names["pkg_config"] = "gumbo"
86+
self.cpp_info.set_property("pkg_config_name", "gumbo")
6787
self.cpp_info.libs = ["gumbo"]
68-
if self.settings.os == "Linux":
88+
if self.settings.os in ["Linux", "FreeBSD"]:
6989
self.cpp_info.system_libs.append("m")
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
cmake_minimum_required(VERSION 3.1)
2-
project(test_package C)
2+
project(test_package LANGUAGES C)
33

4-
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5-
conan_basic_setup()
4+
find_package(gumbo-parser REQUIRED CONFIG)
65

76
add_executable(${PROJECT_NAME} test_package.c)
8-
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
7+
target_link_libraries(${PROJECT_NAME} PRIVATE gumbo-parser::gumbo-parser)
Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,26 @@
1-
from conans import ConanFile, CMake, tools
1+
from conan import ConanFile
2+
from conan.tools.build import can_run
3+
from conan.tools.cmake import CMake, cmake_layout
24
import os
35

46

57
class TestPackageConan(ConanFile):
6-
settings = "os", "compiler", "build_type", "arch"
7-
generators = "cmake"
8+
settings = "os", "arch", "compiler", "build_type"
9+
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
10+
test_type = "explicit"
11+
12+
def layout(self):
13+
cmake_layout(self)
14+
15+
def requirements(self):
16+
self.requires(self.tested_reference_str)
817

918
def build(self):
1019
cmake = CMake(self)
1120
cmake.configure()
1221
cmake.build()
1322

1423
def test(self):
15-
if not tools.cross_building(self.settings):
16-
bin_path = os.path.join("bin", "test_package")
17-
self.run(bin_path, run_environment=True)
24+
if can_run(self):
25+
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
26+
self.run(bin_path, env="conanrun")
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake_minimum_required(VERSION 3.1)
2+
project(test_package)
3+
4+
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
5+
conan_basic_setup(TARGETS)
6+
7+
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
8+
${CMAKE_CURRENT_BINARY_DIR}/test_package)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from conans import ConanFile, CMake, tools
2+
import os
3+
4+
5+
class TestPackageConan(ConanFile):
6+
settings = "os", "arch", "compiler", "build_type"
7+
generators = "cmake", "cmake_find_package_multi"
8+
9+
def build(self):
10+
cmake = CMake(self)
11+
cmake.configure()
12+
cmake.build()
13+
14+
def test(self):
15+
if not tools.cross_building(self):
16+
bin_path = os.path.join("bin", "test_package")
17+
self.run(bin_path, run_environment=True)

0 commit comments

Comments
 (0)