autoproj 2.12.1 → 2.15.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) 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 +24 -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 +3 -3
  14. data/bin/autoproj_bootstrap +225 -200
  15. data/bin/autoproj_bootstrap.in +7 -8
  16. data/bin/autoproj_install +224 -199
  17. data/bin/autoproj_install.in +6 -7
  18. data/lib/autoproj/aruba_minitest.rb +6 -11
  19. data/lib/autoproj/autobuild.rb +9 -6
  20. data/lib/autoproj/autobuild_extensions/archive_importer.rb +10 -11
  21. data/lib/autoproj/autobuild_extensions/dsl.rb +66 -36
  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/python.rb +18 -0
  25. data/lib/autoproj/autobuild_extensions/svn.rb +1 -2
  26. data/lib/autoproj/base.rb +1 -1
  27. data/lib/autoproj/bash_completion.rb +5 -6
  28. data/lib/autoproj/build_option.rb +22 -24
  29. data/lib/autoproj/cli/base.rb +26 -26
  30. data/lib/autoproj/cli/bootstrap.rb +14 -16
  31. data/lib/autoproj/cli/build.rb +10 -7
  32. data/lib/autoproj/cli/cache.rb +11 -11
  33. data/lib/autoproj/cli/clean.rb +10 -10
  34. data/lib/autoproj/cli/commit.rb +7 -8
  35. data/lib/autoproj/cli/doc.rb +2 -2
  36. data/lib/autoproj/cli/envsh.rb +1 -2
  37. data/lib/autoproj/cli/exec.rb +60 -20
  38. data/lib/autoproj/cli/inspection_tool.rb +13 -7
  39. data/lib/autoproj/cli/locate.rb +30 -41
  40. data/lib/autoproj/cli/log.rb +7 -7
  41. data/lib/autoproj/cli/main.rb +217 -205
  42. data/lib/autoproj/cli/main_doc.rb +22 -21
  43. data/lib/autoproj/cli/main_global.rb +44 -19
  44. data/lib/autoproj/cli/main_plugin.rb +18 -18
  45. data/lib/autoproj/cli/main_test.rb +28 -27
  46. data/lib/autoproj/cli/manifest.rb +7 -7
  47. data/lib/autoproj/cli/osdeps.rb +12 -11
  48. data/lib/autoproj/cli/patcher.rb +2 -3
  49. data/lib/autoproj/cli/query.rb +17 -18
  50. data/lib/autoproj/cli/reconfigure.rb +1 -2
  51. data/lib/autoproj/cli/reset.rb +9 -12
  52. data/lib/autoproj/cli/show.rb +38 -39
  53. data/lib/autoproj/cli/status.rb +56 -44
  54. data/lib/autoproj/cli/switch_config.rb +5 -6
  55. data/lib/autoproj/cli/tag.rb +12 -11
  56. data/lib/autoproj/cli/test.rb +7 -7
  57. data/lib/autoproj/cli/update.rb +97 -43
  58. data/lib/autoproj/cli/utility.rb +14 -12
  59. data/lib/autoproj/cli/version.rb +42 -40
  60. data/lib/autoproj/cli/versions.rb +14 -15
  61. data/lib/autoproj/cli/watch.rb +33 -37
  62. data/lib/autoproj/cli/which.rb +16 -20
  63. data/lib/autoproj/cli.rb +4 -2
  64. data/lib/autoproj/configuration.rb +78 -86
  65. data/lib/autoproj/default.osdeps +29 -3
  66. data/lib/autoproj/environment.rb +42 -23
  67. data/lib/autoproj/exceptions.rb +9 -3
  68. data/lib/autoproj/find_workspace.rb +20 -25
  69. data/lib/autoproj/git_server_configuration.rb +40 -44
  70. data/lib/autoproj/gitorious.rb +1 -1
  71. data/lib/autoproj/installation_manifest.rb +64 -29
  72. data/lib/autoproj/local_package_set.rb +13 -11
  73. data/lib/autoproj/manifest.rb +139 -132
  74. data/lib/autoproj/metapackage.rb +2 -6
  75. data/lib/autoproj/ops/atomic_write.rb +7 -6
  76. data/lib/autoproj/ops/build.rb +4 -6
  77. data/lib/autoproj/ops/cache.rb +41 -43
  78. data/lib/autoproj/ops/cached_env.rb +5 -4
  79. data/lib/autoproj/ops/configuration.rb +519 -507
  80. data/lib/autoproj/ops/import.rb +88 -63
  81. data/lib/autoproj/ops/install.rb +218 -192
  82. data/lib/autoproj/ops/loader.rb +77 -76
  83. data/lib/autoproj/ops/main_config_switcher.rb +36 -45
  84. data/lib/autoproj/ops/phase_reporting.rb +4 -4
  85. data/lib/autoproj/ops/snapshot.rb +250 -247
  86. data/lib/autoproj/ops/tools.rb +76 -78
  87. data/lib/autoproj/ops/watch.rb +6 -6
  88. data/lib/autoproj/ops/which.rb +17 -14
  89. data/lib/autoproj/options.rb +13 -2
  90. data/lib/autoproj/os_package_installer.rb +102 -92
  91. data/lib/autoproj/os_package_query.rb +7 -13
  92. data/lib/autoproj/os_package_resolver.rb +189 -140
  93. data/lib/autoproj/os_repository_installer.rb +4 -4
  94. data/lib/autoproj/os_repository_resolver.rb +8 -6
  95. data/lib/autoproj/package_definition.rb +12 -13
  96. data/lib/autoproj/package_managers/apt_dpkg_manager.rb +19 -11
  97. data/lib/autoproj/package_managers/bundler_manager.rb +186 -129
  98. data/lib/autoproj/package_managers/debian_version.rb +25 -21
  99. data/lib/autoproj/package_managers/emerge_manager.rb +2 -3
  100. data/lib/autoproj/package_managers/gem_manager.rb +68 -77
  101. data/lib/autoproj/package_managers/homebrew_manager.rb +3 -4
  102. data/lib/autoproj/package_managers/manager.rb +8 -3
  103. data/lib/autoproj/package_managers/pacman_manager.rb +2 -3
  104. data/lib/autoproj/package_managers/pip_manager.rb +30 -28
  105. data/lib/autoproj/package_managers/pkg_manager.rb +3 -4
  106. data/lib/autoproj/package_managers/port_manager.rb +2 -3
  107. data/lib/autoproj/package_managers/shell_script_manager.rb +47 -25
  108. data/lib/autoproj/package_managers/unknown_os_manager.rb +5 -8
  109. data/lib/autoproj/package_managers/yum_manager.rb +12 -15
  110. data/lib/autoproj/package_managers/zypper_manager.rb +11 -14
  111. data/lib/autoproj/package_manifest.rb +28 -74
  112. data/lib/autoproj/package_selection.rb +187 -187
  113. data/lib/autoproj/package_set.rb +145 -114
  114. data/lib/autoproj/python.rb +297 -0
  115. data/lib/autoproj/query_base.rb +20 -14
  116. data/lib/autoproj/reporter.rb +19 -19
  117. data/lib/autoproj/repository_managers/apt.rb +102 -68
  118. data/lib/autoproj/repository_managers/unknown_os_manager.rb +3 -3
  119. data/lib/autoproj/ros_condition_parser.rb +84 -0
  120. data/lib/autoproj/ros_package_manifest.rb +125 -0
  121. data/lib/autoproj/shell_completion.rb +16 -13
  122. data/lib/autoproj/source_package_query.rb +29 -36
  123. data/lib/autoproj/system.rb +32 -21
  124. data/lib/autoproj/test.rb +131 -106
  125. data/lib/autoproj/variable_expansion.rb +10 -10
  126. data/lib/autoproj/vcs_definition.rb +53 -37
  127. data/lib/autoproj/version.rb +1 -1
  128. data/lib/autoproj/workspace.rb +143 -108
  129. data/lib/autoproj/zsh_completion.rb +8 -9
  130. data/lib/autoproj.rb +55 -53
  131. data/samples/autoproj/init.rb +1 -2
  132. metadata +86 -65
  133. data/.travis.yml +0 -22
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'pathname'
4
- require 'optparse'
5
- require 'fileutils'
6
- require 'yaml'
7
- require 'English'
3
+ require "pathname"
4
+ require "optparse"
5
+ require "fileutils"
6
+ require "yaml"
7
+ require "English"
8
8
 
