Permalink
Browse files

split out isolate usage/logic

We'll be using more of Isolate in development.
  • Loading branch information...
1 parent 018a9de commit 9ef6b6f551a34922cfd831e2521495e89afe2f94 Eric Wong committed Oct 4, 2010
Showing with 62 additions and 40 deletions.
  1. +11 −3 GNUmakefile
  2. +0 −26 Rakefile
  3. +0 −9 local.mk.sample
  4. +42 −0 script/isolate_for_tests
  5. +8 −1 t/GNUmakefile
  6. +1 −1 t/test-rails3.sh
View
@@ -24,6 +24,14 @@ endif
RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
+isolate_libs := tmp/isolate/.$(RUBY_ENGINE)-$(RUBY_VERSION).libs
+MYLIBS = $(RUBYLIB):$(shell cat $(isolate_libs) 2>/dev/null || \
+ ($(RUBY) ./script/isolate_for_tests >/dev/null && \
+ cat $(isolate_libs) 2>/dev/null))
+
+echo:
+ @echo $(MYLIBS)
+
# dunno how to implement this as concisely in Ruby, and hell, I love awk
awk_slow := awk '/def test_/{print FILENAME"--"$$2".n"}' 2>/dev/null
@@ -117,14 +125,14 @@ run_test = $(quiet_pre) \
%.n: arg = $(subst .n,,$(subst --, -n ,$@))
%.n: t = $(subst .n,$(log_suffix),$@)
%.n: export PATH := $(test_prefix)/bin:$(PATH)
-%.n: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
+%.n: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(MYLIBS)
%.n: $(test_prefix)/.stamp
$(run_test)
$(T): arg = $@
$(T): t = $(subst .rb,$(log_suffix),$@)
$(T): export PATH := $(test_prefix)/bin:$(PATH)
-$(T): export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
+$(T): export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(MYLIBS)
$(T): $(test_prefix)/.stamp
$(run_test)
@@ -251,7 +259,7 @@ $(T_r).%.r: rv = $(subst .r,,$(subst $(T_r).,,$@))
$(T_r).%.r: extra = ' 'v$(rv)
$(T_r).%.r: arg = $(T_r)
$(T_r).%.r: export PATH := $(test_prefix)/bin:$(PATH)
-$(T_r).%.r: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(RUBYLIB)
+$(T_r).%.r: export RUBYLIB := $(test_prefix):$(test_prefix)/lib:$(MYLIBS)
$(T_r).%.r: export UNICORN_RAILS_TEST_VERSION = $(rv)
$(T_r).%.r: export RAILS_GIT_REPO = $(CURDIR)/$(rails_git)
$(T_r).%.r: $(test_prefix)/.stamp $(rails_git)/info/v2.3.8-stamp
View
@@ -189,29 +189,3 @@ begin
end
rescue LoadError
end
-
-task :isolate do
- require 'isolate'
- ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
- opts = {
- :system => false,
- :path => "tmp/isolate/#{ruby_engine}-#{RUBY_VERSION}",
- :multiruby => false, # we want "1.8.7" instead of "1.8"
- }
- fp = File.open(__FILE__, "rb")
- fp.flock(File::LOCK_EX)
-
- # C extensions aren't binary-compatible across Ruby versions
- pid = fork { Isolate.now!(opts) { gem 'sqlite3-ruby', '1.2.5' } }
- _, status = Process.waitpid2(pid)
- status.success? or abort status.inspect
-
- # pure Ruby gems can be shared across all Rubies
- %w(3.0.0).each do |rails_ver|
- opts[:path] = "tmp/isolate/rails-#{rails_ver}"
- pid = fork { Isolate.now!(opts) { gem 'rails', rails_ver } }
- _, status = Process.waitpid2(pid)
- status.success? or abort status.inspect
- end
- fp.flock(File::LOCK_UN)
-end
View
@@ -37,15 +37,6 @@ else
RUBY := $(prefix)/bin/ruby --disable-gems
endif
-# FIXME: use isolate more
-ifndef RUBYLIB
- gems := rack-1.1.0
- gem_paths := $(addprefix $(HOME)/lib/ruby/gems/1.8/gems/,$(gems))
- sp :=
- sp +=
- export RUBYLIB := $(subst $(sp),:,$(addsuffix /lib,$(gem_paths)))
-endif
-
# pipefail is THE reason to use bash (v3+) or never revisions of ksh93
# SHELL := /bin/bash -e -o pipefail
SHELL := /bin/ksh93 -e -o pipefail
@@ -0,0 +1,42 @@
+#!/usr/bin/env ruby
+# scripts/Makefiles can read and eval the output of this script and
+# use it as RUBYLIB
+require 'rubygems'
+require 'isolate'
+fp = File.open(__FILE__, "rb")
+fp.flock(File::LOCK_EX)
+
+ruby_engine = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
+opts = {
+ :system => false,
+ # we want "ruby-1.8.7" and not "ruby-1.8", so disable :multiruby
+ :multiruby => false,
+ :path => "tmp/isolate/#{ruby_engine}-#{RUBY_VERSION}",
+}
+
+pid = fork do
+ Isolate.now!(opts) do
+ gem 'sqlite3-ruby', '1.2.5'
+ gem 'rack', '1.1.0'
+ end
+end
+_, status = Process.waitpid2(pid)
+status.success? or abort status.inspect
+lib_paths = Dir["#{opts[:path]}/gems/*-*/lib"].map { |x| File.expand_path(x) }
+libs = "tmp/isolate/.#{ruby_engine}-#{RUBY_VERSION}.libs"
+File.open("#{libs}.#$$", "w") { |fp| fp.puts lib_paths.join(':') }
+File.rename("#{libs}.#$$", libs)
+
+# pure Ruby gems can be shared across all Rubies
+%w(3.0.0).each do |rails_ver|
+ opts[:path] = "tmp/isolate/rails-#{rails_ver}"
+ pid = fork do
+ Isolate.now!(opts) do
+ gem 'rails', rails_ver
+ end
+ end
+ _, status = Process.waitpid2(pid)
+ status.success? or abort status.inspect
+ more = Dir["#{opts[:path]}/gems/*-*/lib"].map { |x| File.expand_path(x) }
+ lib_paths.concat(more)
+end
View
@@ -17,6 +17,13 @@ endif
RUBY_ENGINE := $(shell $(RUBY) -e 'puts((RUBY_ENGINE rescue "ruby"))')
export RUBY_ENGINE
+isolate_libs := ../tmp/isolate/.$(RUBY_ENGINE)-$(RUBY_VERSION).libs
+MYLIBS := $(shell cat $(isolate_libs))
+ifeq ($(MY_LIBS),)
+ ignore := $(shell cd .. && $(RUBY) ./script/isolate_for_tests)
+ MYLIBS := $(shell cat $(isolate_libs))
+endif
+
T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)
all:: $(T)
@@ -58,7 +65,7 @@ $(test_prefix)/.stamp:
$(T): export RUBY := $(RUBY)
$(T): export RAKE := $(RAKE)
$(T): export PATH := $(test_prefix)/bin:$(PATH)
-$(T): export RUBYLIB := $(test_prefix)/lib:$(RUBYLIB)
+$(T): export RUBYLIB := $(test_prefix)/lib:$(MYLIBS)
$(T): dep $(test_prefix)/.stamp trash/.gitignore
$(TRACER) $(SHELL) $(SH_TEST_OPTS) $@ $(TEST_OPTS)
View
@@ -13,7 +13,7 @@ rails_gems=../tmp/isolate/rails-$RAILS_VERSION/gems
rails_bin="$rails_gems/rails-$RAILS_VERSION/bin/rails"
if ! test -d "$arch_gems" || ! test -d "$rails_gems" || ! test -x "$rails_bin"
then
- ( cd ../ && $RAKE isolate )
+ ( cd ../ && ./script/isolate_for_tests )
fi
for i in $arch_gems/*-* $rails_gems/*-*

0 comments on commit 9ef6b6f

Please sign in to comment.