autoproj 2.0.0.rc31 → 2.0.0.rc32

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: 6f768ab32070ccf5661b6ef7e0713598cc32a2da
4
- data.tar.gz: 6b9bc19bb4c653887479bdcafc512a7a8a308c19
3
+ metadata.gz: bb40d3c2a7fa377b8faa4077b9d31ba82be80603
4
+ data.tar.gz: 36970528dc5d9a53b2fc8231929819c2d41164bc
5
5
  SHA512:
6
- metadata.gz: e0b7cb9352271cf11c4fb9f3d945fdafe5f8211dee6edb15c2320dfe7da6bf10c9a18e73ab77be7f1ce7e01979d8172a491738422819989a2a5f2df502e595bd
7
- data.tar.gz: 3b59fac581a9e8ca86e342bd5799e49b381a6790fef9eb351258c39a653586a282fa54af79e25e6977dfcdc6a490981253ecf672108e91c2fc2bdea153799e60
6
+ metadata.gz: c3b173ea5faf24871a46ab1c7ad91bf6e6e5cc59e3e9e1b78850ca5f03f9e86f0fd4abef4a97ef05e2124d8e56deb12da012ccb7b270ce5b45e2d1abb2d712a3
7
+ data.tar.gz: a01958ed2d32916b5219656557215feb66a9a508cc00bed42419cba9fdecdfe13a1360b1c7463ae632b60d604742da9774c41b9e801e9f23d35cc69888bed09c
data/.gitignore CHANGED
@@ -6,3 +6,4 @@ pkg/
6
6
  /vendor/
7
7
  /.bundle
8
8
  /coverage/
9
+ /.yardoc/
data/autoproj.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
  s.extensions = []
21
21
  s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
22
 
23
+ s.add_runtime_dependency "bundler"
23
24
  s.add_runtime_dependency "autobuild", ">= 1.10.0.a"
24
25
  s.add_runtime_dependency "utilrb", ">= 3.0"
25
26
  s.add_runtime_dependency "thor", '~> 0.19.0', '>= 0.19.1'
@@ -36,6 +36,8 @@ module Autoproj
36
36
  attr_reader :autoproj_options
37
37
  # The Ruby interpreter we use for this install
38
38
  attr_reader :ruby_executable
39
+ # The URL of the source to be used to get gems
40
+ attr_accessor :gem_source
39
41
 
40
42
  def initialize(root_dir)
41
43
  @root_dir = root_dir
@@ -44,6 +46,7 @@ module Autoproj
44
46
  else
45
47
  @gemfile = default_gemfile_contents
46
48
  end
49
+ @gem_source = "https://rubygems.org"
47
50
 
48
51
  @autoproj_options = Array.new
49
52
 
@@ -60,6 +63,10 @@ module Autoproj
60
63
  end
61
64
  @ruby_executable = config['ruby_executable']
62
65
  @local = false
66
+
67
+ default_gem_path = File.join(Dir.home, '.autoproj', 'gems')
68
+ @gems_install_path = default_gem_path
69
+ @autoproj_install_path = default_gem_path
63
70
  end
64
71
 
65
72
  def env_for_child
@@ -96,68 +103,91 @@ module Autoproj
96
103
  return false
97
104
  end
98
105
 
99
-
106
+ # The path to the .autoproj configuration directory
107
+ #
108
+ # @return [String]
100
109
  def dot_autoproj; File.join(root_dir, '.autoproj') end
101
110
 
102
- def autoproj_install_dir; File.join(dot_autoproj, 'autoproj') end
103
111
  # The path to the gemfile used to install autoproj
104
- def autoproj_gemfile_path; File.join(autoproj_install_dir, 'Gemfile') end
105
- def autoproj_config_path; File.join(dot_autoproj, 'config.yml') end
112
+ #
113
+ # @return [String]
114
+ def autoproj_gemfile_path; File.join(dot_autoproj, 'Gemfile') end
106
115
 
107
- def shim_path; File.join(dot_autoproj, 'bin') end
116
+ # The path to the autoproj configuration file
117
+ #
118
+ # @return [String]
119
+ def autoproj_config_path; File.join(dot_autoproj, 'config.yml') end
108
120
 
109
121
  # Whether we can access the network while installing
110
122
  def local?; !!@local end
111
123
  # (see #local?)
112
124
  def local=(flag); @local = flag end
113
125
 