9
9
  module Autoproj
10
10
  module Ops
@@ -71,33 +71,30 @@ module Autoproj
71
71
  @autoproj_options = Array.new
72
72
 
73
73
  @env = Hash.new
74
- env['RUBYOPT'] = []
75
- env['RUBYLIB'] = []
76
- env['PATH'] = self.class.sanitize_env(ENV['PATH'] || "")
77
- env['BUNDLE_GEMFILE'] = []
74
+ env["RUBYOPT"] = []
75
+ env["RUBYLIB"] = []
76
+ env["PATH"] = self.class.sanitize_env(ENV["PATH"] || "")
77
+ env["BUNDLE_GEMFILE"] = []
78
78
 
79
79
  load_config
80
80
 
81
- if config['ruby_executable'] != Gem.ruby
81
+ if config["ruby_executable"] != Gem.ruby
82
82
  raise "this autoproj installation was already bootstrapped using "\
83
- "#{config['ruby_executable']}, but you are currently running "\
84
- "under #{Gem.ruby}. Changing the ruby interpreter in a given "\
85
- "workspace is not supported, you need to do a clean bootstrap"
83
+ "#{config['ruby_executable']}, but you are currently running "\
84
+ "under #{Gem.ruby}. Changing the ruby interpreter in a given "\
85
+ "workspace is not supported, you need to do a clean bootstrap"
86
86
  end
87
- @ruby_executable = config['ruby_executable']
87
+ @ruby_executable = config["ruby_executable"]
88
88
  @local = false
89
89
 
90
- unless @gems_install_path
91
- install_gems_in_gem_user_dir
92
- end
93
- env['GEM_HOME'] = [gems_gem_home]
94
- env['GEM_PATH'] = [gems_gem_home]
90
+ install_gems_in_gem_user_dir unless @gems_install_path
91
+ env["GEM_HOME"] = [gems_gem_home]
92
+ env["GEM_PATH"] = [gems_gem_home]
95
93
  end
96
94
 
97
95
  def env_for_child(env = self.env)
98
96
  env.inject(Hash.new) do |h, (k, v)|
99
- h[k] = if v && !v.empty? then v.join(File::PATH_SEPARATOR)
100
- end
97
+ h[k] = (v.join(File::PATH_SEPARATOR) if v && !v.empty?)
101
98
  h
102
99
  end
103
100
  end
@@ -113,57 +110,75 @@ module Autoproj
113
110
  end
114
111
 
115
112
  def self.sanitize_env(value)
116
- value.split(File::PATH_SEPARATOR).
117
- find_all { |p| !in_workspace?(p) }
113
+ value.split(File::PATH_SEPARATOR)
114
+ .find_all { |p| !in_workspace?(p) }
118
115
  end
119
116
 
120
117
  def self.in_workspace?(base_dir)
121
118
  path = Pathname.new(base_dir)
122
- while !path.root?
123
- if (path + ".autoproj").exist? || (path + "autoproj").exist?
119
+ until path.root?
120
+ if path.join(".autoproj").exist? || path.join("autoproj").exist?
124
121
  return true
125
122
  end
123
+
126
124
  path = path.parent
