autoproj 2.12.0 → 2.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/lint.yml +25 -0
  3. data/.github/workflows/test.yml +30 -0
  4. data/.rubocop.yml +79 -91
  5. data/.rubocop_todo.yml +1473 -0
  6. data/Gemfile +9 -9
  7. data/Rakefile +24 -24
  8. data/autoproj.gemspec +22 -22
  9. data/bin/alocate +4 -4
  10. data/bin/alog +6 -7
  11. data/bin/amake +4 -4
  12. data/bin/aup +4 -4
  13. data/bin/autoproj +2 -2
  14. data/bin/autoproj_bootstrap +186 -183
  15. data/bin/autoproj_bootstrap.in +7 -8
  16. data/bin/autoproj_install +185 -182
  17. data/bin/autoproj_install.in +6 -7
  18. data/lib/autoproj/aruba_minitest.rb +6 -11
  19. data/lib/autoproj/autobuild.rb +5 -6
  20. data/lib/autoproj/autobuild_extensions/archive_importer.rb +10 -11
  21. data/lib/autoproj/autobuild_extensions/dsl.rb +61 -44
  22. data/lib/autoproj/autobuild_extensions/git.rb +27 -26
  23. data/lib/autoproj/autobuild_extensions/package.rb +23 -22
  24. data/lib/autoproj/autobuild_extensions/svn.rb +1 -2
  25. data/lib/autoproj/base.rb +1 -1
  26. data/lib/autoproj/bash_completion.rb +5 -6
  27. data/lib/autoproj/build_option.rb +22 -24
  28. data/lib/autoproj/cli/base.rb +27 -27
  29. data/lib/autoproj/cli/bootstrap.rb +14 -16
  30. data/lib/autoproj/cli/build.rb +18 -10
  31. data/lib/autoproj/cli/cache.rb +51 -8
  32. data/lib/autoproj/cli/clean.rb +10 -10
  33. data/lib/autoproj/cli/commit.rb +7 -8
  34. data/lib/autoproj/cli/doc.rb +2 -2
  35. data/lib/autoproj/cli/envsh.rb +1 -2
  36. data/lib/autoproj/cli/exec.rb +60 -20
  37. data/lib/autoproj/cli/inspection_tool.rb +18 -13
  38. data/lib/autoproj/cli/locate.rb +30 -41
  39. data/lib/autoproj/cli/log.rb +7 -7
  40. data/lib/autoproj/cli/main.rb +217 -205
  41. data/lib/autoproj/cli/main_doc.rb +22 -21
  42. data/lib/autoproj/cli/main_global.rb +44 -19
  43. data/lib/autoproj/cli/main_plugin.rb +18 -18
  44. data/lib/autoproj/cli/main_test.rb +28 -27
  45. data/lib/autoproj/cli/manifest.rb +7 -7
  46. data/lib/autoproj/cli/osdeps.rb +12 -11
  47. data/lib/autoproj/cli/patcher.rb +2 -3
  48. data/lib/autoproj/cli/query.rb +17 -18
  49. data/lib/autoproj/cli/reconfigure.rb +1 -2
  50. data/lib/autoproj/cli/reset.rb +9 -12
  51. data/lib/autoproj/cli/show.rb +48 -55
  52. data/lib/autoproj/cli/status.rb +56 -44
  53. data/lib/autoproj/cli/switch_config.rb +5 -6
  54. data/lib/autoproj/cli/tag.rb +12 -11
  55. data/lib/autoproj/cli/test.rb +7 -7
  56. data/lib/autoproj/cli/update.rb +104 -51
  57. data/lib/autoproj/cli/utility.rb +14 -12
  58. data/lib/autoproj/cli/version.rb +42 -40
  59. data/lib/autoproj/cli/versions.rb +14 -15
  60. data/lib/autoproj/cli/watch.rb +33 -37
  61. data/lib/autoproj/cli/which.rb +16 -20
  62. data/lib/autoproj/cli.rb +4 -2
  63. data/lib/autoproj/configuration.rb +78 -85
  64. data/lib/autoproj/default.osdeps +29 -3
  65. data/lib/autoproj/environment.rb +42 -23
  66. data/lib/autoproj/exceptions.rb +9 -3
  67. data/lib/autoproj/find_workspace.rb +20 -25
  68. data/lib/autoproj/git_server_configuration.rb +40 -44
  69. data/lib/autoproj/gitorious.rb +1 -1
  70. data/lib/autoproj/installation_manifest.rb +64 -29
  71. data/lib/autoproj/local_package_set.rb +13 -11
  72. data/lib/autoproj/manifest.rb +145 -135
  73. data/lib/autoproj/metapackage.rb +2 -6
  74. data/lib/autoproj/ops/atomic_write.rb +7 -6
  75. data/lib/autoproj/ops/build.rb +4 -6
  76. data/lib/autoproj/ops/cache.rb +64 -53
  77. data/lib/autoproj/ops/cached_env.rb +7 -6
  78. data/lib/autoproj/ops/configuration.rb +511 -506
  79. data/lib/autoproj/ops/import.rb +90 -61
  80. data/lib/autoproj/ops/install.rb +179 -175
  81. data/lib/autoproj/ops/loader.rb +77 -76
  82. data/lib/autoproj/ops/main_config_switcher.rb +36 -45
  83. data/lib/autoproj/ops/phase_reporting.rb +4 -4
  84. data/lib/autoproj/ops/snapshot.rb +250 -247
  85. data/lib/autoproj/ops/tools.rb +76 -78
  86. data/lib/autoproj/ops/watch.rb +6 -6
  87. data/lib/autoproj/ops/which.rb +17 -14
  88. data/lib/autoproj/options.rb +13 -2
  89. data/lib/autoproj/os_package_installer.rb +102 -92
  90. data/lib/autoproj/os_package_query.rb +7 -13
  91. data/lib/autoproj/os_package_resolver.rb +189 -140
  92. data/lib/autoproj/os_repository_installer.rb +4 -4
  93. data/lib/autoproj/os_repository_resolver.rb +8 -6
  94. data/lib/autoproj/package_definition.rb +12 -13
  95. data/lib/autoproj/package_managers/apt_dpkg_manager.rb +46 -31
  96. data/lib/autoproj/package_managers/bundler_manager.rb +156 -118
  97. data/lib/autoproj/package_managers/debian_version.rb +25 -21
  98. data/lib/autoproj/package_managers/emerge_manager.rb +2 -3
  99. data/lib/autoproj/package_managers/gem_manager.rb +68 -77
  100. data/lib/autoproj/package_managers/homebrew_manager.rb +3 -4
  101. data/lib/autoproj/package_managers/manager.rb +8 -3
  102. data/lib/autoproj/package_managers/pacman_manager.rb +2 -3
  103. data/lib/autoproj/package_managers/pip_manager.rb +37 -27
  104. data/lib/autoproj/package_managers/pkg_manager.rb +3 -4
  105. data/lib/autoproj/package_managers/port_manager.rb +2 -3
  106. data/lib/autoproj/package_managers/shell_script_manager.rb +66 -36
  107. data/lib/autoproj/package_managers/unknown_os_manager.rb +5 -8
  108. data/lib/autoproj/package_managers/yum_manager.rb +12 -15
  109. data/lib/autoproj/package_managers/zypper_manager.rb +11 -14
  110. data/lib/autoproj/package_manifest.rb +66 -53
  111. data/lib/autoproj/package_selection.rb +187 -187
  112. data/lib/autoproj/package_set.rb +128 -114
  113. data/lib/autoproj/python.rb +285 -0
  114. data/lib/autoproj/query_base.rb +20 -14
  115. data/lib/autoproj/reporter.rb +19 -19
  116. data/lib/autoproj/repository_managers/apt.rb +101 -67
  117. data/lib/autoproj/repository_managers/unknown_os_manager.rb +3 -3
  118. data/lib/autoproj/shell_completion.rb +16 -13
  119. data/lib/autoproj/source_package_query.rb +29 -36
  120. data/lib/autoproj/system.rb +32 -21
  121. data/lib/autoproj/test.rb +131 -106
  122. data/lib/autoproj/variable_expansion.rb +10 -10
  123. data/lib/autoproj/vcs_definition.rb +53 -37
  124. data/lib/autoproj/version.rb +1 -1
  125. data/lib/autoproj/workspace.rb +162 -117
  126. data/lib/autoproj/zsh_completion.rb +8 -9
  127. data/lib/autoproj.rb +53 -53
  128. data/samples/autoproj/init.rb +1 -2
  129. metadata +62 -72
  130. data/.travis.yml +0 -22
