Skip to content

Commit f2dd079

Browse files
larskanisflavorjones
authored andcommitted
Make the pkg-config gem optional.
Using the pkg-config gem as a runtime dependency of nokogiri results in a license conflict. pkg-config is LGPL but nokogiri is MIT. Making the pkg-config gem optional solves this issue. Fixes #1488 and #1496 .
1 parent 6b05c5a commit f2dd079

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

Gemfile

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
source "https://rubygems.org/"
66

77
gem "mini_portile2", "~>2.1.0"
8-
gem "pkg-config", "~>1.1.7"
98

109
gem "rdoc", "~>4.0", :group => [:development, :test]
1110
gem "hoe-bundler", "~>1.2.0", :group => [:development, :test]

Rakefile

-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ HOE = Hoe.spec 'nokogiri' do
128128
unless java?
129129
self.extra_deps += [
130130
["mini_portile2", "~> 2.1.0"], # keep version in sync with extconf.rb
131-
["pkg-config", "~> 1.1.7"], # keep version in sync with extconf.rb
132131
]
133132
end
134133

ext/nokogiri/extconf.rb

+15-14
Original file line numberDiff line numberDiff line change
@@ -106,27 +106,28 @@ def do_clean
106106
exit! 0
107107
end
108108

109-
# The gem version constraint in the Rakefile is not respected at install time.
110-
# Keep this version in sync with the one in the Rakefile !
111-
require 'rubygems'
112-
gem 'pkg-config', '~> 1.1.7'
113-
require 'pkg-config'
114-
message "Using pkg-config version #{PKGConfig::VERSION}\n"
115-
116109
def package_config pkg, options={}
117110
package = pkg_config(pkg)
118111
return package if package
119112

120-
return nil unless PKGConfig.have_package(pkg)
113+
begin
114+
require 'rubygems'
115+
gem 'pkg-config', (gem_ver='~> 1.1.7')
116+
require 'pkg-config' and message("Using pkg-config gem version #{PKGConfig::VERSION}\n")
117+
rescue LoadError
118+
message "pkg-config could not be used to find #{pkg}\nPlease install either `pkg-config` or the pkg-config gem per\n\n gem install pkg-config -v #{gem_ver.inspect}\n\n"
119+
else
120+
return nil unless PKGConfig.have_package(pkg)
121121

122-
cflags = PKGConfig.cflags(pkg)
123-
ldflags = PKGConfig.libs_only_L(pkg)
124-
libs = PKGConfig.libs_only_l(pkg)
122+
cflags = PKGConfig.cflags(pkg)
123+
ldflags = PKGConfig.libs_only_L(pkg)
124+
libs = PKGConfig.libs_only_l(pkg)
125125

126-
Logging::message "PKGConfig package configuration for %s\n", pkg
127-
Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs
126+
Logging::message "PKGConfig package configuration for %s\n", pkg
127+
Logging::message "cflags: %s\nldflags: %s\nlibs: %s\n\n", cflags, ldflags, libs
128128

129-
[cflags, ldflags, libs]
129+
[cflags, ldflags, libs]
130+
end
130131
end
131132

132133
def nokogiri_try_compile

0 commit comments

Comments
 (0)