114
- # Whether bundler should be installed locally in {#dot_autoproj}
115
- def private_bundler?; !!@private_bundler end
116
- # The path to the directory into which the bundler gem should be
117
- # installed
118
- def bundler_gem_home; @private_bundler || Gem.user_dir end
119
- # (see #private_bundler?)
120
- def private_bundler=(flag)
121
- @private_bundler =
122
- if flag.respond_to?(:to_str) then File.expand_path(flag)
123
- elsif flag
124
- File.join(dot_autoproj, 'bundler')
125
- end
126
+ # The user-wide place where RubyGems installs gems
127
+ def dot_gem_dir
128
+ File.join(Gem.user_home, ".gem")
126
129
  end
127
130
 
128
- # Whether autoproj should be installed locally in {#dot_autoproj}
129
- def private_autoproj?; !!@private_autoproj end
130
- # The path to the directory into which the autoproj gem should be
131
- # installed
132
- def autoproj_gem_home; @private_autoproj || Gem.user_dir end
133
- # (see #private_autoproj?)
134
- def private_autoproj=(flag)
135
- @private_autoproj =
136
- if flag.respond_to?(:to_str) then File.expand_path(flag)
137
- elsif flag
138
- File.join(dot_autoproj, 'autoproj')
139
- end
131
+ # The version and platform-specific suffix under {#dot_gem_dir}
132
+ #
133
+ # This is also the suffix used by bundler to install gems
134
+ def gem_path_suffix
135
+ @gem_path_suffix ||= Pathname.new(Gem.user_dir).
136
+ relative_path_from(Pathname.new(dot_gem_dir)).to_s
140
137
  end
141
138
 
142
- # Whether autoproj should be installed locally in {#dot_autoproj}
139
+ # The path into which autoproj and its dependencies should be installed
143
140
  #
144
- # Unlike for {#private_autoproj?} and {#private_bundler?}, there is
145
- # no default path to save the gems as we don't yet know the path to
146
- # the prefix directory
147
- def private_gems?; !!@private_gems end
148
- # (see #private_gems?)
149
- def private_gems=(value)
150
- @private_gems =
151
- if value.respond_to?(:to_str) then File.expand_path(value)
152
- else value
153
- end
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
+ # The path into which the workspace's gems should be installed
161
+ #
162
+ # 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.
166
+ #
167
+ # @return [String]
168
+ attr_reader :gems_install_path
169
+ # The GEM_HOME under which the workspace's gems should be installed
170
+ #
171
+ # @return [String]
172
+ def gems_gem_home; File.join(gems_install_path, gem_path_suffix) end
173
+ # Sets where the workspace's gems should be installed
174
+ #
175
+ # @param [String] path the absolute path that should be given to
176
+ # bundler. The gems themselves will be installed in the
177
+ # {#gem_path_suffix} subdirectory under this
178
+ def gems_install_path=(path)
179
+ @gems_install_path = path
180
+ end
181
+ # Install autoproj in Gem's default user dir
182
+ def install_gems_in_gem_user_dir
183
+ @gems_install_path = File.join(Gem.user_home, '.gem')
154
184
  end
155
185
 
156
186
  # Whether autoproj should prefer OS-independent packages over their
157
187
  # OS-packaged equivalents (e.g. the thor gem vs. the ruby-thor
158
188
  # Debian package)
159
189
  def prefer_indep_over_os_packages?; @prefer_indep_over_os_packages end
160
- # (see #private_gems?)
190
+ # (see #prefer_index_over_os_packages?)
161
191
  def prefer_indep_over_os_packages=(flag); @prefer_indep_over_os_packages = !!flag end
162
192
 
163
193
  def guess_gem_program
@@ -183,40 +213,32 @@ module Autoproj
183
213
  # that should be used
184
214
  # @return [String]
185
215
  def default_gemfile_contents(autoproj_version = ">= 2.0.0.a")