127
125
  end
128
- return false
126
+ false
129
127
  end
130
128
 
131
129
  # The path to the .autoproj configuration directory
132
130
  #
133
131
  # @return [String]
134
- def dot_autoproj; File.join(root_dir, '.autoproj') end
132
+ def dot_autoproj
133
+ File.join(root_dir, ".autoproj")
134
+ end
135
135
 
136
136
  # The path to the gemfile used to install autoproj
137
137
  #
138
138
  # @return [String]
139
- def autoproj_gemfile_path; File.join(dot_autoproj, 'Gemfile') end
139
+ def autoproj_gemfile_path
140
+ File.join(dot_autoproj, "Gemfile")
141
+ end
140
142
 
141
143
  # The path to the autoproj configuration file
142
144
  #
143
145
  # @return [String]
144
- def autoproj_config_path; File.join(dot_autoproj, 'config.yml') end
146
+ def autoproj_config_path
147
+ File.join(dot_autoproj, "config.yml")
148
+ end
145
149
 
146
150
  # Whether the stage2 install should be called or not
147
- def skip_stage2?; !!@skip_stage2 end
151
+ def skip_stage2?
152
+ !!@skip_stage2
153
+ end
148
154
  # (see #skip_stage2?)
149
- def skip_stage2=(flag); @skip_stage2 = flag end
155
+ attr_writer :skip_stage2
150
156
 
151
157
  # Whether we can access the network while installing
152
- def local?; !!@local end
158
+ def local?
159
+ !!@local
160
+ end
153
161
  # (see #local?)
154
- def local=(flag); @local = flag end
162
+ attr_writer :local
155
163
 
156
164
  # The user-wide place where RubyGems installs gems
157
- def dot_gem_dir
158
- File.join(Gem.user_home, ".gem")
165
+ def self.dot_gem_dir
166
+ if Gem.respond_to?(:data_home) # Debian 11+
167
+ File.join(Gem.data_home, "gem")
168
+ else
169
+ File.join(Gem.user_home, ".gem")
170
+ end
159
171
  end
160
172
 
161
173
  # The version and platform-specific suffix under {#dot_gem_dir}
162
174
  #
163
175
  # This is also the suffix used by bundler to install gems
164
- def gem_path_suffix
165
- @gem_path_suffix ||= Pathname.new(Gem.user_dir).
166
- relative_path_from(Pathname.new(dot_gem_dir)).to_s
176
+ def self.gems_path_suffix
177
+ @gems_path_suffix ||=
178
+ Pathname
179
+ .new(Gem.user_dir)
180
+ .relative_path_from(Pathname.new(dot_gem_dir))
181
+ .to_s
167
182
  end
168
183
 
169
184
  # The path into which the workspace's gems should be installed
@@ -172,21 +187,19 @@ module Autoproj
172
187
  # {#gem_path_suffix}.
173
188
  #
174
189
  # @return [String]
175
- attr_reader :gems_install_path
190
+ attr_accessor :gems_install_path
191
+
176
192
  # The GEM_HOME under which the workspace's gems should be installed
177
193
  #
178
194
  # @return [String]
179
195
  def gems_gem_home
180
- File.join(gems_install_path, gem_path_suffix)
196
+ File.join(gems_install_path, self.class.gems_path_suffix)
181
197
  end
182
198
  # Sets where the workspace's gems should be installed
183
199
  #
184
200
  # @param [String] path the absolute path that should be given to
185
201
  # bundler. The gems themselves will be installed in the
186
- # {#gem_path_suffix} subdirectory under this
187
- def gems_install_path=(path)
188
- @gems_install_path = path
189
- end
202
+ # {.gems_path_suffix} subdirectory under this
190
203
 
191
204
  private def xdg_var(varname, default)
192
205
  if (env = ENV[varname]) && !env.empty?
@@ -198,10 +211,11 @@ module Autoproj
198
211
 
199
212
  # Install autoproj in Gem's default user dir
200
213
  def install_gems_in_gem_user_dir
201
- xdg_default_gem_path = xdg_var('XDG_DATA_HOME',
202
- File.join(Dir.home, '.local', 'share', 'autoproj', 'gems'))
214
+ xdg_default_gem_path = xdg_var("XDG_DATA_HOME",
215
+ File.join(Dir.home, ".local", "share", "autoproj", "gems"))
203
216
  default_gem_path = File.join(
204
- Dir.home, '.autoproj', 'gems')
217
+ Dir.home, ".autoproj", "gems"
218
+ )
205
219
  @gems_install_path =
206
220
  if File.directory?(xdg_default_gem_path)
207
221
  xdg_default_gem_path
@@ -218,19 +232,18 @@ module Autoproj
218
232
  def prefer_indep_over_os_packages?
219
233
  @prefer_indep_over_os_packages
220
234
  end
235
+
221
236
  # (see #prefer_index_over_os_packages?)
222
237
  def prefer_indep_over_os_packages=(flag)
223
238
  @prefer_indep_over_os_packages = !!flag
224
239
  end
225
240
 
226
241
  def self.guess_gem_program
227
- ruby_bin = RbConfig::CONFIG['RUBY_INSTALL_NAME']
228
- ruby_bindir = RbConfig::CONFIG['bindir']
242
+ ruby_bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"]
243
+ ruby_bindir = RbConfig::CONFIG["bindir"]
229
244
 
230
- candidates = ['gem']
231
- if ruby_bin =~ /^ruby(.+)$/
232
- candidates.unshift "gem#{$1}"
233
- end
245
+ candidates = ["gem"]
246
+ candidates.unshift "gem#{$1}" if ruby_bin =~ /^ruby(.+)$/
234
247
 
235
248
  candidates.each do |gem_name|
236
249
  if File.file?(gem_full_path = File.join(ruby_bindir, gem_name))
