Skip to content

Commit

Permalink
feat: ruby and native gems always install libxml2/libxslt headers
Browse files Browse the repository at this point in the history
Also, restore VERSION_INFO["libxml"]["libxml2_path"] when using
packaged libraries, so Nokogumbo can find all the headers.

Fixes #1788
  • Loading branch information
flavorjones committed Dec 22, 2020
1 parent 0304e2c commit b1e28f7
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ ext/java/Canna
ext/java/nokogiri/**/*.class
ext/nokogiri/*.dll
gems
lib/nokogiri/**/nokogiri.so
lib/nokogiri/**/nokogiri.bundle
lib/nokogiri/**/nokogiri.so
lib/nokogiri/include
lib/nokogiri/nokogiri.jar
pkg
ports
Expand Down
10 changes: 6 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,13 @@ HOE = Hoe.spec "nokogiri" do |hoe|
hoe.markdown_linkify_files = FileList["*.md"]

hoe.clean_globs += [
"nokogiri.gemspec",
"lib/nokogiri/nokogiri.{bundle,jar,rb,so}",
"lib/nokogiri/[0-9].[0-9]",
"coverage",
"concourse/images/*.generated",
"coverage",
"lib/nokogiri/[0-9].[0-9]",
"lib/nokogiri/include",
"lib/nokogiri/nokogiri.{bundle,jar,rb,so}",
"nokogiri.gemspec",
"tmp",
]
hoe.clean_globs += Dir.glob("ports/*").reject { |d| d =~ %r{/archives$} }

Expand Down
23 changes: 22 additions & 1 deletion ext/nokogiri/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,14 @@ def process_recipe(name, version, static_p, cross_p)
end
end

def copy_packaged_libraries_headers(to_path:, from_recipes:)
FileUtils.rm_rf(to_path, secure: true)
FileUtils.mkdir(to_path)
from_recipes.each do |recipe|
FileUtils.cp_r(Dir[File.join(recipe.path, 'include/*')], to_path)
end
end

def do_help
print NOKOGIRI_HELP_MESSAGE
exit! 0
Expand Down Expand Up @@ -765,6 +773,20 @@ def configure
# When compiling during installation, install nokogiri's header files into lib/nokogiri/include
$INSTALLFILES << ["*.h", "$(rubylibdir)/include"]

unless using_system_libraries?
if cross_build_p
# When precompiling native gems, copy packaged libraries' headers to lib/nokogiri/include to get
# picked up by the cross-compiling callback in the extension task at package time
copy_packaged_libraries_headers(to_path: File.join(PACKAGE_ROOT_DIR, "lib/nokogiri/include"),
from_recipes: [libxml2_recipe, libxslt_recipe])
else
# When compiling during installation, install packaged libraries' header files into lib/nokogiri/include
copy_packaged_libraries_headers(to_path: "include",
from_recipes: [libxml2_recipe, libxslt_recipe])
$INSTALLFILES << ["include/**/*.h", "$(rubylibdir)"]
end
end

create_makefile('nokogiri/nokogiri')

if enable_config('clean', true)
Expand All @@ -778,5 +800,4 @@ def configure
EOF
end
end

# :startdoc:
3 changes: 3 additions & 0 deletions lib/nokogiri/version/info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def to_hash
libxml["source"] = "packaged"
libxml["precompiled"] = libxml2_precompiled?
libxml["patches"] = Nokogiri::LIBXML2_PATCHES

# this is for nokogumbo and shouldn't be forever
libxml["libxml2_path"] = File.expand_path(File.join(File.dirname(__FILE__), "../../nokogiri"))
else
libxml["source"] = "system"
end
Expand Down
8 changes: 8 additions & 0 deletions rakelib/cross-ruby.rake
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,20 @@ else
spec.dependencies.reject! { |dep| dep.name=='mini_portile2' }

# when pre-compiling a native gem, package all the C headers in lib/nokogiri/include:
# - packaged libraries' headers
# - nokogiri's headers
#
# (see the $INSTALLFILES section of extconf.rb for complementary behavior)
# (see scripts/test-gem-file-contents and scripts/test-gem-installation for tests)
headers_dir = "lib/nokogiri/include"

["libxml2", "libxslt"].each do |lib|
unless File.directory?(File.join(headers_dir, lib))
# these should have been copied during cross-compilation
raise "#{lib} headers are not present in #{headers_dir}"
end
end

Dir.glob("ext/nokogiri/*.h").each do |header|
FileUtils.cp(header, headers_dir)
end
Expand Down
4 changes: 2 additions & 2 deletions scripts/test-gem-file-contents
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe File.basename(gemfile) do
end

it "does not contain header files in lib/nokogiri/include" do
# these are copied to lib/nokogiri/include during compilation, not packaged
# these will be copied to lib/nokogiri/include during compilation, not packaged
assert_empty(gemfile_contents.grep(%r{^lib/.*\.h$}))
end

Expand Down Expand Up @@ -145,7 +145,7 @@ describe File.basename(gemfile) do
end

it "contains packaged libraries' header files in lib/nokogiri/include" do
skip "until we fix https://github.com/sparklemotion/nokogiri/pull/1788"
# https://github.com/sparklemotion/nokogiri/pull/1788
assert_includes(gemfile_contents, "lib/nokogiri/include/libxml2/libxml/tree.h")
assert_includes(gemfile_contents, "lib/nokogiri/include/libxslt/xslt.h")
assert_includes(gemfile_contents, "lib/nokogiri/include/libexslt/exslt.h")
Expand Down
6 changes: 3 additions & 3 deletions scripts/test-gem-installation
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ describe gemspec.full_name do

describe "cruby" do
it "installs nokogiri headers" do
skip "until we fix https://github.com/sparklemotion/nokogiri/pull/1788"
# https://github.com/sparklemotion/nokogiri/pull/1788
assert(File.directory?(nokogiri_include_dir),
"expected directory to exist: #{nokogiri_include_dir}")

Expand All @@ -80,15 +80,15 @@ describe gemspec.full_name do
describe "library" do
describe "packaged" do
it "declares where headers are installed" do
skip "until we fix https://github.com/sparklemotion/nokogiri/pull/1788"
# https://github.com/sparklemotion/nokogiri/pull/1788
# this is for nokogumbo and shouldn't be forever
nokogiri_include_parent_dir = File.dirname(nokogiri_include_dir)
assert_equal(nokogiri_include_parent_dir, Nokogiri::VERSION_INFO["libxml"]["libxml2_path"],
"expected Nokogiri::VERSION_INFO to point to #{nokogiri_include_parent_dir}")
end

it "installs packaged libraries' headers" do
skip "until we fix https://github.com/sparklemotion/nokogiri/pull/1788"
# https://github.com/sparklemotion/nokogiri/pull/1788
packaged_library_header_files.each do |header|
assert(File.file?(File.join(nokogiri_include_dir, header)),
"expected #{header} to be installed in #{nokogiri_include_dir}")
Expand Down

0 comments on commit b1e28f7

Please sign in to comment.