186
- ["source \"https://rubygems.org\"",
216
+ ["source \"#{gem_source}\"",
187
217
  "gem \"autoproj\", \"#{autoproj_version}\"",
188
218
  "gem \"utilrb\", \">= 3.0.0.a\""].join("\n")
189
219
  end
190
220
 
191
221
  # Parse the provided command line options and returns the non-options
192
222
  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
-
198
223
  options = OptionParser.new do |opt|
199
224
  opt.on '--local', 'do not access the network (may fail)' do
200
225
  @local = true
201
226
  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
207
- opt.on '--private-bundler[=PATH]', 'install bundler locally in the workspace, or in a dedicated path' do |path|
208
- self.private_bundler = path || true
227
+ opt.on '--gem-source=URL', String, "use this source for RubyGems instead of rubygems.org" do |url|
228
+ self.gem_source = url
209
229
  end
210
- opt.on '--private-autoproj[=PATH]', 'install autoproj locally in the workspace, or in a dedicated path' do |path|
211
- self.private_autoproj = path || true
212
- end
213
- opt.on '--private-gems[=PATH]', 'install gems locally in the prefix directory, or in a dedicated path' do |path|
214
- self.private_gems = path || true
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
215
238
  end
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|
217
- self.private_bundler = path || true
218
- self.private_autoproj = path || true
219
- self.private_gems = path || true
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'
220
242
  end
221
243
  opt.on '--version=VERSION_CONSTRAINT', String, 'use the provided string as a version constraint for autoproj' do |version|
222
244
  @gemfile = default_gemfile_contents(version)
@@ -247,12 +269,12 @@ module Autoproj
247
269
 
248
270
  def find_bundler(gem_program)
249
271
  result = system(
250
- env_for_child.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_home),
272
+ env_for_child,
251
273
  Gem.ruby, gem_program, 'which', 'bundler/setup',
252
274
  out: '/dev/null')
253
275
  return if !result
254
276
 
255
- bundler_path = File.join(bundler_gem_home, 'bin', 'bundler')
277
+ bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
256
278
  if File.exist?(bundler_path)
257
279
  bundler_path
258
280
  end
@@ -262,17 +284,17 @@ module Autoproj
262
284
  local = ['--local'] if local?
263
285
 
264
286
  result = system(
265
- env_for_child.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_home),
266
- Gem.ruby, gem_program, 'install', '--env-shebang', '--no-document', '--no-format-executable',
287
+ env_for_child,
288
+ Gem.ruby, gem_program, 'install', '--env-shebang', '--no-document', '--no-format-executable', '--clear-sources', '--source', gem_source,
267
289
  *local,
268
- "--bindir=#{File.join(bundler_gem_home, 'bin')}", 'bundler')
290
+ "--bindir=#{File.join(autoproj_gem_home, 'bin')}", 'bundler')
269
291
 
270
292
  if !result
271
- STDERR.puts "FATAL: failed to install bundler in #{bundler_gem_home}"
293
+ STDERR.puts "FATAL: failed to install bundler in #{autoproj_gem_home}"
272
294
  nil
273
295
  end
274
296
 
275
- bundler_path = File.join(bundler_gem_home, 'bin', 'bundler')
297
+ bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
276
298
  if File.exist?(bundler_path)
277
299
  bundler_path
278
300
  else
@@ -284,7 +306,7 @@ module Autoproj
284
306
  def install_autoproj(bundler)
285
307
  # Force bundler to update. If the user does not want this, let him specify a
286
308
  # Gemfile with tighter version constraints
287
- lockfile = File.join(autoproj_install_dir, 'Gemfile.lock')
309
+ lockfile = File.join(dot_autoproj, 'Gemfile.lock')
288
310
  if File.exist?(lockfile)
289
311
  FileUtils.rm lockfile
290
312
  end
@@ -293,30 +315,26 @@ module Autoproj
293
315
 
294
316
  opts = Array.new
295
317
  opts << '--local' if local?
296
- if private_autoproj?
297
- clean_env['GEM_PATH'] = bundler_gem_home
298
- clean_env['GEM_HOME'] = nil
299
- opts << "--path=#{autoproj_gem_home}"
300
- end
301
- binstubs_path = File.join(autoproj_install_dir, 'bin')
302
- result = system(clean_env.merge('GEM_HOME' => autoproj_gem_home),
318
+ opts << "--path=#{autoproj_install_path}"
319
+ shims_path = File.join(dot_autoproj, 'bin')
320
+ result = system(clean_env,
303
321
  Gem.ruby, bundler, 'install',
304
322
  "--gemfile=#{autoproj_gemfile_path}",
305
323
  "--shebang=#{Gem.ruby}",
306
- "--binstubs=#{binstubs_path}",
307
- *opts, chdir: autoproj_install_dir)
324
+ "--binstubs=#{shims_path}",
325
+ *opts, chdir: dot_autoproj)
308
326
 
309
327
  if !result
310
328
  STDERR.puts "FATAL: failed to install autoproj in #{dot_autoproj}"
