autoproj 2.0.0.rc15 → 2.0.0.rc16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72bfb787ad1c7703f07969b97c019c9fd49dc3ec
4
- data.tar.gz: 830d1225e29863caecdbbdea21b40a80975c61c9
3
+ metadata.gz: 2e8448a1e71d7b3bf6c58254c59380c93e01dae2
4
+ data.tar.gz: 16bc5d6983bea3fc3a7a40b50ef572cfdb0b25db
5
5
  SHA512:
6
- metadata.gz: 2558027c520e214fa512cb70efb99d95bc69c342ff864a16c9a23ff64e75972a085f70d62bd95e6cb08282379e15741cdfc22af70fdcc5a7d1f979a37479b392
7
- data.tar.gz: 77c978c7afe274015b889a868a1514abb24ec515e6a13a9045b4747f9718120a0f18b293064efa3d2064d1dad626ec7ecbd6c750f8e114789b6b61f3dfda05d9
6
+ metadata.gz: 2008f60c6e37b71ac9ac35219f7754e7b1396bcbf324b4b890f8c06dd242a7665fff0c257478bfff6c2d8d7aeaf7e0817cb631b0194779b6c1b8f830dabc59b1
7
+ data.tar.gz: 9b09e7e1a8a9631f452951077ffd249ab2fecf5c701b0b9d014dd26b1a98a4bde52411366944e2bb32bee9faae42294a72b8a47875a4efdde616ab487582660c
@@ -34,6 +34,8 @@ module Autoproj
34
34
  # A set of options that should be passed to autoproj when calling it
35
35
  # in a subprocess
36
36
  attr_reader :autoproj_options
37
+ # The Ruby interpreter we use for this install
38
+ attr_reader :ruby_executable
37
39
 
38
40
  def initialize(root_dir)
39
41
  @root_dir = root_dir
@@ -54,15 +56,16 @@ module Autoproj
54
56
 
55
57
  load_config
56
58
  if config['ruby_executable'] != Gem.ruby
57
- raise "this autoproj installation was already bootstrapped using #{config['ruby_executable']}, but you are currently running under #{Gem.ruby}. Changing the ruby interpreter in a given workspace is not supported"
59
+ raise "this autoproj installation was already bootstrapped using #{config['ruby_executable']}, but you are currently running under #{Gem.ruby}. Changing the ruby interpreter in a given workspace is not supported, you need to do a clean bootstrap"
58
60
  end
59
-
61
+ @ruby_executable = config['ruby_executable']
60
62
  @local = false
61
63
  end
62
64
 
63
65
  def env_for_child
64
- result = env.inject(Hash.new) do |h, (k, v)|
65
- h[k] = (v.join(File::PATH_SEPARATOR) if v && !v.empty?)
66
+ env.inject(Hash.new) do |h, (k, v)|
67
+ h[k] = if v && !v.empty? then v.join(File::PATH_SEPARATOR)
68
+ end
66
69
  h
67
70
  end
68
71
  end
@@ -101,6 +104,8 @@ module Autoproj
101
104
  def autoproj_gemfile_path; File.join(autoproj_install_dir, 'Gemfile') end
102
105
  def autoproj_config_path; File.join(dot_autoproj, 'config.yml') end
103
106
 
107
+ def shim_path; File.join(dot_autoproj, 'bin') end
108
+
104
109
  # Whether we can access the network while installing
105
110
  def local?; !!@local end
106
111
  # (see #local?)
@@ -161,7 +166,7 @@ module Autoproj
161
166
 
162
167
  candidates = ['gem']
163
168
  if ruby_bin =~ /^ruby(.+)$/
164
- candidates << "gem#{$1}"
169
+ candidates.unshift "gem#{$1}"
165
170
  end
166
171
 
167
172
  candidates.each do |gem_name|
@@ -185,10 +190,20 @@ module Autoproj
185
190
 
186
191
  # Parse the provided command line options and returns the non-options
187
192
  def parse_options(args = ARGV)
193
+ default_gem_path = File.join(Dir.home, '.autoproj', 'gems')
194
+ self.private_bundler = default_gem_path
195
+ self.private_gems = default_gem_path
196
+ self.private_autoproj = default_gem_path
197
+
188
198
  options = OptionParser.new do |opt|
189
199
  opt.on '--local', 'do not access the network (may fail)' do
190
200
  @local = true
191
201
  end
202
+ opt.on '--public', "install gems in the default RubyGems locations. Consider using this if you don't have a v1 install anymore" do
203
+ self.private_bundler = false
204
+ self.private_autoproj = false
205
+ self.private_gems = false
206
+ end
192
207
  opt.on '--private-bundler[=PATH]', 'install bundler locally in the workspace' do |path|
193
208
  self.private_bundler = path || true
194
209
  end
@@ -198,7 +213,7 @@ module Autoproj
198
213
  opt.on '--private-gems[=PATH]', 'install gems locally in the prefix directory' do |path|
199
214
  self.private_gems = path || true
200
215
  end
201
- opt.on '--private[=PATH]', 'whether bundler, autoproj and the workspace gems should be installed locally in the workspace' do |path|
216
+ opt.on '--private[=PATH]', "whether bundler, autoproj and the workspace gems should be installed locally in the workspace. This is the default, with a path of #{default_gem_path}" do |path|
202
217
  self.private_bundler = path || true
203
218
  self.private_autoproj = path || true
