autoproj 2.0.0.rc5 → 2.0.0.rc6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/autoproj_bootstrap +158 -115
- data/bin/autoproj_install +159 -116
- data/bin/autoproj_install.in +1 -1
- data/lib/autoproj/autobuild.rb +2 -2
- data/lib/autoproj/cli/main.rb +13 -13
- data/lib/autoproj/cli/switch_config.rb +7 -2
- data/lib/autoproj/cli/update.rb +1 -8
- data/lib/autoproj/configuration.rb +10 -0
- data/lib/autoproj/environment.rb +3 -5
- data/lib/autoproj/ops/import.rb +5 -1
- data/lib/autoproj/ops/install.rb +158 -115
- data/lib/autoproj/ops/snapshot.rb +11 -3
- data/lib/autoproj/os_package_installer.rb +1 -1
- data/lib/autoproj/os_package_resolver.rb +31 -51
- data/lib/autoproj/package_managers/bundler_manager.rb +29 -29
- data/lib/autoproj/package_managers/gem_manager.rb +1 -1
- data/lib/autoproj/package_managers/shell_script_manager.rb +1 -1
- data/lib/autoproj/version.rb +1 -1
- data/lib/autoproj/workspace.rb +46 -9
- metadata +2 -3
- data/lib/autoproj/cli/upgrade.rb +0 -75
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 41b7b5cc8969f1630e17120dd32b47332d17c005
|
4
|
+
data.tar.gz: 8f58b3e604cd28f113130babad1734142022f7c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6804b7d07665ef3d29456b01c267c27f59f7c5244a7af3cf4466b8c0a8e55e61604eedf6a1af723b24c4804ec988679f3732d9a799d2a963550245636aa01a9
|
7
|
+
data.tar.gz: a81c7bb354134172817c912e2031400b89d687e54d3d9c9c9bc4e76b6329150d84ccf5d9f81e3d58ed085d892660c1a8f701a1bacbcae8cd80bcd172dd13c97f
|
data/bin/autoproj_bootstrap
CHANGED
@@ -26,6 +26,8 @@ module Autoproj
|
|
26
26
|
attr_accessor :gemfile
|
27
27
|
# The environment that is passed to the bundler installs
|
28
28
|
attr_reader :env
|
29
|
+
# The configuration hash
|
30
|
+
attr_reader :config
|
29
31
|
|
30
32
|
def initialize(root_dir)
|
31
33
|
@root_dir = root_dir
|
@@ -35,9 +37,7 @@ module Autoproj
|
|
35
37
|
@gemfile = default_gemfile_contents
|
36
38
|
end
|
37
39
|
|
38
|
-
|
39
|
-
@private_autoproj = false
|
40
|
-
@private_gems = false
|
40
|
+
load_config
|
41
41
|
@local = false
|
42
42
|
@env = self.class.clean_env
|
43
43
|
end
|
@@ -49,7 +49,7 @@ module Autoproj
|
|
49
49
|
%w{PATH GEM_HOME}.each do |name|
|
50
50
|
env[name] = sanitize_env(ENV[name] || "")
|
51
51
|
end
|
52
|
-
env['BUNDLE_GEMFILE'] =
|
52
|
+
env['BUNDLE_GEMFILE'] = []
|
53
53
|
env
|
54
54
|
end
|
55
55
|
|
@@ -60,6 +60,16 @@ module Autoproj
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
def apply_env(env)
|
64
|
+
env.each do |k, v|
|
65
|
+
if v
|
66
|
+
ENV[k] = v
|
67
|
+
else
|
68
|
+
ENV.delete(k)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
63
73
|
def self.sanitize_env(value)
|
64
74
|
value.split(File::PATH_SEPARATOR).
|
65
75
|
find_all { |p| !in_workspace?(p) }
|
@@ -78,7 +88,6 @@ module Autoproj
|
|
78
88
|
|
79
89
|
|
80
90
|
def dot_autoproj; File.join(root_dir, '.autoproj') end
|
81
|
-
def bin_dir; File.join(dot_autoproj, 'bin') end
|
82
91
|
def bundler_install_dir; File.join(dot_autoproj, 'bundler') end
|
83
92
|
def autoproj_install_dir; File.join(dot_autoproj, 'autoproj') end
|
84
93
|
# The path to the gemfile used to install autoproj
|
@@ -93,16 +102,22 @@ module Autoproj
|
|
93
102
|
# Whether bundler should be installed locally in {#dot_autoproj}
|
94
103
|
def private_bundler?; @private_bundler end
|
95
104
|
# (see #private_bundler?)
|
96
|
-
def private_bundler=(flag); @private_bundler = flag end
|
105
|
+
def private_bundler=(flag); @private_bundler = !!flag end
|
97
106
|
# Whether autoproj should be installed locally in {#dot_autoproj}
|
98
107
|
def private_autoproj?; @private_autoproj end
|
99
108
|
# (see #private_autoproj?)
|
100
|
-
def private_autoproj=(flag); @private_autoproj = flag end
|
109
|
+
def private_autoproj=(flag); @private_autoproj = !!flag end
|
101
110
|
# Whether bundler should be installed locally in the workspace
|
102
111
|
# prefix directory
|
103
112
|
def private_gems?; @private_gems end
|
104
113
|
# (see #private_gems?)
|
105
|
-
def private_gems=(flag); @private_gems = flag end
|
114
|
+
def private_gems=(flag); @private_gems = !!flag end
|
115
|
+
# Whether autoproj should prefer OS-independent packages over their
|
116
|
+
# OS-packaged equivalents (e.g. the thor gem vs. the ruby-thor
|
117
|
+
# Debian package)
|
118
|
+
def prefer_indep_over_os_packages?; @prefer_indep_over_os_packages end
|
119
|
+
# (see #private_gems?)
|
120
|
+
def prefer_indep_over_os_packages=(flag); @prefer_indep_over_os_packages = !!flag end
|
106
121
|
|
107
122
|
def guess_gem_program
|
108
123
|
ruby_bin = RbConfig::CONFIG['RUBY_INSTALL_NAME']
|
@@ -158,6 +173,9 @@ module Autoproj
|
|
158
173
|
opt.on '--gemfile=PATH', String, 'use the given Gemfile to install autoproj instead of the default' do |path|
|
159
174
|
@gemfile = File.read(path)
|
160
175
|
end
|
176
|
+
opt.on '--prefer-os-independent-packages', 'prefer OS-independent packages (such as a RubyGem) over their OS-packaged equivalent (e.g. the thor gem vs. the ruby-thor debian package)' do
|
177
|
+
@prefer_indep_over_os_packages = true
|
178
|
+
end
|
161
179
|
end
|
162
180
|
options.parse(ARGV)
|
163
181
|
end
|
@@ -178,77 +196,72 @@ module Autoproj
|
|
178
196
|
STDERR.puts "FATAL: failed to install bundler in #{dot_autoproj}"
|
179
197
|
exit 1
|
180
198
|
end
|
181
|
-
env['
|
182
|
-
|
183
|
-
File.join(bin_dir, 'bundler')
|
199
|
+
env['PATH'].unshift File.join(bundler_install_dir, 'bin')
|
200
|
+
File.join(bundler_install_dir, 'bin', 'bundler')
|
184
201
|
end
|
185
202
|
|
186
|
-
def
|
187
|
-
env
|
188
|
-
|
203
|
+
def find_bundler
|
204
|
+
self.env['PATH'].unshift gem_bindir
|
205
|
+
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
|
+
]
|
189
210
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
196
228
|
end
|
197
|
-
end
|
198
|
-
env.push_path 'PATH', File.join(autoproj_install_dir, 'bin')
|
199
|
-
|
200
|
-
if private_autoproj?
|
201
|
-
env.push_path 'GEM_PATH', autoproj_install_dir
|
202
|
-
end
|
203
|
-
|
204
|
-
# Generate environment files right now, we can at least use bundler
|
205
|
-
File.open(File.join(dot_autoproj, 'env.sh'), 'w') do |io|
|
206
|
-
env.export_env_sh(io)
|
207
|
-
end
|
208
229
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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}"
|
234
|
+
end
|
214
235
|
end
|
215
|
-
end
|
216
236
|
|
217
|
-
|
218
|
-
FileUtils.mkdir_p File.dirname(autoproj_gemfile_path)
|
219
|
-
File.open(autoproj_gemfile_path, 'w') do |io|
|
220
|
-
io.write gemfile
|
221
|
-
end
|
237
|
+
bundler
|
222
238
|
end
|
223
239
|
|
224
|
-
ENV_BUNDLE_GEMFILE_RX = /^(\s*ENV\[['"]BUNDLE_GEMFILE['"]\]\s*)(?:\|\|)?=/
|
225
|
-
|
226
240
|
def install_autoproj(bundler)
|
227
241
|
# Force bundler to update. If the user does not want this, let him specify a
|
228
242
|
# Gemfile with tighter version constraints
|
229
|
-
lockfile = File.join(File.dirname(
|
243
|
+
lockfile = File.join(File.dirname(autoproj_install_dir), 'Gemfile.lock')
|
230
244
|
if File.exist?(lockfile)
|
231
245
|
FileUtils.rm lockfile
|
232
246
|
end
|
233
247
|
|
234
248
|
opts = Array.new
|
235
|
-
|
249
|
+
clean_env = env_for_child.merge('BUNDLE_GEMFILE' => nil)
|
236
250
|
|
237
|
-
|
251
|
+
opts << '--local' if local?
|
238
252
|
if private_autoproj?
|
239
|
-
|
240
|
-
|
241
|
-
'GEM_HOME' => nil)
|
253
|
+
clean_env['GEM_PATH'] = (bundler_install_dir if private_bundler?)
|
254
|
+
clean_env['GEM_HOME'] = nil
|
242
255
|
opts << "--clean" << "--path=#{autoproj_install_dir}"
|
243
256
|
end
|
244
|
-
|
245
257
|
binstubs_path = File.join(autoproj_install_dir, 'bin')
|
246
|
-
|
247
|
-
result = system(env,
|
258
|
+
result = system(clean_env,
|
248
259
|
Gem.ruby, bundler, 'install',
|
249
260
|
"--gemfile=#{autoproj_gemfile_path}",
|
261
|
+
"--shebang=#{Gem.ruby}",
|
250
262
|
"--binstubs=#{binstubs_path}",
|
251
|
-
*opts)
|
263
|
+
*opts, chdir: autoproj_install_dir)
|
264
|
+
|
252
265
|
if !result
|
253
266
|
STDERR.puts "FATAL: failed to install autoproj in #{dot_autoproj}"
|
254
267
|
exit 1
|
@@ -259,10 +272,6 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
259
272
|
# environment by default
|
260
273
|
Dir.glob(File.join(binstubs_path, '*')) do |path|
|
261
274
|
next if !File.file?(path)
|
262
|
-
# Do NOT do that for bundler, otherwise it will fail with an
|
263
|
-
# "already loaded gemfile" message once we e.g. try to do
|
264
|
-
# 'bundler install --gemfile=NEW_GEMFILE'
|
265
|
-
next if File.basename(path) == 'bundler'
|
266
275
|
|
267
276
|
lines = File.readlines(path)
|
268
277
|
matched = false
|
@@ -278,26 +287,53 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
278
287
|
end
|
279
288
|
end
|
280
289
|
|
281
|
-
env['PATH']
|
290
|
+
env['PATH'].unshift File.join(autoproj_install_dir, 'bin')
|
282
291
|
if private_autoproj?
|
283
|
-
env['GEM_PATH']
|
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')
|
284
297
|
end
|
285
298
|
end
|
286
299
|
|
287
|
-
def
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
300
|
+
def save_env_sh(*vars)
|
301
|
+
env = Autobuild::Environment.new
|
302
|
+
env.prepare
|
303
|
+
vars.each do |kv|
|
304
|
+
k, *v = kv.split("=")
|
305
|
+
v = v.join("=")
|
306
|
+
|
307
|
+
if v.empty?
|
308
|
+
env.unset k
|
309
|
+
else
|
310
|
+
env.set k, *v.split(File::PATH_SEPARATOR)
|
311
|
+
end
|
292
312
|
end
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
313
|
+
# Generate environment files right now, we can at least use bundler
|
314
|
+
File.open(File.join(dot_autoproj, 'env.sh'), 'w') do |io|
|
315
|
+
env.export_env_sh(io)
|
316
|
+
end
|
317
|
+
|
318
|
+
# And now the root envsh
|
319
|
+
env = Autobuild::Environment.new
|
320
|
+
env.source_before File.join(dot_autoproj, 'env.sh')
|
321
|
+
env.set('AUTOPROJ_CURRENT_ROOT', root_dir)
|
322
|
+
File.open(File.join(root_dir, 'env.sh'), 'w') do |io|
|
323
|
+
env.export_env_sh(io)
|
298
324
|
end
|
299
325
|
end
|
300
326
|
|
327
|
+
def save_gemfile
|
328
|
+
FileUtils.mkdir_p File.dirname(autoproj_gemfile_path)
|
329
|
+
File.open(autoproj_gemfile_path, 'w') do |io|
|
330
|
+
io.write gemfile
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
ENV_BUNDLE_GEMFILE_RX = /^(\s*ENV\[['"]BUNDLE_GEMFILE['"]\]\s*)(?:\|\|)?=/
|
335
|
+
|
336
|
+
|
301
337
|
def find_in_clean_path(command)
|
302
338
|
clean_path = env_for_child['PATH'].split(File::PATH_SEPARATOR)
|
303
339
|
clean_path.each do |p|
|
@@ -309,12 +345,10 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
309
345
|
nil
|
310
346
|
end
|
311
347
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
'GEM_PATH' => clean_env['GEM_PATH'] || nil
|
317
|
-
]
|
348
|
+
# The path of the bin/ folder for installed gems
|
349
|
+
def gem_bindir
|
350
|
+
return @gem_bindir if @gem_bindir
|
351
|
+
|
318
352
|
# Here, we're getting into the esotheric
|
319
353
|
#
|
320
354
|
# The problem is that e.g. Ubuntu and Debian install an
|
@@ -325,30 +359,12 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
325
359
|
#
|
326
360
|
# So, we're calling 'gem' as a subcommand to discovery the
|
327
361
|
# actual bindir
|
328
|
-
bindir = IO.popen(
|
362
|
+
bindir = IO.popen(env_for_child, [Gem.ruby, '-e', 'puts Gem.bindir']).read
|
329
363
|
if bindir
|
330
|
-
|
364
|
+
@gem_bindir = bindir.chomp
|
331
365
|
else
|
332
|
-
|
333
|
-
exit 1
|
366
|
+
raise "FATAL: cannot run #{Gem.ruby} -e 'puts Gem.bindir'"
|
334
367
|
end
|
335
|
-
|
336
|
-
bundler = find_in_clean_path('bundler')
|
337
|
-
if !bundler
|
338
|
-
clean_path = env_for_child['PATH']
|
339
|
-
STDERR.puts "FATAL: cannot find 'bundler' in PATH=#{clean_path}"
|
340
|
-
if ENV['PATH'] != clean_path
|
341
|
-
STDERR.puts " it appears that you already have some autoproj-generated env.sh loaded"
|
342
|
-
STDERR.puts " - if you are running 'autoproj upgrade', please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
|
343
|
-
STDERR.puts " - if you are running an install, try again in a console where the env.sh is not loaded"
|
344
|
-
exit 1
|
345
|
-
else
|
346
|
-
STDERR.puts " the recommended action is to install it manually first by running 'gem install bundler'"
|
347
|
-
STDERR.puts " or call this command again with --private-bundler to have it installed in the workspace"
|
348
|
-
exit 1
|
349
|
-
end
|
350
|
-
end
|
351
|
-
bundler
|
352
368
|
end
|
353
369
|
|
354
370
|
def install
|
@@ -364,27 +380,54 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
364
380
|
install_autoproj(bundler)
|
365
381
|
end
|
366
382
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
383
|
+
def load_config
|
384
|
+
v1_config_path = File.join(root_dir, 'autoproj', 'config.yml')
|
385
|
+
|
386
|
+
config = Hash.new
|
387
|
+
if File.file?(v1_config_path)
|
388
|
+
config.merge!(YAML.load(File.read(v1_config_path)))
|
389
|
+
end
|
390
|
+
if File.file?(autoproj_config_path)
|
391
|
+
config.merge!(YAML.load(File.read(autoproj_config_path)))
|
392
|
+
end
|
374
393
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
else
|
379
|
-
ENV.delete(k)
|
380
|
-
end
|
381
|
-
end
|
382
|
-
ENV['BUNDLE_GEMFILE'] = autoproj_gemfile_path
|
383
|
-
update_configuration
|
384
|
-
exec Gem.ruby, File.join(autoproj_install_dir, 'bin', 'autoproj'),
|
385
|
-
'install-stage2', root_dir
|
394
|
+
@config = config
|
395
|
+
%w{private_bundler private_gems private_autoproj prefer_indep_over_os_packages}.each do |flag|
|
396
|
+
instance_variable_set "@#{flag}", config.fetch(flag, false)
|
386
397
|
end
|
387
398
|
end
|
399
|
+
|
400
|
+
def save_config
|
401
|
+
config['private_bundler'] = private_bundler?
|
402
|
+
config['private_autoproj'] = private_autoproj?
|
403
|
+
config['private_gems'] = private_gems?
|
404
|
+
config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
|
405
|
+
File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
|
406
|
+
end
|
407
|
+
|
408
|
+
def stage1
|
409
|
+
FileUtils.mkdir_p dot_autoproj
|
410
|
+
save_config
|
411
|
+
install
|
412
|
+
|
413
|
+
clean_env = env_for_child
|
414
|
+
stage2_vars = clean_env.map { |k, v| "#{k}=#{v}" }
|
415
|
+
puts "starting the newly installed autoproj for stage2 install"
|
416
|
+
puts [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].inspect
|
419
|
+
exec clean_env.merge('BUNDLE_GEMFILE' => autoproj_gemfile_path),
|
420
|
+
Gem.ruby, File.join(autoproj_install_dir, 'bin', 'autoproj'),
|
421
|
+
'install-stage2', root_dir, *stage2_vars
|
422
|
+
end
|
423
|
+
|
424
|
+
def stage2(*vars)
|
425
|
+
require 'autobuild'
|
426
|
+
puts "saving env.sh and .autoproj/env.sh"
|
427
|
+
save_env_sh(*vars)
|
428
|
+
puts "calling autoproj envsh"
|
429
|
+
system(Gem.ruby, $0, 'envsh')
|
430
|
+
end
|
388
431
|
end
|
389
432
|
end
|
390
433
|
end
|
data/bin/autoproj_install
CHANGED
@@ -26,6 +26,8 @@ module Autoproj
|
|
26
26
|
attr_accessor :gemfile
|
27
27
|
# The environment that is passed to the bundler installs
|
28
28
|
attr_reader :env
|
29
|
+
# The configuration hash
|
30
|
+
attr_reader :config
|
29
31
|
|
30
32
|
def initialize(root_dir)
|
31
33
|
@root_dir = root_dir
|
@@ -35,9 +37,7 @@ module Autoproj
|
|
35
37
|
@gemfile = default_gemfile_contents
|
36
38
|
end
|
37
39
|
|
38
|
-
|
39
|
-
@private_autoproj = false
|
40
|
-
@private_gems = false
|
40
|
+
load_config
|
41
41
|
@local = false
|
42
42
|
@env = self.class.clean_env
|
43
43
|
end
|
@@ -49,7 +49,7 @@ module Autoproj
|
|
49
49
|
%w{PATH GEM_HOME}.each do |name|
|
50
50
|
env[name] = sanitize_env(ENV[name] || "")
|
51
51
|
end
|
52
|
-
env['BUNDLE_GEMFILE'] =
|
52
|
+
env['BUNDLE_GEMFILE'] = []
|
53
53
|
env
|
54
54
|
end
|
55
55
|
|
@@ -60,6 +60,16 @@ module Autoproj
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
def apply_env(env)
|
64
|
+
env.each do |k, v|
|
65
|
+
if v
|
66
|
+
ENV[k] = v
|
67
|
+
else
|
68
|
+
ENV.delete(k)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
63
73
|
def self.sanitize_env(value)
|
64
74
|
value.split(File::PATH_SEPARATOR).
|
65
75
|
find_all { |p| !in_workspace?(p) }
|
@@ -78,7 +88,6 @@ module Autoproj
|
|
78
88
|
|
79
89
|
|
80
90
|
def dot_autoproj; File.join(root_dir, '.autoproj') end
|
81
|
-
def bin_dir; File.join(dot_autoproj, 'bin') end
|
82
91
|
def bundler_install_dir; File.join(dot_autoproj, 'bundler') end
|
83
92
|
def autoproj_install_dir; File.join(dot_autoproj, 'autoproj') end
|
84
93
|
# The path to the gemfile used to install autoproj
|
@@ -93,16 +102,22 @@ module Autoproj
|
|
93
102
|
# Whether bundler should be installed locally in {#dot_autoproj}
|
94
103
|
def private_bundler?; @private_bundler end
|
95
104
|
# (see #private_bundler?)
|
96
|
-
def private_bundler=(flag); @private_bundler = flag end
|
105
|
+
def private_bundler=(flag); @private_bundler = !!flag end
|
97
106
|
# Whether autoproj should be installed locally in {#dot_autoproj}
|
98
107
|
def private_autoproj?; @private_autoproj end
|
99
108
|
# (see #private_autoproj?)
|
100
|
-
def private_autoproj=(flag); @private_autoproj = flag end
|
109
|
+
def private_autoproj=(flag); @private_autoproj = !!flag end
|
101
110
|
# Whether bundler should be installed locally in the workspace
|
102
111
|
# prefix directory
|
103
112
|
def private_gems?; @private_gems end
|
104
113
|
# (see #private_gems?)
|
105
|
-
def private_gems=(flag); @private_gems = flag end
|
114
|
+
def private_gems=(flag); @private_gems = !!flag end
|
115
|
+
# Whether autoproj should prefer OS-independent packages over their
|
116
|
+
# OS-packaged equivalents (e.g. the thor gem vs. the ruby-thor
|
117
|
+
# Debian package)
|
118
|
+
def prefer_indep_over_os_packages?; @prefer_indep_over_os_packages end
|
119
|
+
# (see #private_gems?)
|
120
|
+
def prefer_indep_over_os_packages=(flag); @prefer_indep_over_os_packages = !!flag end
|
106
121
|
|
107
122
|
def guess_gem_program
|
108
123
|
ruby_bin = RbConfig::CONFIG['RUBY_INSTALL_NAME']
|
@@ -158,6 +173,9 @@ module Autoproj
|
|
158
173
|
opt.on '--gemfile=PATH', String, 'use the given Gemfile to install autoproj instead of the default' do |path|
|
159
174
|
@gemfile = File.read(path)
|
160
175
|
end
|
176
|
+
opt.on '--prefer-os-independent-packages', 'prefer OS-independent packages (such as a RubyGem) over their OS-packaged equivalent (e.g. the thor gem vs. the ruby-thor debian package)' do
|
177
|
+
@prefer_indep_over_os_packages = true
|
178
|
+
end
|
161
179
|
end
|
162
180
|
options.parse(ARGV)
|
163
181
|
end
|
@@ -178,77 +196,72 @@ module Autoproj
|
|
178
196
|
STDERR.puts "FATAL: failed to install bundler in #{dot_autoproj}"
|
179
197
|
exit 1
|
180
198
|
end
|
181
|
-
env['
|
182
|
-
|
183
|
-
File.join(bin_dir, 'bundler')
|
199
|
+
env['PATH'].unshift File.join(bundler_install_dir, 'bin')
|
200
|
+
File.join(bundler_install_dir, 'bin', 'bundler')
|
184
201
|
end
|
185
202
|
|
186
|
-
def
|
187
|
-
env
|
188
|
-
|
203
|
+
def find_bundler
|
204
|
+
self.env['PATH'].unshift gem_bindir
|
205
|
+
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
|
+
]
|
189
210
|
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
196
228
|
end
|
197
|
-
end
|
198
|
-
env.push_path 'PATH', File.join(autoproj_install_dir, 'bin')
|
199
|
-
|
200
|
-
if private_autoproj?
|
201
|
-
env.push_path 'GEM_PATH', autoproj_install_dir
|
202
|
-
end
|
203
|
-
|
204
|
-
# Generate environment files right now, we can at least use bundler
|
205
|
-
File.open(File.join(dot_autoproj, 'env.sh'), 'w') do |io|
|
206
|
-
env.export_env_sh(io)
|
207
|
-
end
|
208
229
|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
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}"
|
234
|
+
end
|
214
235
|
end
|
215
|
-
end
|
216
236
|
|
217
|
-
|
218
|
-
FileUtils.mkdir_p File.dirname(autoproj_gemfile_path)
|
219
|
-
File.open(autoproj_gemfile_path, 'w') do |io|
|
220
|
-
io.write gemfile
|
221
|
-
end
|
237
|
+
bundler
|
222
238
|
end
|
223
239
|
|
224
|
-
ENV_BUNDLE_GEMFILE_RX = /^(\s*ENV\[['"]BUNDLE_GEMFILE['"]\]\s*)(?:\|\|)?=/
|
225
|
-
|
226
240
|
def install_autoproj(bundler)
|
227
241
|
# Force bundler to update. If the user does not want this, let him specify a
|
228
242
|
# Gemfile with tighter version constraints
|
229
|
-
lockfile = File.join(File.dirname(
|
243
|
+
lockfile = File.join(File.dirname(autoproj_install_dir), 'Gemfile.lock')
|
230
244
|
if File.exist?(lockfile)
|
231
245
|
FileUtils.rm lockfile
|
232
246
|
end
|
233
247
|
|
234
248
|
opts = Array.new
|
235
|
-
|
249
|
+
clean_env = env_for_child.merge('BUNDLE_GEMFILE' => nil)
|
236
250
|
|
237
|
-
|
251
|
+
opts << '--local' if local?
|
238
252
|
if private_autoproj?
|
239
|
-
|
240
|
-
|
241
|
-
'GEM_HOME' => nil)
|
253
|
+
clean_env['GEM_PATH'] = (bundler_install_dir if private_bundler?)
|
254
|
+
clean_env['GEM_HOME'] = nil
|
242
255
|
opts << "--clean" << "--path=#{autoproj_install_dir}"
|
243
256
|
end
|
244
|
-
|
245
257
|
binstubs_path = File.join(autoproj_install_dir, 'bin')
|
246
|
-
|
247
|
-
result = system(env,
|
258
|
+
result = system(clean_env,
|
248
259
|
Gem.ruby, bundler, 'install',
|
249
260
|
"--gemfile=#{autoproj_gemfile_path}",
|
261
|
+
"--shebang=#{Gem.ruby}",
|
250
262
|
"--binstubs=#{binstubs_path}",
|
251
|
-
*opts)
|
263
|
+
*opts, chdir: autoproj_install_dir)
|
264
|
+
|
252
265
|
if !result
|
253
266
|
STDERR.puts "FATAL: failed to install autoproj in #{dot_autoproj}"
|
254
267
|
exit 1
|
@@ -259,10 +272,6 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
259
272
|
# environment by default
|
260
273
|
Dir.glob(File.join(binstubs_path, '*')) do |path|
|
261
274
|
next if !File.file?(path)
|
262
|
-
# Do NOT do that for bundler, otherwise it will fail with an
|
263
|
-
# "already loaded gemfile" message once we e.g. try to do
|
264
|
-
# 'bundler install --gemfile=NEW_GEMFILE'
|
265
|
-
next if File.basename(path) == 'bundler'
|
266
275
|
|
267
276
|
lines = File.readlines(path)
|
268
277
|
matched = false
|
@@ -278,26 +287,53 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
278
287
|
end
|
279
288
|
end
|
280
289
|
|
281
|
-
env['PATH']
|
290
|
+
env['PATH'].unshift File.join(autoproj_install_dir, 'bin')
|
282
291
|
if private_autoproj?
|
283
|
-
env['GEM_PATH']
|
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')
|
284
297
|
end
|
285
298
|
end
|
286
299
|
|
287
|
-
def
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
300
|
+
def save_env_sh(*vars)
|
301
|
+
env = Autobuild::Environment.new
|
302
|
+
env.prepare
|
303
|
+
vars.each do |kv|
|
304
|
+
k, *v = kv.split("=")
|
305
|
+
v = v.join("=")
|
306
|
+
|
307
|
+
if v.empty?
|
308
|
+
env.unset k
|
309
|
+
else
|
310
|
+
env.set k, *v.split(File::PATH_SEPARATOR)
|
311
|
+
end
|
292
312
|
end
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
313
|
+
# Generate environment files right now, we can at least use bundler
|
314
|
+
File.open(File.join(dot_autoproj, 'env.sh'), 'w') do |io|
|
315
|
+
env.export_env_sh(io)
|
316
|
+
end
|
317
|
+
|
318
|
+
# And now the root envsh
|
319
|
+
env = Autobuild::Environment.new
|
320
|
+
env.source_before File.join(dot_autoproj, 'env.sh')
|
321
|
+
env.set('AUTOPROJ_CURRENT_ROOT', root_dir)
|
322
|
+
File.open(File.join(root_dir, 'env.sh'), 'w') do |io|
|
323
|
+
env.export_env_sh(io)
|
298
324
|
end
|
299
325
|
end
|
300
326
|
|
327
|
+
def save_gemfile
|
328
|
+
FileUtils.mkdir_p File.dirname(autoproj_gemfile_path)
|
329
|
+
File.open(autoproj_gemfile_path, 'w') do |io|
|
330
|
+
io.write gemfile
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
ENV_BUNDLE_GEMFILE_RX = /^(\s*ENV\[['"]BUNDLE_GEMFILE['"]\]\s*)(?:\|\|)?=/
|
335
|
+
|
336
|
+
|
301
337
|
def find_in_clean_path(command)
|
302
338
|
clean_path = env_for_child['PATH'].split(File::PATH_SEPARATOR)
|
303
339
|
clean_path.each do |p|
|
@@ -309,12 +345,10 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
309
345
|
nil
|
310
346
|
end
|
311
347
|
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
'GEM_PATH' => clean_env['GEM_PATH'] || nil
|
317
|
-
]
|
348
|
+
# The path of the bin/ folder for installed gems
|
349
|
+
def gem_bindir
|
350
|
+
return @gem_bindir if @gem_bindir
|
351
|
+
|
318
352
|
# Here, we're getting into the esotheric
|
319
353
|
#
|
320
354
|
# The problem is that e.g. Ubuntu and Debian install an
|
@@ -325,30 +359,12 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
325
359
|
#
|
326
360
|
# So, we're calling 'gem' as a subcommand to discovery the
|
327
361
|
# actual bindir
|
328
|
-
bindir = IO.popen(
|
362
|
+
bindir = IO.popen(env_for_child, [Gem.ruby, '-e', 'puts Gem.bindir']).read
|
329
363
|
if bindir
|
330
|
-
|
364
|
+
@gem_bindir = bindir.chomp
|
331
365
|
else
|
332
|
-
|
333
|
-
exit 1
|
366
|
+
raise "FATAL: cannot run #{Gem.ruby} -e 'puts Gem.bindir'"
|
334
367
|
end
|
335
|
-
|
336
|
-
bundler = find_in_clean_path('bundler')
|
337
|
-
if !bundler
|
338
|
-
clean_path = env_for_child['PATH']
|
339
|
-
STDERR.puts "FATAL: cannot find 'bundler' in PATH=#{clean_path}"
|
340
|
-
if ENV['PATH'] != clean_path
|
341
|
-
STDERR.puts " it appears that you already have some autoproj-generated env.sh loaded"
|
342
|
-
STDERR.puts " - if you are running 'autoproj upgrade', please contact the autoproj author at https://github.com/rock-core/autoproj/issues/new"
|
343
|
-
STDERR.puts " - if you are running an install, try again in a console where the env.sh is not loaded"
|
344
|
-
exit 1
|
345
|
-
else
|
346
|
-
STDERR.puts " the recommended action is to install it manually first by running 'gem install bundler'"
|
347
|
-
STDERR.puts " or call this command again with --private-bundler to have it installed in the workspace"
|
348
|
-
exit 1
|
349
|
-
end
|
350
|
-
end
|
351
|
-
bundler
|
352
368
|
end
|
353
369
|
|
354
370
|
def install
|
@@ -364,27 +380,54 @@ export AUTOPROJ_CURRENT_ROOT=#{root_dir}
|
|
364
380
|
install_autoproj(bundler)
|
365
381
|
end
|
366
382
|
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
383
|
+
def load_config
|
384
|
+
v1_config_path = File.join(root_dir, 'autoproj', 'config.yml')
|
385
|
+
|
386
|
+
config = Hash.new
|
387
|
+
if File.file?(v1_config_path)
|
388
|
+
config.merge!(YAML.load(File.read(v1_config_path)))
|
389
|
+
end
|
390
|
+
if File.file?(autoproj_config_path)
|
391
|
+
config.merge!(YAML.load(File.read(autoproj_config_path)))
|
392
|
+
end
|
374
393
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
else
|
379
|
-
ENV.delete(k)
|
380
|
-
end
|
381
|
-
end
|
382
|
-
ENV['BUNDLE_GEMFILE'] = autoproj_gemfile_path
|
383
|
-
update_configuration
|
384
|
-
exec Gem.ruby, File.join(autoproj_install_dir, 'bin', 'autoproj'),
|
385
|
-
'install-stage2', root_dir
|
394
|
+
@config = config
|
395
|
+
%w{private_bundler private_gems private_autoproj prefer_indep_over_os_packages}.each do |flag|
|
396
|
+
instance_variable_set "@#{flag}", config.fetch(flag, false)
|
386
397
|
end
|
387
398
|
end
|
399
|
+
|
400
|
+
def save_config
|
401
|
+
config['private_bundler'] = private_bundler?
|
402
|
+
config['private_autoproj'] = private_autoproj?
|
403
|
+
config['private_gems'] = private_gems?
|
404
|
+
config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
|
405
|
+
File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
|
406
|
+
end
|
407
|
+
|
408
|
+
def stage1
|
409
|
+
FileUtils.mkdir_p dot_autoproj
|
410
|
+
save_config
|
411
|
+
install
|
412
|
+
|
413
|
+
clean_env = env_for_child
|
414
|
+
stage2_vars = clean_env.map { |k, v| "#{k}=#{v}" }
|
415
|
+
puts "starting the newly installed autoproj for stage2 install"
|
416
|
+
puts [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].inspect
|
419
|
+
exec clean_env.merge('BUNDLE_GEMFILE' => autoproj_gemfile_path),
|
420
|
+
Gem.ruby, File.join(autoproj_install_dir, 'bin', 'autoproj'),
|
421
|
+
'install-stage2', root_dir, *stage2_vars
|
422
|
+
end
|
423
|
+
|
424
|
+
def stage2(*vars)
|
425
|
+
require 'autobuild'
|
426
|
+
puts "saving env.sh and .autoproj/env.sh"
|
427
|
+
save_env_sh(*vars)
|
428
|
+
puts "calling autoproj envsh"
|
429
|
+
system(Gem.ruby, $0, 'envsh')
|
430
|
+
end
|
388
431
|
end
|
389
432
|
end
|
390
433
|
end
|
@@ -395,4 +438,4 @@ ENV.delete('BUNDLE_GEMFILE')
|
|
395
438
|
ENV.delete('RUBYLIB')
|
396
439
|
ops = Autoproj::Ops::Install.new(Dir.pwd)
|
397
440
|
ops.parse_options(ARGV)
|
398
|
-
ops.
|
441
|
+
ops.stage1
|