311
329
  exit 1
312
330
  end
313
331
  ensure
314
- self.class.clean_binstubs(binstubs_path)
332
+ self.class.clean_binstubs(shims_path, ruby_executable, bundler)
315
333
  end
316
334
 
317
- def self.clean_binstubs(binstubs_path)
318
- %w{bundler bundle rake thor}.each do |bundler_bin|
319
- path = File.join(binstubs_path, bundler_bin)
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)
320
338
  if File.file?(path)
321
339
  FileUtils.rm path
322
340
  end
@@ -325,7 +343,7 @@ module Autoproj
325
343
  # Now tune the binstubs to force the usage of the autoproj
326
344
  # gemfile. Otherwise, they get BUNDLE_GEMFILE from the
327
345
  # environment by default
328
- Dir.glob(File.join(binstubs_path, '*')) do |path|
346
+ Dir.glob(File.join(shim_path, '*')) do |path|
329
347
  next if !File.file?(path)
330
348
 
331
349
  lines = File.readlines(path)
@@ -341,6 +359,9 @@ module Autoproj
341
359
  io.write filtered.join("")
342
360
  end
343
361
  end
362
+
363
+ ensure
364
+ save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
344
365
  end
345
366
 
346
367
  def save_env_sh(*vars)
@@ -413,8 +434,9 @@ module Autoproj
413
434
  end
414
435
  end
415
436
 
416
- def save_ruby_and_bundler_shims(bundler_path)
437
+ def self.save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
417
438
  FileUtils.mkdir_p shim_path
439
+ bundler_rubylib = File.expand_path(File.join('..', '..', 'lib'), bundler_path)
418
440
  File.open(File.join(shim_path, 'bundler'), 'w') do |io|
419
441
  io.puts "#! /bin/sh"
420
442
  io.puts "exec #{ruby_executable} #{bundler_path} \"$@\""
@@ -434,25 +456,25 @@ module Autoproj
434
456
 
435
457
  gem_program = guess_gem_program
436
458
  puts "Detected 'gem' to be #{gem_program}"
459
+ env['GEM_HOME'] = [autoproj_gem_home]
437
460
 
438
461
  if bundler = find_bundler(gem_program)
439
462
  puts "Detected bundler at #{bundler}"
440
463
  else
441
- puts "Installing bundler in #{bundler_gem_home}"
464
+ puts "Installing bundler in #{autoproj_gem_home}"
442
465
  if !(bundler = install_bundler(gem_program))
443
466
  exit 1
444
467
  end
445
- if private_bundler?
446
- env['GEM_PATH'].unshift bundler_gem_home
447
- end
448
468
  end
449
- save_ruby_and_bundler_shims(bundler)
450
- env['PATH'].unshift shim_path
469
+ self.class.save_ruby_and_bundler_shims(
470
+ File.join(dot_autoproj, 'bin'),
471
+ ruby_executable,
472
+ bundler)
473
+ env['PATH'].unshift File.join(dot_autoproj, 'bin')
451
474
  save_gemfile
452
475
 
453
- puts "Installing autoproj#{" in #{autoproj_gem_home}" if private_autoproj?}"
476
+ puts "Installing autoproj in #{autoproj_gem_home}"
454
477
  install_autoproj(bundler)
455
- env['PATH'].unshift File.join(dot_autoproj, 'autoproj', 'bin')
456
478
  end
457
479
 
458
480
  def load_config
@@ -478,21 +500,20 @@ module Autoproj
478
500
  end
479
501
 
480
502
  @config = config
481
- %w{private_bundler private_gems private_autoproj prefer_indep_over_os_packages}.each do |flag|
503
+ %w{autoproj_install_path gems_install_path prefer_indep_over_os_packages}.each do |flag|
482
504
  instance_variable_set "@#{flag}", config.fetch(flag, false)
483
505
  end
484
506
  end
485
507
 
486
508
  def save_config
487
- config['private_bundler'] = (bundler_gem_home if private_bundler?)
488
- config['private_autoproj'] = (autoproj_gem_home if private_autoproj?)
489
- config['private_gems'] = @private_gems
509
+ config['autoproj_install_path'] = autoproj_install_path
510
+ config['gems_install_path'] = gems_install_path
490
511
  config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
491
512
  File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
492
513
  end
493
514
 
494
515
  def autoproj_path