@@ -1,4 +1,4 @@
1
- require 'bundler'
1
+ require "bundler"
2
2
  module Autoproj
3
3
  module PackageManagers
4
4
  # Package manager interface for the RubyGems system
@@ -49,23 +49,23 @@ module Autoproj
49
49
 
50
50
  config = ws.config
51
51
 
52
- env.add_path 'PATH', File.join(ws.prefix_dir, 'gems', 'bin')
53
- env.add_path 'PATH', File.join(ws.dot_autoproj_dir, 'bin')
54
- env.set 'GEM_HOME', config.gems_gem_home
55
- env.clear 'GEM_PATH'
52
+ env.add_path "PATH", File.join(ws.prefix_dir, "gems", "bin")
53
+ env.add_path "PATH", File.join(ws.dot_autoproj_dir, "bin")
54
+ env.set "GEM_HOME", config.gems_gem_home
55
+ env.clear "GEM_PATH"
56
56
  if (bundler_version = config.bundler_version)
57
- env.set 'BUNDLER_VERSION', bundler_version
57
+ env.set "BUNDLER_VERSION", bundler_version
58
58
  else
59
- env.clear 'BUNDLER_VERSION'
59
+ env.clear "BUNDLER_VERSION"
60
60
  end
61
61
 
62
- gemfile_path = File.join(ws.prefix_dir, 'gems', 'Gemfile')
63
- env.set('BUNDLE_GEMFILE', gemfile_path) if File.file?(gemfile_path)
62
+ gemfile_path = File.join(ws.prefix_dir, "gems", "Gemfile")
63
+ env.set("BUNDLE_GEMFILE", gemfile_path) if File.file?(gemfile_path)
64
64
 
