autoproj 2.0.0.rc32 → 2.0.0.rc33

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: bb40d3c2a7fa377b8faa4077b9d31ba82be80603
4
- data.tar.gz: 36970528dc5d9a53b2fc8231929819c2d41164bc
3
+ metadata.gz: a1bbd3c8a0a54c4344fc5865309106b3869d16bf
4
+ data.tar.gz: 84ba1ca1161c05483ab51c3239a59c48e8cfcea4
5
5
  SHA512:
6
- metadata.gz: c3b173ea5faf24871a46ab1c7ad91bf6e6e5cc59e3e9e1b78850ca5f03f9e86f0fd4abef4a97ef05e2124d8e56deb12da012ccb7b270ce5b45e2d1abb2d712a3
7
- data.tar.gz: a01958ed2d32916b5219656557215feb66a9a508cc00bed42419cba9fdecdfe13a1360b1c7463ae632b60d604742da9774c41b9e801e9f23d35cc69888bed09c
6
+ metadata.gz: 311b9232ca6168cb33c3a2ee97cdfe793be6d29904f82e1a78cb863c84dce4e5992d8d529b6ac0c9d47d58aec3417902a50053a1490629f99d3b554f79e05278
7
+ data.tar.gz: 671e7b5fceb741dac1ef521f985bf352e83fabe6a9a79030baf9fbb865eba0c0c69e26103a063a47933def4fb71f6f731bf42abb5c89441bc41d06e67308a283
data/.gitignore CHANGED
@@ -7,3 +7,4 @@ pkg/
7
7
  /.bundle
8
8
  /coverage/
9
9
  /.yardoc/
10
+ test/gem_home
@@ -9,6 +9,11 @@ rvm:
9
9
  matrix:
10
10
  allow_failures:
11
11
  - rvm: 'jruby-9.1.2.0'
12
+
13
+ cache: bundler
14
+
15
+ # Some tests expect gems to be present in vendor/bundle
16
+ install: bundler install --path vendor/bundle
12
17
  script:
13
18
  - bundler exec rake
14
19
  - bundler exec rake test
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
+ gem 'pry'
4
+ gem 'pry-byebug'
3
5
  gem 'autobuild', github: 'rock-core/autobuild', branch: 'master'
4
6
  gemspec
@@ -5,7 +5,9 @@ require 'autoproj/version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "autoproj"
8
- s.version = Autoproj::VERSION
8
+ # The envvar is here for the benefit of tests that require to create gems
9
+ # with a "fake" version
10
+ s.version = ENV['__AUTOPROJ_TEST_FAKE_VERSION'] || Autoproj::VERSION
9
11
  s.authors = ["Sylvain Joyeux"]
10
12
  s.email = "sylvain.joyeux@m4x.org"
11
13
  s.summary = "Easy installation and management of sets of software packages"
@@ -41,12 +41,8 @@ module Autoproj
41
41
 
42
42
  def initialize(root_dir)
43
43
  @root_dir = root_dir
44
- if File.file?(autoproj_gemfile_path)
45
- @gemfile = File.read(autoproj_gemfile_path)
46
- else
47
- @gemfile = default_gemfile_contents
48
- end
49
44
  @gem_source = "https://rubygems.org"
45
+ @gemfile = nil
50
46
 
51
47
  @autoproj_options = Array.new
52
48
 
@@ -66,7 +62,6 @@ module Autoproj
66
62
 
67
63
  default_gem_path = File.join(Dir.home, '.autoproj', 'gems')
68
64
  @gems_install_path = default_gem_path
69
- @autoproj_install_path = default_gem_path
70
65
  end
71
66
 
72
67
  def env_for_child
@@ -136,33 +131,10 @@ module Autoproj
136
131
  relative_path_from(Pathname.new(dot_gem_dir)).to_s
137
132
  end
138
133
 
