autoproj 2.0.0.rc9 → 2.0.0.rc10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1df5021c43b37d6c5518d493f79fbbaea9f2521
4
- data.tar.gz: 0d9eed9c7fa03564259281202ecaba4bf984ef75
3
+ metadata.gz: 30a776d75893c24ae1bef6e5ac4063225e21c0bc
4
+ data.tar.gz: cc366c1d942136097608100172b8d1b559c14dd1
5
5
  SHA512:
6
- metadata.gz: 6acb320695ee6c3991275a4aec2c89a8a5e445888a74d2f0bea7b520f62894f3f7721b6a32fcb1112cf7cf301393f47db0a39b1adda41597ba3026b3ba948e38
7
- data.tar.gz: 3fffc2abaa6b8b5eff4bd4e14f9b6c0884f1e6f3a1c27bd272062319cd1c4446cc1f673c656703c985e4a51286fb3fe30b5a065cc8937c0a5da59c51445c5763
6
+ metadata.gz: b2d3ebc0d936f867e600e6b77b8711954b36522be806f2772172fad01a7d68cc5fbd6da1e2587c79e3c79f2407e0d3572b1060a899bf748376f29833f5070c9d
7
+ data.tar.gz: e6c5e0572ac7ffdabdb2cc0d1e93dfda7be46cd607394ed772dbccadba97bb8abcf801816fe07ca6ca08ba80e9fa4bedaf933109c7b4fa5ec6af3715880013af
data/Gemfile CHANGED
@@ -1,6 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'autobuild', github: 'rock-core/autobuild', branch: 'autoproj-2.0'
4
- gem 'pry'
5
- gem 'pry-byebug'
3
+ gem 'autobuild', github: 'rock-core/autobuild', branch: 'master'
6
4
  gemspec
@@ -37,20 +37,15 @@ module Autoproj
37
37
  @gemfile = default_gemfile_contents
38
38
  end
39
39
 
40
- load_config
41
- @local = false
42
- @env = self.class.clean_env
43
- end
44
-
45
- def self.clean_env
46
- env = Hash.new
40
+ @env = Hash.new
47
41
  env['RUBYLIB'] = []
48
42
  env['GEM_PATH'] = []
49
- %w{PATH GEM_HOME}.each do |name|
50
- env[name] = sanitize_env(ENV[name] || "")
51
- end
43
+ env['GEM_HOME'] = []
44
+ env['PATH'] = self.class.sanitize_env(ENV['PATH'] || "")
52
45
  env['BUNDLE_GEMFILE'] = []
53
- env
46
+
47
+ load_config
48
+ @local = false
54
49
  end
55
50
 
56
51
  def env_for_child
@@ -88,7 +83,7 @@ module Autoproj
88
83
 
89
84
 
90
85
  def dot_autoproj; File.join(root_dir, '.autoproj') end
91
- def bundler_install_dir; File.join(dot_autoproj, 'bundler') end
86
+
92
87
  def autoproj_install_dir; File.join(dot_autoproj, 'autoproj') end
93
88
  # The path to the gemfile used to install autoproj
94
89
  def autoproj_gemfile_path; File.join(autoproj_install_dir, 'Gemfile') end
@@ -100,18 +95,47 @@ module Autoproj
100
95
  def local=(flag); @local = flag end
101
96
 
102
97
  # Whether bundler should be installed locally in {#dot_autoproj}
103
- def private_bundler?; @private_bundler end
98
+ def private_bundler?; !!@private_bundler end
99
+ # The path to the directory into which the bundler gem should be
100
+ # installed
101
+ def bundler_gem_home; @private_bundler || gem_bindir end
104
102
  # (see #private_bundler?)
105
- def private_bundler=(flag); @private_bundler = !!flag end
103
+ def private_bundler=(flag)
104
+ @private_bundler =
105
+ if flag.respond_to?(:to_str) then File.expand_path(flag)
106
+ elsif flag
107
+ File.join(dot_autoproj, 'bundler')
108
+ end
109
+ end
110
+
106
111
  # Whether autoproj should be installed locally in {#dot_autoproj}
107
- def private_autoproj?; @private_autoproj end
112
+ def private_autoproj?; !!@private_autoproj end
113
+ # The path to the directory into which the autoproj gem should be
114
+ # installed
115
+ def autoproj_gem_home; @private_autoproj || gem_bindir end
108
116
  # (see #private_autoproj?)