65
65
  if cache_dir && File.exist?(cache_dir)
66
- vendor_dir = File.join(File.dirname(gemfile_path), 'vendor')
66
+ vendor_dir = File.join(File.dirname(gemfile_path), "vendor")
67
67
  FileUtils.mkdir_p vendor_dir
68
- bundler_cache_dir = File.join(vendor_dir, 'cache')
68
+ bundler_cache_dir = File.join(vendor_dir, "cache")
69
69
  if File.writable?(cache_dir)
70
70
  create_cache_symlink(cache_dir, bundler_cache_dir)
71
71
  else
@@ -75,20 +75,21 @@ module Autoproj
75
75
  end
76
76
  end
77
77
 
78
- Autobuild.programs['bundler'] =
79
- Autobuild.programs['bundle'] =
80
- File.join(ws.dot_autoproj_dir, 'bin', 'bundle')
78
+ Autobuild.programs["bundler"] =
79
+ Autobuild.programs["bundle"] =
80
+ File.join(ws.dot_autoproj_dir, "bin", "bundle")
81
81
 
82
- env.init_from_env 'RUBYLIB'
83
- env.inherit 'RUBYLIB'
82
+ env.init_from_env "RUBYLIB"
83
+ env.inherit "RUBYLIB"
84
84
  # Sanitize the rubylib we get from the environment by removing
85
85
  # anything that comes from Gem or Bundler
86
86
  original_rubylib =
87
- (env['RUBYLIB'] || "").split(File::PATH_SEPARATOR).find_all do |p|
87
+ (env["RUBYLIB"] || "").split(File::PATH_SEPARATOR).find_all do |p|
88
88
  !p.start_with?(Bundler.rubygems.gem_dir) &&
89
89
  Bundler.rubygems.gem_path
90
90
  .none? { |gem_p| p.start_with?(gem_p) }
91
91
  end
92
+
92
93
  # And discover the system's rubylib
93
94
  if (system_rubylib = discover_rubylib)
94
95
  # Do not explicitely add the system rubylib to the
@@ -96,22 +97,22 @@ module Autoproj
96
97
  #
97
98
  # This allows to use a binstub generated for one of ruby
98
99
  # interpreter version on our workspace
99
- env.system_env['RUBYLIB'] = []
100
- env.original_env['RUBYLIB'] = (original_rubylib - system_rubylib)
100
+ env.system_env["RUBYLIB"] = []
101
+ env.original_env["RUBYLIB"] = (original_rubylib - system_rubylib)
101
102
  .join(File::PATH_SEPARATOR)
102
103
  end
103
104
 
104
105
  ws.config.each_reused_autoproj_installation do |p|
105
106
  reused_w = ws.new(p)
106
- env.add_path 'PATH', File.join(reused_w.prefix_dir, 'gems', 'bin')
107
+ env.add_path "PATH", File.join(reused_w.prefix_dir, "gems", "bin")
107
108
  end
108
109
 
109
110
  prefix_gems = File.join(ws.prefix_dir, "gems")
110
111
  FileUtils.mkdir_p prefix_gems
111
- gemfile = File.join(prefix_gems, 'Gemfile')
112
+ gemfile = File.join(prefix_gems, "Gemfile")
112
113
  unless File.exist?(gemfile)
113
114
  Ops.atomic_write(gemfile) do |io|
114
- dot_autoproj_gemfile = File.join(ws.dot_autoproj_dir, 'Gemfile')
115
+ dot_autoproj_gemfile = File.join(ws.dot_autoproj_dir, "Gemfile")
115
116
  io.puts "eval_gemfile \"#{dot_autoproj_gemfile}\""
116
117
  end
117
118
  end
@@ -122,13 +123,14 @@ module Autoproj
122
123
  end
123
124
 
124
125
  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
