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.
@@ -103,7 +103,7 @@ def post_import(&block)
103
103
  end
104
104
 
105
105
  def autoproj_name # :nodoc:
106
- srcdir.gsub /^#{Regexp.quote(Autoproj.root_dir)}\//, ''
106
+ srcdir.gsub(/^#{Regexp.quote(Autoproj.root_dir)}\//, '')
107
107
  end
108
108
 
109
109
  alias __depends_on__ depends_on
@@ -217,28 +217,6 @@ def self.gems_path_suffix
217
217
  relative_path_from(Pathname.new(dot_gem_dir)).to_s
218
218
  end
219
219
 
220
- # The gem install root into which the bundler and autoproj gems, as well
221
- # as autoproj's dependencies, are installed
222
- #
223
- # Note that while this setting is separated from the other gems path,
224
- # the only way to reliably isolate the gems of an autoproj workspace is
225
- # to separate both the autoproj gems and the workspace gems.
226
- #
227
- # The gems are actually installed under a platform and version-specific
228
- # subdirectory (returned by {#gems_path_suffix})
229
- #
230
- # @return [String]
231
- def autoproj_install_path
232
- get('autoproj_install_path')
233
- end
234
-
235
- # The GEM_HOME into which the autoproj gem and its dependencies are installed
236
- #
237
- # @return [String]
238
- def autoproj_gem_home
239
- File.join(autoproj_install_path, self.class.gems_path_suffix)
240
- end
241
-
242
220
  # The gem install root into which the workspace gems are installed
243
221
  #
244
222
  # Note that while this setting is separated from the other gems path,
@@ -251,16 +229,16 @@ def autoproj_gem_home
251
229
  #
252
230
  # @param [Workspace] ws the workspace whose gems are being considered
253
231
  # @return [String]
254
- def gems_install_path(ws)
255
- File.expand_path(get('gems_install_path'), ws.prefix_dir)
232
+ def gems_install_path
233
+ get('gems_install_path')
256
234
  end
257
235
 
258
236
  # The GEM_HOME into which the workspace gems are installed
259
237
  #
260
238
  # @param [Workspace] ws the workspace whose gems are being considered
261
239
  # @return [String]
262
- def gems_gem_home(ws)
263
- File.join(gems_install_path(ws), self.class.gems_path_suffix)
240
+ def gems_gem_home
241
+ File.join(gems_install_path, self.class.gems_path_suffix)
264
242
  end
265
243
 
266
244
  # The full path to the expected ruby executable
@@ -31,12 +31,8 @@ class UnexpectedBinstub < RuntimeError; end
31
31
 
32
32
  def initialize(root_dir)
33
33
  @root_dir = root_dir
34
- if File.file?(autoproj_gemfile_path)
35
- @gemfile = File.read(autoproj_gemfile_path)
36
- else
37
- @gemfile = default_gemfile_contents
38
- end
39
34
  @gem_source = "https://rubygems.org"
35
+ @gemfile = nil
40
36
 
41
37
  @autoproj_options = Array.new
42
38
 
@@ -56,7 +52,6 @@ def initialize(root_dir)
56
52
 
57
53
  default_gem_path = File.join(Dir.home, '.autoproj', 'gems')
58
54
  @gems_install_path = default_gem_path
59
- @autoproj_install_path = default_gem_path
60
55
  end
61
56
 
62
57
  def env_for_child
@@ -126,33 +121,10 @@ def gem_path_suffix
126
121
  relative_path_from(Pathname.new(dot_gem_dir)).to_s
127
122
  end
128
123
 
129
- # The path into which autoproj and its dependencies should be installed
130
- #
131
- # They are installed in a versioned subdirectory of this path, e.g.
132
- # {#gem_path_suffix}. It is always absolute.
133
- #
134
- # @return [String]
135
- attr_reader :autoproj_install_path
136
- # The GEM_HOME into which the autoproj gems should be installed
137
- def autoproj_gem_home; File.join(autoproj_install_path, gem_path_suffix) end
138
- # Sets the place where autoproj should be installed
139
- #
140
- # @param [String] path Sets the path given to bundler, i.e. the
141
- # gems will be installed under the {#gem_path_suffix}
142
- def autoproj_install_path=(path)
143
- @autoproj_install_path = File.expand_path(path)
144
- end
145
- # Install autoproj in Gem's default user dir
146
- def install_autoproj_in_gem_user_dir
147
- @autoproj_install_path = File.join(Gem.user_home, '.gem')
148
- end
149
-
150
124
  # The path into which the workspace's gems should be installed
151
125
  #
152
126
  # They are installed in a versioned subdirectory of this path, e.g.
153
- # {#gem_path_suffix}. Unlike {#autoproj_install_path}, it can be
154
- # relative, in which case it is relative to the workspace's prefix
155
- # directory.
127
+ # {#gem_path_suffix}.
156
128
  #
157
129
  # @return [String]
158
130
  attr_reader :gems_install_path
@@ -180,7 +152,7 @@ def prefer_indep_over_os_packages?; @prefer_indep_over_os_packages end
180
152
  # (see #prefer_index_over_os_packages?)
181
153
  def prefer_indep_over_os_packages=(flag); @prefer_indep_over_os_packages = !!flag end
182
154
 
183
- def guess_gem_program
155
+ def self.guess_gem_program
184
156
  ruby_bin = RbConfig::CONFIG['RUBY_INSTALL_NAME']
185
157
  ruby_bindir = RbConfig::CONFIG['bindir']
186
158
 
@@ -215,25 +187,24 @@ def parse_options(args = ARGV)
215
187
  @local = true
216
188
  end
217
189
  opt.on '--gem-source=URL', String, "use this source for RubyGems instead of rubygems.org" do |url|
218
- self.gem_source = url
190
+ @gem_source = url
219
191
  end
220
- opt.on '--shared-gems[=PATH]', "install gems in a shared location. By default, uses the default RubyGems locations" do |path|
221
- if path
222
- self.autoproj_install_path = path
223
- self.gems_install_path = path
224
- else
225
- self.install_autoproj_in_gem_user_dir
226
- self.install_gems_in_gem_user_dir
227
- end
192
+ opt.on '--gems-path=PATH', "install gems under this path instead of ~/.autoproj/gems" do |path|
193
+ self.gems_install_path = path
228
194
  end
229
- opt.on '--private-gems', "install bundler, autoproj and the workspace gems in dedicated locations within the workspace" do |path|
230
- self.autoproj_install_path = File.join(dot_autoproj, 'gems')
231
- self.gems_install_path = 'gems'
195
+ opt.on '--public-gems', "install gems in the default gem location" do
196
+ self.install_gems_in_gem_user_dir
232
197
  end
233
198
  opt.on '--version=VERSION_CONSTRAINT', String, 'use the provided string as a version constraint for autoproj' do |version|
199
+ if @gemfile
200
+ raise "cannot give both --version and --gemfile"
201
+ end
234
202
  @gemfile = default_gemfile_contents(version)
235
203
  end
236
204
  opt.on '--gemfile=PATH', String, 'use the given Gemfile to install autoproj instead of the default' do |path|
205
+ if @gemfile
206
+ raise "cannot give both --version and --gemfile"
207
+ end
237
208
  @gemfile = File.read(path)
238
209
  end
239
210
  opt.on '--seed-config=PATH', String, 'path to a seed file that should be used to initialize the configuration' do |path|
@@ -264,7 +235,7 @@ def find_bundler(gem_program)
264
235
  out: '/dev/null')