109
- def private_autoproj=(flag); @private_autoproj = !!flag end
110
- # Whether bundler should be installed locally in the workspace
111
- # prefix directory
112
- def private_gems?; @private_gems end
117
+ def private_autoproj=(flag)
118
+ @private_autoproj =
119
+ if flag.respond_to?(:to_str) then File.expand_path(flag)
120
+ elsif flag
121
+ File.join(dot_autoproj, 'autoproj')
122
+ end
123
+ end
124
+
125
+ # Whether autoproj should be installed locally in {#dot_autoproj}
126
+ #
127
+ # Unlike for {#private_autoproj?} and {#private_bundler?}, there is
128
+ # no default path to save the gems as we don't yet know the path to
129
+ # the prefix directory
130
+ def private_gems?; !!@private_gems end
113
131
  # (see #private_gems?)
114
- def private_gems=(flag); @private_gems = !!flag end
132
+ def private_gems=(value)
133
+ @private_gems =
134
+ if value.respond_to?(:to_str) then File.expand_path(value)
135
+ else value
136
+ end
137
+ end
138
+
115
139
  # Whether autoproj should prefer OS-independent packages over their
116
140
  # OS-packaged equivalents (e.g. the thor gem vs. the ruby-thor
117
141
  # Debian package)
@@ -153,19 +177,19 @@ module Autoproj
153
177
  opt.on '--local', 'do not access the network (may fail)' do
154
178
  @local = true
155
179
  end
156
- opt.on '--private-bundler', 'install bundler locally in the workspace' do
157
- @private_bundler = true
180
+ opt.on '--private-bundler[=PATH]', 'install bundler locally in the workspace' do |path|
181
+ self.private_bundler = path || true
158
182
  end
159
- opt.on '--private-autoproj', 'install autoproj locally in the workspace' do
160
- @private_autoproj = true
183
+ opt.on '--private-autoproj[=PATH]', 'install autoproj locally in the workspace' do |path|
184
+ self.private_autoproj = path || true
161
185
  end
162
- opt.on '--private-gems', 'install gems locally in the prefix directory' do
163
- @private_gems = true
186
+ opt.on '--private-gems[=PATH]', 'install gems locally in the prefix directory' do |path|
187
+ self.private_gems = path || true
164
188
  end
165
- opt.on '--private', 'whether bundler, autoproj and the workspace gems should be installed locally in the workspace' do
166
- @private_bundler = true
167
- @private_autoproj = true
168
- @private_gems = true
189
+ opt.on '--private[=PATH]', 'whether bundler, autoproj and the workspace gems should be installed locally in the workspace' do |path|
190
+ self.private_bundler = path || true
191
+ self.private_autoproj = path || true
192
+ self.private_gems = path || true
169
193
  end
170
194
  opt.on '--version=VERSION_CONSTRAINT', String, 'use the provided string as a version constraint for autoproj' do |version|
171
195
  @gemfile = default_gemfile_contents(version)
@@ -187,54 +211,51 @@ module Autoproj
187
211
  local = ['--local'] if local?
188
212
 
189
213
  result = system(
190
- env_for_child.merge('GEM_PATH' => nil, 'GEM_HOME' => bundler_install_dir),
191
- gem_program, 'install', '--no-document', '--no-user-install', '--no-format-executable',
214
+ env_for_child.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_home),
215
+ gem_program, 'install', '--no-document', '--no-format-executable',
192
216
  *local,
193
- "--bindir=#{File.join(bundler_install_dir, 'bin')}", 'bundler')
217
+ "--bindir=#{File.join(bundler_gem_home, 'bin')}", 'bundler')
194
218
 
195
219
  if !result
196
220
  STDERR.puts "FATAL: failed to install bundler in #{dot_autoproj}"
197
221
  exit 1
198
222
  end
199
- env['PATH'].unshift File.join(bundler_install_dir, 'bin')
200
- File.join(bundler_install_dir, 'bin', 'bundler')
223
+ File.join(bundler_gem_home, 'bin', 'bundler')
201
224
  end
202
225
 
203
226
  def find_bundler
204
- self.env['PATH'].unshift gem_bindir
205
227
  clean_env = env_for_child
206
- Gem.paths = Hash[
207
- 'GEM_HOME' => clean_env['GEM_HOME'] || Gem.default_dir,
208
- 'GEM_PATH' => clean_env['GEM_PATH'] || nil
209
- ]
210
-
211
- bundler = find_in_clean_path('bundler')
212
- if !bundler
213
- clean_path = env_for_child['PATH']
214
- STDERR.puts "cannot find 'bundler' in PATH=#{clean_path}"
215
- STDERR.puts "installing it now ..."
216
- result = system(clean_env, Gem.ruby, '-S', 'gem', 'install', 'bundler')
217
- if !result
218
- if ENV['PATH'] != clean_path
219
- STDERR.puts " it appears that you already have some autoproj-generated env.sh loaded"
220
- STDERR.puts " - if you are running 'autoproj upgrade', please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
221
- STDERR.puts " - if you are running an install, try again in a console where the env.sh is not loaded"
222
- exit 1
223
- else
224
- STDERR.puts " the recommended action is to install it manually first by running 'gem install bundler'"
225
- STDERR.puts " or call this command again with --private-bundler to have it installed in the workspace"
226
- exit 1
227
- end
228
- end
228
+ if bundler = find_in_clean_path('bundler', gem_bindir)
229
+ return bundler
230
+ end
231
+
232
+ clean_path = env_for_child['PATH']
233
+ STDERR.puts "cannot find 'bundler' in PATH=#{clean_path}#{File::PATH_SEPARATOR}#{gem_bindir}"
234
+ STDERR.puts "installing it now ..."
235
+ result = system(
236
+ clean_env.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_path),
237
+ Gem.ruby, '-S', 'gem', 'install', 'bundler')
229
238
 
