Skip to content

Commit 3c85081

Browse files
stevecheckowayflavorjones
authored andcommitted
Build libgumbo via autotools and rebuild on source changes
- Implement a minimal autotools build for libgumbo. - Make `rake gumbo:test` use the same libgumbo.a used to build the nokogiri extension. - Make changes to `gumbo-parser/src` trigger a rebuild of libgumbo.
1 parent f306126 commit 3c85081

File tree

12 files changed

+116
-102
lines changed

12 files changed

+116
-102
lines changed

ext/nokogiri/extconf.rb

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,54 +1056,8 @@ def configure
10561056
find_header("nokogiri_gumbo.h") || abort("nokogiri_gumbo.h not found")
10571057
else
10581058
libgumbo_recipe = process_recipe("libgumbo", "1.0.0-nokogiri", static_p, cross_build_p, false) do |recipe|
1059-
recipe.configure_options = []
1060-
1061-
class << recipe
1062-
def downloaded?
1063-
true
1064-
end
1065-
1066-
def extract
1067-
target = File.join(tmp_path, "gumbo-parser")
1068-
output("Copying gumbo-parser files into #{target}...")
1069-
FileUtils.mkdir_p(target)
1070-
FileUtils.cp(Dir.glob(File.join(PACKAGE_ROOT_DIR, "gumbo-parser/src/*")), target)
1071-
end
1072-
1073-
def configured?
1074-
true
1075-
end
1076-
1077-
def install
1078-
lib_dir = File.join(port_path, "lib")
1079-
inc_dir = File.join(port_path, "include")
1080-
FileUtils.mkdir_p([lib_dir, inc_dir])
1081-
FileUtils.cp(File.join(work_path, "libgumbo.a"), lib_dir)
1082-
FileUtils.cp(Dir.glob(File.join(work_path, "*.h")), inc_dir)
1083-
end
1084-
1085-
def compile
1086-
cflags = concat_flags(ENV["CFLAGS"], "-fPIC", "-O2", "-g")
1087-
1088-
env = { "CC" => gcc_cmd, "CFLAGS" => cflags }
1089-
if config_cross_build?
1090-
if host.include?("darwin")
1091-
env["AR"] = "#{host}-libtool"
1092-
env["ARFLAGS"] = "-o"
1093-
else
1094-
env["AR"] = "#{host}-ar"
1095-
end
1096-
env["RANLIB"] = "#{host}-ranlib"
1097-
end
1098-
1099-
execute("compile", make_cmd, { env: env })
1100-
end
1101-
end
1059+
recipe.source_directory = File.join(PACKAGE_ROOT_DIR, "gumbo-parser")
11021060
end
1103-
append_cppflags("-I#{File.join(libgumbo_recipe.path, "include")}")
1104-
$libs = $libs + " " + File.join(libgumbo_recipe.path, "lib", "libgumbo.a")
1105-
$LIBPATH = $LIBPATH | [File.join(libgumbo_recipe.path, "lib")]
1106-
ensure_func("gumbo_parse_with_options", "nokogiri_gumbo.h")
11071061
end
11081062

11091063
have_func("xmlHasFeature") || abort("xmlHasFeature() is missing.") # introduced in libxml 2.6.21
@@ -1142,11 +1096,23 @@ def compile
11421096
File.open("Makefile", "at") do |mk|
11431097
mk.print(<<~EOF)
11441098
1099+
.PHONY: clean-ports
11451100
all: clean-ports
11461101
clean-ports: $(DLLIB)
11471102
\t-$(Q)$(RUBY) $(srcdir)/extconf.rb --clean --#{static_p ? "enable" : "disable"}-static
11481103
EOF
11491104
end
1105+
File.open("Makefile", "at") do |mk|
1106+
mk.print(<<~EOF)
1107+
1108+
.PHONY: rebuild-libgumbo
1109+
1110+
$(TARGET_SO): rebuild-libgumbo
1111+
rebuild-libgumbo:
1112+
\t-$(Q)$(MAKE) -C tmp/#{libgumbo_recipe.host}/ports/libgumbo/1.0.0-nokogiri/libgumbo-1.0.0-nokogiri install
1113+
EOF
1114+
end
1115+
11501116
end
11511117