265
236
  return if !result
266
237
 
267
- bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
238
+ bundler_path = File.join(gems_gem_home, 'bin', 'bundler')
268
239
  if File.exist?(bundler_path)
269
240
  bundler_path
270
241
  end
@@ -277,14 +248,14 @@ def install_bundler(gem_program)
277
248
  env_for_child,
278
249
  Gem.ruby, gem_program, 'install', '--env-shebang', '--no-document', '--no-format-executable', '--clear-sources', '--source', gem_source,
279
250
  *local,
280
- "--bindir=#{File.join(autoproj_gem_home, 'bin')}", 'bundler')
251
+ "--bindir=#{File.join(gems_gem_home, 'bin')}", 'bundler')
281
252
 
282
253
  if !result
283
- STDERR.puts "FATAL: failed to install bundler in #{autoproj_gem_home}"
254
+ STDERR.puts "FATAL: failed to install bundler in #{gems_gem_home}"
284
255
  nil
285
256
  end
286
257
 
287
- bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
258
+ bundler_path = File.join(gems_gem_home, 'bin', 'bundler')
288
259
  if File.exist?(bundler_path)
289
260
  bundler_path
290
261
  else
@@ -305,7 +276,7 @@ def install_autoproj(bundler)
305
276
 
306
277
  opts = Array.new
307
278
  opts << '--local' if local?
308
- opts << "--path=#{autoproj_install_path}"
279
+ opts << "--path=#{gems_install_path}"
309
280
  shims_path = File.join(dot_autoproj, 'bin')