126
+ if File.exist?(bundler_cache_dir)
127
+ if !File.symlink?(bundler_cache_dir)
128
+ Autoproj.warn "cannot use #{cache_dir} as gem cache as "\
129
+ "#{bundler_cache_dir} already exists"
130
+ return
131
+ elsif File.readlink(bundler_cache_dir) == cache_dir
132
+ return
133
+ end
132
134
  end
133
135
 
134
136
  FileUtils.rm_f bundler_cache_dir
@@ -150,7 +152,7 @@ module Autoproj
150
152
  FileUtils.rm_f bundler_cache_dir if File.symlink?(bundler_cache_dir)
151
153
  FileUtils.mkdir_p bundler_cache_dir
152
154
 
153
- Dir.glob(File.join(cache_dir, '*.gem')) do |path_src|
155
+ Dir.glob(File.join(cache_dir, "*.gem")) do |path_src|
154
156
  path_dest = File.join(bundler_cache_dir, File.basename(path_src))
155
157
  next if File.exist?(path_dest)
156
158
 
@@ -160,7 +162,7 @@ module Autoproj
160
162
 
161
163
  # Enumerate the per-gem build configurations
162
164
  def self.per_gem_build_config(ws)
163
- ws.config.get('bundler.build', {})
165
+ ws.config.get("bundler.build", {})
164
166
  end
165
167
 
166
168
  # Add new build configuration arguments for a given gem
@@ -168,9 +170,9 @@ module Autoproj
168
170
  # This is meant to be used from the Autoproj configuration files,
169
171
  # e.g. overrides.rb or package configuration
170
172
  def self.add_build_configuration_for(gem_name, build_config, ws: Autoproj.workspace)
171
- c = ws.config.get('bundler.build', {})
173
+ c = ws.config.get("bundler.build", {})
172
174
  c[gem_name] = [c[gem_name], build_config].compact.join(" ")
173
- ws.config.set('bundler.build', c)
175
+ ws.config.set("bundler.build", c)
174
176
  end
175
177
 
176
178
  # Set the build configuration for the given gem
@@ -178,9 +180,9 @@ module Autoproj
178
180
  # This is meant to be used from the Autoproj configuration files,
179
181
  # e.g. overrides.rb or package configuration
180
182
  def self.configure_build_for(gem_name, build_config, ws: Autoproj.workspace)
181
- c = ws.config.get('bundler.build', {})
183
+ c = ws.config.get("bundler.build", {})
182
184
  c[gem_name] = build_config
183
- ws.config.set('bundler.build', c)
185
+ ws.config.set("bundler.build", c)
184
186
  end
185
187
 
186
188
  # Removes build configuration flags for the given gem
@@ -188,9 +190,9 @@ module Autoproj
188
190
  # This is meant to be used from the Autoproj configuration files,
189
191
  # e.g. overrides.rb or package configuration
190
192
  def self.remove_build_configuration_for(gem_name, ws: Autoproj.workspace)
191
- c = ws.config.get('bundler.build', {})
193
+ c = ws.config.get("bundler.build", {})
192
194
  c.delete(gem_name)
193
- ws.config.set('bundler.build', c)
195
+ ws.config.set("bundler.build", c)
194
196
  end
195
197
 
196
198
  # @api private
@@ -201,7 +203,7 @@ module Autoproj
201
203
  # should be updated
202
204
  # @return [void]
203
205
  def self.apply_build_config(ws)
204
- root_dir = File.join(ws.prefix_dir, 'gems')
206
+ root_dir = File.join(ws.prefix_dir, "gems")
205
207
  current_config_path = File.join(root_dir, ".bundle", "config")
206
208
  current_config =
207
209
  if File.file?(current_config_path)
@@ -219,10 +221,10 @@ module Autoproj
219
221
  next(line) unless (m = line.match(/BUNDLE_BUILD__(.*): "(.*)"$/))
220
222
  next unless (desired_config = build_config.delete(m[1]))
221
223
 
222
- if m[2] != desired_config
223
- "BUNDLE_BUILD__#{m[1]}: \"#{desired_config}\""
224
- else
224
+ if m[2] == desired_config
225
225
  line
226
+ else
227
+ "BUNDLE_BUILD__#{m[1]}: \"#{desired_config}\""
226
228
  end
227
229
  end.compact
228
230
 
@@ -232,7 +234,7 @@ module Autoproj
232
234
 
233
235
  if new_config != current_config
234
236
  FileUtils.mkdir_p File.dirname(current_config_path)
235
- File.open(current_config_path, 'w') do |io|
237
+ File.open(current_config_path, "w") do |io|
236
238
  io.write new_config.join
237
239
  end
238
240
  end
@@ -248,28 +250,10 @@ module Autoproj
248
250
  # @param [Array<String>] system_rubylib the rubylib entries that are
249
251
  # set by the underlying ruby interpreter itself
250
252
  def update_env_rubylib(bundle_rubylib, system_rubylib = discover_rubylib)
