diff --git a/.travis.yml b/.travis.yml index 7eabd06..9b73333 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,3 +7,5 @@ notifications: recipients: - cowboyd@thefrontside.net - bordjukov@gmail.com +before_install: + - sudo apt-get install git-svn \ No newline at end of file diff --git a/Rakefile b/Rakefile index fad8dc1..91c7a0e 100644 --- a/Rakefile +++ b/Rakefile @@ -9,19 +9,15 @@ end require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -V8_Version = Libv8::VERSION.gsub(/\.\d+$/,'') -V8_Source = File.expand_path '../vendor/v8', __FILE__ - require File.expand_path '../ext/libv8/make.rb', __FILE__ +require File.expand_path '../ext/libv8/checkout.rb', __FILE__ include Libv8::Make +include Libv8::Checkout desc "setup the vendored v8 source to correspond to the libv8 gem version" task :checkout do sh "git submodule update --init" - Dir.chdir(V8_Source) do - sh "git fetch" - sh "git checkout #{V8_Version} -f" - end + checkout! end desc "compile v8 via the ruby extension mechanism" @@ -29,7 +25,6 @@ task :compile do sh "ruby ext/libv8/extconf.rb" end - desc "manually invoke the GYP compile. Useful for seeing debug output" task :manual_compile do require File.expand_path '../ext/libv8/arch.rb', __FILE__ @@ -79,6 +74,7 @@ task :clean do sh "rm -rf pkg" sh "git clean -df" sh "cd #{V8_Source} && git checkout -f && git clean -dxf" + sh "cd #{GYP_Source} && git checkout -f && git clean -dxf" end desc "build a binary on heroku (you must have vulcan configured for this)" diff --git a/ext/libv8/builder.rb b/ext/libv8/builder.rb index 13c42d3..13ce6d6 100644 --- a/ext/libv8/builder.rb +++ b/ext/libv8/builder.rb @@ -2,12 +2,14 @@ require 'mkmf' require File.expand_path '../compiler', __FILE__ require File.expand_path '../arch', __FILE__ require File.expand_path '../make', __FILE__ +require File.expand_path '../checkout', __FILE__ module Libv8 class Builder include Libv8::Arch include Libv8::Compiler include Libv8::Make + include Libv8::Checkout def make_flags(*flags) profile = enable_config('debug') ? 'debug' : 'release' @@ -32,7 +34,8 @@ module Libv8 end def build_libv8! - Dir.chdir(File.expand_path '../../../vendor/v8', __FILE__) do + Dir.chdir(V8_Source) do + checkout! setup_python! setup_build_deps! apply_patches! @@ -60,7 +63,7 @@ module Libv8 # This uses the Git mirror of the svn repository used by # "make dependencies", instead of calling that make target `rm -rf build/gyp` - `ln -fs #{File.expand_path '../../../vendor/gyp', __FILE__} build/gyp` + `ln -fs #{GYP_Source} build/gyp` end def apply_patches! diff --git a/ext/libv8/checkout.rb b/ext/libv8/checkout.rb new file mode 100644 index 0000000..56a27df --- /dev/null +++ b/ext/libv8/checkout.rb @@ -0,0 +1,45 @@ +module Libv8 + module Checkout + module_function + + GYP_SVN = 'http://gyp.googlecode.com/svn' + V8_Source = File.expand_path '../../../vendor/v8', __FILE__ + GYP_Source = File.expand_path '../../../vendor/gyp', __FILE__ + + def checkout! + # When compiling from a source gem, it's not a git repository anymore and + # we assume the right code is already checked out. + return unless git?(V8_Source) + + Dir.chdir(V8_Source) do + `git fetch` + `git checkout #{Libv8::VERSION.gsub(/\.\d+$/,'')} -f` + end + + return unless git?(GYP_Source) + + check_git_svn! + + Dir.chdir(GYP_Source) do + mkf = File.readlines(File.join(V8_Source, 'Makefile')) + idx = mkf.index {|l| l =~ /#{GYP_SVN}/} + 1 + rev = /--revision (\d+)/.match(mkf[idx])[1] + `git fetch` + # --git-dir is needed for older versions of git and git-svn + `git --git-dir=../../.git/modules/vendor/gyp/ svn init #{GYP_SVN} -Ttrunk` + `git config --replace-all svn-remote.svn.fetch trunk:refs/remotes/origin/master` + `git checkout $(git --git-dir=../../.git/modules/vendor/gyp/ svn find-rev r#{rev} | tail -n 1) -f` + end + end + + def git?(dir) + File.exists?(File.join(dir, '.git')) + end + + def check_git_svn! + unless system 'git help svn 2>&1 > /dev/null' + fail "git-svn not installed!\nPlease install git-svn." + end + end + end +end diff --git a/vendor/gyp b/vendor/gyp index 878ee28..f7bc250 160000 --- a/vendor/gyp +++ b/vendor/gyp @@ -1 +1 @@ -Subproject commit 878ee285239e5777028c31d6b9d10fbc930ccda2 +Subproject commit f7bc250ccc4d619a1cf238db87e5979f89ff36d7