|
| 1 | +require 'yaml' |
| 2 | +require 'pathname' |
| 3 | +require File.expand_path '../paths', __FILE__ |
| 4 | + |
| 5 | +module Libv8Node |
| 6 | + class Location |
| 7 | + def install! |
| 8 | + File.open(Pathname(__FILE__).dirname.join('.location.yml'), "w") do |f| |
| 9 | + f.write self.to_yaml |
| 10 | + end |
| 11 | + return 0 |
| 12 | + end |
| 13 | + |
| 14 | + def self.load! |
| 15 | + File.open(Pathname(__FILE__).dirname.join('.location.yml')) do |f| |
| 16 | + YAML.load f |
| 17 | + end |
| 18 | + end |
| 19 | + |
| 20 | + class Vendor < Location |
| 21 | + def install! |
| 22 | + require File.expand_path '../builder', __FILE__ |
| 23 | + builder = Libv8Node::Builder.new |
| 24 | + exit_status = builder.build_libv8! |
| 25 | + super if exit_status == 0 |
| 26 | + verify_installation! |
| 27 | + return exit_status |
| 28 | + end |
| 29 | + |
| 30 | + def configure(context = MkmfContext.new) |
| 31 | + context.incflags.insert 0, Libv8Node::Paths.include_paths.map{ |p| "-I#{p}" }.join(" ") + " " |
| 32 | + context.ldflags.insert 0, Libv8Node::Paths.object_paths.join(" ") + " " |
| 33 | + end |
| 34 | + |
| 35 | + def verify_installation! |
| 36 | + include_paths = Libv8Node::Paths.include_paths |
| 37 | + unless include_paths.detect { |p| Pathname(p).join('v8.h').exist? } |
| 38 | + fail HeaderNotFound, "Unable to locate 'v8.h' in the libv8 header paths: #{include_paths.inspect}" |
| 39 | + end |
| 40 | + Libv8Node::Paths.object_paths.each do |p| |
| 41 | + fail ArchiveNotFound, p unless File.exist? p |
| 42 | + end |
| 43 | + end |
| 44 | + |
| 45 | + class HeaderNotFound < StandardError; end |
| 46 | + |
| 47 | + class ArchiveNotFound < StandardError |
| 48 | + def initialize(filename) |
| 49 | + super "libv8 did not install properly, expected binary v8 archive '#{filename}'to exist, but it was not found" |
| 50 | + end |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + class System < Location |
| 55 | + def configure(context = MkmfContext.new) |
| 56 | + context.send(:dir_config, 'v8') |
| 57 | + context.send(:find_header, 'v8.h') or fail NotFoundError |
| 58 | + context.send(:find_header, 'libplatform/libplatform.h') or fail NotFoundError |
| 59 | + context.send(:have_library, 'v8') or fail NotFoundError |
| 60 | + end |
| 61 | + |
| 62 | + class NotFoundError < StandardError |
| 63 | + def initialize(*args) |
| 64 | + super(<<-EOS) |
| 65 | +By using --with-system-v8, you have chosen to use the version |
| 66 | +of V8 found on your system and *not* the one that is bundled with |
| 67 | +the libv8 rubygem. |
| 68 | +
|
| 69 | +However, your system version of v8 could not be located. |
| 70 | +
|
| 71 | +Please make sure your system version of v8 that is compatible |
| 72 | +with #{Libv8Node::VERSION} installed. You may need to use the |
| 73 | +--with-v8-dir option if it is installed in a non-standard location |
| 74 | +EOS |
| 75 | + end |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | + class MkmfContext |
| 80 | + def incflags |
| 81 | + $INCFLAGS |
| 82 | + end |
| 83 | + |
| 84 | + def ldflags |
| 85 | + $LDFLAGS |
| 86 | + end |
| 87 | + end |
| 88 | + end |
| 89 | +end |
0 commit comments