@@ -238,7 +251,7 @@ module Autoproj
238
251
  end
239
252
  end
240
253
  raise ArgumentError, "cannot find a gem program "\
241
- "(tried #{candidates.sort.join(", ")} in #{ruby_bindir})"
254
+ "(tried #{candidates.sort.join(', ')} in #{ruby_bindir})"
242
255
  end
243
256
 
244
257
  # The content of the default {#gemfile}
@@ -254,80 +267,81 @@ module Autoproj
254
267
  end
255
268
 
256
269
  def add_seed_config(path)
257
- @config.merge!(YAML.safe_load(File.read(path)))
270
+ @config.merge!(YAML.safe_load(File.read(path), [Symbol]))
258
271
  end
259
272
 
260
273
  # Parse the provided command line options and returns the non-options
261
274
  def parse_options(args = ARGV)
262
275
  options = OptionParser.new do |opt|
263
- opt.on '--local', 'do not access the network (may fail)' do
276
+ opt.on "--local", "do not access the network (may fail)" do
264
277
  @local = true
265
278
  end
266
- opt.on '--skip-stage2', 'do not run the stage2 install' do
279
+ opt.on "--skip-stage2", "do not run the stage2 install" do
267
280
  @skip_stage2 = true
268
281
  end
269
- opt.on '--debug', 'Run in debug mode' do
270
- @autoproj_options << '--debug'
282
+ opt.on "--debug", "Run in debug mode" do
283
+ @autoproj_options << "--debug"
271
284
  end
272
- opt.on '--gem-source=URL', String, 'use this source for RubyGems '\
273
- 'instead of rubygems.org' do |url|
285
+ opt.on "--gem-source=URL", String, "use this source for RubyGems "\
286
+ "instead of rubygems.org" do |url|
274
287
  @gem_source = url
275
288
  end
276
- opt.on '--gems-path=PATH', 'install gems under this path instead '\
277
- 'of ~/.autoproj/gems' do |path|
278
- self.gems_install_path = path
289
+ opt.on "--gems-path=PATH", "install gems under this path instead "\
290
+ "of ~/.autoproj/gems" do |path|
291
+ self.gems_install_path = path
279
292
  end
280
- opt.on '--public-gems', "install gems in the default gem location" do
281
- self.install_gems_in_gem_user_dir
293
+ opt.on "--public-gems", "install gems in the default gem location" do
294
+ install_gems_in_gem_user_dir
282
295
  end
283
- opt.on '--bundler-version=VERSION_CONSTRAINT', String, 'use the provided '\
284
- 'string as a version constraint for bundler' do |version|
285
- @config['bundler_version'] = version
296
+ opt.on "--bundler-version=VERSION_CONSTRAINT", String, "use the provided "\
297
+ "string as a version constraint for bundler" do |version|
298
+ @config["bundler_version"] = version
286
299
  end
287
- opt.on '--version=VERSION_CONSTRAINT', String, 'use the provided '\
288
- 'string as a version constraint for autoproj' do |version|
289
- if @gemfile
290
- raise "cannot give both --version and --gemfile"
291
- end
300
+ opt.on "--version=VERSION_CONSTRAINT", String, "use the provided "\
301
+ "string as a version constraint for autoproj" do |version|
302
+ raise "cannot give both --version and --gemfile" if @gemfile
303
+
292
304
  @gemfile = default_gemfile_contents(version)
293
305
  end
294
- opt.on '--gemfile=PATH', String, 'use the given Gemfile to install '\
295
- 'autoproj instead of the default' do |path|
296
- if @gemfile
297
- raise "cannot give both --version and --gemfile"
298
- end
306
+ opt.on "--gemfile=PATH", String, "use the given Gemfile to install "\
307
+ "autoproj instead of the default" do |path|
308
+ raise "cannot give both --version and --gemfile" if @gemfile
309
+
299
310
  @gemfile = File.read(path)
300
311
  end
301
- opt.on '--no-seed-config',
302
- 'when reinstalling an existing autoproj workspace, do not '\
303
- 'use the config in .autoproj/ as seed' do
312
+ opt.on "--no-seed-config",
313
+ "when reinstalling an existing autoproj workspace, do not "\
314
+ "use the config in .autoproj/ as seed" do
304
315
  @config.clear
305
316
  end
306
- opt.on '--seed-config=PATH', String, 'path to a seed file that '\
307
- 'should be used to initialize the configuration' do |path|
317
+ opt.on "--seed-config=PATH", String, "path to a seed file that "\
318
+ "should be used to initialize the configuration" do |path|
308
319
  add_seed_config(path)
309
320
  end
310
- opt.on '--prefer-os-independent-packages', 'prefer OS-independent '\
311
- 'packages (such as a RubyGem) over their OS-packaged equivalent '\
312
- '(e.g. the thor gem vs. the ruby-thor debian package)' do
321
+ opt.on "--prefer-os-independent-packages", "prefer OS-independent "\
322
+ "packages (such as a RubyGem) over their OS-packaged equivalent "\
323
+ "(e.g. the thor gem vs. the ruby-thor debian package)" do
313
324
  @prefer_indep_over_os_packages = true
314
325
  end
315
- opt.on '--[no-]color', 'do not use colored output (enabled by '\
316
- 'default if the terminal supports it)' do |color|
326
+ opt.on "--[no-]color", "do not use colored output (enabled by "\
327
+ "default if the terminal supports it)" do |color|
317
328
  if color then @autoproj_options << "--color"
318
- else @autoproj_options << '--no-color'
329
+ else
330
+ @autoproj_options << "--no-color"
319
331
  end
320
332
  end
321
- opt.on '--[no-]progress', 'do not use progress output (enabled by '\
322
- 'default if the terminal supports it)' do |progress|
333
+ opt.on "--[no-]progress", "do not use progress output (enabled by "\
334
+ "default if the terminal supports it)" do |progress|
323
335
  if progress then @autoproj_options << "--progress"
