7 SERVICE_NAME = 'test-svn-server'
10 def escape_value(value)
11 escaped_value = value.gsub(/"/, '\\"') # "
12 "\"#{escaped_value}\""
16 def service_control(command, args={})
17 args = args.collect do |key, value|
18 "#{key}= #{Svnserve.escape_value(value)}"
20 result = `sc #{command} #{SERVICE_NAME} #{args}`
21 if result.match(/FAILED/)
22 raise "Failed to #{command} #{SERVICE_NAME}: #{args}"
24 /^\s*STATE\s*:\s\d+\s*(.*?)\s*$/ =~ result
28 def grant_everyone_full_access(dir)
29 dir = dir.tr(File::SEPARATOR, File::ALT_SEPARATOR)
30 `cacls #{Svnserve.escape_value(dir)} /T /E /P Everyone:F`
35 service_control("query")
43 "STOPPED" == service_control("query") rescue true
47 @svnserve_port = @svnserve_ports.first
48 @repos_svnserve_uri = "svn://#{@svnserve_host}:#{@svnserve_port}"
49 grant_everyone_full_access(@full_repos_path)
51 @@service_created ||= begin
52 @@service_created = true
53 service_control('stop') unless service_stopped?
54 service_control('delete') if service_exists?
56 svnserve_dir = File.expand_path(File.join(@base_dir, "svnserve"))
57 FileUtils.mkdir_p(svnserve_dir)
59 service_control('stop') unless service_stopped?
60 service_control('delete') if service_exists?
61 FileUtils.rm_rf(svnserve_dir)
64 service_control('stop') unless service_stopped?
65 service_control('delete') if service_exists?
66 FileUtils.rm_rf(svnserve_dir)
68 targets = %w(svnserve.exe libsvn_subr-1.dll libsvn_repos-1.dll
69 libsvn_fs-1.dll libsvn_delta-1.dll
70 libaprutil.dll libapr.dll)
71 ENV["PATH"].split(";").each do |path|
73 targets.each do |target|
74 target_path = "#{path}\\#{target}"
75 if File.exists?(target_path)
76 found_targets << target
77 FileUtils.cp(target_path, svnserve_dir)
80 targets -= found_targets
81 break if targets.empty?
84 raise "can't find libraries to work svnserve: #{targets.join(' ')}"
87 grant_everyone_full_access(svnserve_dir)
89 svnserve_path = File.join(svnserve_dir, "svnserve.exe")
90 svnserve_path = svnserve_path.tr(File::SEPARATOR,
92 svnserve_path = Svnserve.escape_value(svnserve_path)
94 root = @full_repos_path.tr(File::SEPARATOR, File::ALT_SEPARATOR)
96 args = ["--service", "--root", Svnserve.escape_value(root),
97 "--listen-host", @svnserve_host,
98 "--listen-port", @svnserve_port]
99 user = ENV["USERNAME"] || Etc.getlogin
100 service_control('create',
101 [["binPath", "#{svnserve_path} #{args.join(' ')}"],
102 ["DisplayName", SERVICE_NAME],
105 service_control('start')
109 def teardown_svnserve
110 service_control('stop') unless service_stopped?
113 def add_pre_revprop_change_hook
114 File.open("#{@repos.pre_revprop_change_hook}.cmd", "w") do |hook|
120 if "%PROPNAME%" == "#{Svn::Core::PROP_REVISION_LOG}" if "%USER%" == "#{@author}" exit 0
127 module SetupEnvironment
128 def setup_test_environment(top_dir, base_dir, ext_dir)
129 build_type = "Release"
131 FileUtils.mkdir_p(ext_dir)
134 base_dir.sub(/^#{Regexp.escape(top_dir + File::SEPARATOR)}/, '')
135 build_base_dir = File.join(top_dir, build_type, relative_base_dir)
137 dll_dir = File.expand_path(build_base_dir)
138 subversion_dir = File.join(build_base_dir, "..", "..", "..")
139 subversion_dir = File.expand_path(subversion_dir)
142 build_conf = File.join(top_dir, "build.conf")
143 File.open(File.join(ext_dir, "#{util_name}.rb" ), 'w') do |util|
144 setup_dll_wrapper_util(dll_dir, util)
145 add_depended_dll_path_to_dll_wrapper_util(top_dir, build_type, util)
146 add_svn_dll_path_to_dll_wrapper_util(build_conf, subversion_dir, util)
147 setup_dll_wrappers(build_conf, ext_dir, dll_dir, util_name) do |lib|
148 svn_lib_dir = File.join(subversion_dir, "libsvn_#{lib}")
149 util.puts("add_path.call(#{svn_lib_dir.dump})")
152 svnserve_dir = File.join(subversion_dir, "svnserve")
153 util.puts("add_path.call(#{svnserve_dir.dump})")
158 def setup_dll_wrapper_util(dll_dir, util)
159 libsvn_swig_ruby_dll_dir = File.join(dll_dir, "libsvn_swig_ruby")
162 paths = ENV["PATH"].split(';')
163 add_path = Proc.new do |path|
164 win_path = path.tr(File::SEPARATOR, File::ALT_SEPARATOR)
165 unless paths.include?(win_path)
166 ENV["PATH"] = "\#{win_path};\#{ENV['PATH']}"
170 add_path.call(#{dll_dir.dump})
171 add_path.call(#{libsvn_swig_ruby_dll_dir.dump})
175 def add_depended_dll_path_to_dll_wrapper_util(top_dir, build_type, util)
177 gen_make_opts = File.join(top_dir, "gen-make.opts")
178 lines = File.read(gen_make_opts).to_a if File.exists?(gen_make_opts)
181 name, value = line.chomp.split(/\s*=\s*/, 2)
182 config[name] = value if value
187 ["apr-util", build_type],
188 ["apr-iconv", build_type],
189 ["berkeley-db", "bin"],
190 ].each do |lib, sub_dir|
191 lib_dir = config["--with-#{lib}"] || lib
192 dirs = [top_dir, lib_dir, sub_dir].compact
193 dll_dir = File.expand_path(File.join(*dirs))
194 util.puts("add_path.call(#{dll_dir.dump})")
198 def add_svn_dll_path_to_dll_wrapper_util(build_conf, subversion_dir, util)
199 File.open(build_conf) do |f|
201 if /^\[(libsvn_.+)\]\s*$/ =~ line
203 lib_dir = File.join(subversion_dir, lib_name)
204 util.puts("add_path.call(#{lib_dir.dump})")
210 def setup_dll_wrappers(build_conf, ext_dir, dll_dir, util_name)
211 File.open(build_conf) do |f|
213 if /^\[swig_(.+)\]\s*$/ =~ line
215 File.open(File.join(ext_dir, "#{lib_name}.rb" ), 'w') do |rb|
217 require File.join(File.dirname(__FILE__), #{util_name.dump})
218 require File.join(#{dll_dir.dump}, File.basename(__FILE__, '.rb')) + '.so'