autoproj 2.11.0 → 2.12.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'autoproj/package_managers/debian_version'
2
4
 
3
5
  module Autoproj
@@ -32,7 +34,9 @@ def keep_uptodate=(flag)
32
34
  ws.config.set('apt_dpkg_update', flag, true)
33
35
  end
34
36
 
35
- def self.parse_package_status(installed_packages, installed_versions, paragraph)
37
+ def self.parse_package_status(
38
+ installed_packages, installed_versions, paragraph, virtual: true
39
+ )
36
40
  if paragraph =~ /^Status: install ok installed$/
37
41
  if paragraph =~ /^Package: (.*)$/
38
42
  package_name = $1
@@ -41,13 +45,13 @@ def self.parse_package_status(installed_packages, installed_versions, paragraph)
41
45
  installed_versions[package_name] = DebianVersion.new($1)
42
46
  end
43
47
  end
44
- if paragraph =~ /^Provides: (.*)$/
48
+ if virtual && paragraph =~ /^Provides: (.*)$/
45
49
  installed_packages.merge($1.split(',').map(&:strip))
46
50
  end
47
51
  end
48
52
  end
49
53
 
50
- def self.parse_dpkg_status(status_file)
54
+ def self.parse_dpkg_status(status_file, virtual: true)
51
55
  installed_packages = Set.new
52
56
  installed_versions = {}
53
57
  dpkg_status = File.read(status_file)
@@ -60,9 +64,11 @@ def self.parse_dpkg_status(status_file)
60
64
 
61
65
  while paragraph_end = dpkg_status.scan_until(/Package: /)
62
66
  paragraph = "Package: #{paragraph_end[0..-10]}"
63
- parse_package_status(installed_packages, installed_versions, paragraph)
67
+ parse_package_status(installed_packages, installed_versions,
68
+ paragraph, virtual: virtual)
64
69
  end
65
- parse_package_status(installed_packages, installed_versions, "Package: #{dpkg_status.rest}")
70
+ parse_package_status(installed_packages, installed_versions,
71
+ "Package: #{dpkg_status.rest}", virtual: virtual)
66
72
  [installed_packages, installed_versions]
67
73
  end
68
74
 
@@ -24,6 +24,14 @@ def self.with_prerelease(*value)
24
24
  end
25
25
  end
26
26
 
27
+ # Directory with cached .gem packages
28
+ #
29
+ # The directory must exist, but may be empty.
30
+ # It is initialized with {BundlerManager.cache_dir}
31
+ #
32
+ # @return [String]
33
+ attr_accessor :cache_dir
34
+
27
35
  # (see Manager#call_while_empty?)
28
36
  def call_while_empty?
29
37
  !workspace_configuration_gemfiles.empty?
@@ -45,14 +53,31 @@ def initialize_environment
45
53
  env.add_path 'PATH', File.join(ws.dot_autoproj_dir, 'bin')
46
54
  env.set 'GEM_HOME', config.gems_gem_home
47
55
  env.clear 'GEM_PATH'
56
+ if (bundler_version = config.bundler_version)
57
+ env.set 'BUNDLER_VERSION', bundler_version
58
+ else
59
+ env.clear 'BUNDLER_VERSION'
60
+ end
48
61
 
49
62
  gemfile_path = File.join(ws.prefix_dir, 'gems', 'Gemfile')
50
63
  env.set('BUNDLE_GEMFILE', gemfile_path) if File.file?(gemfile_path)
51
64
 