139
- # The path into which autoproj and its dependencies should be installed
140
- #
141
- # They are installed in a versioned subdirectory of this path, e.g.
142
- # {#gem_path_suffix}. It is always absolute.
143
- #
144
- # @return [String]
145
- attr_reader :autoproj_install_path
146
- # The GEM_HOME into which the autoproj gems should be installed
147
- def autoproj_gem_home; File.join(autoproj_install_path, gem_path_suffix) end
148
- # Sets the place where autoproj should be installed
149
- #
150
- # @param [String] path Sets the path given to bundler, i.e. the
151
- # gems will be installed under the {#gem_path_suffix}
152
- def autoproj_install_path=(path)
153
- @autoproj_install_path = File.expand_path(path)
154
- end
155
- # Install autoproj in Gem's default user dir
156
- def install_autoproj_in_gem_user_dir
157
- @autoproj_install_path = File.join(Gem.user_home, '.gem')
158
- end
159
-
160
134
  # The path into which the workspace's gems should be installed
161
135
  #
162
136
  # They are installed in a versioned subdirectory of this path, e.g.
163
- # {#gem_path_suffix}. Unlike {#autoproj_install_path}, it can be
164
- # relative, in which case it is relative to the workspace's prefix
165
- # directory.
137
+ # {#gem_path_suffix}.
166
138
  #
167
139
  # @return [String]
168
140
  attr_reader :gems_install_path
@@ -190,7 +162,7 @@ module Autoproj
190
162
  # (see #prefer_index_over_os_packages?)
191
163
  def prefer_indep_over_os_packages=(flag); @prefer_indep_over_os_packages = !!flag end
192
164
 
193
- def guess_gem_program
165
+ def self.guess_gem_program
194
166
  ruby_bin = RbConfig::CONFIG['RUBY_INSTALL_NAME']
195
167
  ruby_bindir = RbConfig::CONFIG['bindir']
196
168
 
@@ -225,25 +197,24 @@ module Autoproj
225
197
  @local = true
226
198
  end
227
199
  opt.on '--gem-source=URL', String, "use this source for RubyGems instead of rubygems.org" do |url|
228
- self.gem_source = url
200
+ @gem_source = url
229
201
  end
230
- opt.on '--shared-gems[=PATH]', "install gems in a shared location. By default, uses the default RubyGems locations" do |path|
231
- if path
232
- self.autoproj_install_path = path
233
- self.gems_install_path = path
234
- else
235
- self.install_autoproj_in_gem_user_dir
236
- self.install_gems_in_gem_user_dir
237
- end
202
+ opt.on '--gems-path=PATH', "install gems under this path instead of ~/.autoproj/gems" do |path|
203
+ self.gems_install_path = path
238
204
  end
239
- opt.on '--private-gems', "install bundler, autoproj and the workspace gems in dedicated locations within the workspace" do |path|
240
- self.autoproj_install_path = File.join(dot_autoproj, 'gems')
241
- self.gems_install_path = 'gems'
205
+ opt.on '--public-gems', "install gems in the default gem location" do
206
+ self.install_gems_in_gem_user_dir
242
207
  end
243
208
  opt.on '--version=VERSION_CONSTRAINT', String, 'use the provided string as a version constraint for autoproj' do |version|
209
+ if @gemfile
210
+ raise "cannot give both --version and --gemfile"
211
+ end
244
212
  @gemfile = default_gemfile_contents(version)
245
213
  end
246
214
  opt.on '--gemfile=PATH', String, 'use the given Gemfile to install autoproj instead of the default' do |path|
215
+ if @gemfile
216
+ raise "cannot give both --version and --gemfile"
217
+ end
247
218
  @gemfile = File.read(path)
248
219
  end
249
220
  opt.on '--seed-config=PATH', String, 'path to a seed file that should be used to initialize the configuration' do |path|
@@ -274,7 +245,7 @@ module Autoproj
274
245
  out: '/dev/null')
275
246
  return if !result
276
247
 
277
- bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
248
+ bundler_path = File.join(gems_gem_home, 'bin', 'bundler')
278
249
  if File.exist?(bundler_path)
279
250
  bundler_path
280
251
  end
@@ -287,14 +258,14 @@ module Autoproj
287
258
  env_for_child,
288
259
  Gem.ruby, gem_program, 'install', '--env-shebang', '--no-document', '--no-format-executable', '--clear-sources', '--source', gem_source,
289
260
  *local,
290
- "--bindir=#{File.join(autoproj_gem_home, 'bin')}", 'bundler')
261
+ "--bindir=#{File.join(gems_gem_home, 'bin')}", 'bundler')
291
262
 