310
281
  result = system(clean_env,
311
282
  Gem.ruby, bundler, 'install',
@@ -319,39 +290,69 @@ def install_autoproj(bundler)
319
290
  exit 1
320
291
  end
321
292
  ensure
322
- self.class.clean_binstubs(shims_path, ruby_executable, bundler)
293
+ self.class.rewrite_shims(shims_path, ruby_executable, autoproj_gemfile_path, gems_gem_home)
323
294
  end
324
295
 
325
- def self.clean_binstubs(shim_path, ruby_executable, bundler_path)
326
- %w{bundler bundle rake thor ruby}.each do |bundler_bin|
327
- path = File.join(shim_path, bundler_bin)
328
- if File.file?(path)
329
- FileUtils.rm path
330
- end
296
+ def self.rewrite_shims(shim_path, ruby_executable, autoproj_gemfile_path, gems_gem_home)
297
+ FileUtils.mkdir_p shim_path
298
+ File.open(File.join(shim_path, 'ruby'), 'w') do |io|
299
+ io.puts "#! /bin/sh"
300
+ io.puts "exec #{ruby_executable} \"$@\""
331
301
  end
302
+ FileUtils.chmod 0755, File.join(shim_path, 'ruby')
332
303
 
333
- # Now tune the binstubs to force the usage of the autoproj
334
- # gemfile. Otherwise, they get BUNDLE_GEMFILE from the
335
- # environment by default
336
- Dir.glob(File.join(shim_path, '*')) do |path|
337
- next if !File.file?(path)
338
-
339
- lines = File.readlines(path)
340
- matched = false
341
- filtered = lines.map do |l|
342
- matched ||= (ENV_BUNDLE_GEMFILE_RX === l)
343
- l.gsub(ENV_BUNDLE_GEMFILE_RX, '\\1=')
344
- end
345
- if !matched
346
- raise UnexpectedBinstub, "expected #{path} to contain a line looking like ENV['BUNDLE_GEMFILE'] ||= but could not find one"
347
- end
348
- File.open(path, 'w') do |io|
349
- io.write filtered.join("")
304
+ FileUtils.touch File.join(shim_path, 'bundler')
305
+ FileUtils.touch File.join(shim_path, 'bundle')
306
+ Dir.glob(File.join(shim_path, '*')) do |bin_script|
307
+ next if !File.file?(bin_script)
308
+ bin_name = File.basename(bin_script)
309
+ next if bin_name == 'ruby'
310
+
311
+ bin_shim = File.join(shim_path, bin_name)
312
+ bin_script_lines = File.readlines(bin_script)
313
+ File.open(bin_shim, 'w') do |io|
314
+ if bin_name == 'bundler' || bin_name == 'bundle'
315
+ io.puts shim_bundler(ruby_executable, autoproj_gemfile_path, gems_gem_home)
316
+ else
317
+ load_line = bin_script_lines.grep(/load Gem.bin_path/).first
318
+ io.puts shim_script(ruby_executable, autoproj_gemfile_path, gems_gem_home, load_line)
319
+ end
350
320
  end
321
+ FileUtils.chmod 0755, bin_shim
351
322
  end
323
+ end
352
324
 
353
- ensure
354
- save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
325
+ def self.shim_bundler(ruby_executable, autoproj_gemfile_path, gems_gem_home)
326
+ "#! #{ruby_executable}
327
+
328
+ if defined?(Bundler)
329
+ Bundler.with_clean_env do
330
+ exec($0, *ARGV)
331
+ end
332
+ end
333
+
334
+ ENV.delete('BUNDLE_GEMFILE')
335
+ ENV['GEM_HOME'] = '#{gems_gem_home}'
336
+ ENV.delete('GEM_PATH')
337
+ Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => '']
338
+
339
+ load Gem.bin_path('bundler', 'bundler')"
340
+ end
341
+
342
+ def self.shim_script(ruby_executable, autoproj_gemfile_path, gems_gem_home, load_line)
343
+ "#! #{ruby_executable}
344
+
345
+ if defined?(Bundler)
346
+ Bundler.with_clean_env do
347
+ exec($0, *ARGV)
348
+ end
349
+ end
350
+
351
+ ENV['BUNDLE_GEMFILE'] = '#{autoproj_gemfile_path}'
352
+ require 'rubygems'
353
+ Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => '']
354
+ require 'bundler/setup'
355
+ #{load_line}"
355
356
  end
356
357
 
357
358
  def save_env_sh(*vars)
@@ -382,6 +383,15 @@ def save_env_sh(*vars)
382
383
  end
383
384
 
384
385
  def save_gemfile