204
219
  self.private_gems = path || true
@@ -235,15 +250,16 @@ module Autoproj
235
250
 
236
251
  result = system(
237
252
  env_for_child.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_home),
238
- gem_program, 'install', '--no-document', '--no-format-executable',
253
+ Gem.ruby, gem_program, 'install', '--no-document', '--no-format-executable',
239
254
  *local,
240
255
  "--bindir=#{File.join(bundler_gem_home, 'bin')}", 'bundler')
241
256
 
242
- if !result
257
+ if result
258
+ File.join(bundler_gem_home, 'bin', 'bundler')
259
+ else
243
260
  STDERR.puts "FATAL: failed to install bundler in #{dot_autoproj}"
244
- return
261
+ nil
245
262
  end
246
- File.join(bundler_gem_home, 'bin', 'bundler')
247
263
  end
248
264
 
249
265
  def find_bundler
@@ -259,11 +275,11 @@ module Autoproj
259
275
  if !bundler
260
276
  if ENV['PATH'] != clean_path
261
277
  STDERR.puts " it appears that you already have some autoproj-generated env.sh loaded"
262
- STDERR.puts " - if you are running 'autoproj upgrade', please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
263
- STDERR.puts " - if you are running an install, try again in a console where the env.sh is not loaded"
278
+ STDERR.puts " - if you are upgrading a v1 install, please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
279
+ STDERR.puts " - if you are running a fresh install, try again in a console where the env.sh is not loaded"
264
280
  exit 1
265
281
  else
266
- STDERR.puts " the recommended action is to install it manually first by running 'gem install bundler'"
282
+ STDERR.puts " you might want to try and install it manually first by running 'gem install bundler'"
267
283
  STDERR.puts " or call this command again with --private-bundler to have it installed in the workspace"
268
284
  exit 1
269
285
  end
@@ -292,7 +308,7 @@ module Autoproj
292
308
  if private_autoproj?
293
309
  clean_env['GEM_PATH'] = bundler_gem_home
294
310
  clean_env['GEM_HOME'] = nil
295
- opts << "--clean" << "--path=#{autoproj_gem_home}"
311
+ opts << "--path=#{autoproj_gem_home}"
296
312
  end
297
313
  binstubs_path = File.join(autoproj_install_dir, 'bin')
298
314
  result = system(clean_env.merge('GEM_HOME' => autoproj_gem_home),
@@ -311,7 +327,7 @@ module Autoproj
311
327
  end
312
328
 
313
329
  def self.clean_binstubs(binstubs_path)
314
- %w{bundler bundle}.each do |bundler_bin|
330
+ %w{bundler bundle rake thor}.each do |bundler_bin|
315
331
  path = File.join(binstubs_path, bundler_bin)
316
332
  if File.file?(path)
317
333
  FileUtils.rm path
@@ -409,6 +425,20 @@ module Autoproj
409
425
  end
410
426
  end
411
427
 
428
+ def save_ruby_and_bundler_shims(bundler_path)
429
+ FileUtils.mkdir_p shim_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
+
412
442
  def install
413
443
  if private_bundler?
414
444
  puts "Installing bundler in #{bundler_gem_home}"
@@ -420,6 +450,8 @@ module Autoproj
420
450
  else
421
451
  exit 1
422
452
  end
453
+ save_ruby_and_bundler_shims(bundler)
454
+ env['PATH'].unshift shim_path
423
455
  save_gemfile
424
456
  puts "Installing autoproj in #{dot_autoproj}"
425
457
  install_autoproj(bundler)
@@ -470,10 +502,21 @@ module Autoproj
470
502
  Gem.ruby, autoproj_path, *args, *autoproj_options
471
503
  end
472
504
 
505
+ def v1_workspace?
506
+ File.file?(File.join(root_dir, 'autoproj', 'config.yml')) &&
507
+ !File.directory?(File.join(root_dir, '.autoproj'))
508
+ end
509
+
473
510
  def stage1
511
+ if v1_workspace? && File.file?(v1_envsh = File.join(root_dir, 'env.sh'))
512
+ FileUtils.cp v1_envsh, 'env.sh-autoproj-v1'
513
+ end
474
514
  FileUtils.mkdir_p dot_autoproj
475
515
  save_config
476
516
  install
517
+ rescue Exception
518
+ FileUtils.rm_rf dot_autoproj
519
+ raise
477
520
  end
478
521
 
479
522
  def call_stage2
@@ -492,6 +535,11 @@ module Autoproj
492
535
  if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options)
493
536
  exit 1
494
537
  end
538
+ # This is really needed on an existing install to install the
539
+ # gems that were present in the v1 layout
540
+ if !system(Gem.ruby, autoproj_path, 'osdeps')
541
+ exit 1
542
+ end
495
543
  end
496
544
  end
497
545
  end
data/bin/autoproj_install CHANGED
@@ -34,6 +34,8 @@ module Autoproj
34
34
  # A set of options that should be passed to autoproj when calling it
35
35
  # in a subprocess
36
36
  attr_reader :autoproj_options
37
+ # The Ruby interpreter we use for this install
38
+ attr_reader :ruby_executable
37
39
 
38
40
  def initialize(root_dir)
39
41
  @root_dir = root_dir
@@ -54,15 +56,16 @@ module Autoproj
54
56
 
55
57
  load_config
56
58
  if config['ruby_executable'] != Gem.ruby
