autoproj 2.13.0 → 2.15.2

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