324
- else @autoproj_options << '--no-progress'
336
+ else
337
+ @autoproj_options << "--no-progress"
325
338
  end
326
339
  end
327
- opt.on '--[no-]interactive', 'if non-interactive, use default '\
328
- 'answer for questions' do |flag|
340
+ opt.on "--[no-]interactive", "if non-interactive, use default "\
341
+ "answer for questions" do |flag|
329
342
  if flag then @autoproj_options << "--interactive"
330
- else @autoproj_options << "--no-interactive"
343
+ else
344
+ @autoproj_options << "--no-interactive"
331
345
  end
332
346
  end
333
347
  end
@@ -336,11 +350,11 @@ module Autoproj
336
350
  end
337
351
 
338
352
  def bundler_version
339
- @config['bundler_version']
353
+ @config["bundler_version"]
340
354
  end
341
355
 
342
356
  def find_bundler(gem_program, version: nil)
343
- bundler_path = File.join(gems_gem_home, 'bin', 'bundle')
357
+ bundler_path = File.join(gems_gem_home, "bin", "bundle")
344
358
  return unless File.exist?(bundler_path)
345
359
 
346
360
  setup_paths =
@@ -359,7 +373,7 @@ module Autoproj
359
373
  def find_versioned_bundler_setup(gem_program, version)
360
374
  contents = IO.popen(
361
375
  [env_for_child, Gem.ruby, gem_program,
362
- 'contents', '-v', version, 'bundler'],
376
+ "contents", "-v", version, "bundler"],
363
377
  &:readlines
364
378
  )
365
379
  return [] unless $CHILD_STATUS.success?
@@ -370,7 +384,7 @@ module Autoproj
370
384
  def find_unversioned_bundler_setup(gem_program)
371
385
  setup_paths = IO.popen(
372
386
  [env_for_child, Gem.ruby, gem_program,
373
- 'which', '-a', 'bundler/setup'],
387
+ "which", "-a", "bundler/setup"],
374
388
  &:readlines
375
389
  )
376
390
  return [] unless $CHILD_STATUS.success?
@@ -379,29 +393,30 @@ module Autoproj
379
393
  end
380
394
 
381
395
  def install_bundler(gem_program, version: nil, silent: false)
382
- local = ['--local'] if local?
396
+ local = ["--local"] if local?
383
397
 
384
398
  redirection = Hash.new
385
- if silent
386
- redirection = Hash[out: :close]
387
- end
399
+ redirection = Hash[out: :close] if silent
388
400
 
389
401
  version_args = []
390
- version_args << '-v' << version if version
402
+ version_args << "-v" << version if version
391
403
 
392
404
  # Shut up the bundler warning about 'bin' not being in PATH
393
405
  env = self.env
394
- env['PATH'] += [File.join(gems_gem_home, 'bin')]
406
+ env = env.merge(
407
+ { "PATH" => env["PATH"] + [File.join(gems_gem_home, "bin")] }
408
+ )
395
409
  result = system(
396
410
  env_for_child(env),
397
- Gem.ruby, gem_program, 'install',
398
- '--env-shebang', '--no-document', '--no-format-executable',
399
- '--clear-sources', '--source', gem_source,
400
- '--no-user-install', '--install-dir', gems_gem_home,
401
- *local, "--bindir=#{File.join(gems_gem_home, 'bin')}",
402
- 'bundler', *version_args, **redirection)
403
-
404
- if !result
411
+ Gem.ruby, gem_program, "install",
412
+ "--env-shebang", "--no-document", "--no-format-executable",
413
+ "--clear-sources", "--source", gem_source,
414
+ "--no-user-install", "--install-dir", gems_gem_home,
415
+ *local, "--bindir=#{File.join(gems_gem_home, 'bin')}",
416
+ "bundler", *version_args, **redirection
417
+ )
418
+
419
+ unless result
405
420
  STDERR.puts "FATAL: failed to install bundler in #{gems_gem_home}"
406
421
  nil
407
422
  end
@@ -410,7 +425,7 @@ module Autoproj
410
425
  bundler_path
411
426
  else
412
427
  STDERR.puts "gem install bundler returned successfully, but still "\
413
- "cannot find bundler in #{gems_gem_home}"
428
+ "cannot find bundler in #{gems_gem_home}"
414
429
  nil
415
430
  end
416
431
  end
@@ -418,37 +433,45 @@ module Autoproj
418
433
  def install_autoproj(bundler, bundler_version: self.bundler_version)
419
434
  # Force bundler to update. If the user does not want this, let
420
435
  # him specify a Gemfile with tighter version constraints
421
- lockfile = File.join(dot_autoproj, 'Gemfile.lock')
422
- if File.exist?(lockfile)
423
- FileUtils.rm lockfile
424
- end
436
+ lockfile = File.join(dot_autoproj, "Gemfile.lock")
437
+ FileUtils.rm lockfile if File.exist?(lockfile)
438
+
439
+ run_bundler(bundler, "config", "set", "--local", "path", gems_install_path,
440
+ bundler_version: bundler_version)
441
+ run_bundler(bundler, "config", "set", "--local", "shebang", Gem.ruby,
442
+ bundler_version: bundler_version)
443
+
444
+ install_args = ["--gemfile=#{autoproj_gemfile_path}"]
445
+ install_args << "--local" if local?
446
+ run_bundler(bundler, "install", *install_args,
447
+ bundler_version: bundler_version)
448
+
449
+ shims_path = File.join(dot_autoproj, "bin")
450
+ run_bundler(bundler, "binstubs", "--all", "--force", "--path", shims_path,
451
+ bundler_version: bundler_version)
452
+ self.class.rewrite_shims(
453
+ shims_path, ruby_executable, root_dir,
454
+ autoproj_gemfile_path, gems_gem_home
455
+ )
456
+ end
425
457
 