230
- bundler = find_in_clean_path('bundler')
231
- if !bundler
232
- STDERR.puts "FATAL: gem install bundler returned successfully, but still cannot find bundler"
233
- STDERR.puts "FATAL: in #{clean_path}"
239
+ if !result
240
+ if ENV['PATH'] != clean_path
241
+ STDERR.puts " it appears that you already have some autoproj-generated env.sh loaded"
242
+ STDERR.puts " - if you are running 'autoproj upgrade', please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
243
+ STDERR.puts " - if you are running an install, try again in a console where the env.sh is not loaded"
244
+ exit 1
245
+ else
246
+ STDERR.puts " the recommended action is to install it manually first by running 'gem install bundler'"
247
+ STDERR.puts " or call this command again with --private-bundler to have it installed in the workspace"
248
+ exit 1
234
249
  end
235
250
  end
236
251
 
237
- bundler
252
+ bundler = File.join(bundler_gem_path, 'bin', 'bundler')
253
+ if File.exist?(bundler)
254
+ bundler
255
+ else
256
+ STDERR.puts "gem install bundler returned successfully, but still cannot find bundler in #{bundler}"
257
+ nil
258
+ end
238
259
  end
239
260
 
240
261
  def install_autoproj(bundler)
@@ -245,17 +266,17 @@ module Autoproj
245
266
  FileUtils.rm lockfile
246
267
  end
247
268
 
248
- opts = Array.new
249
- clean_env = env_for_child.merge('BUNDLE_GEMFILE' => nil)
269
+ clean_env = env_for_child.dup
250
270
 
271
+ opts = Array.new
251
272
  opts << '--local' if local?
252
273
  if private_autoproj?
253
- clean_env['GEM_PATH'] = (bundler_install_dir if private_bundler?)
274
+ clean_env['GEM_PATH'] = bundler_gem_home
254
275
  clean_env['GEM_HOME'] = nil
255
- opts << "--clean" << "--path=#{autoproj_install_dir}"
276
+ opts << "--clean" << "--path=#{autoproj_gem_home}"
256
277
  end
257
278
  binstubs_path = File.join(autoproj_install_dir, 'bin')
