Top Level Namespace

Defined Under Namespace

Modules: Nokogiri, Nokogumbo

Constant Summary collapse

NG_SPEC =
Gem::Specification.find_by_name('nokogiri', "= #{Nokogiri::VERSION}")

Instance Method Summary collapse

Instance Method Details

#download_headersObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'ext/nokogumbo/extconf.rb', line 13

def download_headers
  begin
    require 'yaml'

    dependencies = YAML.load_file(File.join(NG_SPEC.gem_dir, 'dependencies.yml'))
    version = dependencies['libxml2']['version']
    host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
    path = File.join('ports', host, 'libxml2', version, 'include/libxml2')
    return path if File.directory?(path)

    # Make sure we're using the same version Nokogiri uses
    dep_index = NG_SPEC.dependencies.index { |dep| dep.name == 'mini_portile2' and dep.type == :runtime }
    return nil if dep_index.nil?
    requirement = NG_SPEC.dependencies[dep_index].requirement.to_s

    gem 'mini_portile2', requirement
    require 'mini_portile2'
    p = MiniPortile::new('libxml2', version).tap do |r|
      r.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"]
      r.files = [{
        url: "http://xmlsoft.org/sources/libxml2-#{r.version}.tar.gz",
        sha256: dependencies['libxml2']['sha256']
      }]
      r.configure_options += [
        "--without-python",
        "--without-readline",
        "--with-c14n",
        "--with-debug",
        "--with-threads"
      ]
    end
    p.download unless p.downloaded?
    p.extract
    p.configure unless p.configured?
    system('make', '-C', "tmp/#{p.host}/ports/libxml2/#{version}/libxml2-#{version}/include/libxml", 'install-xmlincHEADERS')
    path
  rescue
    puts 'failed to download/install headers'
    nil
  end
end

#modern_nokogiri?Boolean

Returns:

  • (Boolean)


68
69
70
71
72
# File 'ext/nokogumbo/extconf.rb', line 68

def modern_nokogiri?
  nokogiri_version = Gem::Version.new(Nokogiri::VERSION)
  requirement = windows? ? ">= 1.11.2" : ">= 1.11.0.rc4"
  Gem::Requirement.new(requirement).satisfied_by?(nokogiri_version)
end

#windows?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'ext/nokogumbo/extconf.rb', line 64

def windows?
  ::RUBY_PLATFORM =~ /mingw|mswin/
end