495
- File.join(autoproj_install_dir, 'bin', 'autoproj')
516
+ File.join(dot_autoproj, 'bin', 'autoproj')
496
517
  end
497
518
 
498
519
  def run_autoproj(*args)
@@ -531,11 +552,13 @@ module Autoproj
531
552
  puts "saving env.sh and .autoproj/env.sh"
532
553
  save_env_sh(*vars)
533
554
  if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options)
555
+ STDERR.puts "failed to run autoproj envsh on the newly installed autoproj (#{autoproj_path})"
534
556
  exit 1
535
557
  end
536
558
  # This is really needed on an existing install to install the
537
559
  # gems that were present in the v1 layout
538
560
  if !system(Gem.ruby, autoproj_path, 'osdeps')
561
+ STDERR.puts "failed to run autoproj osdeps on the newly installed autoproj (#{autoproj_path})"
539
562
  exit 1
540
563
  end
541
564
  end
data/bin/autoproj_install CHANGED
@@ -36,6 +36,8 @@ module Autoproj
36
36
  attr_reader :autoproj_options
37
37
  # The Ruby interpreter we use for this install
38
38
  attr_reader :ruby_executable
39
+ # The URL of the source to be used to get gems
40
+ attr_accessor :gem_source
39
41
 
40
42
  def initialize(root_dir)
41
43
  @root_dir = root_dir
@@ -44,6 +46,7 @@ module Autoproj
44
46
  else
45
47
  @gemfile = default_gemfile_contents
46
48
  end
49
+ @gem_source = "https://rubygems.org"
47
50
 
48
51
  @autoproj_options = Array.new
49
52
 
@@ -60,6 +63,10 @@ module Autoproj
60
63
  end
61
64
  @ruby_executable = config['ruby_executable']
62
65
  @local = false
66
+
67
+ default_gem_path = File.join(Dir.home, '.autoproj', 'gems')
68
+ @gems_install_path = default_gem_path
69
+ @autoproj_install_path = default_gem_path
63
70
  end
64
71
 
65
72
  def env_for_child
@@ -96,68 +103,91 @@ module Autoproj
96
103
  return false
97
104
  end
98
105
 
99
-
106
+ # The path to the .autoproj configuration directory
107
+ #
108
+ # @return [String]
100
109
  def dot_autoproj; File.join(root_dir, '.autoproj') end
101
110
 
102
- def autoproj_install_dir; File.join(dot_autoproj, 'autoproj') end
103
111
  # The path to the gemfile used to install autoproj
104
- def autoproj_gemfile_path; File.join(autoproj_install_dir, 'Gemfile') end
105
- def autoproj_config_path; File.join(dot_autoproj, 'config.yml') end
112
+ #
113
+ # @return [String]
114
+ def autoproj_gemfile_path; File.join(dot_autoproj, 'Gemfile') end
106
115
 
107
- def shim_path; File.join(dot_autoproj, 'bin') end
116
+ # The path to the autoproj configuration file
117
+ #
118
+ # @return [String]
119
+ def autoproj_config_path; File.join(dot_autoproj, 'config.yml') end
108
120
 
109
121
  # Whether we can access the network while installing
110
122
  def local?; !!@local end
111
123
  # (see #local?)
112
124
  def local=(flag); @local = flag end
113
125
 
114
- # Whether bundler should be installed locally in {#dot_autoproj}
115
- def private_bundler?; !!@private_bundler end
116
- # The path to the directory into which the bundler gem should be
117
- # installed
118
- def bundler_gem_home; @private_bundler || Gem.user_dir end
119
- # (see #private_bundler?)
120
- def private_bundler=(flag)
121
- @private_bundler =
122
- if flag.respond_to?(:to_str) then File.expand_path(flag)
123
- elsif flag
124
- File.join(dot_autoproj, 'bundler')
125
- end
126
+ # The user-wide place where RubyGems installs gems
127
+ def dot_gem_dir
128
+ File.join(Gem.user_home, ".gem")
126
129
  end
127
130
 
128
- # Whether autoproj should be installed locally in {#dot_autoproj}
129
- def private_autoproj?; !!@private_autoproj end
130
- # The path to the directory into which the autoproj gem should be
131
- # installed
132
- def autoproj_gem_home; @private_autoproj || Gem.user_dir end
133
- # (see #private_autoproj?)
134
- def private_autoproj=(flag)
135
- @private_autoproj =
136
- if flag.respond_to?(:to_str) then File.expand_path(flag)
137
- elsif flag
138
- File.join(dot_autoproj, 'autoproj')
139
- end
131
+ # The version and platform-specific suffix under {#dot_gem_dir}
132
+ #
133
+ # This is also the suffix used by bundler to install gems
134
+ def gem_path_suffix
135
+ @gem_path_suffix ||= Pathname.new(Gem.user_dir).
136
+ relative_path_from(Pathname.new(dot_gem_dir)).to_s
140
137
  end