292
263
  if !result
293
- STDERR.puts "FATAL: failed to install bundler in #{autoproj_gem_home}"
264
+ STDERR.puts "FATAL: failed to install bundler in #{gems_gem_home}"
294
265
  nil
295
266
  end
296
267
 
297
- bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
268
+ bundler_path = File.join(gems_gem_home, 'bin', 'bundler')
298
269
  if File.exist?(bundler_path)
299
270
  bundler_path
300
271
  else
@@ -315,7 +286,7 @@ module Autoproj
315
286
 
316
287
  opts = Array.new
317
288
  opts << '--local' if local?
318
- opts << "--path=#{autoproj_install_path}"
289
+ opts << "--path=#{gems_install_path}"
319
290
  shims_path = File.join(dot_autoproj, 'bin')
320
291
  result = system(clean_env,
321
292
  Gem.ruby, bundler, 'install',
@@ -329,39 +300,69 @@ module Autoproj
329
300
  exit 1
330
301
  end
331
302
  ensure
332
- self.class.clean_binstubs(shims_path, ruby_executable, bundler)
303
+ self.class.rewrite_shims(shims_path, ruby_executable, autoproj_gemfile_path, gems_gem_home)
333
304
  end
334
305
 
335
- def self.clean_binstubs(shim_path, ruby_executable, bundler_path)
336
- %w{bundler bundle rake thor ruby}.each do |bundler_bin|
337
- path = File.join(shim_path, bundler_bin)
338
- if File.file?(path)
339
- FileUtils.rm path
340
- end
306
+ def self.rewrite_shims(shim_path, ruby_executable, autoproj_gemfile_path, gems_gem_home)
307
+ FileUtils.mkdir_p shim_path
308
+ File.open(File.join(shim_path, 'ruby'), 'w') do |io|
309
+ io.puts "#! /bin/sh"
310
+ io.puts "exec #{ruby_executable} \"$@\""
341
311
  end
312
+ FileUtils.chmod 0755, File.join(shim_path, 'ruby')
342
313
 
343
- # Now tune the binstubs to force the usage of the autoproj
344
- # gemfile. Otherwise, they get BUNDLE_GEMFILE from the
345
- # environment by default
346
- Dir.glob(File.join(shim_path, '*')) do |path|
347
- next if !File.file?(path)
348
-
349
- lines = File.readlines(path)
350
- matched = false
351
- filtered = lines.map do |l|
352
- matched ||= (ENV_BUNDLE_GEMFILE_RX === l)
353
- l.gsub(ENV_BUNDLE_GEMFILE_RX, '\\1=')
354
- end
355
- if !matched
356
- raise UnexpectedBinstub, "expected #{path} to contain a line looking like ENV['BUNDLE_GEMFILE'] ||= but could not find one"
357
- end
358
- File.open(path, 'w') do |io|
359
- io.write filtered.join("")
314
+ FileUtils.touch File.join(shim_path, 'bundler')
315
+ FileUtils.touch File.join(shim_path, 'bundle')
316
+ Dir.glob(File.join(shim_path, '*')) do |bin_script|
317
+ next if !File.file?(bin_script)
318
+ bin_name = File.basename(bin_script)
319
+ next if bin_name == 'ruby'
320
+
321
+ bin_shim = File.join(shim_path, bin_name)
322
+ bin_script_lines = File.readlines(bin_script)
323
+ File.open(bin_shim, 'w') do |io|
324
+ if bin_name == 'bundler' || bin_name == 'bundle'
325
+ io.puts shim_bundler(ruby_executable, autoproj_gemfile_path, gems_gem_home)
326
+ else
327
+ load_line = bin_script_lines.grep(/load Gem.bin_path/).first
328
+ io.puts shim_script(ruby_executable, autoproj_gemfile_path, gems_gem_home, load_line)
329
+ end
360
330
  end
331
+ FileUtils.chmod 0755, bin_shim
361
332
  end
333
+ end
362
334
 
363
- ensure
364
- save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
335
+ def self.shim_bundler(ruby_executable, autoproj_gemfile_path, gems_gem_home)
336
+ "#! #{ruby_executable}
337
+
338
+ if defined?(Bundler)
339
+ Bundler.with_clean_env do
340
+ exec($0, *ARGV)
341
+ end
342
+ end
343
+
344
+ ENV.delete('BUNDLE_GEMFILE')
345
+ ENV['GEM_HOME'] = '#{gems_gem_home}'
346
+ ENV.delete('GEM_PATH')
347
+ Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => '']
348
+
349
+ load Gem.bin_path('bundler', 'bundler')"
350
+ end
351
+
352
+ def self.shim_script(ruby_executable, autoproj_gemfile_path, gems_gem_home, load_line)
353
+ "#! #{ruby_executable}
354
+
355
+ if defined?(Bundler)
356
+ Bundler.with_clean_env do
357
+ exec($0, *ARGV)
358
+ end
359
+ end
360
+
361
+ ENV['BUNDLE_GEMFILE'] = '#{autoproj_gemfile_path}'
362
+ require 'rubygems'
363
+ Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => '']
364
+ require 'bundler/setup'
365
+ #{load_line}"
365
366
  end
