autoproj 2.0.0.rc32 → 2.0.0.rc33

Sign up to get free protection for your applications and to get access to all the features.
@@ -43,14 +43,30 @@ module SelfTest
43
43
  attr_reader :ws
44
44
 
45
45
  def setup
46
+ @gem_server_pid = nil
46
47
  @tmpdir = Array.new
47
48
  @ws = Workspace.new('/test/dir')
48
49
  ws.load_config
49
50
  Autoproj.workspace = ws
51
+ FileUtils.rm_rf fixture_gem_home
50
52
 
51
53
  super
52
54
  end
53
55
 
56
+ def teardown
57
+ super
58
+ @tmpdir.each do |dir|
59
+ FileUtils.remove_entry_secure dir
60
+ end
61
+ Autobuild::Package.clear
62
+
63
+ if @gem_server_pid
64
+ stop_gem_server
65
+ end
66
+
67
+ FileUtils.rm_rf fixture_gem_home
68
+ end
69
+
54
70
  def create_bootstrap
55
71
  dir = Dir.mktmpdir
56
72
  @tmpdir << dir
@@ -59,13 +75,147 @@ def create_bootstrap
59
75
  Workspace.new(dir)
60
76
  end
61
77
 
62
- def teardown
63
- super
64
- @tmpdir.each do |dir|
65
- FileUtils.remove_entry_secure dir
78
+ def make_tmpdir
79
+ dir = Dir.mktmpdir
80
+ @tmpdir << dir
81
+ dir
82
+ end
83
+
84
+ def scripts_dir
85
+ File.expand_path(File.join('..', '..', 'test', 'scripts'), __dir__)
86
+ end
87
+
88
+ def find_gem_dir(gem_name)
89
+ Bundler.definition.specs.each do |spec|
90
+ if spec.name == gem_name
91
+ return spec
92
+ end
93
+ end
94
+ nil
95
+ end
96
+
97
+ def autoproj_gemfile_to_local_checkout
98
+ autoproj_dir = find_gem_dir('autoproj').full_gem_path
99
+ autobuild_dir = find_gem_dir('autobuild').full_gem_path
100
+ "source \"http://localhost:8808\"
101
+ gem 'autoproj', path: '#{autoproj_dir}'
102
+ gem 'autobuild', path: '#{autobuild_dir}'
103
+ "
104
+ end
105
+
106
+ def invoke_test_script(name, *arguments,
107
+ dir: nil,
108
+ gemfile_source: nil,
109
+ use_autoproj_from_rubygems: (ENV['USE_AUTOPROJ_FROM_RUBYGEMS'] == '1'),
110
+ seed_config: File.join(scripts_dir, 'seed-config.yml'),
111
+ env: Hash.new, display_output: false, copy_from: nil,
112
+ **system_options)
113
+ package_base_dir = File.expand_path(File.join('..', '..'), File.dirname(__FILE__))
114
+ script = File.expand_path(name, scripts_dir)
115
+ if !File.file?(script)
116
+ raise ArgumentError, "no test script #{name} in #{scripts_dir}"
117
+ end
118
+
119
+ if seed_config
120
+ arguments << '--seed-config' << seed_config
121
+ end
122
+
123
+ dir ||= make_tmpdir
124
+
125
+ if gemfile_source || !use_autoproj_from_rubygems
126
+ gemfile_path = File.join(dir, 'Gemfile-dev')
127
+ File.open(gemfile_path, 'w') do |io|
128
+ io.puts(gemfile_source || autoproj_gemfile_to_local_checkout)
129
+ end
130
+ arguments << "--gemfile" << gemfile_path << "--gem-source" << "http://localhost:8808"
131
+ end
132
+
133
+ if copy_from
134
+ test_workspace = File.expand_path(copy_from, scripts_dir)
135
+ if File.directory?(test_workspace)
136
+ FileUtils.cp_r test_workspace, dir
137
+ dir = File.join(dir, File.basename(test_workspace))
138
+ end
139
+ end
140
+ result = nil
141
+ stdout, stderr = capture_subprocess_io do
142
+ result = Bundler.clean_system(
143
+ Hash['PACKAGE_BASE_DIR' => package_base_dir, 'RUBY' => Gem.ruby].merge(env),
144
+ script, *arguments, in: :close, **Hash[chdir: dir].merge(system_options))
145
+ end
146
+
147
+ if !result
148
+ puts stdout
149
+ puts stderr
150
+ flunk("test script #{name} failed")
151
+ elsif display_output
152
+ puts stdout
153
+ puts stderr
154
+ end
155
+ return dir, stdout, stderr
156
+ end
157
+
158
+ def fixture_gem_home
159
+ File.join(__dir__, '..', '..', 'vendor', 'test_gem_home')
160
+ end
161
+
162
+ def prepare_fixture_gem_home
163
+ FileUtils.rm_rf fixture_gem_home
164
+ bundled_gems_path = File.expand_path(File.join("..", ".."), find_gem_dir('utilrb').full_gem_path)
165
+ FileUtils.cp_r bundled_gems_path, fixture_gem_home
166
+
167
+ vendor = File.join(__dir__, '..', '..', 'vendor')
168
+ cached_bundler_gem = File.join(vendor, "bundler-#{Bundler::VERSION}.gem")
169
+ if !File.file?(cached_bundler_gem)
170
+ FileUtils.mkdir_p vendor
171
+ if !system(Ops::Install.guess_gem_program, 'fetch', '-v', Bundler::VERSION, 'bundler', chdir: vendor)
172
+ raise "cannot download the bundler gem"
173
+ end
174
+ end
175
+
176
+ capture_subprocess_io do
177
+ Bundler.clean_system(Hash['GEM_HOME' => fixture_gem_home, 'GEM_PATH' => nil], Ops::Install.guess_gem_program, 'install', '--no-document', cached_bundler_gem)
178
+ end
179
+ end
180
+
181
+ def start_gem_server(path = fixture_gem_home)
182
+ require 'socket'
183
+ require 'rubygems/server'
184
+ if @gem_server_pid
185
+ raise ArgumentError, "#start_gem_server already called, call stop_gem_server before calling start_gem_server again"
186
+ end
187
+ @gem_server_pid = spawn(Hash['RUBYOPT' => nil], Gem.ruby, Ops::Install.guess_gem_program, 'server', '--quiet', '--dir', path, out: :close, err: :close)
188
+ while true
189
+ begin TCPSocket.new('127.0.0.1', 8808)
190
+ break
191
+ rescue Errno::ECONNREFUSED
192
+ end
66
193
  end