57
- raise "this autoproj installation was already bootstrapped using #{config['ruby_executable']}, but you are currently running under #{Gem.ruby}. Changing the ruby interpreter in a given workspace is not supported"
59
+ raise "this autoproj installation was already bootstrapped using #{config['ruby_executable']}, but you are currently running under #{Gem.ruby}. Changing the ruby interpreter in a given workspace is not supported, you need to do a clean bootstrap"
58
60
  end
59
-
61
+ @ruby_executable = config['ruby_executable']
60
62
  @local = false
61
63
  end
62
64
 
63
65
  def env_for_child
64
- result = env.inject(Hash.new) do |h, (k, v)|
65
- h[k] = (v.join(File::PATH_SEPARATOR) if v && !v.empty?)
66
+ env.inject(Hash.new) do |h, (k, v)|
67
+ h[k] = if v && !v.empty? then v.join(File::PATH_SEPARATOR)
68
+ end
66
69
  h
67
70
  end
68
71
  end
@@ -101,6 +104,8 @@ module Autoproj
101
104
  def autoproj_gemfile_path; File.join(autoproj_install_dir, 'Gemfile') end
102
105
  def autoproj_config_path; File.join(dot_autoproj, 'config.yml') end
103
106
 
107
+ def shim_path; File.join(dot_autoproj, 'bin') end
108
+
104
109
  # Whether we can access the network while installing
105
110
  def local?; !!@local end
106
111
  # (see #local?)
@@ -161,7 +166,7 @@ module Autoproj
161
166
 
162
167
  candidates = ['gem']
163
168
  if ruby_bin =~ /^ruby(.+)$/
164
- candidates << "gem#{$1}"
169
+ candidates.unshift "gem#{$1}"
165
170
  end
166
171
 
167
172
  candidates.each do |gem_name|
@@ -185,10 +190,20 @@ module Autoproj
185
190
 
186
191
  # Parse the provided command line options and returns the non-options
187
192
  def parse_options(args = ARGV)
193
+ default_gem_path = File.join(Dir.home, '.autoproj', 'gems')
194
+ self.private_bundler = default_gem_path
195
+ self.private_gems = default_gem_path
196
+ self.private_autoproj = default_gem_path
197
+
188
198
  options = OptionParser.new do |opt|
189
199
  opt.on '--local', 'do not access the network (may fail)' do
190
200
  @local = true
191
201
  end
202
+ opt.on '--public', "install gems in the default RubyGems locations. Consider using this if you don't have a v1 install anymore" do
203
+ self.private_bundler = false
204
+ self.private_autoproj = false
205
+ self.private_gems = false
206
+ end
192
207
  opt.on '--private-bundler[=PATH]', 'install bundler locally in the workspace' do |path|
193
208
  self.private_bundler = path || true
194
209
  end
@@ -198,7 +213,7 @@ module Autoproj
198
213
  opt.on '--private-gems[=PATH]', 'install gems locally in the prefix directory' do |path|
199
214
  self.private_gems = path || true
200
215
  end
201
- opt.on '--private[=PATH]', 'whether bundler, autoproj and the workspace gems should be installed locally in the workspace' do |path|
216
+ opt.on '--private[=PATH]', "whether bundler, autoproj and the workspace gems should be installed locally in the workspace. This is the default, with a path of #{default_gem_path}" do |path|
202
217
  self.private_bundler = path || true
203
218
  self.private_autoproj = path || true
204
219
  self.private_gems = path || true
@@ -235,15 +250,16 @@ module Autoproj
235
250
 
236
251
  result = system(
237
252
  env_for_child.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_home),
238
- gem_program, 'install', '--no-document', '--no-format-executable',
253
+ Gem.ruby, gem_program, 'install', '--no-document', '--no-format-executable',
239
254
  *local,
240
255
  "--bindir=#{File.join(bundler_gem_home, 'bin')}", 'bundler')
241
256
 
242
- if !result
257
+ if result
258
+ File.join(bundler_gem_home, 'bin', 'bundler')
259
+ else
243
260
  STDERR.puts "FATAL: failed to install bundler in #{dot_autoproj}"
244
- return
261
+ nil
245
262
  end
246
- File.join(bundler_gem_home, 'bin', 'bundler')
247
263
  end
248
264
 
249
265
  def find_bundler
@@ -259,11 +275,11 @@ module Autoproj
259
275
  if !bundler
260
276
  if ENV['PATH'] != clean_path
261
277
  STDERR.puts " it appears that you already have some autoproj-generated env.sh loaded"
262
- STDERR.puts " - if you are running 'autoproj upgrade', please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
263
- STDERR.puts " - if you are running an install, try again in a console where the env.sh is not loaded"
278
+ STDERR.puts " - if you are upgrading a v1 install, please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
279
+ STDERR.puts " - if you are running a fresh install, try again in a console where the env.sh is not loaded"
264
280
  exit 1
265
281
  else
266
- STDERR.puts " the recommended action is to install it manually first by running 'gem install bundler'"
282
+ STDERR.puts " you might want to try and install it manually first by running 'gem install bundler'"
267
283
  STDERR.puts " or call this command again with --private-bundler to have it installed in the workspace"
268
284
  exit 1
269
285
  end
@@ -292,7 +308,7 @@ module Autoproj
292
308
  if private_autoproj?
