autoproj 2.14.0 → 2.15.0

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