141
138
 
142
- # Whether autoproj should be installed locally in {#dot_autoproj}
139
+ # The path into which autoproj and its dependencies should be installed
143
140
  #
144
- # Unlike for {#private_autoproj?} and {#private_bundler?}, there is
145
- # no default path to save the gems as we don't yet know the path to
146
- # the prefix directory
147
- def private_gems?; !!@private_gems end
148
- # (see #private_gems?)
149
- def private_gems=(value)
150
- @private_gems =
151
- if value.respond_to?(:to_str) then File.expand_path(value)
152
- else value
153
- end
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
+ # The path into which the workspace's gems should be installed
161
+ #
162
+ # 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.
166
+ #
167
+ # @return [String]
168
+ attr_reader :gems_install_path
169
+ # The GEM_HOME under which the workspace's gems should be installed
170
+ #
171
+ # @return [String]
172
+ def gems_gem_home; File.join(gems_install_path, gem_path_suffix) end
173
+ # Sets where the workspace's gems should be installed
174
+ #
175
+ # @param [String] path the absolute path that should be given to
176
+ # bundler. The gems themselves will be installed in the
177
+ # {#gem_path_suffix} subdirectory under this
178
+ def gems_install_path=(path)
179
+ @gems_install_path = path
180
+ end
181
+ # Install autoproj in Gem's default user dir
182
+ def install_gems_in_gem_user_dir
183
+ @gems_install_path = File.join(Gem.user_home, '.gem')
154
184
  end
155
185
 
156
186
  # Whether autoproj should prefer OS-independent packages over their
157
187
  # OS-packaged equivalents (e.g. the thor gem vs. the ruby-thor
158
188
  # Debian package)
159
189
  def prefer_indep_over_os_packages?; @prefer_indep_over_os_packages end
160
- # (see #private_gems?)
190
+ # (see #prefer_index_over_os_packages?)
161
191
  def prefer_indep_over_os_packages=(flag); @prefer_indep_over_os_packages = !!flag end
162
192
 
163
193
  def guess_gem_program
@@ -183,40 +213,32 @@ module Autoproj
183
213
  # that should be used
184
214
  # @return [String]
185
215
  def default_gemfile_contents(autoproj_version = ">= 2.0.0.a")
186
- ["source \"https://rubygems.org\"",
216
+ ["source \"#{gem_source}\"",
187
217
  "gem \"autoproj\", \"#{autoproj_version}\"",
188
218
  "gem \"utilrb\", \">= 3.0.0.a\""].join("\n")
189
219
  end
190
220
 
191
221
  # Parse the provided command line options and returns the non-options
192
222
  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
-
198
223
  options = OptionParser.new do |opt|
199
224
  opt.on '--local', 'do not access the network (may fail)' do
200
225
  @local = true
201
226
  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
207
- opt.on '--private-bundler[=PATH]', 'install bundler locally in the workspace, or in a dedicated path' do |path|
208
- self.private_bundler = path || true
227
+ opt.on '--gem-source=URL', String, "use this source for RubyGems instead of rubygems.org" do |url|
228
+ self.gem_source = url
209
229
  end
210
- opt.on '--private-autoproj[=PATH]', 'install autoproj locally in the workspace, or in a dedicated path' do |path|
211
- self.private_autoproj = path || true
212
- end
213
- opt.on '--private-gems[=PATH]', 'install gems locally in the prefix directory, or in a dedicated path' do |path|
214
- self.private_gems = path || true
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
215
238
  end
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|
217
- self.private_bundler = path || true
218
- self.private_autoproj = path || true
219
- self.private_gems = path || true
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'
220
242
  end
221
243
  opt.on '--version=VERSION_CONSTRAINT', String, 'use the provided string as a version constraint for autoproj' do |version|
222
244
  @gemfile = default_gemfile_contents(version)
@@ -247,12 +269,12 @@ module Autoproj
247
269
 
248
270
  def find_bundler(gem_program)
249
271
  result = system(
250
- env_for_child.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_home),
272
+ env_for_child,
251
273
  Gem.ruby, gem_program, 'which', 'bundler/setup',
252
274
  out: '/dev/null')