293
309
  clean_env['GEM_PATH'] = bundler_gem_home
294
310
  clean_env['GEM_HOME'] = nil
295
- opts << "--clean" << "--path=#{autoproj_gem_home}"
311
+ opts << "--path=#{autoproj_gem_home}"
296
312
  end
297
313
  binstubs_path = File.join(autoproj_install_dir, 'bin')
298
314
  result = system(clean_env.merge('GEM_HOME' => autoproj_gem_home),
@@ -311,7 +327,7 @@ module Autoproj
311
327
  end
312
328
 
313
329
  def self.clean_binstubs(binstubs_path)
314
- %w{bundler bundle}.each do |bundler_bin|
330
+ %w{bundler bundle rake thor}.each do |bundler_bin|
315
331
  path = File.join(binstubs_path, bundler_bin)
316
332
  if File.file?(path)
317
333
  FileUtils.rm path
@@ -409,6 +425,20 @@ module Autoproj
409
425
  end
410
426
  end
411
427
 
428
+ def save_ruby_and_bundler_shims(bundler_path)
429
+ FileUtils.mkdir_p shim_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
+
412
442
  def install
413
443
  if private_bundler?
414
444
  puts "Installing bundler in #{bundler_gem_home}"
@@ -420,6 +450,8 @@ module Autoproj
420
450
  else
421
451
  exit 1
422
452
  end
453
+ save_ruby_and_bundler_shims(bundler)
454
+ env['PATH'].unshift shim_path
423
455
  save_gemfile
424
456
  puts "Installing autoproj in #{dot_autoproj}"
425
457
  install_autoproj(bundler)
@@ -470,10 +502,21 @@ module Autoproj
470
502
  Gem.ruby, autoproj_path, *args, *autoproj_options
471
503
  end
472
504
 
505
+ def v1_workspace?
506
+ File.file?(File.join(root_dir, 'autoproj', 'config.yml')) &&
507
+ !File.directory?(File.join(root_dir, '.autoproj'))
508
+ end
509
+
473
510
  def stage1
511
+ if v1_workspace? && File.file?(v1_envsh = File.join(root_dir, 'env.sh'))
512
+ FileUtils.cp v1_envsh, 'env.sh-autoproj-v1'
513
+ end
474
514
  FileUtils.mkdir_p dot_autoproj
475
515
  save_config
476
516
  install
517
+ rescue Exception
518
+ FileUtils.rm_rf dot_autoproj
519
+ raise
477
520
  end
478
521
 
479
522
  def call_stage2
@@ -492,6 +535,11 @@ module Autoproj
492
535
  if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options)
493
536
  exit 1
494
537
  end
538
+ # This is really needed on an existing install to install the
539
+ # gems that were present in the v1 layout
540
+ if !system(Gem.ruby, autoproj_path, 'osdeps')
541
+ exit 1
542
+ end
495
543
  end
496
544
  end
497
545
  end
@@ -320,24 +320,6 @@ def query(query_string = nil)
320
320
  run_autoproj_cli(:query, :Query, Hash[], *Array(query_string))
321
321
  end
322
322
 
323
- desc 'upgrade', "upgrade autoproj itself, and the workspace layout"
324
- option :local, type: :boolean, default: false,
325
- desc: 'do not access the network (will fail if some gems are missing)'
326
- option :gemfile, type: :string,
327
- desc: 'path to a gemfile that should be used to install autoproj'
328
- def upgrade
329
- require 'autoproj/ops/install'
330
- installer = Autoproj::Ops::Install.new(Dir.pwd)
331
-
332
- if options.has_key?('local')
333
- installer.local = options['local']
334
- end
335
- if options[:gemfile]
336
- installer.gemfile = File.read(options[:gemfile])
337
- end
338
- installer.stage1
339
- end
340
-
341
323
  desc 'install_stage2 ROOT_DIR [ENVVAR=VALUE ...]', 'used by autoproj_install to finalize the installation',
342
324
  hide: true
343
325
  def install_stage2(root_dir, *vars)
@@ -9,9 +9,13 @@ def run(user_selection, options = Hash.new)
9
9
  finalize_setup(user_selection,
10
10
  ignore_non_imported_packages: true)
11
11
 
12
+ options = Kernel.validate_options options,
13
+ update: true,
14
+ shell_helpers: ws.config.shell_helpers?
12
15
  ws.install_os_packages(
13
16
  osdep_packages,
14
17
  install_only: !options[:update])
18
+ ws.export_env_sh(shell_helpers: options[:shell_helpers])
15
19
  end
16
20
  end
17
21
  end
@@ -226,19 +226,32 @@ def private_gems?
226
226
  !!get('private_gems', false)
227
227
  end
228
228
 
229
- def gems_gem_home
229
+ # The path provided to bundler to install the gems
230
+ def gems_bundler_path
230
231
  value = get('private_gems', false)
231
232
  if value.respond_to?(:to_str)
232
- return value
233
+ value
233
234
  elsif value
234
235
  default = File.join(ws.prefix_dir, 'gems')
235
236
  set('private_gems', default)
236
237
  default
237
- else
238
- Gem.user_dir
239
238
  end
240
239
  end
241
240
 