366
367
 
367
368
  def save_env_sh(*vars)
@@ -392,6 +393,15 @@ module Autoproj
392
393
  end
393
394
 
394
395
  def save_gemfile
396
+ gemfile =
397
+ if @gemfile
398
+ @gemfile
399
+ elsif File.file?(autoproj_gemfile_path)
400
+ File.read(autoproj_gemfile_path)
401
+ else
402
+ default_gemfile_contents
403
+ end
404
+
395
405
  FileUtils.mkdir_p File.dirname(autoproj_gemfile_path)
396
406
  File.open(autoproj_gemfile_path, 'w') do |io|
397
407
  io.write gemfile
@@ -434,46 +444,32 @@ module Autoproj
434
444
  end
435
445
  end
436
446
 
437
- def self.save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
438
- FileUtils.mkdir_p shim_path
439
- bundler_rubylib = File.expand_path(File.join('..', '..', 'lib'), bundler_path)
440
- File.open(File.join(shim_path, 'bundler'), 'w') do |io|
441
- io.puts "#! /bin/sh"
442
- io.puts "exec #{ruby_executable} #{bundler_path} \"$@\""
443
- end
444
- FileUtils.chmod 0755, File.join(shim_path, 'bundler')
445
- File.open(File.join(shim_path, 'ruby'), 'w') do |io|
446
- io.puts "#! /bin/sh"
447
- io.puts "exec #{ruby_executable} \"$@\""
448
- end
449
- FileUtils.chmod 0755, File.join(shim_path, 'ruby')
450
- end
451
-
452
447
  def install
453
448
  if ENV['BUNDLER_GEMFILE']
454
449
  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"
455
450
  end
456
451
 
457
- gem_program = guess_gem_program
452
+ gem_program = self.class.guess_gem_program
458
453
  puts "Detected 'gem' to be #{gem_program}"
459
- env['GEM_HOME'] = [autoproj_gem_home]
454
+ env['GEM_HOME'] = [gems_gem_home]
460
455
 
461
456
  if bundler = find_bundler(gem_program)
462
457
  puts "Detected bundler at #{bundler}"
463
458
  else
464
- puts "Installing bundler in #{autoproj_gem_home}"
459
+ puts "Installing bundler in #{gems_gem_home}"
465
460
  if !(bundler = install_bundler(gem_program))
466
461
  exit 1
467
462
  end
468
463
  end
469
- self.class.save_ruby_and_bundler_shims(
464
+ self.class.rewrite_shims(
470
465
  File.join(dot_autoproj, 'bin'),
471
466
  ruby_executable,
472
- bundler)
467
+ autoproj_gemfile_path,
468
+ gems_gem_home)
473
469
  env['PATH'].unshift File.join(dot_autoproj, 'bin')
474
470
  save_gemfile
475
471
 
476
- puts "Installing autoproj in #{autoproj_gem_home}"
472
+ puts "Installing autoproj in #{gems_gem_home}"
477
473
  install_autoproj(bundler)
478
474
  end
479
475
 
@@ -500,13 +496,12 @@ module Autoproj
500
496
  end