251
- current = (ws.env.resolved_env['RUBYLIB'] || '')
253
+ current = (ws.env.resolved_env["RUBYLIB"] || "")
252
254
  .split(File::PATH_SEPARATOR) + system_rubylib
253
255
  (bundle_rubylib - current).each do |p|
254
- ws.env.add_path('RUBYLIB', p)
255
- end
256
- end
257
-
258
- # @api private
259
- #
260
- # Parse an osdep entry into a gem name and gem version
261
- #
262
- # The 'gem' entries in the osdep files can contain a version
263
- # specification. This method parses the two parts and return them
264
- #
265
- # @param [String] entry the osdep entry
266
- # @return [(String,String),(String,nil)] the gem name, and an
267
- # optional version specification
268
- def parse_package_entry(entry)
269
- if entry =~ /^([^><=~]*)([><=~]+.*)$/
270
- [$1.strip, $2.strip]
271
- else
272
- [entry]
256
+ ws.env.add_path("RUBYLIB", p)
273
257
  end
274
258
  end
275
259
 
@@ -319,21 +303,21 @@ module Autoproj
319
303
  )
320
304
  FileUtils.rm "#{gemfile}.lock" if update && File.file?("#{gemfile}.lock")
321
305
 
322
- options << '--path' << gem_path
306
+ options << "--path" << gem_path
323
307
  options << "--shebang" << Gem.ruby
324
308
  options << "--binstubs" << binstubs if binstubs
325
309
 
326
310
  apply_build_config(ws)
327
311
 
328
312
  connections = Set.new
329
- run_bundler(ws, 'install', *options,
313
+ run_bundler(ws, "install", *options,
330
314
  bundler_version: bundler_version,
331
315
  gem_home: gem_home, gemfile: gemfile) do |line|
332
316
  case line
333
317
  when /Installing (.*)/
334
318
  Autobuild.message " bundler: installing #{$1}"
335
319
  when /Fetching.*from (.*)/
336
- host = $1.gsub(/\.+$/, '')
320
+ host = $1.gsub(/\.+$/, "")
337
321
  unless connections.include?(host)
338
322
  Autobuild.message " bundler: connected to #{host}"
339
323
  connections << host
@@ -343,41 +327,42 @@ module Autoproj
343
327
  end
344
328
 
345
329
  def self.bundle_gem_path(ws, gem_name,
346
- bundler_version: ws.config.bundler_version,
347
- gem_home: nil, gemfile: nil)
330
+ bundler_version: ws.config.bundler_version,
331
+ gem_home: nil, gemfile: nil)
348
332
  path = String.new
349
333
  run_bundler(
350
- ws, 'show', gem_name,
334
+ ws, "show", gem_name,
351
335
  bundler_version: bundler_version, gem_home: gem_home,
352
- gemfile: gemfile) { |line| path << line }
336
+ gemfile: gemfile
337
+ ) { |line| path << line }
353
338
  path.chomp
354
339
  end
355
340
 
356
341
  def self.default_bundler(ws)
357
- File.join(ws.dot_autoproj_dir, 'bin', 'bundle')
342
+ File.join(ws.dot_autoproj_dir, "bin", "bundle")
358
343
  end
359
344
 
360
345
  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))
364
- bundle = Autobuild.programs['bundle'] || default_bundler(ws)
346
+ bundler_version: ws.config.bundler_version,
347
+ gem_home: ws.config.gems_gem_home,
348
+ gemfile: default_gemfile_path(ws))
349
+ bundle = Autobuild.programs["bundle"] || default_bundler(ws)
365
350
 
366
351
  Autoproj.bundler_with_unbundled_env do
367
352
  bundler_version_env =
368
353
  if bundler_version
369
- { 'BUNDLER_VERSION' => bundler_version }
354
+ { "BUNDLER_VERSION" => bundler_version }
370
355
  else
371
356
  {}
372
357
  end
373
358
  target_env = Hash[
374
- 'GEM_HOME' => gem_home,
375
- 'GEM_PATH' => nil,
376
- 'BUNDLE_GEMFILE' => gemfile,
377
- 'RUBYOPT' => nil,
378
- 'RUBYLIB' => rubylib_for_bundler,
359
+ "GEM_HOME" => gem_home,
360
+ "GEM_PATH" => nil,
361
+ "BUNDLE_GEMFILE" => gemfile,
362
+ "RUBYOPT" => nil,
363
+ "RUBYLIB" => rubylib_for_bundler,
379
364
  ].merge(bundler_version_env)
