Skip to content
This repository
tree: bdaf1704fb
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 124 lines (98 sloc) 3.521 kb
1 2 3 4 5 6 7 8 9 10 11 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 42 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 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
require "rubygems"
require "hoe"
require 'erb'
require "./lib/johnson/version.rb"

# what sort of extension are we building?
kind = Config::CONFIG["DLEXT"]

GENERATED_NODE = "ext/spidermonkey/immutable_node.c"

Hoe.new("johnson", Johnson::VERSION) do |p|
  p.rubyforge_name = "johnson"
  p.author = "John Barnette"
  p.email = "jbarnette@rubyforge.org"
  p.summary = "Johnson wraps JavaScript in a loving Ruby embrace."
  p.description = p.paragraphs_of("README.txt", 2..5).join("\n\n")
  p.url = p.paragraphs_of("README.txt", 0).first.split(/\n/)[1..-1]
  p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
  
  p.clean_globs = [
    "lib/johnson/spidermonkey.#{kind}",
    "ext/spidermonkey/Makefile",
    "ext/spidermonkey/*.{o,so,bundle,log}",
    GENERATED_NODE,
    "vendor/spidermonkey/**/*.OBJ"]
    
  p.test_globs = ["test/**/*_test.rb"]
    
  p.spec_extras = { :extensions => ["ext/spidermonkey/extconf.rb"] }
end

namespace :test do
  Rake::TestTask.new("todo") do |t|
    t.test_files = FileList['todo/**/*_test.rb']
    t.verbose = true
  end
end

# make sure the C bits are up-to-date when testing
Rake::Task[:test].prerequisites << :extensions
Rake::Task["test:todo"].prerequisites << :extensions

Rake::Task[:check_manifest].prerequisites << GENERATED_NODE

task :build => :extensions

# gem depends on the native extension actually building
Rake::Task[:gem].prerequisites << :extensions

desc "Our johnson requires extensions."
task :extensions => ["lib/johnson/spidermonkey.#{kind}"]

task :spidermonkey => "vendor/spidermonkey/jsapi.h" do
  if ENV['CROSS']
    Dir.chdir("vendor/spidermonkey") { sh "make -f Makefile.ref OS_CONFIG=#{ENV['CROSS']}" }
  else
    Dir.chdir("vendor/spidermonkey") { sh "make -f Makefile.ref" }
  end
end

task :spidermonkey => "vendor/spidermonkey/config/#{ENV['CROSS']}.mk" if ENV['CROSS']

file "vendor/spidermonkey/config/MINGW32.mk" => "MINGW32.mk" do |t|
  cp t.prerequisites.first, t.name
end

file "vendor/spidermonkey/jsapi.h" do
  # if this file's missing, pull in the submodule
  sh "git submodule init && git submodule update"
end

file "ext/spidermonkey/spidermonkey.#{kind}" =>
  ["ext/spidermonkey/Makefile"] + FileList["ext/spidermonkey/*.{c,h}"].to_a do
  
  Dir.chdir("ext/spidermonkey") { sh "make" }
end

# for testing, we toss the SpiderMonkey extension in lib/johnson
file "lib/johnson/spidermonkey.#{kind}" =>
  "ext/spidermonkey/spidermonkey.#{kind}" do |t|

  cp t.prerequisites.first, t.name
end

file "ext/spidermonkey/Makefile" =>
  [:spidermonkey, GENERATED_NODE, "ext/spidermonkey/extconf.rb"] do
  
  dirs = (ENV['CROSS'] ? [ENV["CROSSLIB"]] : []) + $:
  command = ["ruby"] + dirs.map{|dir| "-I#{File.expand_path dir}"} + ["extconf.rb"]
  Dir.chdir("ext/spidermonkey") { sh *command }
end

def jsops
  ops = []
  File.open('vendor/spidermonkey/jsopcode.tbl', 'rb') { |f|
    f.each_line do |line|
      if line =~ /^OPDEF\((\w+),/
        ops << $1
      end
    end
  }
  ops
end

def tokens
  toks = []
  File.open('vendor/spidermonkey/jsscan.h', 'rb') { |f|
    f.each_line do |line|
      line.scan(/TOK_\w+/).each do |token|
        next if token == 'TOK_ERROR'
        toks << token
      end
    end
  }
  toks.uniq
end

file GENERATED_NODE => ["ext/spidermonkey/immutable_node.c.erb", "vendor/spidermonkey/jsopcode.tbl", "vendor/spidermonkey/jsscan.h"] do |t|
  template = ERB.new(File.open(t.prerequisites.first, 'rb') { |x| x.read })
  File.open(GENERATED_NODE, 'wb') { |f|
    f.write template.result(binding)
  }
end
Something went wrong with that request. Please try again.