autoproj 2.12.1 → 2.15.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/lint.yml +25 -0
- data/.github/workflows/test.yml +30 -0
- data/.rubocop.yml +79 -91
- data/.rubocop_todo.yml +1473 -0
- data/Gemfile +9 -9
- data/Rakefile +24 -24
- data/autoproj.gemspec +24 -22
- data/bin/alocate +4 -4
- data/bin/alog +6 -7
- data/bin/amake +4 -4
- data/bin/aup +4 -4
- data/bin/autoproj +3 -3
- data/bin/autoproj_bootstrap +225 -200
- data/bin/autoproj_bootstrap.in +7 -8
- data/bin/autoproj_install +224 -199
- data/bin/autoproj_install.in +6 -7
- data/lib/autoproj/aruba_minitest.rb +6 -11
- data/lib/autoproj/autobuild.rb +9 -6
- data/lib/autoproj/autobuild_extensions/archive_importer.rb +10 -11
- data/lib/autoproj/autobuild_extensions/dsl.rb +66 -36
- data/lib/autoproj/autobuild_extensions/git.rb +27 -26
- data/lib/autoproj/autobuild_extensions/package.rb +23 -22
- data/lib/autoproj/autobuild_extensions/python.rb +18 -0
- data/lib/autoproj/autobuild_extensions/svn.rb +1 -2
- data/lib/autoproj/base.rb +1 -1
- data/lib/autoproj/bash_completion.rb +5 -6
- data/lib/autoproj/build_option.rb +22 -24
- data/lib/autoproj/cli/base.rb +26 -26
- data/lib/autoproj/cli/bootstrap.rb +14 -16
- data/lib/autoproj/cli/build.rb +10 -7
- data/lib/autoproj/cli/cache.rb +11 -11
- data/lib/autoproj/cli/clean.rb +10 -10
- data/lib/autoproj/cli/commit.rb +7 -8
- data/lib/autoproj/cli/doc.rb +2 -2
- data/lib/autoproj/cli/envsh.rb +1 -2
- data/lib/autoproj/cli/exec.rb +60 -20
- data/lib/autoproj/cli/inspection_tool.rb +13 -7
- data/lib/autoproj/cli/locate.rb +30 -41
- data/lib/autoproj/cli/log.rb +7 -7
- data/lib/autoproj/cli/main.rb +217 -205
- data/lib/autoproj/cli/main_doc.rb +22 -21
- data/lib/autoproj/cli/main_global.rb +44 -19
- data/lib/autoproj/cli/main_plugin.rb +18 -18
- data/lib/autoproj/cli/main_test.rb +28 -27
- data/lib/autoproj/cli/manifest.rb +7 -7
- data/lib/autoproj/cli/osdeps.rb +12 -11
- data/lib/autoproj/cli/patcher.rb +2 -3
- data/lib/autoproj/cli/query.rb +17 -18
- data/lib/autoproj/cli/reconfigure.rb +1 -2
- data/lib/autoproj/cli/reset.rb +9 -12
- data/lib/autoproj/cli/show.rb +38 -39
- data/lib/autoproj/cli/status.rb +56 -44
- data/lib/autoproj/cli/switch_config.rb +5 -6
- data/lib/autoproj/cli/tag.rb +12 -11
- data/lib/autoproj/cli/test.rb +7 -7
- data/lib/autoproj/cli/update.rb +97 -43
- data/lib/autoproj/cli/utility.rb +14 -12
- data/lib/autoproj/cli/version.rb +42 -40
- data/lib/autoproj/cli/versions.rb +14 -15
- data/lib/autoproj/cli/watch.rb +33 -37
- data/lib/autoproj/cli/which.rb +16 -20
- data/lib/autoproj/cli.rb +4 -2
- data/lib/autoproj/configuration.rb +78 -86
- data/lib/autoproj/default.osdeps +29 -3
- data/lib/autoproj/environment.rb +42 -23
- data/lib/autoproj/exceptions.rb +9 -3
- data/lib/autoproj/find_workspace.rb +20 -25
- data/lib/autoproj/git_server_configuration.rb +40 -44
- data/lib/autoproj/gitorious.rb +1 -1
- data/lib/autoproj/installation_manifest.rb +64 -29
- data/lib/autoproj/local_package_set.rb +13 -11
- data/lib/autoproj/manifest.rb +139 -132
- data/lib/autoproj/metapackage.rb +2 -6
- data/lib/autoproj/ops/atomic_write.rb +7 -6
- data/lib/autoproj/ops/build.rb +4 -6
- data/lib/autoproj/ops/cache.rb +41 -43
- data/lib/autoproj/ops/cached_env.rb +5 -4
- data/lib/autoproj/ops/configuration.rb +519 -507
- data/lib/autoproj/ops/import.rb +88 -63
- data/lib/autoproj/ops/install.rb +218 -192
- data/lib/autoproj/ops/loader.rb +77 -76
- data/lib/autoproj/ops/main_config_switcher.rb +36 -45
- data/lib/autoproj/ops/phase_reporting.rb +4 -4
- data/lib/autoproj/ops/snapshot.rb +250 -247
- data/lib/autoproj/ops/tools.rb +76 -78
- data/lib/autoproj/ops/watch.rb +6 -6
- data/lib/autoproj/ops/which.rb +17 -14
- data/lib/autoproj/options.rb +13 -2
- data/lib/autoproj/os_package_installer.rb +102 -92
- data/lib/autoproj/os_package_query.rb +7 -13
- data/lib/autoproj/os_package_resolver.rb +189 -140
- data/lib/autoproj/os_repository_installer.rb +4 -4
- data/lib/autoproj/os_repository_resolver.rb +8 -6
- data/lib/autoproj/package_definition.rb +12 -13
- data/lib/autoproj/package_managers/apt_dpkg_manager.rb +19 -11
- data/lib/autoproj/package_managers/bundler_manager.rb +186 -129
- data/lib/autoproj/package_managers/debian_version.rb +25 -21
- data/lib/autoproj/package_managers/emerge_manager.rb +2 -3
- data/lib/autoproj/package_managers/gem_manager.rb +68 -77
- data/lib/autoproj/package_managers/homebrew_manager.rb +3 -4
- data/lib/autoproj/package_managers/manager.rb +8 -3
- data/lib/autoproj/package_managers/pacman_manager.rb +2 -3
- data/lib/autoproj/package_managers/pip_manager.rb +30 -28
- data/lib/autoproj/package_managers/pkg_manager.rb +3 -4
- data/lib/autoproj/package_managers/port_manager.rb +2 -3
- data/lib/autoproj/package_managers/shell_script_manager.rb +47 -25
- data/lib/autoproj/package_managers/unknown_os_manager.rb +5 -8
- data/lib/autoproj/package_managers/yum_manager.rb +12 -15
- data/lib/autoproj/package_managers/zypper_manager.rb +11 -14
- data/lib/autoproj/package_manifest.rb +28 -74
- data/lib/autoproj/package_selection.rb +187 -187
- data/lib/autoproj/package_set.rb +145 -114
- data/lib/autoproj/python.rb +297 -0
- data/lib/autoproj/query_base.rb +20 -14
- data/lib/autoproj/reporter.rb +19 -19
- data/lib/autoproj/repository_managers/apt.rb +102 -68
- data/lib/autoproj/repository_managers/unknown_os_manager.rb +3 -3
- data/lib/autoproj/ros_condition_parser.rb +84 -0
- data/lib/autoproj/ros_package_manifest.rb +125 -0
- data/lib/autoproj/shell_completion.rb +16 -13
- data/lib/autoproj/source_package_query.rb +29 -36
- data/lib/autoproj/system.rb +32 -21
- data/lib/autoproj/test.rb +131 -106
- data/lib/autoproj/variable_expansion.rb +10 -10
- data/lib/autoproj/vcs_definition.rb +53 -37
- data/lib/autoproj/version.rb +1 -1
- data/lib/autoproj/workspace.rb +143 -108
- data/lib/autoproj/zsh_completion.rb +8 -9
- data/lib/autoproj.rb +55 -53
- data/samples/autoproj/init.rb +1 -2
- metadata +86 -65
- data/.travis.yml +0 -22
data/lib/autoproj/ops/install.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
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[
|
75
|
-
env[
|
76
|
-
env[
|
77
|
-
env[
|
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[
|
81
|
+
if config["ruby_executable"] != Gem.ruby
|
82
82
|
raise "this autoproj installation was already bootstrapped using "\
|
83
|
-
|
84
|
-
|
85
|
-
|
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[
|
87
|
+
@ruby_executable = config["ruby_executable"]
|
88
88
|
@local = false
|
89
89
|
|
90
|
-
unless @gems_install_path
|
91
|
-
|
92
|
-
|
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?
|
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
|
-
|
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
|
-
|
123
|
-
if (
|
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
|
-
|
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
|
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
|
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
|
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
|
151
|
+
def skip_stage2?
|
152
|
+
!!@skip_stage2
|
153
|
+
end
|
148
154
|
# (see #skip_stage2?)
|
149
|
-
|
155
|
+
attr_writer :skip_stage2
|
150
156
|
|
151
157
|
# Whether we can access the network while installing
|
152
|
-
def local
|
158
|
+
def local?
|
159
|
+
!!@local
|
160
|
+
end
|
153
161
|
# (see #local?)
|
154
|
-
|
162
|
+
attr_writer :local
|
155
163
|
|
156
164
|
# The user-wide place where RubyGems installs gems
|
157
|
-
def dot_gem_dir
|
158
|
-
|
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
|
165
|
-
@
|
166
|
-
|
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
|
-
|
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,
|
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
|
-
# {
|
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(
|
202
|
-
|
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,
|
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[
|
228
|
-
ruby_bindir = RbConfig::CONFIG[
|
242
|
+
ruby_bin = RbConfig::CONFIG["RUBY_INSTALL_NAME"]
|
243
|
+
ruby_bindir = RbConfig::CONFIG["bindir"]
|
229
244
|
|
230
|
-
candidates = [
|
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
|
-
|
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
|
276
|
+
opt.on "--local", "do not access the network (may fail)" do
|
264
277
|
@local = true
|
265
278
|
end
|
266
|
-
opt.on
|
279
|
+
opt.on "--skip-stage2", "do not run the stage2 install" do
|
267
280
|
@skip_stage2 = true
|
268
281
|
end
|
269
|
-
opt.on
|
270
|
-
@autoproj_options <<
|
282
|
+
opt.on "--debug", "Run in debug mode" do
|
283
|
+
@autoproj_options << "--debug"
|
271
284
|
end
|
272
|
-
opt.on
|
273
|
-
|
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
|
277
|
-
|
278
|
-
self.gems_install_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
|
281
|
-
|
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
|
284
|
-
|
285
|
-
@config[
|
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
|
288
|
-
|
289
|
-
if @gemfile
|
290
|
-
|
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
|
295
|
-
|
296
|
-
if @gemfile
|
297
|
-
|
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
|
302
|
-
|
303
|
-
|
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
|
307
|
-
|
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
|
311
|
-
|
312
|
-
|
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
|
316
|
-
|
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
|
329
|
+
else
|
330
|
+
@autoproj_options << "--no-color"
|
319
331
|
end
|
320
332
|
end
|
321
|
-
opt.on
|
322
|
-
|
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
|
336
|
+
else
|
337
|
+
@autoproj_options << "--no-progress"
|
325
338
|
end
|
326
339
|
end
|
327
|
-
opt.on
|
328
|
-
|
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
|
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[
|
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,
|
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
|
-
|
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
|
-
|
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 = [
|
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 <<
|
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
|
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,
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
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
|
-
|
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,
|
422
|
-
if File.exist?(lockfile)
|
423
|
-
|
424
|
-
|
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
|
-
|
458
|
+
class BundlerFailed < RuntimeError; end
|
427
459
|
|
428
|
-
|
429
|
-
|
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
|
-
|
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
|
-
|
447
|
-
|
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,
|
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,
|
486
|
+
FileUtils.chmod 0755, File.join(shim_path, "ruby")
|
464
487
|
|
465
|
-
Dir.glob(File.join(shim_path,
|
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 ==
|
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,
|
480
|
-
if bin_name ==
|
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
|
-
|
506
|
+
autoproj_gemfile_path, gems_gem_home)
|
483
507
|
else
|
484
508
|
io.puts shim_script(bin_script_lines, ruby_executable, root_dir,
|
485
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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,
|
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,
|
589
|
-
env.set(
|
590
|
-
File.open(File.join(root_dir,
|
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,
|
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[
|
629
|
-
|
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,
|
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[
|
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
|
697
|
+
gem_program = self.class.guess_gem_program
|
673
698
|
puts "Detected 'gem' to be #{gem_program}"
|
674
|
-
env[
|
675
|
-
env[
|
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,
|
710
|
+
File.join(dot_autoproj, "bin"),
|
686
711
|
ruby_executable,
|
687
712
|
root_dir,
|
688
713
|
autoproj_gemfile_path,
|
689
|
-
gems_gem_home
|
690
|
-
|
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,
|
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[
|
709
|
-
ruby_bindir = RbConfig::CONFIG[
|
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[
|
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
|
-
|
715
|
-
|
716
|
-
|
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[
|
745
|
+
config["ruby_executable"] = ruby_executable
|
720
746
|
end
|
721
747
|
|
722
748
|
@config = config
|
723
|
-
%w
|
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[
|
730
|
-
config[
|
731
|
-
File.open(autoproj_config_path,
|
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,
|
761
|
+
File.join(dot_autoproj, "bin", "autoproj")
|
736
762
|
end
|
737
763
|
|
738
764
|
def run_autoproj(*args)
|
739
|
-
system env_for_child.merge(
|
740
|
-
|
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,
|
745
|
-
!File.directory?(File.join(root_dir,
|
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,
|
750
|
-
FileUtils.cp v1_envsh,
|
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
|
-
|
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
|
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
|
-
|
800
|
+
unless system(Gem.ruby, autoproj_path, "envsh", *@autoproj_options)
|
775
801
|
STDERR.puts "failed to run autoproj envsh on the newly installed "\
|
776
|
-
|
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
|
-
|
808
|
+
unless system(Gem.ruby, autoproj_path, "osdeps", *@autoproj_options)
|
783
809
|
STDERR.puts "failed to run autoproj osdeps on the newly installed "\
|
784
|
-
|
810
|
+
"autoproj (#{autoproj_path})"
|
785
811
|
exit 1
|
786
812
|
end
|
787
813
|
end
|