Hi,
In <ae6cb1100701302336k7cd76do888818cd7d827f4a@mail.gmail.com>
"Re: Status report for Ruby bindings on Windows" on Tue, 30 Jan 2007 23:36:43 -0800,
"Joe Swatosh" <joe.swatosh@gmail.com> wrote:
> > > * I didn't try your run-test.rb patch for windows. I've been toying
> > > with going a different way with that and I will include a patch to
> > > show what I'm thinking.
> >
> > Thanks! Could you try my new attached patch? The patch is
> > based on yours.
> >
>
> Sorry. We get the correct setup_test_environment method, but the
> setup_svnserve isn't being overridden.
I'm sorry... What about my new patch?
Thanks,
--
kou
Index: subversion/bindings/swig/ruby/test/util.rb
===================================================================
--- subversion/bindings/swig/ruby/test/util.rb (revision 23287)
+++ subversion/bindings/swig/ruby/test/util.rb (working copy)
@@ -9,7 +9,6 @@
end
module SvnTestUtil
-
def setup_basic(need_svnserve=false)
@need_svnserve = need_svnserve
@author = ENV["USER"] || "sample-user"
@@ -106,44 +105,6 @@
@fs = nil
end
- def setup_svnserve
- @svnserve_port = nil
- @repos_svnserve_uri = nil
- @svnserve_ports.each do |port|
- @svnserve_pid = fork {
- STDERR.close
- exec("svnserve",
- "--listen-host", @svnserve_host,
- "--listen-port", port,
- "-d", "--foreground")
- }
- pid, status = Process.waitpid2(@svnserve_pid, Process::WNOHANG)
- if status and status.exited?
- STDERR.puts "port #{port} couldn't be used for svnserve"
- else
- @svnserve_port = port
- @repos_svnserve_uri =
- "svn://#{@svnserve_host}:#{@svnserve_port}#{@full_repos_path}"
- break
- end
- end
- if @svnserve_port.nil?
- msg = "Can't run svnserve because available port "
- msg << "isn't exist in [#{@svnserve_ports.join(', ')}]"
- raise msg
- end
- end
-
- def teardown_svnserve
- if @svnserve_pid
- Process.kill(:TERM, @svnserve_pid)
- begin
- Process.waitpid(@svnserve_pid)
- rescue Errno::ECHILD
- end
- end
- end
-
def setup_wc
teardown_wc
make_context("").checkout(@repos_uri, @wc_path)
@@ -185,26 +146,6 @@
add_pre_revprop_change_hook
end
- def add_pre_revprop_change_hook
- File.open(@repos.pre_revprop_change_hook, "w") do |hook|
- hook.print <<-HOOK
-#!/bin/sh
-REPOS="$1"
-REV="$2"
-USER="$3"
-PROPNAME="$4"
-
-if [ "$PROPNAME" = "#{Svn::Core::PROP_REVISION_LOG}" -a \
- "$USER" = "#{@author}" ]; then
- exit 0
-fi
-
-exit 1
- HOOK
- end
- FileUtils.chmod(0755, @repos.pre_revprop_change_hook)
- end
-
def youngest_rev
@fs.youngest_rev
end
@@ -247,4 +188,82 @@
def windows?
/cygwin|mingw|mswin32|bccwin32/.match(RUBY_PLATFORM)
end
+
+ module Svnserve
+ def setup_svnserve
+ @svnserve_port = nil
+ @repos_svnserve_uri = nil
+ @svnserve_ports.each do |port|
+ @svnserve_pid = fork {
+ STDERR.close
+ exec("svnserve",
+ "--listen-host", @svnserve_host,
+ "--listen-port", port,
+ "-d", "--foreground")
+ }
+ pid, status = Process.waitpid2(@svnserve_pid, Process::WNOHANG)
+ if status and status.exited?
+ STDERR.puts "port #{port} couldn't be used for svnserve"
+ else
+ @svnserve_port = port
+ @repos_svnserve_uri =
+ "svn://#{@svnserve_host}:#{@svnserve_port}#{@full_repos_path}"
+ break
+ end
+ end
+ if @svnserve_port.nil?
+ msg = "Can't run svnserve because available port "
+ msg << "isn't exist in [#{@svnserve_ports.join(', ')}]"
+ raise msg
+ end
+ end
+
+ def teardown_svnserve
+ if @svnserve_pid
+ Process.kill(:TERM, @svnserve_pid)
+ begin
+ Process.waitpid(@svnserve_pid)
+ rescue Errno::ECHILD
+ end
+ end
+ end
+
+ def add_pre_revprop_change_hook
+ File.open(@repos.pre_revprop_change_hook, "w") do |hook|
+ hook.print <<-HOOK
+#!/bin/sh
+REPOS="$1"
+REV="$2"
+USER="$3"
+PROPNAME="$4"
+
+if [ "$PROPNAME" = "#{Svn::Core::PROP_REVISION_LOG}" -a \
+ "$USER" = "#{@author}" ]; then
+ exit 0
+fi
+
+exit 1
+ HOOK
+ end
+ FileUtils.chmod(0755, @repos.pre_revprop_change_hook)
+ end
+ end
+
+ module SetupEnvironment
+ def setup_test_environment(top_dir, base_dir, ext_dir)
+ svnserve_dir = File.join(top_dir, 'subversion', 'svnserve')
+ ENV["PATH"] = "#{svnserve_dir}:#{ENV['PATH']}"
+ FileUtils.ln_sf(File.join(base_dir, ".libs"), ext_dir)
+ end
+ end
+
+ if windows?
+ require 'windows_util'
+ include Windows::Svnserve
+ extend Windows::SetupEnvironment
+ else
+ include Svnserve
+ extend SetupEnvironment
+ end
end
+
Index: subversion/bindings/swig/ruby/test/run-test.rb
===================================================================
--- subversion/bindings/swig/ruby/test/run-test.rb (revision 23287)
+++ subversion/bindings/swig/ruby/test/run-test.rb (working copy)
@@ -5,24 +5,18 @@
test_dir = File.expand_path(File.join(File.dirname(__FILE__)))
base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
-top_dir = File.expand_path(File.join(base_dir, "..", "..", ".."))
+top_dir = File.expand_path(File.join(base_dir, "..", "..", "..", ".."))
ext_dir = File.join(base_dir, ".ext")
ext_svn_dir = File.join(ext_dir, "svn")
+ext_svn_ext_dir = File.join(ext_svn_dir, "ext")
FileUtils.mkdir_p(ext_svn_dir)
at_exit {FileUtils.rm_rf(ext_dir)}
$LOAD_PATH.unshift(test_dir)
require 'util'
-if SvnTestUtil.windows?
- ext_svn_ext_dir = File.join(ext_svn_dir, "ext")
- FileUtils.mkdir_p(ext_svn_ext_dir)
- FileUtils.cp(Dir.glob(File.join(base_dir, "*.dll"), ext_svn_ext_dir))
-else
- ENV["PATH"] = "#{File.join(top_dir, 'subversion', 'svnserve')}:#{ENV['PATH']}"
- FileUtils.ln_sf(File.join(base_dir, ".libs"), File.join(ext_svn_dir, "ext"))
-end
+SvnTestUtil.setup_test_environment(top_dir, base_dir, ext_svn_ext_dir)
$LOAD_PATH.unshift(ext_dir)
$LOAD_PATH.unshift(base_dir)
Index: subversion/bindings/swig/ruby/test/windows_util.rb
===================================================================
--- subversion/bindings/swig/ruby/test/windows_util.rb (revision 0)
+++ subversion/bindings/swig/ruby/test/windows_util.rb (revision 0)
@@ -0,0 +1,124 @@
+require 'fileutils'
+
+module SvnTestUtil
+ module Windows
+ module Svnserve
+ begin
+ require 'win32/service'
+
+ SERVICE_NAME = 'test-svn-server'
+
+ def setup_svnserve
+ @svnserve_port = @svnserve_ports.first
+ @repos_svnserve_uri = "svn://#{@svnserve_host}:#{@svnserve_port}"
+
+ unless Win32::Service.exists?(SERVICE_NAME)
+ # Here we assume that svnserve is going available on the path when
+ # the service starts. So use "svnserve" unqualified. This isn't
+ # normally how I'd recommend installing a windows service, but for
+ # running these tests it is a significantly simplifying assumption.
+ # We can't even test for svnserve being on the path here because
+ # when the service starts, it'll be running as LocalSystem and the
+ # new process may actually have a different path than we have here.
+
+ Win32::Service.new.create_service do |s|
+ s.service_name = SERVICE_NAME
+ root = @full_repos_path.tr('/','\\')
+ s.binary_path_name = "svnserve"
+ s.binary_path_name << " --service"
+ s.binary_path_name << " --root \"#{root}\""
+ s.binary_path_name << " --listen-host #{@svnserve_host}"
+ s.binary_path_name << " --listen-port #{@svnserve_port}"
+ end.close
+ at_exit{Win32::Service.delete(SERVICE_NAME)}
+ end
+
+ Win32::Service.start(SERVICE_NAME)
+ end
+
+ def teardown_svnserve
+ Win32::Service.stop(SERVICE_NAME) rescue Win32::ServiceError
+ end
+ rescue LoadError
+ puts "Testing with file:// instead of svn://."
+ puts "Install win32-service to enable testing with svnserve."
+
+ def setup_svnserve
+ @repos_svnserve_uri = @repos_uri
+ end
+
+ def teardown_svnserve
+ end
+ end
+
+ def add_pre_revprop_change_hook
+ File.open("#{@repos.pre_revprop_change_hook}.cmd", "w") do |hook|
+ hook.print <<-HOOK
+set REPOS=%1
+set REV=%2
+set USER=%3
+set PROPNAME=%4
+if "%PROPNAME%" == "#{Svn::Core::PROP_REVISION_LOG}" if "%USER%" == "#{@author}" exit 0
+exit 1
+ HOOK
+ end
+ end
+ end
+
+ module SetupEnvironment
+ def setup_test_environment(top_dir, base_dir, ext_dir)
+ build_type = "Release"
+
+ FileUtils.mkdir_p(ext_dir)
+
+ svn_version_h = File.join(top_dir, "subversion", "include",
+ "svn_version.h")
+ version = nil
+ File.open(svn_version_h) do |f|
+ f.each do |line|
+ if /^\s*#\s*define\s+SVN_VER_MAJOR\s+(\d+)/ =~ line
+ version = $1
+ break
+ end
+ end
+ end
+
+ # First we copy the ruby swig implementation library into the ext
+ # directory. So we can make it available to the bindings themselves.
+ # We assume that the libraries that libsvn_swig_ruby depends on will
+ # be available on the path.
+ relative_base_dir =
+ base_dir.sub(/^#{Regexp.escape(top_dir + File::SEPARATOR)}/, '')
+ build_base_dir = File.join(top_dir, build_type, relative_base_dir)
+ libsvn_swig_ruby_name = 'libsvn_swig_ruby'
+ dll = File.join(build_base_dir, libsvn_swig_ruby_name,
+ "#{libsvn_swig_ruby_name}-#{version}.dll")
+ FileUtils.cp(dll, ext_dir)
+
+ # Now we copy the actual swig dlls into the ext directory. Since they
+ # depend on libsvn_swig_ruby we have to provide a way for them to find
+ # libsvn_swig_ruby. Since a require will try to load a .rb before a
+ # .dll or .so, we generate an .rb that adds the ext directory to the
+ # path, before requiring the .dll (including the extension).
+ build_conf = File.join(top_dir, "build.conf")
+ File.open(build_conf) do |f|
+ f.each do |line|
+ if /^\[swig_(.+)\]\s*$/ =~ line
+ lib_name = $1
+ FileUtils.cp(File.join(build_base_dir, "#{lib_name}.dll"), ext_dir)
+ File.open(File.join(ext_dir, "#{lib_name}.rb" ), 'w') do |rb|
+ rb.puts(<<-'EOC')
+ext_dir = File.expand_path(File.dirname(__FILE__)).tr('/','\\')
+unless ENV["PATH"].split(';').include?(ext_dir)
+ ENV["PATH"] = "#{ext_dir};#{ENV['PATH']}"
+end
+require File.join(ext_dir, File.basename(__FILE__, '.rb')) + '.dll'
+EOC
+ end
+ end
+ end
+ end
+ end
+ end
+ end
+end
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jan 31 11:25:35 2007