241
+ # The GEM_HOME derived from {#gems_bundler_path}
242
+ #
243
+ # RubyGems and Bundler install gems in a subdirectory specific to the
244
+ # Ruby platform and version. This adds the relevant suffix to
245
+ # {#gems_bundler_path}
246
+ def gems_gem_home
247
+ base_path = gems_bundler_path || File.join(Gem.user_dir, '.gem')
248
+ path_suffix = Pathname.new(Gem.user_dir).
249
+ relative_path_from(Pathname.new(File.join(Gem.user_home, '.gem'))).
250
+ to_s
251
+ File.join(base_path, path_suffix)
252
+ end
253
+
254
+ # The full path to the expected ruby executable
242
255
  def ruby_executable
243
256
  if path = get('ruby_executable', nil)
244
257
  path
@@ -249,6 +262,8 @@ def ruby_executable
249
262
  end
250
263
  end
251
264
 
265
+ # Verify that the Ruby executable that is being used to run autoproj
266
+ # matches the one expected in the configuration
252
267
  def validate_ruby_executable
253
268
  actual = OSPackageResolver.autodetect_ruby_program
254
269
  if has_value_for?('ruby_executable')
@@ -82,7 +82,9 @@ def self.find_v1_workspace_dir(base_dir = default_find_base_dir)
82
82
  path = Pathname.new(base_dir)
83
83
  while !path.root?
84
84
  if (path + "autoproj").exist?
85
- return path.to_s
85
+ if !(path + ".autoproj").exist?
86
+ return path.to_s
87
+ end
86
88
  end
87
89
  path = path.parent
88
90
  end
@@ -24,6 +24,8 @@ class UnexpectedBinstub < RuntimeError; end
24
24
  # A set of options that should be passed to autoproj when calling it
25
25
  # in a subprocess
26
26
  attr_reader :autoproj_options
27
+ # The Ruby interpreter we use for this install
28
+ attr_reader :ruby_executable
27
29
 
28
30
  def initialize(root_dir)
29
31
  @root_dir = root_dir
@@ -44,15 +46,16 @@ def initialize(root_dir)
44
46
 
45
47
  load_config
46
48
  if config['ruby_executable'] != Gem.ruby
47
- raise "this autoproj installation was already bootstrapped using #{config['ruby_executable']}, but you are currently running under #{Gem.ruby}. Changing the ruby interpreter in a given workspace is not supported"
49
+ raise "this autoproj installation was already bootstrapped using #{config['ruby_executable']}, but you are currently running under #{Gem.ruby}. Changing the ruby interpreter in a given workspace is not supported, you need to do a clean bootstrap"
48
50
  end
49
-
51
+ @ruby_executable = config['ruby_executable']
50
52
  @local = false
51
53
  end
52
54
 
53
55
  def env_for_child
54
- result = env.inject(Hash.new) do |h, (k, v)|
55
- h[k] = (v.join(File::PATH_SEPARATOR) if v && !v.empty?)
56
+ env.inject(Hash.new) do |h, (k, v)|
57
+ h[k] = if v && !v.empty? then v.join(File::PATH_SEPARATOR)
58
+ end
56
59
  h
57
60
  end
58
61
  end
@@ -91,6 +94,8 @@ def autoproj_install_dir; File.join(dot_autoproj, 'autoproj') end
91
94
  def autoproj_gemfile_path; File.join(autoproj_install_dir, 'Gemfile') end
92
95
  def autoproj_config_path; File.join(dot_autoproj, 'config.yml') end
93
96
 
97
+ def shim_path; File.join(dot_autoproj, 'bin') end
98
+
94
99
  # Whether we can access the network while installing
95
100
  def local?; !!@local end
96
101
  # (see #local?)
@@ -151,7 +156,7 @@ def guess_gem_program
151
156
 
152
157
  candidates = ['gem']
153
158
  if ruby_bin =~ /^ruby(.+)$/
154
- candidates << "gem#{$1}"
159
+ candidates.unshift "gem#{$1}"
155
160
  end
156
161
 
157
162
  candidates.each do |gem_name|
@@ -175,10 +180,20 @@ def default_gemfile_contents(autoproj_version = ">= 2.0.0.a")
175
180
 
176
181
  # Parse the provided command line options and returns the non-options
177
182
  def parse_options(args = ARGV)
183
+ default_gem_path = File.join(Dir.home, '.autoproj', 'gems')
184
+ self.private_bundler = default_gem_path
185
+ self.private_gems = default_gem_path
186
+ self.private_autoproj = default_gem_path
187
+
178
188
  options = OptionParser.new do |opt|
179
189
  opt.on '--local', 'do not access the network (may fail)' do
180
190
  @local = true
181
191
  end
192
+ opt.on '--public', "install gems in the default RubyGems locations. Consider using this if you don't have a v1 install anymore" do
193
+ self.private_bundler = false
194
+ self.private_autoproj = false
195
+ self.private_gems = false
196
+ end
182
197
  opt.on '--private-bundler[=PATH]', 'install bundler locally in the workspace' do |path|
183
198
  self.private_bundler = path || true
184
199
  end
@@ -188,7 +203,7 @@ def parse_options(args = ARGV)
188
203
  opt.on '--private-gems[=PATH]', 'install gems locally in the prefix directory' do |path|
189
204
  self.private_gems = path || true
190
205
  end
191
- opt.on '--private[=PATH]', 'whether bundler, autoproj and the workspace gems should be installed locally in the workspace' do |path|
206
+ opt.on '--private[=PATH]', "whether bundler, autoproj and the workspace gems should be installed locally in the workspace. This is the default, with a path of #{default_gem_path}" do |path|
192
207
  self.private_bundler = path || true