258
- result = system(clean_env,
279
+ result = system(clean_env.merge('GEM_HOME' => autoproj_gem_home),
259
280
  Gem.ruby, bundler, 'install',
260
281
  "--gemfile=#{autoproj_gemfile_path}",
261
282
  "--shebang=#{Gem.ruby}",
@@ -266,6 +287,17 @@ module Autoproj
266
287
  STDERR.puts "FATAL: failed to install autoproj in #{dot_autoproj}"
267
288
  exit 1
268
289
  end
290
+ ensure
291
+ self.class.clean_binstubs(binstubs_path)
292
+ end
293
+
294
+ def self.clean_binstubs(binstubs_path)
295
+ %w{bundler bundle}.each do |bundler_bin|
296
+ path = File.join(binstubs_path, bundler_bin)
297
+ if File.file?(path)
298
+ FileUtils.rm path
299
+ end
300
+ end
269
301
 
270
302
  # Now tune the binstubs to force the usage of the autoproj
271
303
  # gemfile. Otherwise, they get BUNDLE_GEMFILE from the
@@ -286,15 +318,6 @@ module Autoproj
286
318
  io.write filtered.join("")
287
319
  end
288
320
  end
289
-
290
- env['PATH'].unshift File.join(autoproj_install_dir, 'bin')
291
- if private_autoproj?
292
- env['GEM_PATH'].unshift autoproj_install_dir
293
- end
294
- ensure
295
- if binstubs_path
296
- FileUtils.rm_f File.join(binstubs_path, 'bundler')
297
- end
298
321
  end
299
322
 
300
323
  def save_env_sh(*vars)
@@ -334,8 +357,8 @@ module Autoproj
334
357
  ENV_BUNDLE_GEMFILE_RX = /^(\s*ENV\[['"]BUNDLE_GEMFILE['"]\]\s*)(?:\|\|)?=/
335
358
 
336
359
 
337
- def find_in_clean_path(command)
338
- clean_path = env_for_child['PATH'].split(File::PATH_SEPARATOR)
360
+ def find_in_clean_path(command, *additional_paths)
361
+ clean_path = env_for_child['PATH'].split(File::PATH_SEPARATOR) + additional_paths
339
362
  clean_path.each do |p|
340
363
  full_path = File.join(p, command)
341
364
  if File.file?(full_path)
@@ -359,7 +382,7 @@ module Autoproj
359
382
  #
360
383
  # So, we're calling 'gem' as a subcommand to discovery the
361
384
  # actual bindir
362
- bindir = IO.popen(env_for_child, [Gem.ruby, '-e', 'puts Gem.bindir']).read
385
+ bindir = IO.popen(env_for_child, [Gem.ruby, '-e', 'puts "#{Gem.user_dir}/bin"']).read
363
386
  if bindir
364
387
  @gem_bindir = bindir.chomp
365
388
  else
@@ -369,11 +392,12 @@ module Autoproj
369
392
 
370
393
  def install
371
394
  if private_bundler?
372
- puts "Installing bundler in #{bundler_install_dir}"
395
+ puts "Installing bundler in #{bundler_gem_home}"
373
396
  bundler = install_bundler
374
- else
375
- bundler = find_bundler
397
+ elsif bundler = find_bundler
376
398
  puts "Detected bundler at #{bundler}"
399
+ else
400
+ exit 1
377
401
  end
378
402
  save_gemfile
379
403
  puts "Installing autoproj in #{dot_autoproj}"
@@ -391,6 +415,17 @@ module Autoproj
391
415
  config.merge!(YAML.load(File.read(autoproj_config_path)))
392
416
  end
393
417
 
418
+ ruby = RbConfig::CONFIG['RUBY_INSTALL_NAME']
419
+ ruby_bindir = RbConfig::CONFIG['bindir']
420
+ ruby_executable = File.join(ruby_bindir, ruby)
421
+ if current = config['ruby_executable'] # When upgrading or reinstalling
422
+ if current != ruby_executable
423
+ raise "this workspace has already been initialized using #{current}, you cannot run autoproj install with #{ruby_executable}. If you know what you're doing, delete the ruby_executable line in config.yml and try again"
424
+ end
425
+ else
426
+ config['ruby_executable'] = ruby_executable
427
+ end
428
+
394
429
  @config = config
395
430
  %w{private_bundler private_gems private_autoproj prefer_indep_over_os_packages}.each do |flag|
396
431
  instance_variable_set "@#{flag}", config.fetch(flag, false)
@@ -398,25 +433,33 @@ module Autoproj
398
433
  end
399
434
 
400
435
  def save_config
401
- config['private_bundler'] = private_bundler?
402
- config['private_autoproj'] = private_autoproj?
403
- config['private_gems'] = private_gems?
436
+ config['private_bundler'] = (bundler_gem_home if private_bundler?)
437
+ config['private_autoproj'] = (autoproj_gem_home if private_autoproj?)
438
+ config['private_gems'] = @private_gems
404
439
  config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
405
440
  File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
406
441
  end
407
442
 
443
+ def autoproj_path
444
+ File.join(autoproj_install_dir, 'bin', 'autoproj')
445
+ end
446
+
447
+ def run_autoproj(*args)
448
+ system env_for_child.merge('BUNDLE_GEMFILE' => autoproj_gemfile_path),
449
+ Gem.ruby, autoproj_path, *args
450
+ end
451
+
408
452
  def stage1
409
453
  FileUtils.mkdir_p dot_autoproj
410
454
  save_config
411
455
  install
456
+ end
412
457
 
458
+ def call_stage2
413
459
  clean_env = env_for_child
414
460
  stage2_vars = clean_env.map { |k, v| "#{k}=#{v}" }
415
461
  puts "starting the newly installed autoproj for stage2 install"
416
- result = system clean_env.merge('BUNDLE_GEMFILE' => autoproj_gemfile_path),
417
- Gem.ruby, File.join(autoproj_install_dir, 'bin', 'autoproj'),
418
- 'install-stage2', root_dir, *stage2_vars
419
- if !result
462
+ if !run_autoproj('install-stage2', root_dir, *stage2_vars)
420
463
  raise "failed to execute autoproj install-stage2"
421
464
  end
422
465
  end
@@ -426,7 +469,7 @@ module Autoproj
426
469
  puts "saving env.sh and .autoproj/env.sh"
427
470
  save_env_sh(*vars)
428
471
  puts "calling autoproj envsh"
429
- system(Gem.ruby, $0, 'envsh')
472
+ system(Gem.ruby, autoproj_path, 'envsh')
430
473
  end
431
474
  end
432
475
  end
@@ -439,9 +482,6 @@ ENV.delete('RUBYLIB')
439
482
  ops = Autoproj::Ops::Install.new(Dir.pwd)
440
483
  bootstrap_options = ops.parse_options(ARGV)
441
484
  ops.stage1
442
-
443
- # we assume that Install#run loads bundler and autobuild. Load autoproj and run
444
- # bootstrap
445
- require 'autoproj/cli/main'
446
- Autoproj::CLI::Main.start(['bootstrap', *bootstrap_options])
485
+ ops.call_stage2
486
+ ops.run_autoproj 'bootstrap', *bootstrap_options
447
487
 
@@ -12,9 +12,6 @@ ENV.delete('RUBYLIB')
12
12
  ops = Autoproj::Ops::Install.new(Dir.pwd)
13
13
  bootstrap_options = ops.parse_options(ARGV)
14
14
  ops.stage1
15
-
16
- # we assume that Install#run loads bundler and autobuild. Load autoproj and run
17
- # bootstrap
18
- require 'autoproj/cli/main'
19
- Autoproj::CLI::Main.start(['bootstrap', *bootstrap_options])
15
+ ops.call_stage2
16
+ ops.run_autoproj 'bootstrap', *bootstrap_options
20
17
 
data/bin/autoproj_install CHANGED
@@ -37,20 +37,15 @@ module Autoproj
37
37
  @gemfile = default_gemfile_contents
38
38
  end
39
39
 
40
- load_config
41
- @local = false
42
- @env = self.class.clean_env
43
- end
44
-
45
- def self.clean_env
46
- env = Hash.new
40
+ @env = Hash.new
47
41
  env['RUBYLIB'] = []
48
42
  env['GEM_PATH'] = []
49
- %w{PATH GEM_HOME}.each do |name|
50
- env[name] = sanitize_env(ENV[name] || "")
51
- end
43
+ env['GEM_HOME'] = []
44
+ env['PATH'] = self.class.sanitize_env(ENV['PATH'] || "")
52
45
  env['BUNDLE_GEMFILE'] = []
53
- env
46
+
47
+ load_config
48
+ @local = false
54
49
  end
55
50
 
56
51
  def env_for_child
@@ -88,7 +83,7 @@ module Autoproj
88
83
 
89
84
 
90
85
  def dot_autoproj; File.join(root_dir, '.autoproj') end
91
- def bundler_install_dir; File.join(dot_autoproj, 'bundler') end
86
+
92
87
  def autoproj_install_dir; File.join(dot_autoproj, 'autoproj') end
93
88
  # The path to the gemfile used to install autoproj
94
89
  def autoproj_gemfile_path; File.join(autoproj_install_dir, 'Gemfile') end
@@ -100,18 +95,47 @@ module Autoproj
100
95
  def local=(flag); @local = flag end
101
96
 
102
97
  # Whether bundler should be installed locally in {#dot_autoproj}
103
- def private_bundler?; @private_bundler end
98
+ def private_bundler?; !!@private_bundler end
99
+ # The path to the directory into which the bundler gem should be
100
+ # installed
101
+ def bundler_gem_home; @private_bundler || gem_bindir end
104
102
  # (see #private_bundler?)
105
- def private_bundler=(flag); @private_bundler = !!flag end
103
+ def private_bundler=(flag)
104
+ @private_bundler =
105
+ if flag.respond_to?(:to_str) then File.expand_path(flag)
106
+ elsif flag
107
+ File.join(dot_autoproj, 'bundler')
108
+ end
109
+ end
110
+
106
111
  # Whether autoproj should be installed locally in {#dot_autoproj}
107
- def private_autoproj?; @private_autoproj end
112
+ def private_autoproj?; !!@private_autoproj end
113
+ # The path to the directory into which the autoproj gem should be
114
+ # installed
115
+ def autoproj_gem_home; @private_autoproj || gem_bindir end
108
116
  # (see #private_autoproj?)
109
- def private_autoproj=(flag); @private_autoproj = !!flag end
110
- # Whether bundler should be installed locally in the workspace
111
- # prefix directory
112
- def private_gems?; @private_gems end
117
+ def private_autoproj=(flag)
118
+ @private_autoproj =
119
+ if flag.respond_to?(:to_str) then File.expand_path(flag)
120
+ elsif flag
121
+ File.join(dot_autoproj, 'autoproj')
122
+ end
123
+ end
124
+
125
+ # Whether autoproj should be installed locally in {#dot_autoproj}
126
+ #
127
+ # Unlike for {#private_autoproj?} and {#private_bundler?}, there is
128
+ # no default path to save the gems as we don't yet know the path to
129
+ # the prefix directory
130
+ def private_gems?; !!@private_gems end
113
131
  # (see #private_gems?)
114
- def private_gems=(flag); @private_gems = !!flag end
132
+ def private_gems=(value)
133
+ @private_gems =
134
+ if value.respond_to?(:to_str) then File.expand_path(value)
135
+ else value
136
+ end
137
+ end
138
+
115
139
  # Whether autoproj should prefer OS-independent packages over their
116
140
  # OS-packaged equivalents (e.g. the thor gem vs. the ruby-thor
117
141
  # Debian package)
@@ -153,19 +177,19 @@ module Autoproj
153
177
  opt.on '--local', 'do not access the network (may fail)' do
154
178
  @local = true
155
179
  end
156
- opt.on '--private-bundler', 'install bundler locally in the workspace' do
157
- @private_bundler = true
180
+ opt.on '--private-bundler[=PATH]', 'install bundler locally in the workspace' do |path|
181
+ self.private_bundler = path || true
158
182
  end
159
- opt.on '--private-autoproj', 'install autoproj locally in the workspace' do
160
- @private_autoproj = true
183
+ opt.on '--private-autoproj[=PATH]', 'install autoproj locally in the workspace' do |path|
184
+ self.private_autoproj = path || true
161
185
  end
162
- opt.on '--private-gems', 'install gems locally in the prefix directory' do
163
- @private_gems = true
186
+ opt.on '--private-gems[=PATH]', 'install gems locally in the prefix directory' do |path|
187
+ self.private_gems = path || true
164
188
  end
165
- opt.on '--private', 'whether bundler, autoproj and the workspace gems should be installed locally in the workspace' do
166
- @private_bundler = true
167
- @private_autoproj = true
168
- @private_gems = true
189
+ opt.on '--private[=PATH]', 'whether bundler, autoproj and the workspace gems should be installed locally in the workspace' do |path|
190
+ self.private_bundler = path || true
191
+ self.private_autoproj = path || true
192
+ self.private_gems = path || true
169
193
  end
170
194
  opt.on '--version=VERSION_CONSTRAINT', String, 'use the provided string as a version constraint for autoproj' do |version|
171
195
  @gemfile = default_gemfile_contents(version)
@@ -187,54 +211,51 @@ module Autoproj
187
211
  local = ['--local'] if local?
188
212
 
189
213
  result = system(
190
- env_for_child.merge('GEM_PATH' => nil, 'GEM_HOME' => bundler_install_dir),
191
- gem_program, 'install', '--no-document', '--no-user-install', '--no-format-executable',
214
+ env_for_child.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_home),
215
+ gem_program, 'install', '--no-document', '--no-format-executable',
192
216
  *local,
193
- "--bindir=#{File.join(bundler_install_dir, 'bin')}", 'bundler')
217
+ "--bindir=#{File.join(bundler_gem_home, 'bin')}", 'bundler')
194
218
 
195
219
  if !result
196
220
  STDERR.puts "FATAL: failed to install bundler in #{dot_autoproj}"
197
221
  exit 1
198
222
  end
199
- env['PATH'].unshift File.join(bundler_install_dir, 'bin')
200
- File.join(bundler_install_dir, 'bin', 'bundler')
223
+ File.join(bundler_gem_home, 'bin', 'bundler')
201
224
  end
202
225
 
203
226
  def find_bundler
204
- self.env['PATH'].unshift gem_bindir
205
227
  clean_env = env_for_child
206
- Gem.paths = Hash[
207
- 'GEM_HOME' => clean_env['GEM_HOME'] || Gem.default_dir,
208
- 'GEM_PATH' => clean_env['GEM_PATH'] || nil
209
- ]
210
-
211
- bundler = find_in_clean_path('bundler')
212
- if !bundler
213
- clean_path = env_for_child['PATH']
214
- STDERR.puts "cannot find 'bundler' in PATH=#{clean_path}"
215
- STDERR.puts "installing it now ..."
216
- result = system(clean_env, Gem.ruby, '-S', 'gem', 'install', 'bundler')
217
- if !result
218
- if ENV['PATH'] != clean_path
219
- STDERR.puts " it appears that you already have some autoproj-generated env.sh loaded"
220
- STDERR.puts " - if you are running 'autoproj upgrade', please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
221
- STDERR.puts " - if you are running an install, try again in a console where the env.sh is not loaded"
222
- exit 1
223
- else
224
- STDERR.puts " the recommended action is to install it manually first by running 'gem install bundler'"
225
- STDERR.puts " or call this command again with --private-bundler to have it installed in the workspace"
226
- exit 1
227
- end
228
- end
228
+ if bundler = find_in_clean_path('bundler', gem_bindir)
229
+ return bundler
230
+ end
231
+
232
+ clean_path = env_for_child['PATH']
233
+ STDERR.puts "cannot find 'bundler' in PATH=#{clean_path}#{File::PATH_SEPARATOR}#{gem_bindir}"
234
+ STDERR.puts "installing it now ..."
235
+ result = system(
236
+ clean_env.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_path),
237
+ Gem.ruby, '-S', 'gem', 'install', 'bundler')
229
238
 
230
- bundler = find_in_clean_path('bundler')
231
- if !bundler
232
- STDERR.puts "FATAL: gem install bundler returned successfully, but still cannot find bundler"
233
- STDERR.puts "FATAL: in #{clean_path}"
239
+ if !result
240
+ if ENV['PATH'] != clean_path
241
+ STDERR.puts " it appears that you already have some autoproj-generated env.sh loaded"
242
+ STDERR.puts " - if you are running 'autoproj upgrade', please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
243
+ STDERR.puts " - if you are running an install, try again in a console where the env.sh is not loaded"
244
+ exit 1
245
+ else
246
+ STDERR.puts " the recommended action is to install it manually first by running 'gem install bundler'"
247
+ STDERR.puts " or call this command again with --private-bundler to have it installed in the workspace"
248
+ exit 1
234
249
  end
235
250
  end
236
251
 
237
- bundler
252
+ bundler = File.join(bundler_gem_path, 'bin', 'bundler')
253
+ if File.exist?(bundler)
254
+ bundler
255
+ else
256
+ STDERR.puts "gem install bundler returned successfully, but still cannot find bundler in #{bundler}"
257
+ nil
258
+ end
238
259
  end
239
260
 
240
261
  def install_autoproj(bundler)
@@ -245,17 +266,17 @@ module Autoproj
245
266
  FileUtils.rm lockfile
246
267
  end
247
268
 
248
- opts = Array.new
249
- clean_env = env_for_child.merge('BUNDLE_GEMFILE' => nil)
269
+ clean_env = env_for_child.dup
250
270
 
271
+ opts = Array.new
251
272
  opts << '--local' if local?
252
273
  if private_autoproj?
253
- clean_env['GEM_PATH'] = (bundler_install_dir if private_bundler?)
274
+ clean_env['GEM_PATH'] = bundler_gem_home
254
275
  clean_env['GEM_HOME'] = nil
255
- opts << "--clean" << "--path=#{autoproj_install_dir}"
276
+ opts << "--clean" << "--path=#{autoproj_gem_home}"
256
277
  end
257
278
  binstubs_path = File.join(autoproj_install_dir, 'bin')
258
- result = system(clean_env,
279
+ result = system(clean_env.merge('GEM_HOME' => autoproj_gem_home),
259
280
  Gem.ruby, bundler, 'install',
260
281
  "--gemfile=#{autoproj_gemfile_path}",
261
282
  "--shebang=#{Gem.ruby}",
@@ -266,6 +287,17 @@ module Autoproj
266
287
  STDERR.puts "FATAL: failed to install autoproj in #{dot_autoproj}"
267
288
  exit 1
268
289
  end
290
+ ensure
291
+ self.class.clean_binstubs(binstubs_path)
292
+ end
293
+
294
+ def self.clean_binstubs(binstubs_path)
295
+ %w{bundler bundle}.each do |bundler_bin|
296
+ path = File.join(binstubs_path, bundler_bin)
297
+ if File.file?(path)
298
+ FileUtils.rm path
299
+ end
300
+ end
269
301
 
270
302
  # Now tune the binstubs to force the usage of the autoproj
271
303
  # gemfile. Otherwise, they get BUNDLE_GEMFILE from the
@@ -286,15 +318,6 @@ module Autoproj
286
318
  io.write filtered.join("")
287
319
  end
288
320
  end
289
-
290
- env['PATH'].unshift File.join(autoproj_install_dir, 'bin')
291
- if private_autoproj?
292
- env['GEM_PATH'].unshift autoproj_install_dir
293
- end
294
- ensure
295
- if binstubs_path
296
- FileUtils.rm_f File.join(binstubs_path, 'bundler')
297
- end
298
321
  end
299
322
 
300
323
  def save_env_sh(*vars)
@@ -334,8 +357,8 @@ module Autoproj
334
357
  ENV_BUNDLE_GEMFILE_RX = /^(\s*ENV\[['"]BUNDLE_GEMFILE['"]\]\s*)(?:\|\|)?=/
335
358
 
336
359
 
337
- def find_in_clean_path(command)
338
- clean_path = env_for_child['PATH'].split(File::PATH_SEPARATOR)
360
+ def find_in_clean_path(command, *additional_paths)
361
+ clean_path = env_for_child['PATH'].split(File::PATH_SEPARATOR) + additional_paths
339
362
  clean_path.each do |p|
340
363
  full_path = File.join(p, command)
341
364
  if File.file?(full_path)
@@ -359,7 +382,7 @@ module Autoproj
359
382
  #
360
383
  # So, we're calling 'gem' as a subcommand to discovery the
361
384
  # actual bindir
362
- bindir = IO.popen(env_for_child, [Gem.ruby, '-e', 'puts Gem.bindir']).read
385
+ bindir = IO.popen(env_for_child, [Gem.ruby, '-e', 'puts "#{Gem.user_dir}/bin"']).read
363
386
  if bindir
364
387
  @gem_bindir = bindir.chomp
365
388
  else
@@ -369,11 +392,12 @@ module Autoproj
369
392
 
370
393
  def install
371
394
  if private_bundler?
372
- puts "Installing bundler in #{bundler_install_dir}"
395
+ puts "Installing bundler in #{bundler_gem_home}"
373
396
  bundler = install_bundler
374
- else
375
- bundler = find_bundler
397
+ elsif bundler = find_bundler
376
398
  puts "Detected bundler at #{bundler}"
399
+ else
400
+ exit 1
377
401
  end
378
402
  save_gemfile
379
403
  puts "Installing autoproj in #{dot_autoproj}"
@@ -391,6 +415,17 @@ module Autoproj
391
415
  config.merge!(YAML.load(File.read(autoproj_config_path)))
392
416
  end
393
417
 
418
+ ruby = RbConfig::CONFIG['RUBY_INSTALL_NAME']
419
+ ruby_bindir = RbConfig::CONFIG['bindir']
420
+ ruby_executable = File.join(ruby_bindir, ruby)
421
+ if current = config['ruby_executable'] # When upgrading or reinstalling
422
+ if current != ruby_executable
423
+ raise "this workspace has already been initialized using #{current}, you cannot run autoproj install with #{ruby_executable}. If you know what you're doing, delete the ruby_executable line in config.yml and try again"
424
+ end
425
+ else
426
+ config['ruby_executable'] = ruby_executable
427
+ end
428
+
394
429
  @config = config
395
430
  %w{private_bundler private_gems private_autoproj prefer_indep_over_os_packages}.each do |flag|
396
431
  instance_variable_set "@#{flag}", config.fetch(flag, false)
@@ -398,25 +433,33 @@ module Autoproj
398
433
  end
399
434
 
400
435
  def save_config
401
- config['private_bundler'] = private_bundler?
402
- config['private_autoproj'] = private_autoproj?
403
- config['private_gems'] = private_gems?
436
+ config['private_bundler'] = (bundler_gem_home if private_bundler?)
437
+ config['private_autoproj'] = (autoproj_gem_home if private_autoproj?)
438
+ config['private_gems'] = @private_gems
404
439
  config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
405
440
  File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
406
441
  end
407
442
 
443
+ def autoproj_path
444
+ File.join(autoproj_install_dir, 'bin', 'autoproj')
445
+ end
446
+
447
+ def run_autoproj(*args)
448
+ system env_for_child.merge('BUNDLE_GEMFILE' => autoproj_gemfile_path),
449
+ Gem.ruby, autoproj_path, *args
450
+ end
451
+
408
452
  def stage1
409
453
  FileUtils.mkdir_p dot_autoproj
410
454
  save_config
411
455
  install
456
+ end
412
457
 
458
+ def call_stage2
413
459
  clean_env = env_for_child
414
460
  stage2_vars = clean_env.map { |k, v| "#{k}=#{v}" }
415
461
  puts "starting the newly installed autoproj for stage2 install"
416
- result = system clean_env.merge('BUNDLE_GEMFILE' => autoproj_gemfile_path),
417
- Gem.ruby, File.join(autoproj_install_dir, 'bin', 'autoproj'),
418
- 'install-stage2', root_dir, *stage2_vars
419
- if !result
462
+ if !run_autoproj('install-stage2', root_dir, *stage2_vars)
420
463
  raise "failed to execute autoproj install-stage2"
421
464
  end
422
465
  end
@@ -426,7 +469,7 @@ module Autoproj
426
469
  puts "saving env.sh and .autoproj/env.sh"
427
470
  save_env_sh(*vars)
428
471
  puts "calling autoproj envsh"
429
- system(Gem.ruby, $0, 'envsh')
472
+ system(Gem.ruby, autoproj_path, 'envsh')
430
473
  end
431
474
  end
432
475
  end
@@ -439,3 +482,4 @@ ENV.delete('RUBYLIB')
439
482
  ops = Autoproj::Ops::Install.new(Dir.pwd)
440
483
  ops.parse_options(ARGV)
441
484
  ops.stage1
485
+ ops.call_stage2