253
275
  return if !result
254
276
 
255
- bundler_path = File.join(bundler_gem_home, 'bin', 'bundler')
277
+ bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
256
278
  if File.exist?(bundler_path)
257
279
  bundler_path
258
280
  end
@@ -262,17 +284,17 @@ module Autoproj
262
284
  local = ['--local'] if local?
263
285
 
264
286
  result = system(
265
- env_for_child.merge('GEM_PATH' => "", 'GEM_HOME' => bundler_gem_home),
266
- Gem.ruby, gem_program, 'install', '--env-shebang', '--no-document', '--no-format-executable',
287
+ env_for_child,
288
+ Gem.ruby, gem_program, 'install', '--env-shebang', '--no-document', '--no-format-executable', '--clear-sources', '--source', gem_source,
267
289
  *local,
268
- "--bindir=#{File.join(bundler_gem_home, 'bin')}", 'bundler')
290
+ "--bindir=#{File.join(autoproj_gem_home, 'bin')}", 'bundler')
269
291
 
270
292
  if !result
271
- STDERR.puts "FATAL: failed to install bundler in #{bundler_gem_home}"
293
+ STDERR.puts "FATAL: failed to install bundler in #{autoproj_gem_home}"
272
294
  nil
273
295
  end
274
296
 
275
- bundler_path = File.join(bundler_gem_home, 'bin', 'bundler')
297
+ bundler_path = File.join(autoproj_gem_home, 'bin', 'bundler')
276
298
  if File.exist?(bundler_path)
277
299
  bundler_path
278
300
  else
@@ -284,7 +306,7 @@ module Autoproj
284
306
  def install_autoproj(bundler)
285
307
  # Force bundler to update. If the user does not want this, let him specify a
286
308
  # Gemfile with tighter version constraints
287
- lockfile = File.join(autoproj_install_dir, 'Gemfile.lock')
309
+ lockfile = File.join(dot_autoproj, 'Gemfile.lock')
288
310
  if File.exist?(lockfile)
289
311
  FileUtils.rm lockfile
290
312
  end
@@ -293,30 +315,26 @@ module Autoproj
293
315
 
294
316
  opts = Array.new
295
317
  opts << '--local' if local?
296
- if private_autoproj?
297
- clean_env['GEM_PATH'] = bundler_gem_home
298
- clean_env['GEM_HOME'] = nil
299
- opts << "--path=#{autoproj_gem_home}"
300
- end
301
- binstubs_path = File.join(autoproj_install_dir, 'bin')
302
- result = system(clean_env.merge('GEM_HOME' => autoproj_gem_home),
318
+ opts << "--path=#{autoproj_install_path}"
319
+ shims_path = File.join(dot_autoproj, 'bin')
320
+ result = system(clean_env,
303
321
  Gem.ruby, bundler, 'install',
304
322
  "--gemfile=#{autoproj_gemfile_path}",
305
323
  "--shebang=#{Gem.ruby}",
306
- "--binstubs=#{binstubs_path}",
307
- *opts, chdir: autoproj_install_dir)
324
+ "--binstubs=#{shims_path}",
325
+ *opts, chdir: dot_autoproj)
308
326
 
309
327
  if !result
310
328
  STDERR.puts "FATAL: failed to install autoproj in #{dot_autoproj}"
311
329
  exit 1
312
330
  end
313
331
  ensure
314
- self.class.clean_binstubs(binstubs_path)
332
+ self.class.clean_binstubs(shims_path, ruby_executable, bundler)
315
333
  end
316
334
 
317
- def self.clean_binstubs(binstubs_path)
318
- %w{bundler bundle rake thor}.each do |bundler_bin|
319
- path = File.join(binstubs_path, bundler_bin)
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)
320
338
  if File.file?(path)
321
339
  FileUtils.rm path
322
340
  end
@@ -325,7 +343,7 @@ module Autoproj
325
343
  # Now tune the binstubs to force the usage of the autoproj
326
344
  # gemfile. Otherwise, they get BUNDLE_GEMFILE from the
327
345
  # environment by default
328
- Dir.glob(File.join(binstubs_path, '*')) do |path|
346
+ Dir.glob(File.join(shim_path, '*')) do |path|
329
347
  next if !File.file?(path)
330
348
 