193
208
  self.private_autoproj = path || true
194
209
  self.private_gems = path || true
@@ -225,15 +240,16 @@ def install_bundler
225
240
 
226
241
  result = system(
227
242
  env_for_child.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_home),
228
- gem_program, 'install', '--no-document', '--no-format-executable',
243
+ Gem.ruby, gem_program, 'install', '--no-document', '--no-format-executable',
229
244
  *local,
230
245
  "--bindir=#{File.join(bundler_gem_home, 'bin')}", 'bundler')
231
246
 
232
- if !result
247
+ if result
248
+ File.join(bundler_gem_home, 'bin', 'bundler')
249
+ else
233
250
  STDERR.puts "FATAL: failed to install bundler in #{dot_autoproj}"
234
- return
251
+ nil
235
252
  end
236
- File.join(bundler_gem_home, 'bin', 'bundler')
237
253
  end
238
254
 
239
255
  def find_bundler
@@ -249,11 +265,11 @@ def find_bundler
249
265
  if !bundler
250
266
  if ENV['PATH'] != clean_path
251
267
  STDERR.puts " it appears that you already have some autoproj-generated env.sh loaded"
252
- STDERR.puts " - if you are running 'autoproj upgrade', please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
253
- STDERR.puts " - if you are running an install, try again in a console where the env.sh is not loaded"
268
+ STDERR.puts " - if you are upgrading a v1 install, please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
269
+ STDERR.puts " - if you are running a fresh install, try again in a console where the env.sh is not loaded"
254
270
  exit 1
255
271
  else
256
- STDERR.puts " the recommended action is to install it manually first by running 'gem install bundler'"
272
+ STDERR.puts " you might want to try and install it manually first by running 'gem install bundler'"
257
273
  STDERR.puts " or call this command again with --private-bundler to have it installed in the workspace"
258
274
  exit 1
259
275
  end
@@ -282,7 +298,7 @@ def install_autoproj(bundler)
282
298
  if private_autoproj?
283
299
  clean_env['GEM_PATH'] = bundler_gem_home
284
300
  clean_env['GEM_HOME'] = nil
285
- opts << "--clean" << "--path=#{autoproj_gem_home}"
301
+ opts << "--path=#{autoproj_gem_home}"
286
302
  end
287
303
  binstubs_path = File.join(autoproj_install_dir, 'bin')
288
304
  result = system(clean_env.merge('GEM_HOME' => autoproj_gem_home),
@@ -301,7 +317,7 @@ def install_autoproj(bundler)
301
317
  end
302
318
 
303
319
  def self.clean_binstubs(binstubs_path)
304
- %w{bundler bundle}.each do |bundler_bin|
320
+ %w{bundler bundle rake thor}.each do |bundler_bin|
305
321
  path = File.join(binstubs_path, bundler_bin)
306
322
  if File.file?(path)
307
323
  FileUtils.rm path
@@ -399,6 +415,20 @@ def gem_bindir
399
415
  end
400
416
  end
401
417
 
418
+ def save_ruby_and_bundler_shims(bundler_path)
419
+ FileUtils.mkdir_p shim_path
420
+ File.open(File.join(shim_path, 'bundler'), 'w') do |io|
421
+ io.puts "#! /bin/sh"
422
+ io.puts "exec #{ruby_executable} #{bundler_path} \"$@\""
423
+ end
424
+ FileUtils.chmod 0755, File.join(shim_path, 'bundler')
425
+ File.open(File.join(shim_path, 'ruby'), 'w') do |io|
426
+ io.puts "#! /bin/sh"
427
+ io.puts "exec #{ruby_executable} \"$@\""
428
+ end
429
+ FileUtils.chmod 0755, File.join(shim_path, 'ruby')
430
+ end
431
+
402
432
  def install
403
433
  if private_bundler?
404
434
  puts "Installing bundler in #{bundler_gem_home}"
@@ -410,6 +440,8 @@ def install
410
440
  else
411
441
  exit 1
412
442
  end
443
+ save_ruby_and_bundler_shims(bundler)
444
+ env['PATH'].unshift shim_path
413
445
  save_gemfile
414
446
  puts "Installing autoproj in #{dot_autoproj}"
415
447
  install_autoproj(bundler)
@@ -460,10 +492,21 @@ def run_autoproj(*args)
460
492
  Gem.ruby, autoproj_path, *args, *autoproj_options
461
493
  end
462
494
 
495
+ def v1_workspace?
496
+ File.file?(File.join(root_dir, 'autoproj', 'config.yml')) &&
497
+ !File.directory?(File.join(root_dir, '.autoproj'))
498
+ end
499
+
463
500
  def stage1
501
+ if v1_workspace? && File.file?(v1_envsh = File.join(root_dir, 'env.sh'))
502
+ FileUtils.cp v1_envsh, 'env.sh-autoproj-v1'
503
+ end
464
504
  FileUtils.mkdir_p dot_autoproj
465
505
  save_config
466
506
  install
507
+ rescue Exception
508
+ FileUtils.rm_rf dot_autoproj
509
+ raise
467
510
  end
468
511
 
469
512
  def call_stage2
@@ -482,6 +525,11 @@ def stage2(*vars)
482
525
  if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options)
483
526
  exit 1
484
527
  end
