From 8546eb7b8ea68cbeed0285f20afa49bd9150144b Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 28 Feb 2020 17:39:43 -0500 Subject: [PATCH 1/7] Rakefile: extract concourse tasks --- Rakefile | 11 ++--------- tasks/concourse.rb | 7 +++++++ 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 tasks/concourse.rb diff --git a/Rakefile b/Rakefile index 13b175d035..58ef9b6404 100644 --- a/Rakefile +++ b/Rakefile @@ -165,7 +165,6 @@ HOE = Hoe.spec 'nokogiri' do 'nokogiri.gemspec', 'lib/nokogiri/nokogiri.{bundle,jar,rb,so}', 'lib/nokogiri/[0-9].[0-9]', - 'concourse/images/*.generated' ] self.clean_globs += Dir.glob("ports/*").reject { |d| d =~ %r{/archives$} } @@ -327,13 +326,6 @@ if Hoe.plugins.include?(:debugging) end end -require 'concourse' -Concourse.new("nokogiri", fly_target: "ci") do |c| - c.add_pipeline "nokogiri", "nokogiri.yml" - c.add_pipeline "nokogiri-pr", "nokogiri-pr.yml" - c.add_pipeline "nokogiri-v1.10.x", "nokogiri-v1.10.x.yml" -end - # ---------------------------------------- def verify_dll(dll, cross_ruby) @@ -405,8 +397,9 @@ namespace "gem" do end end +require_relative "tasks/concourse" require_relative "tasks/docker" -require_relative "tasks/set-version-to-timestamp" require_relative "tasks/docs-linkify" +require_relative "tasks/set-version-to-timestamp" # vim: syntax=Ruby diff --git a/tasks/concourse.rb b/tasks/concourse.rb new file mode 100644 index 0000000000..96c1bf224b --- /dev/null +++ b/tasks/concourse.rb @@ -0,0 +1,7 @@ +require "concourse" + +Concourse.new("nokogiri", fly_target: "ci") do |c| + c.add_pipeline "nokogiri", "nokogiri.yml" + c.add_pipeline "nokogiri-pr", "nokogiri-pr.yml" + c.add_pipeline "nokogiri-v1.10.x", "nokogiri-v1.10.x.yml" +end From d1e06f396dd4bf4b6992d1554556f9c987bfafc2 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Fri, 28 Feb 2020 17:44:19 -0500 Subject: [PATCH 2/7] Rakefile: extract css parser/tokenizer generation --- Rakefile | 20 +------------------- tasks/css-generate.rb | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 tasks/css-generate.rb diff --git a/Rakefile b/Rakefile index 58ef9b6404..5da0cc5185 100644 --- a/Rakefile +++ b/Rakefile @@ -10,9 +10,6 @@ Hoe.plugin :git Hoe.plugin :gemspec Hoe.plugin :bundler -GENERATED_PARSER = "lib/nokogiri/css/parser.rb" -GENERATED_TOKENIZER = "lib/nokogiri/css/tokenizer.rb" - def java? /java/ === RUBY_PLATFORM end @@ -280,22 +277,6 @@ end # ---------------------------------------- -desc "Generate css/parser.rb and css/tokenizer.rex" -task 'generate' => [GENERATED_PARSER, GENERATED_TOKENIZER] -task 'gem:spec' => 'generate' if Rake::Task.task_defined?("gem:spec") -[:compile, :check_manifest].each do |task_name| - Rake::Task[task_name].prerequisites << GENERATED_PARSER - Rake::Task[task_name].prerequisites << GENERATED_TOKENIZER -end - -file GENERATED_PARSER => "lib/nokogiri/css/parser.y" do |t| - sh "racc -l -o #{t.name} #{t.prerequisites.first}" -end - -file GENERATED_TOKENIZER => "lib/nokogiri/css/tokenizer.rex" do |t| - sh "rex --independent -o #{t.name} #{t.prerequisites.first}" -end - # ---------------------------------------- desc "set environment variables to build and/or test with debug options" @@ -398,6 +379,7 @@ namespace "gem" do end require_relative "tasks/concourse" +require_relative "tasks/css-generate" require_relative "tasks/docker" require_relative "tasks/docs-linkify" require_relative "tasks/set-version-to-timestamp" diff --git a/tasks/css-generate.rb b/tasks/css-generate.rb new file mode 100644 index 0000000000..538265f8c6 --- /dev/null +++ b/tasks/css-generate.rb @@ -0,0 +1,27 @@ +namespace "css" do + PARSER_DEPS = { "lib/nokogiri/css/parser.rb" => "lib/nokogiri/css/parser.y" } + TOKENIZER_DEPS = { "lib/nokogiri/css/tokenizer.rb" => "lib/nokogiri/css/tokenizer.rex" } + DEPS = PARSER_DEPS.merge(TOKENIZER_DEPS) + + desc "Generate CSS parser and tokenizer" + task "generate" => DEPS.keys + + desc "Clean up generated CSS parser and tokenizer" + task "clean" do + DEPS.keys.each { |f| FileUtils.rm_f f, :verbose => true } + end + + file PARSER_DEPS do |t| + sh "racc -l -o #{t.name} #{t.prerequisites.first}" + end + + file TOKENIZER_DEPS do |t| + sh "rex --independent -o #{t.name} #{t.prerequisites.first}" + end +end + +task "gem:spec" => "css:generate" if Hoe.plugins.include?(:gemspec) +task "compile" => "css:generate" +task "check_manifest" => "css:generate" + +task "generate" => "css:generate" # backwards compatibility, see concourse/tasks/rake-test/run.sh From ee0fe6bcc65cec87f94a4f089ebbfe93572595ba Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sat, 29 Feb 2020 08:45:11 -0500 Subject: [PATCH 3/7] Rakefile: extract rubocop tasks --- Rakefile | 10 +--------- tasks/rubocop.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) create mode 100644 tasks/rubocop.rb diff --git a/Rakefile b/Rakefile index 5da0cc5185..5277493b20 100644 --- a/Rakefile +++ b/Rakefile @@ -292,15 +292,6 @@ task :java_debug do end Rake::Task[:test].prerequisites << :java_debug -task :rubocop => [:rubocop_security, :rubocop_frozen_string_literals] -task :rubocop_security do - sh "rubocop lib --only Security" -end -task :rubocop_frozen_string_literals do - sh "rubocop lib --auto-correct --only Style/FrozenStringLiteralComment" -end -Rake::Task[:test].prerequisites << :rubocop - if Hoe.plugins.include?(:debugging) ['valgrind', 'valgrind:mem', 'valgrind:mem0'].each do |task_name| Rake::Task["test:#{task_name}"].prerequisites << :compile @@ -382,6 +373,7 @@ require_relative "tasks/concourse" require_relative "tasks/css-generate" require_relative "tasks/docker" require_relative "tasks/docs-linkify" +require_relative "tasks/rubocop" require_relative "tasks/set-version-to-timestamp" # vim: syntax=Ruby diff --git a/tasks/rubocop.rb b/tasks/rubocop.rb new file mode 100644 index 0000000000..e9f58c1213 --- /dev/null +++ b/tasks/rubocop.rb @@ -0,0 +1,14 @@ +desc "Run rubocop checks" +task :rubocop => [:rubocop_security, :rubocop_frozen_string_literals] + +desc "Run rubocop security check" +task :rubocop_security do + sh "rubocop lib --only Security" +end + +desc "Run rubocop string literals check" +task :rubocop_frozen_string_literals do + sh "rubocop lib --auto-correct --only Style/FrozenStringLiteralComment" +end + +task :test => :rubocop From d168f9c7eabd31337d514ba55abb154b319f868b Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sat, 29 Feb 2020 08:59:56 -0500 Subject: [PATCH 4/7] Rakefile: extract debug tasks --- Rakefile | 24 +----------------------- tasks/debug.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 23 deletions(-) create mode 100644 tasks/debug.rb diff --git a/Rakefile b/Rakefile index 5277493b20..7e5b83d766 100644 --- a/Rakefile +++ b/Rakefile @@ -277,29 +277,6 @@ end # ---------------------------------------- -# ---------------------------------------- - -desc "set environment variables to build and/or test with debug options" -task :debug do - ENV['NOKOGIRI_DEBUG'] = "true" - ENV['CFLAGS'] ||= "" - ENV['CFLAGS'] += " -DDEBUG" -end - -task :java_debug do - ENV['JRUBY_OPTS'] = "#{ENV['JRUBY_OPTS']} --debug --dev" - ENV['JAVA_OPTS'] = '-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y' if ENV['JAVA_DEBUG'] -end -Rake::Task[:test].prerequisites << :java_debug - -if Hoe.plugins.include?(:debugging) - ['valgrind', 'valgrind:mem', 'valgrind:mem0'].each do |task_name| - Rake::Task["test:#{task_name}"].prerequisites << :compile - end -end - -# ---------------------------------------- - def verify_dll(dll, cross_ruby) dll_imports = cross_ruby.dlls dump = `#{['env', 'LANG=C', cross_ruby.tool('objdump'), '-p', dll].shelljoin}` @@ -371,6 +348,7 @@ end require_relative "tasks/concourse" require_relative "tasks/css-generate" +require_relative "tasks/debug" require_relative "tasks/docker" require_relative "tasks/docs-linkify" require_relative "tasks/rubocop" diff --git a/tasks/debug.rb b/tasks/debug.rb new file mode 100644 index 0000000000..7faa21facc --- /dev/null +++ b/tasks/debug.rb @@ -0,0 +1,14 @@ +desc "Set environment variables to build and/or test with debug options" +task :debug do + ENV["NOKOGIRI_DEBUG"] = "true" + ENV["CFLAGS"] ||= "" + ENV["CFLAGS"] += " -DDEBUG" +end + +task :java_debug do + ENV["JRUBY_OPTS"] = "#{ENV["JRUBY_OPTS"]} --debug --dev" + if ENV["JAVA_DEBUG"] + ENV["JAVA_OPTS"] = "-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y" + end +end +task :test => :java_debug From 4d2a6f34269718975ff60610153e9bdf4b4146d0 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sat, 29 Feb 2020 09:19:40 -0500 Subject: [PATCH 5/7] Rakefile: extract cross-ruby setup --- Rakefile | 124 ++------------------------------------------ tasks/cross-ruby.rb | 115 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+), 119 deletions(-) create mode 100644 tasks/cross-ruby.rb diff --git a/Rakefile b/Rakefile index 7e5b83d766..f45c7ad56f 100644 --- a/Rakefile +++ b/Rakefile @@ -1,10 +1,12 @@ # -*- ruby -*- require 'rubygems' -require 'shellwords' -require "rake_compiler_dock" gem 'hoe' require 'hoe' + +require 'shellwords' +require "rake_compiler_dock" + Hoe.plugin :debugging Hoe.plugin :git Hoe.plugin :gemspec @@ -16,123 +18,7 @@ end ENV['LANG'] = "en_US.UTF-8" # UBUNTU 10.04, Y U NO DEFAULT TO UTF-8? -CrossRuby = Struct.new(:version, :host) { - def ver - @ver ||= version[/\A[^-]+/] - end - - def minor_ver - @minor_ver ||= ver[/\A\d\.\d(?=\.)/] - end - - def api_ver_suffix - case minor_ver - when nil - raise "unsupported version: #{ver}" - else - minor_ver.delete('.') << '0' - end - end - - def platform - @platform ||= - case host - when /\Ax86_64.*mingw32/ - 'x64-mingw32' - when /\Ai[3-6]86.*mingw32/ - 'x86-mingw32' - when /\Ax86_64.*linux/ - 'x86_64-linux' - when /\Ai[3-6]86.*linux/ - 'x86-linux' - else - raise "unsupported host: #{host}" - end - end - - WINDOWS_PLATFORM_REGEX = /mingw|mswin/ - MINGW32_PLATFORM_REGEX = /mingw32/ - LINUX_PLATFORM_REGEX = /linux/ - - def windows? - !!(platform =~ WINDOWS_PLATFORM_REGEX) - end - - def tool(name) - (@binutils_prefix ||= - case platform - when 'x64-mingw32' - 'x86_64-w64-mingw32-' - when 'x86-mingw32' - 'i686-w64-mingw32-' - when 'x86_64-linux' - 'x86_64-linux-gnu-' - when 'x86-linux' - 'i686-linux-gnu-' - end) + name - end - - def target - case platform - when 'x64-mingw32' - 'pei-x86-64' - when 'x86-mingw32' - 'pei-i386' - end - end - - def libruby_dll - case platform - when 'x64-mingw32' - "x64-msvcrt-ruby#{api_ver_suffix}.dll" - when 'x86-mingw32' - "msvcrt-ruby#{api_ver_suffix}.dll" - end - end - - def dlls - case platform - when MINGW32_PLATFORM_REGEX - [ - 'kernel32.dll', - 'msvcrt.dll', - 'ws2_32.dll', - *(case - when ver >= '2.0.0' - 'user32.dll' - end), - libruby_dll, - ] - when LINUX_PLATFORM_REGEX - [ - 'libm.so.6', - *(case - when ver < '2.6.0' - 'libpthread.so.0' - end), - 'libc.so.6', - ] - end - end - - def dll_ref_versions - case platform - when LINUX_PLATFORM_REGEX - {"GLIBC"=>"2.17"} - end - end -} - -CROSS_RUBIES = File.read('.cross_rubies').lines.flat_map { |line| - case line - when /\A([^#]+):([^#]+)/ - CrossRuby.new($1, $2) - else - [] - end -} - -ENV['RUBY_CC_VERSION'] ||= CROSS_RUBIES.map(&:ver).uniq.join(":") +require_relative "tasks/cross-ruby" HOE = Hoe.spec 'nokogiri' do developer 'Aaron Patterson', 'aaronp@rubyforge.org' diff --git a/tasks/cross-ruby.rb b/tasks/cross-ruby.rb new file mode 100644 index 0000000000..a2141c0bb5 --- /dev/null +++ b/tasks/cross-ruby.rb @@ -0,0 +1,115 @@ +CrossRuby = Struct.new(:version, :host) do + def ver + @ver ||= version[/\A[^-]+/] + end + + def minor_ver + @minor_ver ||= ver[/\A\d\.\d(?=\.)/] + end + + def api_ver_suffix + case minor_ver + when nil + raise "unsupported version: #{ver}" + else + minor_ver.delete(".") << "0" + end + end + + def platform + @platform ||= case host + when /\Ax86_64.*mingw32/ + "x64-mingw32" + when /\Ai[3-6]86.*mingw32/ + "x86-mingw32" + when /\Ax86_64.*linux/ + "x86_64-linux" + when /\Ai[3-6]86.*linux/ + "x86-linux" + else + raise "unsupported host: #{host}" + end + end + + WINDOWS_PLATFORM_REGEX = /mingw|mswin/ + MINGW32_PLATFORM_REGEX = /mingw32/ + LINUX_PLATFORM_REGEX = /linux/ + + def windows? + !!(platform =~ WINDOWS_PLATFORM_REGEX) + end + + def tool(name) + (@binutils_prefix ||= case platform + when "x64-mingw32" + "x86_64-w64-mingw32-" + when "x86-mingw32" + "i686-w64-mingw32-" + when "x86_64-linux" + "x86_64-linux-gnu-" + when "x86-linux" + "i686-linux-gnu-" + end) + name + end + + def target + case platform + when "x64-mingw32" + "pei-x86-64" + when "x86-mingw32" + "pei-i386" + end + end + + def libruby_dll + case platform + when "x64-mingw32" + "x64-msvcrt-ruby#{api_ver_suffix}.dll" + when "x86-mingw32" + "msvcrt-ruby#{api_ver_suffix}.dll" + end + end + + def dlls + case platform + when MINGW32_PLATFORM_REGEX + [ + "kernel32.dll", + "msvcrt.dll", + "ws2_32.dll", + *(case + when ver >= "2.0.0" + "user32.dll" + end), + libruby_dll, + ] + when LINUX_PLATFORM_REGEX + [ + "libm.so.6", + *(case + when ver < "2.6.0" + "libpthread.so.0" + end), + "libc.so.6", + ] + end + end + + def dll_ref_versions + case platform + when LINUX_PLATFORM_REGEX + { "GLIBC" => "2.17" } + end + end +end + +CROSS_RUBIES = File.read(".cross_rubies").lines.flat_map do |line| + case line + when /\A([^#]+):([^#]+)/ + CrossRuby.new($1, $2) + else + [] + end +end + +ENV["RUBY_CC_VERSION"] ||= CROSS_RUBIES.map(&:ver).uniq.join(":") From 063b7503b37b180e99cf5870d8bc2c6149bf4a2d Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sat, 29 Feb 2020 09:20:45 -0500 Subject: [PATCH 6/7] Rakefile: extract utility methods --- Rakefile | 20 +------------------- tasks/util.rb | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 19 deletions(-) create mode 100644 tasks/util.rb diff --git a/Rakefile b/Rakefile index f45c7ad56f..cf67b5853b 100644 --- a/Rakefile +++ b/Rakefile @@ -12,12 +12,9 @@ Hoe.plugin :git Hoe.plugin :gemspec Hoe.plugin :bundler -def java? - /java/ === RUBY_PLATFORM -end - ENV['LANG'] = "en_US.UTF-8" # UBUNTU 10.04, Y U NO DEFAULT TO UTF-8? +require_relative "tasks/util" require_relative "tasks/cross-ruby" HOE = Hoe.spec 'nokogiri' do @@ -85,21 +82,6 @@ end # ---------------------------------------- -def add_file_to_gem relative_source_path - dest_path = File.join(gem_build_path, relative_source_path) - dest_dir = File.dirname(dest_path) - - mkdir_p dest_dir unless Dir.exist?(dest_dir) - rm_f dest_path if File.exist?(dest_path) - safe_ln relative_source_path, dest_path - - HOE.spec.files << relative_source_path -end - -def gem_build_path - File.join 'pkg', HOE.spec.full_name -end - if java? # TODO: clean this section up. require "rake/javaextensiontask" diff --git a/tasks/util.rb b/tasks/util.rb new file mode 100644 index 0000000000..fce9fcfde8 --- /dev/null +++ b/tasks/util.rb @@ -0,0 +1,18 @@ +def java? + /java/ === RUBY_PLATFORM +end + +def add_file_to_gem(relative_source_path) + dest_path = File.join(gem_build_path, relative_source_path) + dest_dir = File.dirname(dest_path) + + mkdir_p dest_dir unless Dir.exist?(dest_dir) + rm_f dest_path if File.exist?(dest_path) + safe_ln relative_source_path, dest_path + + HOE.spec.files << relative_source_path +end + +def gem_build_path + File.join "pkg", HOE.spec.full_name +end From a265687248b89e72d3a156877cd3281009c5c373 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Sat, 29 Feb 2020 09:31:57 -0500 Subject: [PATCH 7/7] Rakefile: extract cross-ruby tasks --- Rakefile | 71 --------------------------------------------- tasks/cross-ruby.rb | 69 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 71 deletions(-) diff --git a/Rakefile b/Rakefile index cf67b5853b..6c740a90e0 100644 --- a/Rakefile +++ b/Rakefile @@ -143,77 +143,6 @@ Nokogiri is built with the packaged libraries: #{libs}. end end -# ---------------------------------------- - -def verify_dll(dll, cross_ruby) - dll_imports = cross_ruby.dlls - dump = `#{['env', 'LANG=C', cross_ruby.tool('objdump'), '-p', dll].shelljoin}` - if cross_ruby.windows? - raise "unexpected file format for generated dll #{dll}" unless /file format #{Regexp.quote(cross_ruby.target)}\s/ === dump - raise "export function Init_nokogiri not in dll #{dll}" unless /Table.*\sInit_nokogiri\s/mi === dump - - # Verify that the expected DLL dependencies match the actual dependencies - # and that no further dependencies exist. - dll_imports_is = dump.scan(/DLL Name: (.*)$/).map(&:first).map(&:downcase).uniq - if dll_imports_is.sort != dll_imports.sort - raise "unexpected dll imports #{dll_imports_is.inspect} in #{dll}" - end - else - # Verify that the expected so dependencies match the actual dependencies - # and that no further dependencies exist. - dll_imports_is = dump.scan(/NEEDED\s+(.*)/).map(&:first).uniq - if dll_imports_is.sort != dll_imports.sort - raise "unexpected so imports #{dll_imports_is.inspect} in #{dll} (expected #{dll_imports.inspect})" - end - - # Verify that the expected so version requirements match the actual dependencies. - dll_ref_versions_list = dump.scan(/0x[\da-f]+ 0x[\da-f]+ \d+ (\w+)_([\d\.]+)$/i) - # Build a hash of library versions like {"LIBUDEV"=>"183", "GLIBC"=>"2.17"} - dll_ref_versions_is = dll_ref_versions_list.each.with_object({}) do |(lib, ver), h| - if !h[lib] || ver.split(".").map(&:to_i).pack("C*") > h[lib].split(".").map(&:to_i).pack("C*") - h[lib] = ver - end - end - if dll_ref_versions_is != cross_ruby.dll_ref_versions - raise "unexpected so version requirements #{dll_ref_versions_is.inspect} in #{dll}" - end - end - puts "#{dll}: Looks good!" -end - -CROSS_RUBIES.each do |cross_ruby| - task "tmp/#{cross_ruby.platform}/stage/lib/nokogiri/#{cross_ruby.minor_ver}/nokogiri.so" do |t| - verify_dll t.name, cross_ruby - end -end - -namespace "gem" do - CROSS_RUBIES.map(&:platform).uniq.each do |plat| - desc "build native fat binary gems for windows and linux" - multitask "native" => plat - - desc "build native gem for #{plat} platform" - task plat do - RakeCompilerDock.sh <<-EOT, platform: plat - gem install bundler && - bundle && - rake native:#{plat} pkg/#{HOE.spec.full_name}-#{plat}.gem MAKE='nice make -j`nproc`' RUBY_CC_VERSION=#{ENV['RUBY_CC_VERSION']} - EOT - end - end - - desc "build native fat binary gems for windows" - multitask "windows" => CROSS_RUBIES.map(&:platform).uniq.grep(WINDOWS_PLATFORM_REGEX) - - desc "build native fat binary gems for linux" - multitask "linux" => CROSS_RUBIES.map(&:platform).uniq.grep(LINUX_PLATFORM_REGEX) - - desc "build a jruby gem with docker" - task "jruby" do - RakeCompilerDock.sh "gem install bundler && bundle && rake java gem", rubyvm: 'jruby' - end -end - require_relative "tasks/concourse" require_relative "tasks/css-generate" require_relative "tasks/debug" diff --git a/tasks/cross-ruby.rb b/tasks/cross-ruby.rb index a2141c0bb5..b77d7b43dd 100644 --- a/tasks/cross-ruby.rb +++ b/tasks/cross-ruby.rb @@ -113,3 +113,72 @@ def dll_ref_versions end ENV["RUBY_CC_VERSION"] ||= CROSS_RUBIES.map(&:ver).uniq.join(":") + +def verify_dll(dll, cross_ruby) + dll_imports = cross_ruby.dlls + dump = `#{["env", "LANG=C", cross_ruby.tool("objdump"), "-p", dll].shelljoin}` + if cross_ruby.windows? + raise "unexpected file format for generated dll #{dll}" unless /file format #{Regexp.quote(cross_ruby.target)}\s/ === dump + raise "export function Init_nokogiri not in dll #{dll}" unless /Table.*\sInit_nokogiri\s/mi === dump + + # Verify that the expected DLL dependencies match the actual dependencies + # and that no further dependencies exist. + dll_imports_is = dump.scan(/DLL Name: (.*)$/).map(&:first).map(&:downcase).uniq + if dll_imports_is.sort != dll_imports.sort + raise "unexpected dll imports #{dll_imports_is.inspect} in #{dll}" + end + else + # Verify that the expected so dependencies match the actual dependencies + # and that no further dependencies exist. + dll_imports_is = dump.scan(/NEEDED\s+(.*)/).map(&:first).uniq + if dll_imports_is.sort != dll_imports.sort + raise "unexpected so imports #{dll_imports_is.inspect} in #{dll} (expected #{dll_imports.inspect})" + end + + # Verify that the expected so version requirements match the actual dependencies. + dll_ref_versions_list = dump.scan(/0x[\da-f]+ 0x[\da-f]+ \d+ (\w+)_([\d\.]+)$/i) + # Build a hash of library versions like {"LIBUDEV"=>"183", "GLIBC"=>"2.17"} + dll_ref_versions_is = dll_ref_versions_list.each.with_object({}) do |(lib, ver), h| + if !h[lib] || ver.split(".").map(&:to_i).pack("C*") > h[lib].split(".").map(&:to_i).pack("C*") + h[lib] = ver + end + end + if dll_ref_versions_is != cross_ruby.dll_ref_versions + raise "unexpected so version requirements #{dll_ref_versions_is.inspect} in #{dll}" + end + end + puts "#{dll}: Looks good!" +end + +CROSS_RUBIES.each do |cross_ruby| + task "tmp/#{cross_ruby.platform}/stage/lib/nokogiri/#{cross_ruby.minor_ver}/nokogiri.so" do |t| + verify_dll t.name, cross_ruby + end +end + +namespace "gem" do + CROSS_RUBIES.map(&:platform).uniq.each do |plat| + desc "build native fat binary gems for windows and linux" + multitask "native" => plat + + desc "build native gem for #{plat} platform" + task plat do + RakeCompilerDock.sh <<-EOT, platform: plat + gem install bundler --no-document && + bundle && + rake native:#{plat} pkg/#{HOE.spec.full_name}-#{plat}.gem MAKE='nice make -j`nproc`' RUBY_CC_VERSION=#{ENV["RUBY_CC_VERSION"]} + EOT + end + end + + desc "build native fat binary gems for windows" + multitask "windows" => CROSS_RUBIES.map(&:platform).uniq.grep(WINDOWS_PLATFORM_REGEX) + + desc "build native fat binary gems for linux" + multitask "linux" => CROSS_RUBIES.map(&:platform).uniq.grep(LINUX_PLATFORM_REGEX) + + desc "build a jruby gem with docker" + task "jruby" do + RakeCompilerDock.sh "gem install bundler --no-document && bundle && rake java gem", rubyvm: "jruby" + end +end