380
- ws.run('autoproj', 'osdeps',
365
+ ws.run("autoproj", "osdeps",
381
366
  bundle, *commandline,
382
367
  working_directory: File.dirname(gemfile),
383
368
  env: target_env) { |line| yield(line) if block_given? }
@@ -399,21 +384,21 @@ module Autoproj
399
384
  begin Bundler::Dsl.evaluate(gemfile, nil, [])
400
385
  rescue Exception => e
401
386
  cleaned_message = e
402
- .message
403
- .gsub(/There was an error parsing([^:]+)/,
404
- "Error in gem definitions")
405
- .gsub(/# from.*/, '')
387
+ .message
388
+ .gsub(/There was an error parsing([^:]+)/,
389
+ "Error in gem definitions")
390
+ .gsub(/# from.*/, "")
406
391
  raise ConfigError, cleaned_message
407
392
  end
408
393
  gems_remotes |= bundler_def.send(:sources).rubygems_remotes.to_set
409
394
  bundler_def.dependencies.each do |d|
410
395
  d.groups.each do |group_name|
411
- if !d.platforms.empty?
396
+ if d.platforms.empty?
397
+ dependencies[group_name][""][d.name] = d
398
+ else
412
399
  d.platforms.each do |platform_name|
413
400
  dependencies[group_name][platform_name][d.name] = d
414
401
  end
415
- else
416
- dependencies[group_name][''][d.name] = d
417
402
  end
418
403
  end
419
404
  end
@@ -422,7 +407,7 @@ module Autoproj
422
407
  contents = []
423
408
  gems_remotes.each do |g|
424
409
  g = g.to_s
425
- g = g[0..-2] if g.end_with?('/')
410
+ g = g[0..-2] if g.end_with?("/")
426
411
  contents << "source '#{g}'"
427
412
  end
428
413
  valid_keys = %w[group groups git path glob name branch ref tag
@@ -443,11 +428,11 @@ module Autoproj
443
428
  options = options.map { |k, v| "#{k}: \"#{v}\"" }
444
429
  end
445
430
  contents << [" #{platform_indent}gem \"#{d.name}\",
446
- \"#{d.requirement}\"", *options].join(', ')
431
+ \"#{d.requirement}\"", *options].join(", ")
447
432
  end
448
- contents << ' end' unless platform_name.empty?
433
+ contents << " end" unless platform_name.empty?
449
434
  end
450
- contents << 'end'
435
+ contents << "end"
451
436
  end
452
437
  contents.join("\n")
453
438
  end
@@ -455,7 +440,7 @@ module Autoproj
455
440
  def workspace_configuration_gemfiles
456
441
  gemfiles = []
457
442
  ws.manifest.each_package_set do |source|
458
- pkg_set_gemfile = File.join(source.local_dir, 'Gemfile')
443
+ pkg_set_gemfile = File.join(source.local_dir, "Gemfile")
459
444
  if source.local_dir && File.file?(pkg_set_gemfile)
460
445
  gemfiles << pkg_set_gemfile
461
446
  end
@@ -468,7 +453,58 @@ module Autoproj
468
453
  end
469
454
 
470
455
  def self.default_gemfile_path(ws)
471
- File.join(ws.prefix_dir, 'gems', 'Gemfile')
456
+ File.join(ws.prefix_dir, "gems", "Gemfile")
457
+ end
458
+
459
+ GemEntry = Struct.new :name, :version, :options do
460
+ def self.parse(object)
461
+ if object.respond_to?(:to_str)
462
+ parse_from_string(object)
463
+ elsif object.respond_to?(:to_hash)
464
+ parse_from_hash(object)
465
+ else
466
+ raise ArgumentError,
467
+ "expected #{object} to either be a string or a map"
468
+ end
469
+ end
470
+
471
+ # Parse an osdep entry string into a gem name and gem version
472
+ #
473
+ # The 'gem' entries in the osdep files can contain a version
474
+ # specification. This method parses the two parts and return them
475
+ #
476
+ # @param [String] entry the osdep entry
477
+ # @return [(String,String),(String,nil)] the gem name, and an
478
+ # optional version specification
479
+ def self.parse_from_string(entry)
480
+ if entry =~ /^([^><=~]*)([><=~]+.*)$/
481
+ GemEntry.new($1.strip, $2.strip, {})
482
+ else
483
+ GemEntry.new(entry, nil, {})
484
+ end
485
+ end
486
+
487
+ # Parse an option hash into a GemEntry
488
+ def self.parse_from_hash(hash)
489
+ hash = hash.dup
490
+ unless (name = hash.delete("name"))
491
+ raise ArgumentError,
492
+ "expected gem entry #{hash} to have at least a 'name' key"
493
+ end
494
+
495
+ version = hash.delete("version")
496
+ GemEntry.new(name, version, hash)
497
+ end
498
+
499
+ def to_gemfile_line
500
+ options_s = options.map { |k, v| "#{k}: \"#{v}\"" }.join(", ")
501
+ entries = [
502
+ "\"#{name}\"",
503
+ ("\"#{version}\"" if version),
504
+ (options_s unless options_s.empty?)
505
+ ].compact
506
+ "gem #{entries.join(', ')}"
507
+ end
472
508
  end
473
509
 
474
510
  def install(gems, filter_uptodate_packages: false, install_only: false)
@@ -485,21 +521,21 @@ module Autoproj
485
521
  backup_files(backups)
486
522
  unless File.file?("#{gemfile_path}.orig")
487
523
  Ops.atomic_write("#{gemfile_path}.orig") do |io|
488
- dot_autoproj_gemfile = File.join(ws.dot_autoproj_dir, 'Gemfile')
524
+ dot_autoproj_gemfile = File.join(ws.dot_autoproj_dir, "Gemfile")
489
525
  io.puts "eval_gemfile \"#{dot_autoproj_gemfile}\""
490
526
  end
491
527
  end
492
528
 
493
529
  gemfiles = workspace_configuration_gemfiles
494
- gemfiles << File.join(ws.dot_autoproj_dir, 'Gemfile')
530
+ gemfiles << File.join(ws.dot_autoproj_dir, "Gemfile")
495
531
 
496
532
  # Save the osdeps entries in a temporary gemfile and finally
497
533
  # merge the whole lot of it
498
- gemfile_contents = Tempfile.open 'autoproj-gemfile' do |io|
499
- gems.sort.each do |name|
500
- name, version = parse_package_entry(name)
501
- io.puts "gem \"#{name}\", \"#{version || '>= 0'}\""
502
- end
534
+ gemfile_contents = Tempfile.open "autoproj-gemfile" do |io|
535
+ gems.map { |entry| GemEntry.parse(entry) }
536
+ .sort_by(&:name)
537
+ .each { |entry| io.puts entry.to_gemfile_line }
538
+
503
539
  io.flush
504
540
  gemfiles.unshift io.path
505
541
  # The autoproj gemfile needs to be last, we really don't
@@ -518,7 +554,7 @@ module Autoproj
518
554
  end
519
555
 
520
556
  options = Array.new
521
- binstubs_path = File.join(root_dir, 'bin')
557
+ binstubs_path = File.join(root_dir, "bin")
522
558
  if updated || !install_only || !File.file?("#{gemfile_path}.lock")
523
559
  self.class.run_bundler_install(ws, gemfile_path, *options,
524
560
  binstubs: binstubs_path)
@@ -538,20 +574,21 @@ module Autoproj
538
574
  raise
539
575
  ensure
540
576
  if binstubs_path
541
- FileUtils.rm_f File.join(binstubs_path, 'bundle')
542
- FileUtils.rm_f File.join(binstubs_path, 'bundler')
577
+ FileUtils.rm_f File.join(binstubs_path, "bundle")
578
+ FileUtils.rm_f File.join(binstubs_path, "bundler")
543
579
  end
544
580
  backup_clean(backups)
545
581
  end
546
582
 
547
583
  def discover_rubylib
548
- require 'bundler'
549
- Tempfile.open 'autoproj-rubylib' do |io|
584
+ require "bundler"
585
+ Tempfile.open "autoproj-rubylib" do |io|
550
586
  result = Autoproj.bundler_unbundled_system(
551
- Hash['RUBYLIB' => nil],
552
- Autobuild.tool('ruby'), '-e', 'puts $LOAD_PATH',
587
+ Hash["RUBYLIB" => nil],
588
+ Autobuild.tool("ruby"), "-e", "puts $LOAD_PATH",
553
589
  out: io,
554
- err: '/dev/null')
590
+ err: "/dev/null"
591
+ )
555
592
  if result
556
593
  io.rewind
557
594
  io.readlines.map(&:chomp).find_all { |l| !l.empty? }
@@ -565,19 +602,20 @@ module Autoproj
565
602
  end
566
603
 
567
604
  def discover_bundle_rubylib(silent_errors: false)
568
- require 'bundler'
569
- gemfile = File.join(ws.prefix_dir, 'gems', 'Gemfile')
605
+ require "bundler"
606
+ gemfile = File.join(ws.prefix_dir, "gems", "Gemfile")
570
607
  silent_redirect = Hash.new
571
608
  silent_redirect[:err] = :close if silent_errors
572
609
  env = ws.env.resolved_env
573
- Tempfile.open 'autoproj-rubylib' do |io|
610
+ Tempfile.open "autoproj-rubylib" do |io|
574
611
  result = Autoproj.bundler_unbundled_system(
575
- Hash['GEM_HOME' => env['GEM_HOME'], 'GEM_PATH' => env['GEM_PATH'],
576
- 'BUNDLE_GEMFILE' => gemfile, 'RUBYOPT' => nil,
577
- 'RUBYLIB' => self.class.rubylib_for_bundler],
578
- Autobuild.tool('ruby'), '-rbundler/setup',
579
- '-e', 'puts $LOAD_PATH',
580
- out: io, **silent_redirect)
612
+ Hash["GEM_HOME" => env["GEM_HOME"], "GEM_PATH" => env["GEM_PATH"],
613
+ "BUNDLE_GEMFILE" => gemfile, "RUBYOPT" => nil,
614
+ "RUBYLIB" => self.class.rubylib_for_bundler],
615
+ Autobuild.tool("ruby"), "-rbundler/setup",
616
+ "-e", "puts $LOAD_PATH",
617
+ out: io, **silent_redirect
618
+ )
581
619
 
582
620
  if result
583
621
  io.rewind
@@ -20,14 +20,15 @@ module Autoproj
20
20
  def <=>(b)
21
21
  (0..2).inject(0) do |result, i|
22
22
  return result unless result == 0
23
- normalize(compare_fragments(self.split[i], b.split[i]))
23
+
24
+ normalize(compare_fragments(split[i], b.split[i]))
24
25
  end
25
26
  end
26
27
 
27
28
  def self.compare(a, b)
28
- new(a)<=>new(b)
29
+ new(a) <=> new(b)
29
30
  end
30
-
31
+
31
32
  private
32
33
 
33
34
  def normalize(value)
@@ -38,21 +39,21 @@ module Autoproj
38
39
 
39
40
  # Reference: https://www.debian.org/doc/debian-policy/ch-controlfields.html#version
40
41
  def parse_version
41
- @epoch = '0'
42
- @debian_revision = '0'
42
+ @epoch = "0"
43
+ @debian_revision = "0"
43
44
 
44
- @upstream_version = @version.split(':')
45
+ @upstream_version = @version.split(":")
45
46
  if @upstream_version.size > 1
46
47
  @epoch = @upstream_version.first
47
- @upstream_version = @upstream_version[1..-1].join(':')
48
+ @upstream_version = @upstream_version[1..-1].join(":")
48
49
  else
49
50
  @upstream_version = @upstream_version.first
50
51
  end
51
52
 
52
- @upstream_version = @upstream_version.split('-')
53
+ @upstream_version = @upstream_version.split("-")
53
54
  if @upstream_version.size > 1
54
55
  @debian_revision = @upstream_version.last
55
- @upstream_version = @upstream_version[0..-2].join('-')
56
+ @upstream_version = @upstream_version[0..-2].join("-")
56
57
  else
57
58
  @upstream_version = @upstream_version.first
58
59
  end
@@ -68,15 +69,15 @@ module Autoproj
68
69
 
69
70
  def order(c)
70
71
  if digit?(c)
71
- return 0
72
+ 0
72
73
  elsif alpha?(c)
73
- return c.ord
74
- elsif c == '~'
75
- return -1
74
+ c.ord
75
+ elsif c == "~"
76
+ -1
76
77
  elsif c
77
- return c.ord + 256
78
+ c.ord + 256
78
79
  else
79
- return 0
80
+ 0
80
81
  end
81
82
  end
82
83
 
@@ -89,13 +90,14 @@ module Autoproj
89
90
  while i != a.size && j != b.size && (!digit?(a[i]) || !digit?(b[j]))
90
91
  vc = order(a[i])
91
92
  rc = order(b[j])
92
- return vc-rc if vc != rc
93
+ return vc - rc if vc != rc
94
+
93
95
  i += 1
94
96
  j += 1
95
97
  end
96
98
 
97
- i += 1 while a[i] == '0'
98
- j += 1 while b[j] == '0'
99
+ i += 1 while a[i] == "0"
100
+ j += 1 while b[j] == "0"
99
101
  while digit?(a[i]) && digit?(b[j])
100
102
  first_diff = a[i].ord - b[j].ord if first_diff == 0
101
103
  i += 1
@@ -110,12 +112,14 @@ module Autoproj
110
112
  return 0 if i == a.size && j == b.size
111
113
 
112
114
  if i == a.size
113
- return 1 if b[j] == '~'
115
+ return 1 if b[j] == "~"
116
+
114
117
  return -1
115
118
  end
116
119
  if j == b.size
117
- return -1 if a[i] == '~'
118
- return 1
120
+ return -1 if a[i] == "~"
121
+
122
+ 1
119
123
  end
120
124
  end
121
125
  end
@@ -5,10 +5,9 @@ module Autoproj
5
5
  class EmergeManager < ShellScriptManager
6
6
  def initialize(ws)
7
7
  super(ws, true,
8
- %w{emerge},
9
- %w{emerge --noreplace})
8
+ %w[emerge],
9
+ %w[emerge --noreplace])
10
10
  end
11
11
  end
12
12
  end
13
13
  end
14
-