52
- Autobuild.programs['bundler'] = File.join(ws.dot_autoproj_dir,
53
- 'bin', 'bundle')
54
- Autobuild.programs['bundle'] = File.join(ws.dot_autoproj_dir,
55
- 'bin', 'bundle')
65
+ if cache_dir && File.exist?(cache_dir)
66
+ vendor_dir = File.join(File.dirname(gemfile_path), 'vendor')
67
+ FileUtils.mkdir_p vendor_dir
68
+ bundler_cache_dir = File.join(vendor_dir, 'cache')
69
+ if File.writable?(cache_dir)
70
+ create_cache_symlink(cache_dir, bundler_cache_dir)
71
+ else
72
+ Autoproj.warn "BundlerManager: #{cache_dir} is read-only "\
73
+ "copying the cache instead of symlinking it"
74
+ create_cache_copy(cache_dir, bundler_cache_dir)
75
+ end
76
+ end
77
+
78
+ Autobuild.programs['bundler'] =
79
+ Autobuild.programs['bundle'] =
80
+ File.join(ws.dot_autoproj_dir, 'bin', 'bundle')
56
81
 
57
82
  env.init_from_env 'RUBYLIB'
58
83
  env.inherit 'RUBYLIB'
@@ -96,6 +121,43 @@ def initialize_environment
96
121
  end
97
122
  end
98
123
 
124
+ def create_cache_symlink(cache_dir, bundler_cache_dir)
125
+ valid = !File.exist?(bundler_cache_dir) ||
126
+ File.symlink?(bundler_cache_dir)
127
+
128
+ unless valid
129
+ Autoproj.warn "cannot use #{cache_dir} as gem cache as "\
130
+ "#{bundler_cache_dir} already exists"
131
+ return
132
+ end
133
+
134
+ FileUtils.rm_f bundler_cache_dir
135
+ FileUtils.ln_s cache_dir, bundler_cache_dir
136
+ end
137
+
138
+ def create_cache_copy(cache_dir, bundler_cache_dir)
139
+ valid = !File.exist?(bundler_cache_dir) ||
140
+ File.directory?(bundler_cache_dir) ||
141
+ File.symlink?(bundler_cache_dir)
142
+
143
+ unless valid
144
+ Autoproj.warn "cannot use #{cache_dir} as gem cache as "\
145
+ "#{bundler_cache_dir} already exists"
146
+ return
147
+ end
148
+
149
+ # Gracefully upgrade from the symlinks
150
+ FileUtils.rm_f bundler_cache_dir if File.symlink?(bundler_cache_dir)
151
+ FileUtils.mkdir_p bundler_cache_dir
152
+
153
+ Dir.glob(File.join(cache_dir, '*.gem')) do |path_src|
154
+ path_dest = File.join(bundler_cache_dir, File.basename(path_src))
155
+ next if File.exist?(path_dest)
156
+
157
+ FileUtils.cp path_src, path_dest
158
+ end
159
+ end
160
+
99
161
  # Enumerate the per-gem build configurations
100
162
  def self.per_gem_build_config(ws)
101
163
  ws.config.get('bundler.build', {})
@@ -248,10 +310,13 @@ def backup_clean(mapping)
248
310
  end
249
311
  end
250
312
 
251
- def self.run_bundler_install(ws, gemfile, *options,
252
- update: true, binstubs: nil,
253
- gem_home: ws.config.gems_gem_home,
254
- gem_path: ws.config.gems_install_path)
313
+ def self.run_bundler_install(
314
+ ws, gemfile, *options,
315
+ update: true, binstubs: nil,
316
+ bundler_version: ws.config.bundler_version,
317
+ gem_home: ws.config.gems_gem_home,
318
+ gem_path: ws.config.gems_install_path
319
+ )
255
320
  FileUtils.rm "#{gemfile}.lock" if update && File.file?("#{gemfile}.lock")
256
321
 
257
322
  options << '--path' << gem_path