386
+ gemfile =
387
+ if @gemfile
388
+ @gemfile
389
+ elsif File.file?(autoproj_gemfile_path)
390
+ File.read(autoproj_gemfile_path)
391
+ else
392
+ default_gemfile_contents
393
+ end
394
+
385
395
  FileUtils.mkdir_p File.dirname(autoproj_gemfile_path)
386
396
  File.open(autoproj_gemfile_path, 'w') do |io|
387
397
  io.write gemfile
@@ -424,46 +434,32 @@ def gem_bindir
424
434
  end
425
435
  end
426
436
 
427
- def self.save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
428
- FileUtils.mkdir_p shim_path
429
- bundler_rubylib = File.expand_path(File.join('..', '..', 'lib'), bundler_path)
430
- File.open(File.join(shim_path, 'bundler'), 'w') do |io|
431
- io.puts "#! /bin/sh"
432
- io.puts "exec #{ruby_executable} #{bundler_path} \"$@\""
433
- end
434
- FileUtils.chmod 0755, File.join(shim_path, 'bundler')
435
- File.open(File.join(shim_path, 'ruby'), 'w') do |io|
436
- io.puts "#! /bin/sh"
437
- io.puts "exec #{ruby_executable} \"$@\""
438
- end
439
- FileUtils.chmod 0755, File.join(shim_path, 'ruby')
440
- end
441
-
442
437
  def install
443
438
  if ENV['BUNDLER_GEMFILE']
444
439
  raise "cannot run autoproj_install or autoproj_bootstrap while under a 'bundler exec' subcommand or having loaded an env.sh. Open a new console and try again"
445
440
  end
446
441
 
447
- gem_program = guess_gem_program
442
+ gem_program = self.class.guess_gem_program
448
443
  puts "Detected 'gem' to be #{gem_program}"
449
- env['GEM_HOME'] = [autoproj_gem_home]
444
+ env['GEM_HOME'] = [gems_gem_home]
450
445
 
451
446
  if bundler = find_bundler(gem_program)
452
447
  puts "Detected bundler at #{bundler}"
453
448
  else
454
- puts "Installing bundler in #{autoproj_gem_home}"
449
+ puts "Installing bundler in #{gems_gem_home}"
455
450
  if !(bundler = install_bundler(gem_program))
456
451
  exit 1
457
452
  end
458
453
  end
459
- self.class.save_ruby_and_bundler_shims(
454
+ self.class.rewrite_shims(
460
455
  File.join(dot_autoproj, 'bin'),
461
456
  ruby_executable,
462
- bundler)
457
+ autoproj_gemfile_path,
458
+ gems_gem_home)
463
459
  env['PATH'].unshift File.join(dot_autoproj, 'bin')
464
460
  save_gemfile
465
461
 
466
- puts "Installing autoproj in #{autoproj_gem_home}"
462
+ puts "Installing autoproj in #{gems_gem_home}"
467
463
  install_autoproj(bundler)
468
464
  end
469
465
 
@@ -490,13 +486,12 @@ def load_config
490
486
  end
491
487
 
492
488
  @config = config
493
- %w{autoproj_install_path gems_install_path prefer_indep_over_os_packages}.each do |flag|
489
+ %w{gems_install_path prefer_indep_over_os_packages}.each do |flag|
494
490
  instance_variable_set "@#{flag}", config.fetch(flag, false)
495
491
  end
496
492
  end
497
493
 
498
494
  def save_config
499
- config['autoproj_install_path'] = autoproj_install_path
500
495
  config['gems_install_path'] = gems_install_path
501
496
  config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
502
497
  File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
@@ -541,13 +536,13 @@ def stage2(*vars)
541
536
  require 'autobuild'
542
537
  puts "saving env.sh and .autoproj/env.sh"
543
538
  save_env_sh(*vars)
544
- if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options)
539
+ if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options, '--debug')
545
540
  STDERR.puts "failed to run autoproj envsh on the newly installed autoproj (#{autoproj_path})"
546
541
  exit 1
547
542
  end
548
543
  # This is really needed on an existing install to install the
549
544
  # gems that were present in the v1 layout
550
- if !system(Gem.ruby, autoproj_path, 'osdeps')
545
+ if !system(Gem.ruby, autoproj_path, 'osdeps', '--debug')
551
546
  STDERR.puts "failed to run autoproj osdeps on the newly installed autoproj (#{autoproj_path})"
552
547
  exit 1
553
548
  end
@@ -38,8 +38,8 @@ def initialize_environment
38
38
 
39
39
  env.add_path 'PATH', File.join(ws.prefix_dir, 'gems', 'bin')
40
40
  env.add_path 'PATH', File.join(ws.dot_autoproj_dir, 'bin')