501
497
 
502
498
  @config = config
503
- %w{autoproj_install_path gems_install_path prefer_indep_over_os_packages}.each do |flag|
499
+ %w{gems_install_path prefer_indep_over_os_packages}.each do |flag|
504
500
  instance_variable_set "@#{flag}", config.fetch(flag, false)
505
501
  end
506
502
  end
507
503
 
508
504
  def save_config
509
- config['autoproj_install_path'] = autoproj_install_path
510
505
  config['gems_install_path'] = gems_install_path
511
506
  config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
512
507
  File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
@@ -551,13 +546,13 @@ module Autoproj
551
546
  require 'autobuild'
552
547
  puts "saving env.sh and .autoproj/env.sh"
553
548
  save_env_sh(*vars)
554
- if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options)
549
+ if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options, '--debug')
555
550
  STDERR.puts "failed to run autoproj envsh on the newly installed autoproj (#{autoproj_path})"
556
551
  exit 1
557
552
  end
558
553
  # This is really needed on an existing install to install the
559
554
  # gems that were present in the v1 layout
560
- if !system(Gem.ruby, autoproj_path, 'osdeps')
555
+ if !system(Gem.ruby, autoproj_path, 'osdeps', '--debug')
561
556
  STDERR.puts "failed to run autoproj osdeps on the newly installed autoproj (#{autoproj_path})"
562
557
  exit 1
563
558
  end
@@ -41,12 +41,8 @@ module Autoproj
41
41
 
42
42
  def initialize(root_dir)
43
43
  @root_dir = root_dir
44
- if File.file?(autoproj_gemfile_path)
45
- @gemfile = File.read(autoproj_gemfile_path)
46
- else
47
- @gemfile = default_gemfile_contents
48
- end
49
44
  @gem_source = "https://rubygems.org"
45
+ @gemfile = nil
50
46
 
51
47
  @autoproj_options = Array.new
52
48
 
@@ -66,7 +62,6 @@ module Autoproj
66
62
 
67
63
  default_gem_path = File.join(Dir.home, '.autoproj', 'gems')
68
64
  @gems_install_path = default_gem_path
69
- @autoproj_install_path = default_gem_path
70
65
  end
71
66
 
72
67
  def env_for_child
@@ -136,33 +131,10 @@ module Autoproj
136
131
  relative_path_from(Pathname.new(dot_gem_dir)).to_s
137
132
  end
138
133
 
139
- # The path into which autoproj and its dependencies should be installed
140
- #
141
- # They are installed in a versioned subdirectory of this path, e.g.
142
- # {#gem_path_suffix}. It is always absolute.
143
- #
144
- # @return [String]
145
- attr_reader :autoproj_install_path
146
- # The GEM_HOME into which the autoproj gems should be installed
147
- def autoproj_gem_home; File.join(autoproj_install_path, gem_path_suffix) end
148
- # Sets the place where autoproj should be installed
149
- #
150
- # @param [String] path Sets the path given to bundler, i.e. the
151
- # gems will be installed under the {#gem_path_suffix}
152
- def autoproj_install_path=(path)
153
- @autoproj_install_path = File.expand_path(path)
154
- end
155
- # Install autoproj in Gem's default user dir
156
- def install_autoproj_in_gem_user_dir
157
- @autoproj_install_path = File.join(Gem.user_home, '.gem')
158
- end
159
-
160
134
  # The path into which the workspace's gems should be installed
161
135
  #
162
136
  # They are installed in a versioned subdirectory of this path, e.g.
163
- # {#gem_path_suffix}. Unlike {#autoproj_install_path}, it can be
164
- # relative, in which case it is relative to the workspace's prefix
165
- # directory.
137
+ # {#gem_path_suffix}.
166
138
  #
167
139
  # @return [String]
168
140
  attr_reader :gems_install_path
@@ -190,7 +162,7 @@ module Autoproj
190
162
  # (see #prefer_index_over_os_packages?)
191
163
  def prefer_indep_over_os_packages=(flag); @prefer_indep_over_os_packages = !!flag end
192
164
 
193
- def guess_gem_program
165
+ def self.guess_gem_program
194
166
  ruby_bin = RbConfig::CONFIG['RUBY_INSTALL_NAME']
