lib/autoproj/package_managers/bundler_manager.rb in autoproj-2.0.0.rc37 vs lib/autoproj/package_managers/bundler_manager.rb in autoproj-2.0.0.rc38
- old
+ new
@@ -22,17 +22,22 @@
@with_prerelease = saved_flag
end
end
end
- def initialize(ws)
- super
- self.call_while_empty = true
+ # (see Manager#call_while_empty?)
+ def call_while_empty?
+ !workspace_configuration_gemfiles.empty?
end
- # Filters all paths that come from other autoproj installations out
- # of GEM_PATH
+ # (see Manager#strict?)
+ def strict?
+ true
+ end
+
+ # Set up the workspace environment to work with the bundler-managed
+ # gems
def initialize_environment
env = ws.env
config = ws.config
@@ -85,43 +90,79 @@
if bundle_rubylib = discover_bundle_rubylib(silent_errors: true)
update_env_rubylib(bundle_rubylib, system_rubylib)
end
end
+ # @api private
+ #
+ # Update RUBYLIB to add the gems that are part of the bundler
+ # install
+ #
+ # @param [Array<String>] bundle_rubylib the rubylib entries reported
+ # by bundler
+ # @param [Array<String>] system_rubylib the rubylib entries that are
+ # set by the underlying ruby interpreter itself
def update_env_rubylib(bundle_rubylib, system_rubylib = discover_rubylib)
current = (ws.env.resolved_env['RUBYLIB'] || '').split(File::PATH_SEPARATOR) + system_rubylib
(bundle_rubylib - current).each do |p|
ws.env.add_path('RUBYLIB', p)
end
end
+ # @api private
+ #
+ # Parse an osdep entry into a gem name and gem version
+ #
+ # The 'gem' entries in the osdep files can contain a version
+ # specification. This method parses the two parts and return them
+ #
+ # @param [String] entry the osdep entry
+ # @return [(String,String),(String,nil)] the gem name, and an
+ # optional version specification
def parse_package_entry(entry)
if entry =~ /^([^><=~]*)([><=~]+.*)$/
[$1.strip, $2.strip]
else
[entry]
end
end
class NotCleanState < RuntimeError; end
-
+
+ # @api private
+ #
+ # Create backup files matching a certain file mapping
+ #
+ # @param [Hash<String,String>] mapping a mapping from the original
+ # file to the file into which it should be backed up. The source
+ # file might not exist.
def backup_files(mapping)
mapping.each do |file, backup_file|
if File.file?(file)
FileUtils.cp file, backup_file
end
end
end
+ # @api private
+ #
+ # Restore backups saved by {#backup_file}
+ #
+ # @param (see #backup_file)
def backup_restore(mapping)
mapping.each do |file, backup_file|
if File.file?(backup_file)
FileUtils.cp backup_file, file
end
end
end
+ # @api private
+ #
+ # Remove backups created by {#backup_files}
+ #
+ # @param (see #backup_file)
def backup_clean(mapping)
mapping.each do |file, backup_file|
if File.file?(backup_file)
FileUtils.rm backup_file
end
@@ -181,12 +222,12 @@
# Parse the contents of a gemfile into a set of
def merge_gemfiles(*path, unlock: [])
gems_remotes = Set.new
dependencies = Hash.new do |h, k|
- h[k] = Hash.new do |h, k|
- h[k] = Hash.new do |a, b|
+ h[k] = Hash.new do |i, j|
+ i[j] = Hash.new do |a, b|
a[b] = Array.new
end
end
end
path.each do |gemfile|
@@ -237,10 +278,24 @@
contents << "end"
end
contents.join("\n")
end
+ def workspace_configuration_gemfiles
+ gemfiles = []
+ ws.manifest.each_package_set do |source|
+ if source.local_dir && File.file?(pkg_set_gemfile = File.join(source.local_dir, 'Gemfile'))
+ gemfiles << pkg_set_gemfile
+ end
+ end
+ # In addition, look into overrides.d
+ Dir.glob(File.join(ws.overrides_dir, "*.gemfile")) do |overrides_gemfile_path|
+ gemfiles << overrides_gemfile_path
+ end
+ gemfiles
+ end
+
def install(gems, filter_uptodate_packages: false, install_only: false)
root_dir = File.join(ws.prefix_dir, 'gems')
gemfile_path = File.join(root_dir, 'Gemfile')
gemfile_lock_path = "#{gemfile_path}.lock"
backups = Hash[
@@ -255,19 +310,10 @@
File.open("#{gemfile_path}.orig", 'w') do |io|
io.puts "eval_gemfile \"#{File.join(ws.dot_autoproj_dir, 'Gemfile')}\""
end
end
- gemfiles = []
- ws.manifest.each_package_set do |source|
- if source.local_dir && File.file?(pkg_set_gemfile = File.join(source.local_dir, 'Gemfile'))
- gemfiles << pkg_set_gemfile
- end
- end
- # In addition, look into overrides.d
- Dir.glob(File.join(ws.overrides_dir, "*.gemfile")) do |gemfile_path|
- gemfiles << gemfile_path
- end
+ gemfiles = workspace_configuration_gemfiles
gemfiles << File.join(ws.dot_autoproj_dir, 'Gemfile')
# Save the osdeps entries in a temporary gemfile and finally
# merge the whole lot of it
gemfile_contents = Tempfile.open 'autoproj-gemfile' do |io|