528
+ # This is really needed on an existing install to install the
529
+ # gems that were present in the v1 layout
530
+ if !system(Gem.ruby, autoproj_path, 'osdeps')
531
+ exit 1
532
+ end
485
533
  end
486
534
  end
487
535
  end
@@ -31,11 +31,11 @@ def initialize_environment
31
31
 
32
32
  config = ws.config
33
33
 
34
- env.add_path 'PATH', File.join(Gem.user_dir, 'bin')
35
34
  env.add_path 'PATH', File.join(ws.prefix_dir, 'gems', 'bin')
36
35
  env.add_path 'PATH', File.join(config.bundler_gem_home, 'bin')
37
36
  env.add_path 'PATH', File.join(ws.dot_autoproj_dir, 'autoproj', 'bin')
38
37
  env.set 'GEM_HOME', config.gems_gem_home
38
+ env.set 'GEM_PATH', config.bundler_gem_home
39
39
 
40
40
  root_dir = File.join(ws.prefix_dir, 'gems')
41
41
  gemfile_path = File.join(root_dir, 'Gemfile')
@@ -46,11 +46,10 @@ def initialize_environment
46
46
  if !config.private_bundler? || !config.private_autoproj? || !config.private_gems?
47
47
  env.set('GEM_PATH', *Gem.default_path)
48
48
  end
49
+ Autobuild.programs['bundler'] = File.join(ws.dot_autoproj_dir, 'bin', 'bundler')
50
+
49
51
  if config.private_bundler?
50
- Autobuild.programs['bundler'] = File.join(config.bundler_gem_home, 'bin', 'bundler')
51
52
  env.add_path 'GEM_PATH', config.bundler_gem_home
52
- else
53
- Autobuild.programs['bundler'] = env.find_in_path('bundler')
54
53
  end
55
54
 
56
55
  env.init_from_env 'RUBYLIB'
@@ -64,6 +63,11 @@ def initialize_environment
64
63
  end
65
64
  # And discover the system's rubylib
66
65
  if system_rubylib = discover_rubylib
66
+ # Do not explicitely add the system rubylib to the
67
+ # environment, the interpreter will do it for us.
68
+ #
69
+ # This allows to use a binstub generated for one of ruby
70
+ # interpreter version on our workspace
67
71
  env.system_env['RUBYLIB'] = []
68
72
  env.original_env['RUBYLIB'] = (original_rubylib - system_rubylib).join(File::PATH_SEPARATOR)
69
73
  end
@@ -160,6 +164,63 @@ def self.run_bundler_install(ws, gemfile, *options, update: true, binstubs: nil)
160
164
  end
161
165
  end
162
166
 
167
+ # Parse the contents of a gemfile into a set of
168
+ def merge_gemfiles(*path, unlock: [])
169
+ gems_remotes = Set.new
170
+ dependencies = Hash.new do |h, k|
171
+ h[k] = Hash.new do |h, k|
172
+ h[k] = Hash.new do |a, b|
173
+ a[b] = Array.new
174
+ end
175
+ end
176
+ end
177
+ path.each do |gemfile|
178
+ bundler_def = Bundler::Dsl.evaluate(gemfile, nil, [])
179
+ gems_remotes |= bundler_def.send(:sources).rubygems_remotes.to_set
180
+ bundler_def.dependencies.each do |d|
181
+ d.groups.each do |group_name|
182
+ if !d.platforms.empty?
183
+ d.platforms.each do |platform_name|
184
+ dependencies[group_name][platform_name][d.name] = d
185
+ end
186
+ else
187
+ dependencies[group_name][''][d.name] = d
188
+ end
189
+ end
190
+ end
191
+ end
192
+
193
+ contents = []
194
+ gems_remotes.each do |g|
195
+ g = g.to_s
196
+ if g.end_with?('/')
197
+ g = g[0..-2]
198
+ end
199
+ contents << "source '#{g.to_s}'"
200
+ end
201
+ dependencies.each do |group_name, by_platform|
202
+ contents << "group :#{group_name} do"
203
+ by_platform.each do |platform_name, deps|
204
+ deps = deps.values.sort_by(&:name)
205
+ if !platform_name.empty?
206
+ contents << " platform :#{platform_name} do"
207
+ platform_indent = " "
208
+ end
209
+ deps.each do |d|
210
+ if d.source
211
+ options = d.source.options.map { |k, v| "#{k}: \"#{v}\"" }
212
+ end
213
+ contents << [" #{platform_indent}gem \"#{d.name}\", \"#{d.requirement}\"", *options].join(", ")
214
+ end
215
+ if !platform_name.empty?
216
+ contents << " end"
217
+ end
218
+ end
219
+ contents << "end"
220
+ end
221
+ contents.join("\n")
222
+ end
223
+
163
224
  def install(gems, filter_uptodate_packages: false, install_only: false)
164
225
  root_dir = File.join(ws.prefix_dir, 'gems')
165
226
  gemfile_path = File.join(root_dir, 'Gemfile')
@@ -188,20 +249,21 @@ def install(gems, filter_uptodate_packages: false, install_only: false)
188
249
  Dir.glob(File.join(ws.overrides_dir, "*.gemfile")) do |gemfile_path|
189
250
  gemfiles << gemfile_path
190
251
  end
