From 19b1bb5ae4a9856b1c5130e268ad571e8b5aabbd Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Thu, 24 Dec 2020 14:56:39 -0500 Subject: [PATCH] feat: version info emits version info about other libs used also: - make extconf more consistent in using append_cppflags for CPP flags - jruby version also emits lib info this way --- ext/nokogiri/extconf.rb | 18 ++++++++++++++---- ext/nokogiri/nokogiri.c | 4 ++++ lib/nokogiri/version/info.rb | 11 +++++++++-- test/test_version.rb | 4 ++-- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/ext/nokogiri/extconf.rb b/ext/nokogiri/extconf.rb index 52b5f41991a..f3f07bdeae5 100644 --- a/ext/nokogiri/extconf.rb +++ b/ext/nokogiri/extconf.rb @@ -19,6 +19,9 @@ REQUIRED_MINI_PORTILE_VERSION = "~> 2.5.0" REQUIRED_PKG_CONFIG_VERSION = "~> 1.1" +# Keep track of what versions of what libraries we build against +OTHER_LIBRARY_VERSIONS = {} + NOKOGIRI_HELP_MESSAGE = <<~HELP USAGE: ruby #{$0} [options] @@ -339,6 +342,10 @@ def process_recipe(name, version, static_p, cross_p) require 'mini_portile2' message "Using mini_portile version #{MiniPortile::VERSION}\n" + if name != "libxml2" && name != "libxslt" + OTHER_LIBRARY_VERSIONS[name] = version + end + MiniPortile.new(name, version).tap do |recipe| recipe.target = File.join(PACKAGE_ROOT_DIR, "ports") # Prefer host_alias over host in order to use i586-mingw32msvc as @@ -695,8 +702,8 @@ def configure ] end - append_cflags("-DNOKOGIRI_PACKAGED_LIBRARIES") - append_cflags("-DNOKOGIRI_PRECOMPILED_LIBRARIES") if cross_build_p + append_cppflags("-DNOKOGIRI_PACKAGED_LIBRARIES") + append_cppflags("-DNOKOGIRI_PRECOMPILED_LIBRARIES") if cross_build_p $LIBPATH = ["#{zlib_recipe.path}/lib"] | $LIBPATH if zlib_recipe $LIBPATH = ["#{libiconv_recipe.path}/lib"] | $LIBPATH if libiconv_recipe @@ -724,8 +731,8 @@ def configure end end - # Defining a macro that expands to a C string; double quotes are significant. - $CPPFLAGS << ' ' << "-DNOKOGIRI_#{recipe.name.upcase}_PATCHES=\"#{recipe.patch_files.map { |path| File.basename(path) }.join(' ')}\"".inspect + patches_string = recipe.patch_files.map { |path| File.basename(path) }.join(' ') + append_cppflags(%Q[-DNOKOGIRI_#{recipe.name.upcase}_PATCHES="\\\"#{patches_string}\\\""]) case libname when 'xml2' @@ -770,6 +777,9 @@ def configure have_func('vasprintf') +other_library_versions_string = OTHER_LIBRARY_VERSIONS.map { |k,v| [k,v].join(":") }.join(",") +append_cppflags(%Q[-DNOKOGIRI_OTHER_LIBRARY_VERSIONS="\\\"#{other_library_versions_string}\\\""]) + unless using_system_libraries? if cross_build_p # When precompiling native gems, copy packaged libraries' headers to ext/nokogiri/include diff --git a/ext/nokogiri/nokogiri.c b/ext/nokogiri/nokogiri.c index 4300d413119..963253ad96f 100644 --- a/ext/nokogiri/nokogiri.c +++ b/ext/nokogiri/nokogiri.c @@ -94,6 +94,10 @@ void Init_nokogiri() rb_const_set(mNokogiri, rb_intern("LIBXML_ICONV_ENABLED"), Qfalse); #endif +#ifdef NOKOGIRI_OTHER_LIBRARY_VERSIONS + rb_const_set(mNokogiri, rb_intern("OTHER_LIBRARY_VERSIONS"), NOKOGIRI_STR_NEW2(NOKOGIRI_OTHER_LIBRARY_VERSIONS)); +#endif + xmlInitParser(); init_xml_document(); diff --git a/lib/nokogiri/version/info.rb b/lib/nokogiri/version/info.rb index aacc92f8445..8c61d220488 100644 --- a/lib/nokogiri/version/info.rb +++ b/lib/nokogiri/version/info.rb @@ -114,9 +114,16 @@ def to_hash end vi["warnings"] = warnings + end + + if defined?(Nokogiri::OTHER_LIBRARY_VERSIONS) + # see extconf for how this string is assembled: "lib1name:lib1version,lib2name:lib2version" + vi["other_libraries"] = Hash[*Nokogiri::OTHER_LIBRARY_VERSIONS.split(/[,:]/)] elsif jruby? - vi["xerces"] = Nokogiri::XERCES_VERSION - vi["nekohtml"] = Nokogiri::NEKO_VERSION + vi["other_libraries"] = {}.tap do |ol| + ol["xerces"] = Nokogiri::XERCES_VERSION + ol["nekohtml"] = Nokogiri::NEKO_VERSION + end end end end diff --git a/test/test_version.rb b/test/test_version.rb index d79907c2c0d..45812229ebb 100644 --- a/test/test_version.rb +++ b/test/test_version.rb @@ -20,12 +20,12 @@ def test_version_info_basics def test_version_info_for_xerces skip("xerces is only used for JRuby") unless Nokogiri.jruby? - assert_equal(Nokogiri::XERCES_VERSION, version_info["xerces"]) + assert_equal(Nokogiri::XERCES_VERSION, version_info["other_libraries"]["xerces"]) end def test_version_info_for_nekohtml skip("nekohtml is only used for JRuby") unless Nokogiri.jruby? - assert_equal(Nokogiri::NEKO_VERSION, version_info["nekohtml"]) + assert_equal(Nokogiri::NEKO_VERSION, version_info["other_libraries"]["nekohtml"]) end def test_version_info_for_libxml