426
- clean_env = env_for_child.dup
458
+ class BundlerFailed < RuntimeError; end
427
459
 
428
- opts = Array.new
429
- opts << '--local' if local?
430
- opts << "--path=#{gems_install_path}"
431
- shims_path = File.join(dot_autoproj, 'bin')
460
+ def run_bundler(bundler, *args, bundler_version: self.bundler_version)
461
+ clean_env = env_for_child.dup
432
462
 
433
463
  version_arg = []
434
464
  version_arg << "_#{bundler_version}_" if bundler_version
435
465
 
436
466
  result = system(
437
- clean_env,
438
- Gem.ruby, bundler, *version_arg, 'install',
439
- "--gemfile=#{autoproj_gemfile_path}",
440
- "--shebang=#{Gem.ruby}",
441
- "--binstubs=#{shims_path}",
442
- *opts, chdir: dot_autoproj
467
+ clean_env, Gem.ruby, bundler, *version_arg,
468
+ *args, chdir: dot_autoproj
443
469
  )
444
470
 
445
471
  unless result
446
- STDERR.puts "FATAL: failed to install autoproj in #{dot_autoproj}"
447
- exit 1
472
+ raise BundlerFailed,
473
+ "FAILED: bundler #{args.join(', ')} in #{dot_autoproj}"
448
474
  end
449
- ensure
450
- self.class.rewrite_shims(shims_path, ruby_executable,
451
- root_dir, autoproj_gemfile_path, gems_gem_home)
452
475
  end
453
476
 
454
477
  EXCLUDED_FROM_SHIMS = %w[rake thor].freeze
@@ -456,13 +479,13 @@ module Autoproj
456
479
  def self.rewrite_shims(shim_path, ruby_executable,
457
480
  root_dir, autoproj_gemfile_path, gems_gem_home)
458
481
  FileUtils.mkdir_p shim_path
459
- File.open(File.join(shim_path, 'ruby'), 'w') do |io|
482
+ File.open(File.join(shim_path, "ruby"), "w") do |io|
460
483
  io.puts "#! /bin/sh"
461
484
  io.puts "exec #{ruby_executable} \"$@\""
462
485
  end
463
- FileUtils.chmod 0755, File.join(shim_path, 'ruby')
486
+ FileUtils.chmod 0755, File.join(shim_path, "ruby")
464
487
 
465
- Dir.glob(File.join(shim_path, '*')) do |bin_script|
488
+ Dir.glob(File.join(shim_path, "*")) do |bin_script|
466
489
  next unless File.file?(bin_script)
467
490
 
468
491
  bin_name = File.basename(bin_script)
@@ -470,25 +493,30 @@ module Autoproj
470
493
  FileUtils.rm_f bin_script
471
494
  next
472
495
  end
473
- next if bin_name == 'ruby'
496
+ next if bin_name == "ruby"
474
497
 
475
498
  bin_shim = File.join(shim_path, bin_name)
476
499
  bin_script_lines = File.readlines(bin_script)
477
500
  next if has_autoproj_preamble?(bin_script_lines)
501
+ next unless ruby_script?(bin_script_lines)
478
502
 
479
- File.open(bin_shim, 'w') do |io|
480
- if bin_name == 'bundler' || bin_name == 'bundle'
503
+ File.open(bin_shim, "w") do |io|
504
+ if bin_name == "bundler" || bin_name == "bundle"
481
505
  io.puts shim_bundler(bin_script_lines, ruby_executable,
482
- autoproj_gemfile_path, gems_gem_home)
506
+ autoproj_gemfile_path, gems_gem_home)
483
507
  else
484
508
  io.puts shim_script(bin_script_lines, ruby_executable, root_dir,
485
- autoproj_gemfile_path, gems_gem_home)
509
+ autoproj_gemfile_path, gems_gem_home)
486
510
  end
487
511
  end
488
512
  FileUtils.chmod 0755, bin_shim
489
513
  end
490
514
  end
491
515
 
516
+ def self.ruby_script?(script_lines)
517
+ script_lines.first =~ /\#\s*!(.*ruby.*)/
518
+ end
519
+
492
520
  def self.new_style_bundler_binstub?(script_lines)
493
521
  script_lines.any? { |l| l =~ /This file was generated by Bundler/ }
494
522
  end
@@ -517,7 +545,7 @@ Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => '']
517
545
  end
518
546
 
519
547
  def self.shim_bundler_old(ruby_executable, autoproj_gemfile_path, gems_gem_home)
520
- "#! #{ruby_executable}
548
+ "#! #{ruby_executable}
521
549
 
522
550
  #{WITHOUT_BUNDLER}
523
551
  ENV['BUNDLE_GEMFILE'] ||= '#{autoproj_gemfile_path}'
@@ -529,13 +557,13 @@ load Gem.bin_path('bundler', 'bundler')"
529
557
  end
530
558
 
531
559
  def self.shim_script(script_lines, ruby_executable, root_dir,
532
- autoproj_gemfile_path, gems_gem_home)
560
+ autoproj_gemfile_path, gems_gem_home)
533
561
  new_style = !script_lines.empty? && script_lines.any? do |l|
534
562
  l =~ /This file was generated by Bundler/
535
563
  end
536
564
  load_line = script_lines.grep(/load Gem.bin_path/).first
537
565
  return shim_script_old(ruby_executable, root_dir,
538
- autoproj_gemfile_path, gems_gem_home, load_line) \
566
+ autoproj_gemfile_path, gems_gem_home, load_line) \
539
567
  unless new_style
540
568
 
541
569
  script_lines.insert(1, <<-AUTOPROJ_PREAMBLE)