191
-
192
- # Generate the gemfile and remove the lockfile
193
- gemfile_lines = gems.map do |name|
194
- name, version = parse_package_entry(name)
195
- "gem \"#{name}\", \"#{version || ">= 0"}\""
196
- end
197
- gemfiles.each do |gemfile|
198
- gemfile_lines.concat(File.readlines(gemfile).map(&:chomp))
252
+ gemfiles << File.join(ws.dot_autoproj_dir, 'autoproj', 'Gemfile')
253
+
254
+ # Save the osdeps entries in a temporary gemfile and finally
255
+ # merge the whole lot of it
256
+ gemfile_contents = Tempfile.open 'autoproj-gemfile' do |io|
257
+ osdeps_gemfile_lines = gems.sort.map do |name|
258
+ name, version = parse_package_entry(name)
259
+ io.puts "gem \"#{name}\", \"#{version || ">= 0"}\""
260
+ end
261
+ io.flush
262
+ gemfiles.unshift io.path
263
+ # The autoproj gemfile needs to be last, we really don't
264
+ # want to mess it up
265
+ merge_gemfiles(*gemfiles)
199
266
  end
200
- gemfile_lines = gemfile_lines.sort.uniq
201
- gemfile_contents = [
202
- "eval_gemfile \"#{File.join(ws.dot_autoproj_dir, 'autoproj', 'Gemfile')}\"",
203
- *gemfile_lines
204
- ].join("\n")
205
267
 
206
268
  FileUtils.mkdir_p root_dir
207
269
  if updated = (!File.exist?(gemfile_path) || File.read(gemfile_path) != gemfile_contents)
@@ -212,7 +274,7 @@ def install(gems, filter_uptodate_packages: false, install_only: false)
212
274
 
213
275
  options = Array.new
214
276
  if ws.config.private_gems?
215
- options << "--path" << ws.config.gems_gem_home
277
+ options << "--path" << ws.config.gems_bundler_path
216
278
  end
217
279
 
218
280
  binstubs_path = File.join(root_dir, 'bin')
@@ -233,7 +295,7 @@ def install(gems, filter_uptodate_packages: false, install_only: false)
233
295
  backup_restore(backups)
234
296
  raise
235
297
  ensure
236
- FileUtils.rm_f File.join(binstubs_path, 'bundler')
298
+ FileUtils.rm_f File.join(binstubs_path, 'bundler') if binstubs_path
237
299
  backup_clean(backups)
238
300
  end
239
301
 
@@ -246,6 +308,7 @@ def discover_rubylib
246
308
  out: io,
247
309
  err: '/dev/null')
248
310
  if result
311
+ io.rewind
249
312
  io.readlines.map { |l| l.chomp }.find_all { |l| !l.empty? }
250
313
  end
251
314
  end
@@ -260,11 +323,12 @@ def discover_bundle_rubylib(silent_errors: false)
260
323
  end
261
324
  Tempfile.open 'autoproj-rubylib' do |io|
262
325
  result = Bundler.clean_system(
263
- Hash['BUNDLE_GEMFILE' => gemfile],
264
- Autobuild.tool('bundler'), 'exec', 'ruby', '-e', 'puts $LOAD_PATH',
326
+ Hash['BUNDLE_GEMFILE' => gemfile, 'RUBYLIB' => nil],
327
+ Autobuild.tool('bundler'), 'exec', Autobuild.tool('ruby'), '-rbundler/setup', '-e', 'puts $LOAD_PATH',
265
328
  out: io, **silent_redirect)
266
329
 
267
330
  if result
331
+ io.rewind
268
332
  io.readlines.map { |l| l.chomp }.find_all { |l| !l.empty? }
269
333
  end
270
334
  end
@@ -1,3 +1,3 @@
1
1
  module Autoproj
2
- VERSION = "2.0.0.rc15"
2
+ VERSION = "2.0.0.rc16"
3
3
  end
@@ -64,10 +64,10 @@ def self.from_dir(dir)
64
64
  def self.from_environment
65
65
  if path = Autoproj.find_workspace_dir
66
66
  from_dir(path)
67
- elsif envvar = ENV['AUTOPROJ_CURRENT_ROOT']
68
- raise NotWorkspace, "AUTOPROJ_CURRENT_ROOT is currently set to #{envvar}, but that is not an Autoproj workspace"
69
67
  elsif Autoproj.find_v1_workspace_dir(dir = Autoproj.default_find_base_dir)
70
68
  raise OutdatedWorkspace, "#{dir} looks like a v1 workspace, run autoproj upgrade before continuing"
69
+ elsif envvar = ENV['AUTOPROJ_CURRENT_ROOT']
70
+ raise NotWorkspace, "AUTOPROJ_CURRENT_ROOT is currently set to #{envvar}, but that is not an Autoproj workspace"
71
71
  else
72
72
  raise NotWorkspace, "not in an Autoproj installation, and no env.sh has been loaded so far"
73
73
  end
@@ -342,9 +342,6 @@ def run(*args, &block)
342
342
  end
343
343
  options_env = options.fetch(:env, Hash.new)
344
344
  options[:env] = env.resolved_env.merge(options_env)
345
- if options_env['BUNDLE_GEMFILE']
346
- raise
347
- end
348
345
  Autobuild::Subprocess.run(*args, options, &block)
349
346
  end
350
347
 
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.rc15
4
+ version: 2.0.0.rc16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Joyeux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-05 00:00:00.000000000 Z
11
+ date: 2016-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: autobuild