summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2010-10-04 23:55:31 +0000
committerEric Wong <normalperson@yhbt.net>2010-10-04 23:56:18 +0000
commit9ef6b6f551a34922cfd831e2521495e89afe2f94 (patch)
treeb041131b4ee0d5969b3b4e959112c660cf6d48dc
parent018a9deff4bd9273e053f369d746256e5b3ac99b (diff)
We'll be using more of Isolate in development.
-rw-r--r--GNUmakefile14
-rw-r--r--Rakefile26
-rw-r--r--local.mk.sample9
-rwxr-xr-xscript/isolate_for_tests42
-rw-r--r--t/GNUmakefile9
-rw-r--r--t/test-rails3.sh2
6 files changed, 62 insertions, 40 deletions
diff --git a/GNUmakefile b/GNUmakefile
index b5fe9fd..0b3238c 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -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
diff --git a/Rakefile b/Rakefile
index c140b89..626eb42 100644
--- a/Rakefile
+++ b/Rakefile
@@ -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
diff --git a/local.mk.sample b/local.mk.sample
index c950d87..25bca5d 100644
--- a/local.mk.sample
+++ b/local.mk.sample
@@ -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
diff --git a/script/isolate_for_tests b/script/isolate_for_tests
new file mode 100755
index 0000000..1919289
--- /dev/null
+++ b/script/isolate_for_tests
@@ -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
diff --git a/t/GNUmakefile b/t/GNUmakefile
index e80c43a..9af9551 100644
--- a/t/GNUmakefile
+++ b/t/GNUmakefile
@@ -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)
 
diff --git a/t/test-rails3.sh b/t/test-rails3.sh
index b398f03..907ef0d 100644
--- a/t/test-rails3.sh
+++ b/t/test-rails3.sh
@@ -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/*-*