331
349
  lines = File.readlines(path)
@@ -341,6 +359,9 @@ module Autoproj
341
359
  io.write filtered.join("")
342
360
  end
343
361
  end
362
+
363
+ ensure
364
+ save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
344
365
  end
345
366
 
346
367
  def save_env_sh(*vars)
@@ -413,8 +434,9 @@ module Autoproj
413
434
  end
414
435
  end
415
436
 
416
- def save_ruby_and_bundler_shims(bundler_path)
437
+ def self.save_ruby_and_bundler_shims(shim_path, ruby_executable, bundler_path)
417
438
  FileUtils.mkdir_p shim_path
439
+ bundler_rubylib = File.expand_path(File.join('..', '..', 'lib'), bundler_path)
418
440
  File.open(File.join(shim_path, 'bundler'), 'w') do |io|
419
441
  io.puts "#! /bin/sh"
420
442
  io.puts "exec #{ruby_executable} #{bundler_path} \"$@\""
@@ -434,25 +456,25 @@ module Autoproj
434
456
 
435
457
  gem_program = guess_gem_program
436
458
  puts "Detected 'gem' to be #{gem_program}"
459
+ env['GEM_HOME'] = [autoproj_gem_home]
437
460
 
438
461
  if bundler = find_bundler(gem_program)
439
462
  puts "Detected bundler at #{bundler}"
440
463
  else
441
- puts "Installing bundler in #{bundler_gem_home}"
464
+ puts "Installing bundler in #{autoproj_gem_home}"
442
465
  if !(bundler = install_bundler(gem_program))
443
466
  exit 1
444
467
  end
445
- if private_bundler?
446
- env['GEM_PATH'].unshift bundler_gem_home
447
- end
448
468
  end
449
- save_ruby_and_bundler_shims(bundler)
450
- env['PATH'].unshift shim_path
469
+ self.class.save_ruby_and_bundler_shims(
470
+ File.join(dot_autoproj, 'bin'),
471
+ ruby_executable,
472
+ bundler)
473
+ env['PATH'].unshift File.join(dot_autoproj, 'bin')
451
474
  save_gemfile
452
475
 
453
- puts "Installing autoproj#{" in #{autoproj_gem_home}" if private_autoproj?}"
476
+ puts "Installing autoproj in #{autoproj_gem_home}"
454
477
  install_autoproj(bundler)
455
- env['PATH'].unshift File.join(dot_autoproj, 'autoproj', 'bin')
456
478
  end
457
479
 
458
480
  def load_config
@@ -478,21 +500,20 @@ module Autoproj
478
500
  end
479
501
 
480
502
  @config = config
481
- %w{private_bundler private_gems private_autoproj prefer_indep_over_os_packages}.each do |flag|
503
+ %w{autoproj_install_path gems_install_path prefer_indep_over_os_packages}.each do |flag|
482
504
  instance_variable_set "@#{flag}", config.fetch(flag, false)
483
505
  end
484
506
  end
485
507
 
486
508
  def save_config
487
- config['private_bundler'] = (bundler_gem_home if private_bundler?)
488
- config['private_autoproj'] = (autoproj_gem_home if private_autoproj?)
489
- config['private_gems'] = @private_gems
509
+ config['autoproj_install_path'] = autoproj_install_path
510
+ config['gems_install_path'] = gems_install_path
490
511
  config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
491
512
  File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
492
513
  end
493
514
 
494
515
  def autoproj_path
495
- File.join(autoproj_install_dir, 'bin', 'autoproj')
516
+ File.join(dot_autoproj, 'bin', 'autoproj')
496
517
  end
497
518
 
498
519
  def run_autoproj(*args)
@@ -531,11 +552,13 @@ module Autoproj
531
552
  puts "saving env.sh and .autoproj/env.sh"
532
553
  save_env_sh(*vars)
533
554
  if !system(Gem.ruby, autoproj_path, 'envsh', *autoproj_options)
555
+ STDERR.puts "failed to run autoproj envsh on the newly installed autoproj (#{autoproj_path})"
534
556
  exit 1
535
557
  end
536
558
  # This is really needed on an existing install to install the
537
559
  # gems that were present in the v1 layout
538
560
  if !system(Gem.ruby, autoproj_path, 'osdeps')
561
+ STDERR.puts "failed to run autoproj osdeps on the newly installed autoproj (#{autoproj_path})"
539
562
  exit 1
540
563
  end
541
564
  end