class Object

Constants

NG_SPEC

Public Instance Methods

download_headers() click to toggle source
# File ext/nokogumbo/extconf.rb, line 12
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