41
- env.set 'GEM_HOME', config.gems_gem_home(ws)
42
- env.set 'GEM_PATH', config.autoproj_gem_home
41
+ env.set 'GEM_HOME', config.gems_gem_home
42
+ env.clear 'GEM_PATH'
43
43
 
44
44
  gemfile_path = File.join(ws.prefix_dir, 'gems', 'Gemfile')
45
45
  if File.file?(gemfile_path)
@@ -128,34 +128,54 @@ def backup_clean(mapping)
128
128
  end
129
129
  end
130
130
 
131
- def self.run_bundler_install(ws, gemfile, *options, update: true, binstubs: nil)
131
+ def self.run_bundler_install(ws, gemfile, *options, update: true, binstubs: nil, gem_path: ws.config.gems_install_path)
132
132
  if update && File.file?("#{gemfile}.lock")
133
133
  FileUtils.rm "#{gemfile}.lock"
134
134
  end
135
135
 
136
+ options << '--path' << gem_path
136
137
  options << "--shebang" << Gem.ruby
137
138
  if binstubs
138
139
  options << "--binstubs" << binstubs
139
140
  end
140
141
 
142
+ connections = Set.new
143
+ run_bundler(ws, 'install', *options, gemfile: gemfile) do |line|
144
+ case line
145
+ when /Installing (.*)/
146
+ Autobuild.message " bundler: installing #{$1}"
147
+ when /Fetching.*from (.*)/
148
+ host = $1.gsub(/\.+$/, '')
149
+ if !connections.include?(host)
150
+ Autobuild.message " bundler: connected to #{host}"
151
+ connections << host
152
+ end
153
+ end
154
+ end
155
+ end
156
+
157
+ def self.bundle_gem_path(ws, gem_name, gemfile: nil)
158
+ path = String.new
159
+ PackageManagers::BundlerManager.run_bundler(ws, 'show', gem_name, gemfile: gemfile) do |line|
160
+ path << line
161
+ end
162
+ path.chomp
163
+ end
164
+
165
+ def self.run_bundler(ws, *commandline, gemfile: nil)
141
166
  Bundler.with_clean_env do
142
- connections = Set.new
167
+ target_env = Hash[
168
+ 'GEM_HOME' => nil,
169
+ 'GEM_PATH' => nil,
170
+ 'BUNDLE_GEMFILE' => gemfile,
171
+ 'RUBYOPT' => nil,
172
+ 'RUBYLIB' => nil
173
+ ]
143
174
  ws.run 'autoproj', 'osdeps',
144
- Autobuild.tool('bundler'), 'install',
145
- *options,
146
- working_directory: File.dirname(gemfile), env: Hash['BUNDLE_GEMFILE' => nil, 'RUBYOPT' => nil] do |line|
147
-
148
- case line
149
- when /Installing (.*)/
150
- Autobuild.message " bundler: installing #{$1}"
151
- when /Fetching.*from (.*)/
152
- host = $1.gsub(/\.+$/, '')
153
- if !connections.include?(host)
154
- Autobuild.message " bundler: connected to #{host}"
155
- connections << host
156
- end
175
+ Autobuild.tool('bundler'), *commandline,
176
+ working_directory: File.dirname(gemfile), env: target_env do |line|
177
+ yield(line) if block_given?
157
178
  end
158
- end
159
179
  end
160
180
  end
161
181
 
@@ -313,12 +333,13 @@ def discover_bundle_rubylib(silent_errors: false)
313
333
  gemfile = File.join(ws.prefix_dir, 'gems', 'Gemfile')
314
334
  silent_redirect = Hash.new
315
335
  if silent_errors
316
- silent_redirect[:err] = '/dev/null'
336
+ silent_redirect[:err] = :close
317
337
  end
338
+ env = ws.env.resolved_env
318
339
  Tempfile.open 'autoproj-rubylib' do |io|
319
340
  result = Bundler.clean_system(
320
- Hash['BUNDLE_GEMFILE' => gemfile, 'RUBYLIB' => nil],
321
- Autobuild.tool('bundler'), 'exec', Autobuild.tool('ruby'), '-rbundler/setup', '-e', 'puts $LOAD_PATH',
341
+ Hash['GEM_HOME' => env['GEM_HOME'], 'GEM_PATH' => env['GEM_PATH'], 'BUNDLE_GEMFILE' => gemfile, 'RUBYOPT' => nil, 'RUBYLIB' => nil],
342
+ Autobuild.tool('ruby'), '-rbundler/setup', '-e', 'puts $LOAD_PATH',
322
343
  out: io, **silent_redirect)
323
344
 
324
345
  if result