195
167
  ruby_bindir = RbConfig::CONFIG['bindir']
196
168
 
@@ -225,25 +197,24 @@ module Autoproj
225
197
  @local = true
226
198
  end
227
199
  opt.on '--gem-source=URL', String, "use this source for RubyGems instead of rubygems.org" do |url|
228
- self.gem_source = url
200
+ @gem_source = url
229
201
  end
230
- opt.on '--shared-gems[=PATH]', "install gems in a shared location. By default, uses the default RubyGems locations" do |path|
231
- if path
232
- self.autoproj_install_path = path
233
- self.gems_install_path = path
234
- else
235
- self.install_autoproj_in_gem_user_dir
236
- self.install_gems_in_gem_user_dir
237
- end
202
+ opt.on '--gems-path=PATH', "install gems under this path instead of ~/.autoproj/gems" do |path|
203
+ self.gems_install_path = path
238
204
  end
239
- opt.on '--private-gems', "install bundler, autoproj and the workspace gems in dedicated locations within the workspace" do |path|
240
- self.autoproj_install_path = File.join(dot_autoproj, 'gems')
241
- self.gems_install_path = 'gems'
205
+ opt.on '--public-gems', "install gems in the default gem location" do
206
+ self.install_gems_in_gem_user_dir
242
207
  end
243
208
  opt.on '--version=VERSION_CONSTRAINT', String, 'use the provided string as a version constraint for autoproj' do |version|
209
+ if @gemfile
210
+ raise "cannot give both --version and --gemfile"
211
+ end
244
212
  @gemfile = default_gemfile_contents(version)
245
213
  end
246
214
  opt.on '--gemfile=PATH', String, 'use the given Gemfile to install autoproj instead of the default' do |path|
215
+ if @gemfile
216
+ raise "cannot give both --version and --gemfile"
217
+ end
247
218
  @gemfile = File.read(path)
248
219
  end
249
220
  opt.on '--seed-config=PATH', String, 'path to a seed file that should be used to initialize the configuration' do |path|
@@ -274,7 +245,7 @@ module Autoproj
274
245
  out: '/dev/null')
275
246
  return if !result
276
247
 
277
- bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
248
+ bundler_path = File.join(gems_gem_home, 'bin', 'bundler')
278
249
  if File.exist?(bundler_path)
279
250
  bundler_path
280
251
  end
@@ -287,14 +258,14 @@ module Autoproj
287
258
  env_for_child,
288
259
  Gem.ruby, gem_program, 'install', '--env-shebang', '--no-document', '--no-format-executable', '--clear-sources', '--source', gem_source,
289
260
  *local,
290
- "--bindir=#{File.join(autoproj_gem_home, 'bin')}", 'bundler')
261
+ "--bindir=#{File.join(gems_gem_home, 'bin')}", 'bundler')
291
262
 
292
263
  if !result
293
- STDERR.puts "FATAL: failed to install bundler in #{autoproj_gem_home}"
264
+ STDERR.puts "FATAL: failed to install bundler in #{gems_gem_home}"
294
265
  nil
295
266
  end
296
267
 
297
- bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
268
+ bundler_path = File.join(gems_gem_home, 'bin', 'bundler')
298
269
  if File.exist?(bundler_path)
299
270
  bundler_path
300
271
  else
@@ -315,7 +286,7 @@ module Autoproj
315
286
 
316
287
  opts = Array.new
317
288
  opts << '--local' if local?
318
- opts << "--path=#{autoproj_install_path}"
289
+ opts << "--path=#{gems_install_path}"
319
290
  shims_path = File.join(dot_autoproj, 'bin')