@@ -549,12 +577,12 @@ ENV['BUNDLE_GEMFILE'] = '#{autoproj_gemfile_path}'
549
577
  ENV['AUTOPROJ_CURRENT_ROOT'] = '#{root_dir}'
550
578
  Gem.paths = Hash['GEM_HOME' => '#{gems_gem_home}', 'GEM_PATH' => '']
551
579
  AUTOPROJ_PREAMBLE
552
- return script_lines.join
580
+ script_lines.join
553
581
  end
554
582
 
555
583
  def self.shim_script_old(ruby_executable, root_dir, autoproj_gemfile_path,
556
584
  gems_gem_home, load_line)
557
- "#! #{ruby_executable}
585
+ "#! #{ruby_executable}
558
586
 
559
587
  #{RUBYLIB_REINIT}
560
588
  ENV['BUNDLE_GEMFILE'] = '#{autoproj_gemfile_path}'
@@ -579,15 +607,15 @@ require 'bundler/setup'
579
607
  end
580
608
  end
581
609
  # Generate environment files right now, we can at least use bundler
582
- File.open(File.join(dot_autoproj, 'env.sh'), 'w') do |io|
610
+ File.open(File.join(dot_autoproj, "env.sh"), "w") do |io|
583
611
  env.export_env_sh(io)
584
612
  end
585
613
 
586
614
  # And now the root envsh
587
615
  env = Autobuild::Environment.new
588
- env.source_before File.join(dot_autoproj, 'env.sh')
589
- env.set('AUTOPROJ_CURRENT_ROOT', root_dir)
590
- File.open(File.join(root_dir, 'env.sh'), 'w') do |io|
616
+ env.source_before File.join(dot_autoproj, "env.sh")
617
+ env.set("AUTOPROJ_CURRENT_ROOT", root_dir)
618
+ File.open(File.join(root_dir, "env.sh"), "w") do |io|
591
619
  env.export_env_sh(io)
592
620
  end
593
621
  end
@@ -616,22 +644,19 @@ require 'bundler/setup'
616
644
  ].join("\n")
617
645
 
618
646
  FileUtils.mkdir_p File.dirname(autoproj_gemfile_path)
619
- File.open(autoproj_gemfile_path, 'w') do |io|
647
+ File.open(autoproj_gemfile_path, "w") do |io|
620
648
  io.write gemfile
621
649
  end
622
650
  end
623
651
 