11521118
# rubocop:enable Style/GlobalVars

gumbo-parser/.gitignore

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
build
2-
googletest
3-
src/*.o
4-
fuzzer/build
5-
src/libgumbo.a
1+
/build
2+
/googletest
3+
/src/*.o
4+
/fuzzer/build
5+
/src/libgumbo.a
6+
/aclocal.m4
7+
/autom4te.cache/
8+
/configure
9+
/configure.in
10+
Makefile.in

gumbo-parser/Makefile.am

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
if HAS_TESTS
2+
SUBDIRS = src test
3+
else
4+
SUBDIRS = src
5+
endif

gumbo-parser/build-aux/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory except for this file.
2+
# Credit: https://stackoverflow.com/a/932982
3+
*
4+
!/.gitignore

gumbo-parser/configure.ac

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
AC_INIT([Gumbo], [1.0])
2+
AC_CONFIG_SRCDIR([src/nokogiri_gumbo.h])
3+
AC_CONFIG_AUX_DIR([build-aux])
4+
AM_INIT_AUTOMAKE([subdir-objects foreign serial-tests no-dist no-installinfo no-installman -Wall])
5+
AC_PROG_RANLIB
6+
AC_PROG_CC
7+
AC_PROG_CXX
8+
AM_PROG_AR
9+
AM_CONDITIONAL([HAS_TESTS], [test -d "${srcdir}/test"])
10+
AC_CONFIG_FILES([Makefile src/Makefile test/Makefile])
11+
AC_OUTPUT

gumbo-parser/src/Makefile

Lines changed: 0 additions & 34 deletions
This file was deleted.

gumbo-parser/src/Makefile.am

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
lib_LIBRARIES = libgumbo.a
2+
libgumbo_a_SOURCES = \
3+
ascii.c \
4+
attribute.c \
5+
char_ref.c \
6+
error.c \
7+
foreign_attrs.c \
8+
parser.c \
9+
string_buffer.c \
10+
string_piece.c \
11+
svg_attrs.c \
12+
svg_tags.c \
13+
tag.c \
14+
tag_lookup.c \
15+
token_buffer.c \
16+
tokenizer.c \
17+
utf8.c \
18+
util.c \
19+
vector.c
20+
include_HEADERS = nokogiri_gumbo.h

gumbo-parser/test/Makefile.am

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
check_LIBRARIES = libgtest_main.a
2+
libgtest_main_a_SOURCES = ../googletest/src/gtest-all.cc ../googletest/src/gtest_main.cc
3+
libgtest_main_a_CPPFLAGS = -I$(top_srcdir)/googletest/include -I$(top_srcdir)/googletest
4+
libgtest_main_a_CXXFLAGS = -pthread
5+
6+
check_PROGRAMS = gumbotest
7+
gumbotest_SOURCES = attribute.cc \
8+
parser.cc \
9+
string_buffer.cc \
10+
string_piece.cc \
11+
test_utils.cc \
12+
token_buffer.cc \
13+
tokenizer.cc \
14+
utf8.cc \
15+
vector.cc
16+
17+
gumbotest_LDADD = libgtest_main.a ../src/libgumbo.a
18+
gumbotest_LDFLAGS = -pthread
19+
gumbotest_CPPFLAGS = -I$(top_srcdir)/googletest/include -I$(top_srcdir)/src
20+
21+
TESTS = gumbotest

nokogiri.gemspec

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,13 @@ Gem::Specification.new do |spec|
182182
"ext/nokogiri/xml_xpath_context.c",
183183
"ext/nokogiri/xslt_stylesheet.c",
184184
"gumbo-parser/CHANGES.md",
185-
"gumbo-parser/Makefile",
185+
"gumbo-parser/Makefile.am",
186+
"gumbo-parser/Makefile.in",
186187
"gumbo-parser/THANKS",
187-
"gumbo-parser/src/Makefile",
188+
"gumbo-parser/configure",
189+
"gumbo-parser/configure.ac",
190+
"gumbo-parser/src/Makefile.am",
191+
"gumbo-parser/src/Makefile.in",
188192
"gumbo-parser/src/README.md",
189193
"gumbo-parser/src/ascii.c",
190194
"gumbo-parser/src/ascii.h",

0 commit comments

Comments
 (0)