320
291
  result = system(clean_env,
321
292
  Gem.ruby, bundler, 'install',
@@ -329,39 +300,69 @@ module Autoproj
329
300
  exit 1
330
301
  end
331
302
  ensure
332
- self.class.clean_binstubs(shims_path, ruby_executable, bundler)
303
+ self.class.rewrite_shims(shims_path, ruby_executable, autoproj_gemfile_path, gems_gem_home)
333
304
  end
334
305
 
335
- def self.clean_binstubs(shim_path, ruby_executable, bundler_path)
336
- %w{bundler bundle rake thor ruby}.each do |bundler_bin|
337
- path = File.join(shim_path, bundler_bin)
338
- if File.file?(path)
339
- FileUtils.rm path
340
- end
306
+ def self.rewrite_shims(shim_path, ruby_executable, autoproj_gemfile_path, gems_gem_home)
307
+ FileUtils.mkdir_p shim_path
308
+ File.open(File.join(shim_path, 'ruby'), 'w') do |io|
309
+ io.puts "#! /bin/sh"
310
+ io.puts "exec #{ruby_executable} \"$@\""
341
311
  end
312
+ FileUtils.chmod 0755, File.join(shim_path, 'ruby')
342
313
 
343
- # Now tune the binstubs to force the usage of the autoproj
344
- # gemfile. Otherwise, they get BUNDLE_GEMFILE from the
345
- # environment by default
346
- Dir.glob(File.join(shim_path, '*')) do |path|
347
- next if !File.file?(path)
348
-
349
- lines = File.readlines(path)
350
- matched = false
351
- filtered = lines.map do |l|
352
- matched ||= (ENV_BUNDLE_GEMFILE_RX === l)
353
- l.gsub(ENV_BUNDLE_GEMFILE_RX, '\\1=')
354
- end
355
- if !matched
356
- raise UnexpectedBinstub, "expected #{path} to contain a line looking like ENV['BUNDLE_GEMFILE'] ||= but could not find one"
357
- end
358
- File.open(path, 'w') do |io|
359
- io.write filtered.join("")
314
+ FileUtils.touch File.join(shim_path, 'bundler')
315
+ FileUtils.touch File.join(shim_path, 'bundle')
316
+ Dir.glob(File.join(shim_path, '*')) do |bin_script|
317
+ next if !File.file?(bin_script)
318
+ bin_name = File.basename(bin_script)
319
+ next if bin_name == 'ruby'
320
+
321
+ bin_shim = File.join(shim_path, bin_name)
322
+ bin_script_lines = File.readlines(bin_script)
323
+ File.open(bin_shim, 'w') do |io|
324
+ if bin_name == 'bundler' || bin_name == 'bundle'
325
+ io.puts shim_bundler(ruby_executable, autoproj_gemfile_path, gems_gem_home)
326
+ else
327
+ load_line = bin_script_lines.grep(/load Gem.bin_path/).first
328
+ io.puts shim_script(ruby_executable, autoproj_gemfile_path, gems_gem_home, load_line)
329
+ end
360
330
  end
331
+ FileUtils.chmod 0755, bin_shim
361
332
  end
333
+ end
362
334
 
363
- ensure
364
- save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
335
+ def self.shim_bundler(ruby_executable, autoproj_gemfile_path, gems_gem_home)
336
+ "#! #{ruby_executable}
337
+
338
+ if defined?(Bundler)
339
+ Bundler.with_clean_env do
340
+ exec($0, *ARGV)
341
+ end
342
+ end
343
+
344
+ ENV.delete('BUNDLE_GEMFILE')
345
+ ENV['GEM_HOME'] = '#{gems_gem_home}'
346
+ ENV.delete('GEM_PATH')
347
+ Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => '']
348
+
349
+ load Gem.bin_path('bundler', 'bundler')"
350
+ end
351
+
352
+ def self.shim_script(ruby_executable, autoproj_gemfile_path, gems_gem_home, load_line)
353
+ "#! #{ruby_executable}
354
+
355
+ if defined?(Bundler)
356
+ Bundler.with_clean_env do
357
+ exec($0, *ARGV)
358
+ end
359
+ end
360
+
361
+ ENV['BUNDLE_GEMFILE'] = '#{autoproj_gemfile_path}'
362
+ require 'rubygems'
363
+ Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => '']
364
+ require 'bundler/setup'
365
+ #{load_line}"
365
366
  end
366
367
 
367
368
  def save_env_sh(*vars)
@@ -392,6 +393,15 @@ module Autoproj
392
393
  end
393
394
 
394
395
  def save_gemfile