67
- Autobuild::Package.clear
68
194
  end
195
+
196
+ def stop_gem_server
197
+ Process.kill 'INT', @gem_server_pid
198
+ Process.waitpid @gem_server_pid
199
+ @gem_server_pid = nil
200
+ end
201
+
202
+ def find_bundled_gem_path(bundler, gem_name, gemfile)
203
+ out_r, out_w = IO.pipe
204
+ result = Bundler.clean_system(
205
+ bundler, 'show', gem_name,
206
+ out: out_w,
207
+ chdir: File.dirname(gemfile))
208
+ out_w.close
209
+ output = out_r.read.chomp
210
+ assert result, "#{output}"
211
+ output
212
+ end
213
+
214
+ def workspace_env(varname)
215
+ _, stdout, _ = invoke_test_script 'display-env.sh', varname, dir: install_dir
216
+ stdout.chomp
217
+ end
218
+
69
219
  end
70
220
  end
71
221
 
@@ -1,3 +1,3 @@
1
1
  module Autoproj
2
- VERSION = "2.0.0.rc32"
2
+ VERSION = "2.0.0.rc33"
3
3
  end
@@ -309,27 +309,22 @@ def update_autoproj(restart_on_update: true)
309
309
 
310
310
  gemfile = File.join(dot_autoproj_dir, 'Gemfile')
311
311
  binstubs = File.join(dot_autoproj_dir, 'bin')
312
+ old_autoproj_path = PackageManagers::BundlerManager.bundle_gem_path(
313
+ self, 'autoproj', gemfile: gemfile)
312
314
  begin
313
315
  PackageManagers::BundlerManager.run_bundler_install(
314
316
  self, gemfile, binstubs: binstubs)
315
317
  ensure
316
- Ops::Install.clean_binstubs(binstubs, config.ruby_executable, File.join(config.autoproj_gem_home, 'bin', 'bundler'))
318
+ Ops::Install.rewrite_shims(binstubs, config.ruby_executable, gemfile, config.gems_gem_home)
317
319
  end
320
+ new_autoproj_path = PackageManagers::BundlerManager.bundle_gem_path(
321
+ self, 'autoproj', gemfile: gemfile)
318
322
 
319
- # Find out what version of autoproj bundler locked on
320
- autoproj = File.readlines("#{gemfile}.lock").
321
- find_all { |l| l =~ /^\s+autoproj \(\d.*\)$/ }
322
- if autoproj.size == 1
323
- autoproj[0] =~ /^\s+autoproj \((.*)\)$/
324
- installed_version = $1
325
- else
326
- raise "unexpected format for #{gemfile}.lock, cannot determine installed version of autoproj"
327
- end
328
323
 
329
324
  # First things first, see if we need to update ourselves
330
- if (VERSION != installed_version) && restart_on_update
325
+ if (new_autoproj_path != old_autoproj_path) && restart_on_update
331
326
  puts
332
- Autoproj.message "autoproj has been updated to #{installed_version} (from #{VERSION}), restarting"
327
+ Autoproj.message "autoproj has been updated, restarting"
333
328
  puts
334
329
 
335
330
  # We updated autobuild or autoproj themselves ... Restart !
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoproj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc32
4
+ version: 2.0.0.rc33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Joyeux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-22 00:00:00.000000000 Z
11
+ date: 2016-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler