Top Level Namespace
Defined Under Namespace
Constant Summary collapse
- ROOT =
File.(File.join(File.dirname(__FILE__), '..', '..'))
Instance Method Summary collapse
- #add_cflags(flags) ⇒ Object
- #asplode(lib) ⇒ Object
- #do_clean ⇒ Object
-
#do_help ⇒ Object
functions.
- #have_iconv?(using = nil) ⇒ Boolean
- #iconv_configure_flags ⇒ Object
- #lib_a(ldflag) ⇒ Object
-
#monkey_patch_mini_portile ⇒ Object
Workaround for #1102.
-
#Nokogiri(*args, &block) ⇒ Object
Parser a document contained in
args
. - #preserving_globals ⇒ Object
- #process_recipe(name, version, static_p, cross_p) ⇒ Object
Instance Method Details
#add_cflags(flags) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'ext/nokogiri/extconf.rb', line 74 def add_cflags(flags) print "checking if the C compiler accepts #{flags}... " with_cflags("#{$CFLAGS} #{flags}") do if try_compile("int main() {return 0;}", werror: true) puts 'yes' true else puts 'no' false end end end |
#asplode(lib) ⇒ Object
101 102 103 |
# File 'ext/nokogiri/extconf.rb', line 101 def asplode(lib) abort "-----\n#{lib} is missing. Please locate mkmf.log to investigate how it is failing.\n-----" end |
#do_clean ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'ext/nokogiri/extconf.rb', line 43 def do_clean require 'pathname' require 'fileutils' root = Pathname(ROOT) pwd = Pathname(Dir.pwd) # Skip if this is a development work tree unless (root + '.git').exist? "Cleaning files only used during build.\n" # (root + 'tmp') cannot be removed at this stage because # nokogiri.so is yet to be copied to lib. # clean the ports build directory Pathname.glob(pwd.join('tmp', '*', 'ports')) { |dir| FileUtils.rm_rf(dir, verbose: true) FileUtils.rmdir(dir.parent, parents: true, verbose: true) } if enable_config('static') # ports installation can be safely removed if statically linked. FileUtils.rm_rf(root + 'ports', verbose: true) else FileUtils.rm_rf(root + 'ports' + 'archives', verbose: true) end end exit! 0 end |
#do_help ⇒ Object
functions
12 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 |
# File 'ext/nokogiri/extconf.rb', line 12 def do_help print <<HELP usage: ruby #{$0} [options] --disable-clean Do not clean out intermediate files after successful build. --disable-static Do not statically link bundled libraries. --with-iconv-dir=DIR Use the iconv library placed under DIR. --with-zlib-dir=DIR Use the zlib library placed under DIR. --use-system-libraries Use system libraries intead of building and using the bundled libraries. --with-xml2-dir=DIR / --with-xml2-config=CONFIG --with-xslt-dir=DIR / --with-xslt-config=CONFIG --with-exslt-dir=DIR / --with-exslt-config=CONFIG Use libxml2/libxslt/libexslt as specified. --enable-cross-build Do cross-build. HELP exit! 0 end |
#have_iconv?(using = nil) ⇒ Boolean
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'ext/nokogiri/extconf.rb', line 105 def have_iconv?(using = nil) checking_for(using ? "iconv using #{using}" : 'iconv') { ['', '-liconv'].any? { |opt| preserving_globals { yield if block_given? try_link(<<-'SRC', opt) #include <stdlib.h> #include <iconv.h> int main(void) { iconv_t cd = iconv_open("", ""); iconv(cd, NULL, NULL, NULL, NULL); return EXIT_SUCCESS; } SRC } } } end |
#iconv_configure_flags ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'ext/nokogiri/extconf.rb', line 127 def iconv_configure_flags # If --with-iconv-dir or --with-opt-dir is given, it should be # the first priority %w[iconv opt].each { |name| if (config = preserving_globals { dir_config(name) }).any? && have_iconv?("--with-#{name}-* flags") { dir_config(name) } idirs, ldirs = config.map { |dirs| Array(dirs).flat_map { |dir| dir.split(File::PATH_SEPARATOR) } if dirs } return [ '--with-iconv=yes', *("CPPFLAGS=#{idirs.map { |dir| '-I' << dir }.join(' ')}".quote if idirs), *("LDFLAGS=#{ldirs.map { |dir| '-L' << dir }.join(' ')}".quote if ldirs), ] end } if have_iconv? return ['--with-iconv=yes'] end if (config = preserving_globals { pkg_config('libiconv') }) && have_iconv?('pkg-config libiconv') { pkg_config('libiconv') } cflags, ldflags, libs = config return [ '--with-iconv=yes', "CPPFLAGS=#{cflags}".quote, "LDFLAGS=#{ldflags}".quote, "LIBS=#{libs}".quote, ] end asplode "libiconv" end |
#lib_a(ldflag) ⇒ Object
275 276 277 278 279 280 |
# File 'ext/nokogiri/extconf.rb', line 275 def lib_a(ldflag) case ldflag when /\A-l(.+)/ "lib#{$1}.#{$LIBEXT}" end end |
#monkey_patch_mini_portile ⇒ Object
Workaround for #1102
291 292 293 294 295 296 297 298 299 300 301 |
# File 'ext/nokogiri/extconf.rb', line 291 def monkey_patch_mini_portile MiniPortile.class_eval do def patch @patch_files.each do |full_path| next unless File.exists?(full_path) output "Running patch with #{full_path}..." execute('patch', %Q(patch -p1 < #{full_path})) end end end end |
#Nokogiri(*args, &block) ⇒ Object
Parser a document contained in args
. Nokogiri will try to guess what type of document you are attempting to parse. For more information, see Nokogiri.parse
To specify the type of document, use Nokogiri.XML or Nokogiri.HTML.
131 132 133 134 135 136 137 |
# File 'lib/nokogiri.rb', line 131 def Nokogiri(*args, &block) if block_given? Nokogiri::HTML::Builder.new(&block).doc.root else Nokogiri.parse(*args) end end |
#preserving_globals ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'ext/nokogiri/extconf.rb', line 87 def preserving_globals values = [ $arg_config, $CFLAGS, $CPPFLAGS, $LDFLAGS, $LIBPATH, $libs ].map(&:dup) yield ensure $arg_config, $CFLAGS, $CPPFLAGS, $LDFLAGS, $LIBPATH, $libs = values end |
#process_recipe(name, version, static_p, cross_p) ⇒ Object
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 |
# File 'ext/nokogiri/extconf.rb', line 166 def process_recipe(name, version, static_p, cross_p) MiniPortile.new(name, version).tap do |recipe| recipe.target = portsdir = File.join(ROOT, "ports") # Prefer host_alias over host in order to use i586-mingw32msvc as # correct compiler prefix for cross build, but use host if not set. recipe.host = RbConfig::CONFIG["host_alias"].empty? ? RbConfig::CONFIG["host"] : RbConfig::CONFIG["host_alias"] recipe.patch_files = Dir[File.join(portsdir, "patches", name, "*.patch")].sort yield recipe env = Hash.new { |hash, key| hash[key] = "#{ENV[key]}" # (ENV[key].dup rescue '') } recipe..flatten! recipe..delete_if { |option| case option.shellsplit.first when /\A(\w+)=(.*)\z/ env[$1] = $2 true else false end } if static_p recipe. += [ "--disable-shared", "--enable-static", ] env['CFLAGS'] = "-fPIC #{env['CFLAGS']}" else recipe. += [ "--enable-shared", "--disable-static", ] end if cross_p recipe. += [ "--target=#{recipe.host}", "--host=#{recipe.host}", ] end if RbConfig::CONFIG['target_cpu'] == 'universal' %w[CFLAGS LDFLAGS].each { |key| unless env[key].shellsplit.include?('-arch') env[key] << ' ' << RbConfig::CONFIG['ARCH_FLAG'] end } end recipe. += env.map { |key, value| "#{key}=#{value}".shellescape } <<-"EOS" ************************************************************************ IMPORTANT NOTICE: Buidling Nokogiri with a packaged version of #{name}-#{version}#{'.' if recipe.patch_files.empty?} EOS unless recipe.patch_files.empty? "with the following patches applied:\n" recipe.patch_files.each { |patch| "\t- %s\n" % File.basename(patch) } end <<-"EOS" Team Nokogiri will keep on doing their best to provide security updates in a timely manner, but if this is a concern for you and want to use the system library instead; abort this installation process and reinstall nokogiri as follows: gem install nokogiri -- --use-system-libraries [--with-xml2-config=/path/to/xml2-config] [--with-xslt-config=/path/to/xslt-config] If you are using Bundler, tell it to use the option: bundle config build.nokogiri --use-system-libraries bundle install EOS <<-"EOS" if name == 'libxml2' Note, however, that nokogiri is not fully compatible with arbitrary versions of libxml2 provided by OS/package vendors. EOS <<-"EOS" ************************************************************************ EOS checkpoint = "#{recipe.target}/#{recipe.name}-#{recipe.version}-#{recipe.host}.installed" unless File.exist?(checkpoint) recipe.cook FileUtils.touch checkpoint end recipe.activate end end |