624
652
  ENV_BUNDLE_GEMFILE_RX = /^(\s*ENV\[['"]BUNDLE_GEMFILE['"]\]\s*)(?:\|\|)?=/
625
653
 
626
-
627
654
  def find_in_clean_path(command, *additional_paths)
628
- clean_path = env_for_child['PATH'].split(File::PATH_SEPARATOR) +
629
- additional_paths
655
+ clean_path = env_for_child["PATH"].split(File::PATH_SEPARATOR) +
656
+ additional_paths
630
657
  clean_path.each do |p|
631
658
  full_path = File.join(p, command)
632
- if File.file?(full_path)
633
- return full_path
634
- end
659
+ return full_path if File.file?(full_path)
635
660
  end
636
661
  nil
637
662
  end
@@ -652,7 +677,7 @@ require 'bundler/setup'
652
677
  # actual bindir
653
678
  bindir = IO.popen(
654
679
  env_for_child,
655
- [Gem.ruby, '-e', 'puts "#{Gem.user_dir}/bin"'], # rubocop:disable Lint/InterpolationCheck
680
+ [Gem.ruby, "-e", 'puts "#{Gem.user_dir}/bin"'], # rubocop:disable Lint/InterpolationCheck
656
681
  &:read
657
682
  )
658
683
  if bindir
@@ -663,16 +688,16 @@ require 'bundler/setup'
663
688
  end
664
689
 
665
690
  def install(bundler_version: self.bundler_version)
666
- if ENV['BUNDLER_GEMFILE']
691
+ if ENV["BUNDLER_GEMFILE"]
667
692
  raise "cannot run autoproj_install or autoproj_bootstrap while "\
668
693
  "under a 'bundler exec' subcommand or having loaded an "\
669
694
  "env.sh. Open a new console and try again"
670
695
  end
671
696
 
672
- gem_program = self.class.guess_gem_program
697
+ gem_program = self.class.guess_gem_program
673
698
  puts "Detected 'gem' to be #{gem_program}"
674
- env['GEM_HOME'] = [gems_gem_home]
675
- env['GEM_PATH'] = [gems_gem_home]
699
+ env["GEM_HOME"] = [gems_gem_home]
700
+ env["GEM_PATH"] = [gems_gem_home]
676
701
 
677
702
  if (bundler = find_bundler(gem_program, version: bundler_version))
678
703
  puts "Detected bundler at #{bundler}"
@@ -682,12 +707,13 @@ require 'bundler/setup'
682
707
  exit(1) unless bundler
683
708
  end
684
709
  self.class.rewrite_shims(
685
- File.join(dot_autoproj, 'bin'),
710
+ File.join(dot_autoproj, "bin"),
686
711
  ruby_executable,
687
712
  root_dir,
688
713
  autoproj_gemfile_path,
689
- gems_gem_home)
690
- env['PATH'].unshift File.join(dot_autoproj, 'bin')
714
+ gems_gem_home
715
+ )
716
+ env["PATH"].unshift File.join(dot_autoproj, "bin")
691
717
  save_gemfile
692
718
 
693
719
  puts "Installing autoproj in #{gems_gem_home}"
@@ -695,7 +721,7 @@ require 'bundler/setup'
695
721
  end
696
722
 
697
723
  def load_config
698
- v1_config_path = File.join(root_dir, 'autoproj', 'config.yml')
724
+ v1_config_path = File.join(root_dir, "autoproj", "config.yml")
699
725
 
700
726
  config = Hash.new
701
727
  if File.file?(v1_config_path)
@@ -705,49 +731,49 @@ require 'bundler/setup'
705
731
  config.merge!(YAML.load(File.read(autoproj_config_path)) || Hash.new)
706
732
  end
707
733
 
708
- ruby = RbConfig::CONFIG['RUBY_INSTALL_NAME']
709
- ruby_bindir = RbConfig::CONFIG['bindir']
734
+ ruby = RbConfig::CONFIG["RUBY_INSTALL_NAME"]
735
+ ruby_bindir = RbConfig::CONFIG["bindir"]
710
736
  ruby_executable = File.join(ruby_bindir, ruby)
711
- if current = config['ruby_executable'] # When upgrading or reinstalling
737
+ if (current = config["ruby_executable"]) # When upgrading or reinstalling
712
738
  if current != ruby_executable
713
739
  raise "this workspace has already been initialized using "\
714
- "#{current}, you cannot run autoproj install with "\
715
- "#{ruby_executable}. If you know what you're doing, "\
716
- "delete the ruby_executable line in config.yml and try again"
740
+ "#{current}, you cannot run autoproj install with "\
741
+ "#{ruby_executable}. If you know what you're doing, "\
742
+ "delete the ruby_executable line in config.yml and try again"
717
743
  end
718
744
  else
719
- config['ruby_executable'] = ruby_executable
745
+ config["ruby_executable"] = ruby_executable
720
746
  end
721
747
 
722
748
  @config = config
723
- %w{gems_install_path prefer_indep_over_os_packages}.each do |flag|
749
+ %w[gems_install_path prefer_indep_over_os_packages].each do |flag|
724
750
  instance_variable_set "@#{flag}", config.fetch(flag, false)
725
751
  end
726
752
  end
727
753
 
728
754
  def save_config
729
- config['gems_install_path'] = gems_install_path
730
- config['prefer_indep_over_os_packages'] = prefer_indep_over_os_packages?
731
- File.open(autoproj_config_path, 'w') { |io| YAML.dump(config, io) }
755
+ config["gems_install_path"] = gems_install_path
756
+ config["prefer_indep_over_os_packages"] = prefer_indep_over_os_packages?
757
+ File.open(autoproj_config_path, "w") { |io| YAML.dump(config, io) }
732
758
  end
733
759
 
734
760
  def autoproj_path
735
- File.join(dot_autoproj, 'bin', 'autoproj')
761
+ File.join(dot_autoproj, "bin", "autoproj")
736
762
  end
737
763
 
738
764
  def run_autoproj(*args)
739
- system env_for_child.merge('BUNDLE_GEMFILE' => autoproj_gemfile_path),
740
- Gem.ruby, autoproj_path, *args, *@autoproj_options
765
+ system env_for_child.merge("BUNDLE_GEMFILE" => autoproj_gemfile_path),
766
+ Gem.ruby, autoproj_path, *args, *@autoproj_options
741
767
  end
742
768
 
743
769
  def v1_workspace?
744
- File.file?(File.join(root_dir, 'autoproj', 'config.yml')) &&
745
- !File.directory?(File.join(root_dir, '.autoproj'))
770
+ File.file?(File.join(root_dir, "autoproj", "config.yml")) &&
771
+ !File.directory?(File.join(root_dir, ".autoproj"))
746
772
  end
747
773
 
748
774
  def stage1
749
- if v1_workspace? && File.file?(v1_envsh = File.join(root_dir, 'env.sh'))
750
- FileUtils.cp v1_envsh, 'env.sh-autoproj-v1'
775
+ if v1_workspace? && File.file?(v1_envsh = File.join(root_dir, "env.sh"))
776
+ FileUtils.cp v1_envsh, "env.sh-autoproj-v1"
751
777
  end
752
778
  FileUtils.mkdir_p dot_autoproj
753
779
  save_config
@@ -761,27 +787,27 @@ require 'bundler/setup'
761
787
  clean_env = env_for_child
762
788
  stage2_vars = clean_env.map { |k, v| "#{k}=#{v}" }
763
789
  puts "starting the newly installed autoproj for stage2 install"
764
- if !run_autoproj('install-stage2', root_dir, *stage2_vars, *@autoproj_options)
790
+ unless run_autoproj("install-stage2", root_dir, *stage2_vars, *@autoproj_options)
765
791
  raise "failed to execute autoproj install-stage2"
766
792
  end
767
793
  end
768
794
 
769
795
  def stage2(*vars)
770
- require 'autobuild'
796
+ require "autobuild"
771
797
  puts "saving temporary env.sh and .autoproj/env.sh"
772
798
  save_env_sh(*vars)
773
799
  puts "running 'autoproj envsh' to generate a proper env.sh"
774
- if !system(Gem.ruby, autoproj_path, 'envsh', *@autoproj_options)
800
+ unless system(Gem.ruby, autoproj_path, "envsh", *@autoproj_options)
775
801
  STDERR.puts "failed to run autoproj envsh on the newly installed "\
776
- "autoproj (#{autoproj_path})"
802
+ "autoproj (#{autoproj_path})"
777
803
  exit 1
778
804
  end
779
805
  # This is really needed on an existing install to install the
780
806
  # gems that were present in the v1 layout
781
807
  puts "running 'autoproj osdeps' to re-install missing gems"
782
- if !system(Gem.ruby, autoproj_path, 'osdeps', *@autoproj_options)
808
+ unless system(Gem.ruby, autoproj_path, "osdeps", *@autoproj_options)
783
809
  STDERR.puts "failed to run autoproj osdeps on the newly installed "\
784
- "autoproj (#{autoproj_path})"
810
+ "autoproj (#{autoproj_path})"
785
811
  exit 1
786
812
  end
787
813
  end