@@ -262,6 +327,7 @@ def self.run_bundler_install(ws, gemfile, *options,
262
327
 
263
328
  connections = Set.new
264
329
  run_bundler(ws, 'install', *options,
330
+ bundler_version: bundler_version,
265
331
  gem_home: gem_home, gemfile: gemfile) do |line|
266
332
  case line
267
333
  when /Installing (.*)/
@@ -276,11 +342,13 @@ def self.run_bundler_install(ws, gemfile, *options,
276
342
  end
277
343
  end
278
344
 
279
- def self.bundle_gem_path(ws, gem_name, gem_home: nil, gemfile: nil)
345
+ def self.bundle_gem_path(ws, gem_name,
346
+ bundler_version: ws.config.bundler_version,
347
+ gem_home: nil, gemfile: nil)
280
348
  path = String.new
281
- PackageManagers::BundlerManager.run_bundler(
349
+ run_bundler(
282
350
  ws, 'show', gem_name,
283
- gem_home: gem_home,
351
+ bundler_version: bundler_version, gem_home: gem_home,
284
352
  gemfile: gemfile) { |line| path << line }
285
353
  path.chomp
286
354
  end
@@ -289,17 +357,26 @@ def self.default_bundler(ws)
289
357
  File.join(ws.dot_autoproj_dir, 'bin', 'bundle')
290
358
  end
291
359
 
292
- def self.run_bundler(ws, *commandline, gem_home: nil, gemfile: nil)
360
+ def self.run_bundler(ws, *commandline,
361
+ bundler_version: ws.config.bundler_version,
362
+ gem_home: ws.config.gems_gem_home,
363
+ gemfile: default_gemfile_path(ws))
293
364
  bundle = Autobuild.programs['bundle'] || default_bundler(ws)
294
365
 
295
- Bundler.with_clean_env do
366
+ Autoproj.bundler_with_unbundled_env do
367
+ bundler_version_env =
368
+ if bundler_version
369
+ { 'BUNDLER_VERSION' => bundler_version }
370
+ else
371
+ {}
372
+ end
296
373
  target_env = Hash[
297
374
  'GEM_HOME' => gem_home,
298
375
  'GEM_PATH' => nil,
299
376
  'BUNDLE_GEMFILE' => gemfile,
300
377
  'RUBYOPT' => nil,
301
- 'RUBYLIB' => rubylib_for_bundler
302
- ]
378
+ 'RUBYLIB' => rubylib_for_bundler,
379
+ ].merge(bundler_version_env)
303
380
  ws.run('autoproj', 'osdeps',
304
381
  bundle, *commandline,
305
382
  working_directory: File.dirname(gemfile),
@@ -390,9 +467,13 @@ def workspace_configuration_gemfiles
390
467
  gemfiles
391
468
  end
392
469
 
470
+ def self.default_gemfile_path(ws)
471
+ File.join(ws.prefix_dir, 'gems', 'Gemfile')
472
+ end
473
+
393
474
  def install(gems, filter_uptodate_packages: false, install_only: false)
394
- root_dir = File.join(ws.prefix_dir, 'gems')
395
- gemfile_path = File.join(root_dir, 'Gemfile')
475
+ gemfile_path = self.class.default_gemfile_path(ws)
476
+ root_dir = File.dirname(gemfile_path)
396
477
  gemfile_lock_path = "#{gemfile_path}.lock"
397
478
  backups = Hash[
398
479
  gemfile_path => "#{gemfile_path}.orig",
@@ -466,7 +547,7 @@ def install(gems, filter_uptodate_packages: false, install_only: false)
466
547
  def discover_rubylib
467
548
  require 'bundler'
468
549
  Tempfile.open 'autoproj-rubylib' do |io|
469
- result = Bundler.clean_system(
550
+ result = Autoproj.bundler_unbundled_system(
470
551
  Hash['RUBYLIB' => nil],
471
552
  Autobuild.tool('ruby'), '-e', 'puts $LOAD_PATH',
472
553
  out: io,
@@ -490,7 +571,7 @@ def discover_bundle_rubylib(silent_errors: false)
490
571
  silent_redirect[:err] = :close if silent_errors
491
572
  env = ws.env.resolved_env
492
573
  Tempfile.open 'autoproj-rubylib' do |io|
493
- result = Bundler.clean_system(
574
+ result = Autoproj.bundler_unbundled_system(
494
575
  Hash['GEM_HOME' => env['GEM_HOME'], 'GEM_PATH' => env['GEM_PATH'],
495
576
  'BUNDLE_GEMFILE' => gemfile, 'RUBYOPT' => nil,
496
577
  'RUBYLIB' => self.class.rubylib_for_bundler],
@@ -15,7 +15,7 @@ def filter_uptodate_packages(packages)
15
15
  # somewhere else
16
16
  packages = packages.uniq
17
17
  command_line = "brew info --json=v1 #{packages.join(' ')}"
18
- result = Bundler.with_clean_env do
18
+ result = Autoproj.bundler_with_unbundled_env do
19
19
  (Autobuild::Subprocess.run 'autoproj', 'osdeps', command_line).first
20
20
  end
21
21
 
@@ -30,7 +30,7 @@ def filter_uptodate_packages(packages)
30
30
  end
31
31
  return packages
32
32
  end
33
-
33
+
34
34
  # fall back if something else went wrong
35
35
  if packages.size != result.size
36
36
  Autoproj.warn "brew info returns less or more packages when requested. Falling back to install all packages"
@@ -71,6 +71,7 @@ def setup
71
71
  Autobuild.logdir = make_tmpdir
72
72
  ws_define_package_manager 'os'
73
73
  ws_define_package_manager 'os_indep'
74
+ Autobuild.progress_display_period = 0
74
75
 
75
76
  super
76
77
  end
@@ -80,6 +81,7 @@ def teardown
80
81
  @tmpdir.each do |dir|
81
82
  FileUtils.remove_entry_secure dir
82
83
  end
84
+ Rake::Task.clear
83
85
  Autobuild::Package.clear
84
86
  Autoproj.silent = false
85
87
 
@@ -94,6 +96,11 @@ def teardown
94
96
  end
95
97
  end
96
98
 
99
+ def data_path(*args)
100
+ File.expand_path(File.join(*args),
101
+ File.join(__dir__, '..', '..', 'test', 'data'))
102
+ end
103
+
97
104
  def create_bootstrap
98
105
  ws_create
99
106
  end
@@ -170,7 +177,7 @@ def invoke_test_script(name, *arguments,
170
177
  'PACKAGE_BASE_DIR' => package_base_dir,
171
178
  'RUBY' => Gem.ruby
172
179
  ]
173
- result = Bundler.clean_system(
180
+ result = Autoproj.bundler_unbundled_system(
174
181
  default_env.merge(env), script, *arguments,
175
182
  in: :close, **Hash[chdir: dir].merge(system_options))
176
183
  end
@@ -201,7 +208,7 @@ def prepare_fixture_gem_home
201
208
  cached_bundler_gem = File.join(vendor, bundler_filename)
202
209
  unless File.file?(cached_bundler_gem)
203
210
  FileUtils.mkdir_p vendor
204
- Bundler.clean_system(
211
+ Autoproj.bundler_unbundled_system(
205
212
  Ops::Install.guess_gem_program, 'fetch', '-v',
206
213
  Bundler::VERSION, 'bundler', chdir: vendor)
207
214
 
@@ -211,7 +218,7 @@ def prepare_fixture_gem_home
211
218
  end
212
219
 
213
220
  capture_subprocess_io do
214
- Bundler.clean_system(
221
+ Autoproj.bundler_unbundled_system(
215
222
  Hash['GEM_HOME' => fixture_gem_home, 'GEM_PATH' => nil],
216
223
  Ops::Install.guess_gem_program, 'install', '--no-document',
217
224
  cached_bundler_gem)
@@ -256,7 +263,7 @@ def capture_deprecation_message
256
263
 
257
264
  def find_bundled_gem_path(bundler, gem_name, gemfile)
258
265
  out_r, out_w = IO.pipe
259
- result = Bundler.clean_system(
266
+ result = Autoproj.bundler_unbundled_system(
260
267
  bundler, 'show', gem_name,
261
268
  out: out_w,
262
269
  chdir: File.dirname(gemfile))
@@ -370,9 +377,16 @@ def ws_add_osdep_entries_to_layout(entries)
370
377
 
371
378
  def ws_define_package(package_type, package_name,
372
379
  package_set: ws.manifest.main_package_set,
373
- create: true)
380
+ create: true, &block)
374
381
  package = Autobuild.send(package_type, package_name)
375
- package.srcdir = File.join(ws.root_dir, package_name.to_s)
382
+ ws_setup_package(
383
+ package, package_set: package_set, create: create, &block
384
+ )
385
+ end
386
+
387
+ def ws_setup_package(package, package_set: ws.manifest.main_package_set,
388
+ create: true)
389
+ package.srcdir = File.join(ws.root_dir, package.name.to_s)
376
390
  FileUtils.mkdir_p package.srcdir if create
377
391
  autoproj_package = ws.register_package(package, nil, package_set)
378
392
  yield(package) if block_given?
@@ -1,3 +1,3 @@
1
1
  module Autoproj
2
- VERSION = "2.11.0"
2
+ VERSION = "2.12.0"
3
3
  end
@@ -370,6 +370,14 @@ def setup
370
370
  Autobuild.logdir = log_dir
371
371
  if (cache_dir = config.importer_cache_dir)
372
372
  Autobuild::Importer.default_cache_dirs = cache_dir
373
+ os_package_installer.each_manager_with_name do |name, manager|
374
+ next unless manager.respond_to?(:cache_dir=)
375
+
376
+ manager_cache_path = File.join(cache_dir, 'package_managers', name)
377
+ if File.directory?(manager_cache_path)
378
+ manager.cache_dir = manager_cache_path
379
+ end
380
+ end
373
381
  end
374
382
  setup_os_package_installer
375
383
  install_ruby_shims
@@ -416,7 +424,11 @@ def update_bundler
416
424
  gem_program = Ops::Install.guess_gem_program
417
425
  install = Ops::Install.new(root_dir)
418
426
  Autoproj.message " updating bundler"
419
- install.install_bundler(gem_program, silent: true)
427
+ install.install_bundler(
428
+ gem_program,
429
+ version: config.bundler_version,
430
+ silent: true
431
+ )
420
432
  end
421
433
 
422
434
  def update_autoproj(restart_on_update: true)
@@ -430,18 +442,21 @@ def update_autoproj(restart_on_update: true)
430
442
  binstubs = File.join(dot_autoproj_dir, 'bin')
431
443
  if restart_on_update
432
444
  old_autoproj_path = PackageManagers::BundlerManager.bundle_gem_path(
433
- self, 'autoproj', gem_home: config.gems_gem_home, gemfile: gemfile)
445
+ self, 'autoproj', gemfile: gemfile
446
+ )
434
447
  end
435
448
  begin
436
449
  Autoproj.message " updating autoproj"
437
450
  PackageManagers::BundlerManager.run_bundler_install(
438
- self, gemfile, binstubs: binstubs)
451
+ self, gemfile, binstubs: binstubs
452
+ )
439
453
  ensure
440
454
  rewrite_shims
441
455
  end
442
456
  if restart_on_update
443
457
  new_autoproj_path = PackageManagers::BundlerManager.bundle_gem_path(
444
- self, 'autoproj', gem_home: config.gems_gem_home, gemfile: gemfile)
458
+ self, 'autoproj', gemfile: gemfile
459
+ )
445
460
  end
446
461
 
447
462
  # First things first, see if we need to update ourselves
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autoproj
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.0
4
+ version: 2.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sylvain Joyeux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-03 00:00:00.000000000 Z
11
+ date: 2020-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -376,6 +376,7 @@ files:
376
376
  - lib/autoproj/ops/install.rb
377
377
  - lib/autoproj/ops/loader.rb
378
378
  - lib/autoproj/ops/main_config_switcher.rb
379
+ - lib/autoproj/ops/phase_reporting.rb
379
380
  - lib/autoproj/ops/snapshot.rb
380
381
  - lib/autoproj/ops/tools.rb
381
382
  - lib/autoproj/ops/watch.rb