396
+ gemfile =
397
+ if @gemfile
398
+ @gemfile
399
+ elsif File.file?(autoproj_gemfile_path)
400
+ File.read(autoproj_gemfile_path)
401
+ else
402
+ default_gemfile_contents
403
+ end
404
+
395
405
  FileUtils.mkdir_p File.dirname(autoproj_gemfile_path)
396
406
  File.open(autoproj_gemfile_path, 'w') do |io|
397
407
  io.write gemfile
@@ -434,46 +444,32 @@ module Autoproj
434
444
  end
435
445
  end
436
446
 
437
- def self.save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
438
- FileUtils.mkdir_p shim_path
439
- bundler_rubylib = File.expand_path(File.join('..', '..', 'lib'), bundler_path)
440
- File.open(File.join(shim_path, 'bundler'), 'w') do |io|
441
- io.puts "#! /bin/sh"
442
- io.puts "exec #{ruby_executable} #{bundler_path} \"$@\""
443
- end
444
- FileUtils.chmod 0755, File.join(shim_path, 'bundler')
445
- File.open(File.join(shim_path, 'ruby'), 'w') do |io|
446
- io.puts "#! /bin/sh"
447
- io.puts "exec #{ruby_executable} \"$@\""
448
- end
449
- FileUtils.chmod 0755, File.join(shim_path, 'ruby')
450
- end
451
-
452
447
  def install
453
448
  if ENV['BUNDLER_GEMFILE']
454
449
  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"
455
450
  end
456
451
 
457
- gem_program = guess_gem_program
452
+ gem_program = self.class.guess_gem_program
458
453
  puts "Detected 'gem' to be #{gem_program}"
459
- env['GEM_HOME'] = [autoproj_gem_home]
454
+ env['GEM_HOME'] = [gems_gem_home]
460
455
 
461
456
  if bundler = find_bundler(gem_program)
462
457
  puts "Detected bundler at #{bundler}"
463
458
  else
464
- puts "Installing bundler in #{autoproj_gem_home}"
459
+ puts "Installing bundler in #{gems_gem_home}"
465
460
  if !(bundler = install_bundler(gem_program))
466
461
  exit 1
467
462
  end
468
463
  end
469
- self.class.save_ruby_and_bundler_shims(
464
+ self.class.rewrite_shims(
470
465
  File.join(dot_autoproj, 'bin'),
471
466
  ruby_executable,
472
- bundler)
467
+ autoproj_gemfile_path,
468
+ gems_gem_home)
473
469
  env['PATH'].unshift File.join(dot_autoproj, 'bin')
474
470
  save_gemfile
475
471
 
476
- puts "Installing autoproj in #{autoproj_gem_home}"
472
+ puts "Installing autoproj in #{gems_gem_home}"
477
473
  install_autoproj(bundler)
478
474
  end
479
475
 
@@ -500,13 +496,12 @@ module Autoproj
500
496
  end
501
497
 
502
498
  @config = config
503
- %w{autoproj_install_path gems_install_path prefer_indep_over_os_packages}.each do |flag|
499
+ %w{gems_install_path prefer_indep_over_os_packages}.each do |flag|
504
500
  instance_variable_set "@#{flag}", config.fetch(flag, false)
505
501
  end
506
502
  end
507
503
 
508
504
  def save_config
509
- config['autoproj_install_path'] = autoproj_install_path
510
505
  config['gems_install_path'] = gems_install_path
511
506
  config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
512
507
  File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
@@ -551,13 +546,13 @@ module Autoproj
551
546
  require 'autobuild'
552
547
  puts "saving env.sh and .autoproj/env.sh"
553
548
  save_env_sh(*vars)
554
- if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options)
549
+ if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options, '--debug')
555
550
  STDERR.puts "failed to run autoproj envsh on the newly installed autoproj (#{autoproj_path})"
556
551
  exit 1
557
552
  end
558
553
  # This is really needed on an existing install to install the
559
554
  # gems that were present in the v1 layout
560
- if !system(Gem.ruby, autoproj_path, 'osdeps')
555
+ if !system(Gem.ruby, autoproj_path, 'osdeps', '--debug')
561
556
  STDERR.puts "failed to run autoproj osdeps on the newly installed autoproj (#{autoproj_path})"
562
557
  exit 1
563
558
  end