2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-07-09 19:21:36 -04:00
|
|
|
##
|
2014-09-13 23:30:02 -04:00
|
|
|
# A semi-compatible DSL for the Bundler Gemfile and Isolate gem dependencies
|
|
|
|
# files.
|
|
|
|
#
|
|
|
|
# To work with both the Bundler Gemfile and Isolate formats this
|
|
|
|
# implementation takes some liberties to allow compatibility with each, most
|
|
|
|
# notably in #source.
|
|
|
|
#
|
|
|
|
# A basic gem dependencies file will look like the following:
|
|
|
|
#
|
|
|
|
# source 'https://rubygems.org'
|
|
|
|
#
|
|
|
|
# gem 'rails', '3.2.14a
|
|
|
|
# gem 'devise', '~> 2.1', '>= 2.1.3'
|
|
|
|
# gem 'cancan'
|
|
|
|
# gem 'airbrake'
|
|
|
|
# gem 'pg'
|
|
|
|
#
|
|
|
|
# RubyGems recommends saving this as gem.deps.rb over Gemfile or Isolate.
|
|
|
|
#
|
|
|
|
# To install the gems in this Gemfile use `gem install -g` to install it and
|
|
|
|
# create a lockfile. The lockfile will ensure that when you make changes to
|
|
|
|
# your gem dependencies file a minimum amount of change is made to the
|
|
|
|
# dependencies of your gems.
|
|
|
|
#
|
|
|
|
# RubyGems can activate all the gems in your dependencies file at startup
|
|
|
|
# using the RUBYGEMS_GEMDEPS environment variable or through Gem.use_gemdeps.
|
|
|
|
# See Gem.use_gemdeps for details and warnings.
|
|
|
|
#
|
|
|
|
# See `gem help install` and `gem help gem_dependencies` for further details.
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
class Gem::RequestSet::GemDependencyAPI
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
ENGINE_MAP = { # :nodoc:
|
|
|
|
:jruby => %w[jruby],
|
|
|
|
:jruby_18 => %w[jruby],
|
|
|
|
:jruby_19 => %w[jruby],
|
|
|
|
:maglev => %w[maglev],
|
|
|
|
:mri => %w[ruby],
|
|
|
|
:mri_18 => %w[ruby],
|
|
|
|
:mri_19 => %w[ruby],
|
|
|
|
:mri_20 => %w[ruby],
|
|
|
|
:mri_21 => %w[ruby],
|
|
|
|
:rbx => %w[rbx],
|
2019-02-14 07:59:03 -05:00
|
|
|
:truffleruby => %w[truffleruby],
|
|
|
|
:ruby => %w[ruby rbx maglev truffleruby],
|
|
|
|
:ruby_18 => %w[ruby rbx maglev truffleruby],
|
|
|
|
:ruby_19 => %w[ruby rbx maglev truffleruby],
|
|
|
|
:ruby_20 => %w[ruby rbx maglev truffleruby],
|
|
|
|
:ruby_21 => %w[ruby rbx maglev truffleruby],
|
2018-10-21 20:27:02 -04:00
|
|
|
}.freeze
|
2013-11-10 12:51:40 -05:00
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
mswin = Gem::Platform.new 'x86-mswin32'
|
|
|
|
mswin64 = Gem::Platform.new 'x64-mswin64'
|
2013-11-10 12:51:40 -05:00
|
|
|
x86_mingw = Gem::Platform.new 'x86-mingw32'
|
|
|
|
x64_mingw = Gem::Platform.new 'x64-mingw32'
|
|
|
|
|
|
|
|
PLATFORM_MAP = { # :nodoc:
|
|
|
|
:jruby => Gem::Platform::RUBY,
|
|
|
|
:jruby_18 => Gem::Platform::RUBY,
|
|
|
|
:jruby_19 => Gem::Platform::RUBY,
|
|
|
|
:maglev => Gem::Platform::RUBY,
|
|
|
|
:mingw => x86_mingw,
|
|
|
|
:mingw_18 => x86_mingw,
|
|
|
|
:mingw_19 => x86_mingw,
|
|
|
|
:mingw_20 => x86_mingw,
|
|
|
|
:mingw_21 => x86_mingw,
|
|
|
|
:mri => Gem::Platform::RUBY,
|
|
|
|
:mri_18 => Gem::Platform::RUBY,
|
|
|
|
:mri_19 => Gem::Platform::RUBY,
|
|
|
|
:mri_20 => Gem::Platform::RUBY,
|
|
|
|
:mri_21 => Gem::Platform::RUBY,
|
2014-09-13 23:30:02 -04:00
|
|
|
:mswin => mswin,
|
|
|
|
:mswin_18 => mswin,
|
|
|
|
:mswin_19 => mswin,
|
|
|
|
:mswin_20 => mswin,
|
|
|
|
:mswin_21 => mswin,
|
|
|
|
:mswin64 => mswin64,
|
|
|
|
:mswin64_19 => mswin64,
|
|
|
|
:mswin64_20 => mswin64,
|
|
|
|
:mswin64_21 => mswin64,
|
2013-11-10 12:51:40 -05:00
|
|
|
:rbx => Gem::Platform::RUBY,
|
|
|
|
:ruby => Gem::Platform::RUBY,
|
|
|
|
:ruby_18 => Gem::Platform::RUBY,
|
|
|
|
:ruby_19 => Gem::Platform::RUBY,
|
|
|
|
:ruby_20 => Gem::Platform::RUBY,
|
|
|
|
:ruby_21 => Gem::Platform::RUBY,
|
2019-02-14 07:59:03 -05:00
|
|
|
:truffleruby => Gem::Platform::RUBY,
|
2013-11-10 12:51:40 -05:00
|
|
|
:x64_mingw => x64_mingw,
|
|
|
|
:x64_mingw_20 => x64_mingw,
|
|
|
|
:x64_mingw_21 => x64_mingw
|
2018-10-21 20:27:02 -04:00
|
|
|
}.freeze
|
2013-11-10 12:51:40 -05:00
|
|
|
|
|
|
|
gt_eq_0 = Gem::Requirement.new '>= 0'
|
|
|
|
tilde_gt_1_8_0 = Gem::Requirement.new '~> 1.8.0'
|
|
|
|
tilde_gt_1_9_0 = Gem::Requirement.new '~> 1.9.0'
|
|
|
|
tilde_gt_2_0_0 = Gem::Requirement.new '~> 2.0.0'
|
|
|
|
tilde_gt_2_1_0 = Gem::Requirement.new '~> 2.1.0'
|
|
|
|
|
|
|
|
VERSION_MAP = { # :nodoc:
|
|
|
|
:jruby => gt_eq_0,
|
|
|
|
:jruby_18 => tilde_gt_1_8_0,
|
|
|
|
:jruby_19 => tilde_gt_1_9_0,
|
|
|
|
:maglev => gt_eq_0,
|
|
|
|
:mingw => gt_eq_0,
|
|
|
|
:mingw_18 => tilde_gt_1_8_0,
|
|
|
|
:mingw_19 => tilde_gt_1_9_0,
|
|
|
|
:mingw_20 => tilde_gt_2_0_0,
|
|
|
|
:mingw_21 => tilde_gt_2_1_0,
|
|
|
|
:mri => gt_eq_0,
|
|
|
|
:mri_18 => tilde_gt_1_8_0,
|
|
|
|
:mri_19 => tilde_gt_1_9_0,
|
|
|
|
:mri_20 => tilde_gt_2_0_0,
|
|
|
|
:mri_21 => tilde_gt_2_1_0,
|
|
|
|
:mswin => gt_eq_0,
|
2014-09-13 23:30:02 -04:00
|
|
|
:mswin_18 => tilde_gt_1_8_0,
|
|
|
|
:mswin_19 => tilde_gt_1_9_0,
|
|
|
|
:mswin_20 => tilde_gt_2_0_0,
|
|
|
|
:mswin_21 => tilde_gt_2_1_0,
|
|
|
|
:mswin64 => gt_eq_0,
|
|
|
|
:mswin64_19 => tilde_gt_1_9_0,
|
|
|
|
:mswin64_20 => tilde_gt_2_0_0,
|
|
|
|
:mswin64_21 => tilde_gt_2_1_0,
|
2013-11-10 12:51:40 -05:00
|
|
|
:rbx => gt_eq_0,
|
|
|
|
:ruby => gt_eq_0,
|
|
|
|
:ruby_18 => tilde_gt_1_8_0,
|
|
|
|
:ruby_19 => tilde_gt_1_9_0,
|
|
|
|
:ruby_20 => tilde_gt_2_0_0,
|
|
|
|
:ruby_21 => tilde_gt_2_1_0,
|
2019-02-14 07:59:03 -05:00
|
|
|
:truffleruby => gt_eq_0,
|
2013-11-10 12:51:40 -05:00
|
|
|
:x64_mingw => gt_eq_0,
|
|
|
|
:x64_mingw_20 => tilde_gt_2_0_0,
|
|
|
|
:x64_mingw_21 => tilde_gt_2_1_0,
|
2018-10-21 20:27:02 -04:00
|
|
|
}.freeze
|
2013-11-10 12:51:40 -05:00
|
|
|
|
|
|
|
WINDOWS = { # :nodoc:
|
|
|
|
:mingw => :only,
|
|
|
|
:mingw_18 => :only,
|
|
|
|
:mingw_19 => :only,
|
|
|
|
:mingw_20 => :only,
|
|
|
|
:mingw_21 => :only,
|
|
|
|
:mri => :never,
|
|
|
|
:mri_18 => :never,
|
|
|
|
:mri_19 => :never,
|
|
|
|
:mri_20 => :never,
|
|
|
|
:mri_21 => :never,
|
|
|
|
:mswin => :only,
|
2014-09-13 23:30:02 -04:00
|
|
|
:mswin_18 => :only,
|
|
|
|
:mswin_19 => :only,
|
|
|
|
:mswin_20 => :only,
|
|
|
|
:mswin_21 => :only,
|
|
|
|
:mswin64 => :only,
|
|
|
|
:mswin64_19 => :only,
|
|
|
|
:mswin64_20 => :only,
|
|
|
|
:mswin64_21 => :only,
|
2013-11-10 12:51:40 -05:00
|
|
|
:rbx => :never,
|
|
|
|
:ruby => :never,
|
|
|
|
:ruby_18 => :never,
|
|
|
|
:ruby_19 => :never,
|
|
|
|
:ruby_20 => :never,
|
|
|
|
:ruby_21 => :never,
|
|
|
|
:x64_mingw => :only,
|
|
|
|
:x64_mingw_20 => :only,
|
|
|
|
:x64_mingw_21 => :only,
|
2018-10-21 20:27:02 -04:00
|
|
|
}.freeze
|
2013-11-10 12:51:40 -05:00
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
##
|
|
|
|
# The gems required by #gem statements in the gem.deps.rb file
|
|
|
|
|
|
|
|
attr_reader :dependencies
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
##
|
|
|
|
# A set of gems that are loaded via the +:git+ option to #gem
|
|
|
|
|
|
|
|
attr_reader :git_set # :nodoc:
|
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
##
|
2013-11-10 12:51:40 -05:00
|
|
|
# A Hash containing gem names and files to require from those gems.
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
attr_reader :requires
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2013-10-17 20:41:36 -04:00
|
|
|
##
|
|
|
|
# A set of gems that are loaded via the +:path+ option to #gem
|
|
|
|
|
|
|
|
attr_reader :vendor_set # :nodoc:
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
##
|
|
|
|
# The groups of gems to exclude from installation
|
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
attr_accessor :without_groups # :nodoc:
|
2013-11-10 12:51:40 -05:00
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
##
|
|
|
|
# Creates a new GemDependencyAPI that will add dependencies to the
|
|
|
|
# Gem::RequestSet +set+ based on the dependency API description in +path+.
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def initialize(set, path)
|
2013-07-09 19:21:36 -04:00
|
|
|
@set = set
|
|
|
|
@path = path
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
@current_groups = nil
|
2014-09-13 23:30:02 -04:00
|
|
|
@current_platforms = nil
|
2013-11-18 19:34:13 -05:00
|
|
|
@current_repository = nil
|
2014-09-13 23:30:02 -04:00
|
|
|
@dependencies = {}
|
2013-11-18 19:34:13 -05:00
|
|
|
@default_sources = true
|
|
|
|
@git_set = @set.git_set
|
2014-09-13 23:30:02 -04:00
|
|
|
@git_sources = {}
|
|
|
|
@installing = false
|
2013-11-18 19:34:13 -05:00
|
|
|
@requires = Hash.new { |h, name| h[name] = [] }
|
|
|
|
@vendor_set = @set.vendor_set
|
2016-02-01 07:43:26 -05:00
|
|
|
@source_set = @set.source_set
|
2013-11-18 19:34:13 -05:00
|
|
|
@gem_sources = {}
|
|
|
|
@without_groups = []
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
git_source :github do |repo_name|
|
|
|
|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include? "/"
|
|
|
|
|
|
|
|
"git://github.com/#{repo_name}.git"
|
|
|
|
end
|
|
|
|
|
|
|
|
git_source :bitbucket do |repo_name|
|
|
|
|
repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include? "/"
|
|
|
|
|
|
|
|
user, = repo_name.split "/", 2
|
|
|
|
|
|
|
|
"https://#{user}@bitbucket.org/#{repo_name}.git"
|
|
|
|
end
|
2013-11-18 19:34:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Adds +dependencies+ to the request set if any of the +groups+ are allowed.
|
|
|
|
# This is used for gemspec dependencies.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def add_dependencies(groups, dependencies) # :nodoc:
|
2013-11-18 19:34:13 -05:00
|
|
|
return unless (groups & @without_groups).empty?
|
|
|
|
|
|
|
|
dependencies.each do |dep|
|
|
|
|
@set.gem dep.name, *dep.requirement
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private :add_dependencies
|
|
|
|
|
|
|
|
##
|
|
|
|
# Finds a gemspec with the given +name+ that lives at +path+.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def find_gemspec(name, path) # :nodoc:
|
2013-11-18 19:34:13 -05:00
|
|
|
glob = File.join path, "#{name}.gemspec"
|
|
|
|
|
|
|
|
spec_files = Dir[glob]
|
|
|
|
|
|
|
|
case spec_files.length
|
|
|
|
when 1 then
|
|
|
|
spec_file = spec_files.first
|
|
|
|
|
|
|
|
spec = Gem::Specification.load spec_file
|
|
|
|
|
|
|
|
return spec if spec
|
|
|
|
|
|
|
|
raise ArgumentError, "invalid gemspec #{spec_file}"
|
|
|
|
when 0 then
|
|
|
|
raise ArgumentError, "no gemspecs found at #{Dir.pwd}"
|
|
|
|
else
|
|
|
|
raise ArgumentError,
|
|
|
|
"found multiple gemspecs at #{Dir.pwd}, " +
|
|
|
|
"use the name: option to specify the one you want"
|
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
##
|
2014-09-13 23:30:02 -04:00
|
|
|
# Changes the behavior of gem dependency file loading to installing mode.
|
|
|
|
# In installing mode certain restrictions are ignored such as ruby version
|
|
|
|
# mismatch checks.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def installing=(installing) # :nodoc:
|
2014-09-13 23:30:02 -04:00
|
|
|
@installing = installing
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Loads the gem dependency file and returns self.
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def load
|
|
|
|
instance_eval File.read(@path).untaint, @path, 1
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
self
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
##
|
|
|
|
# :category: Gem Dependencies DSL
|
2014-09-13 23:30:02 -04:00
|
|
|
#
|
2013-10-16 22:08:53 -04:00
|
|
|
# :call-seq:
|
|
|
|
# gem(name)
|
|
|
|
# gem(name, *requirements)
|
|
|
|
# gem(name, *requirements, options)
|
|
|
|
#
|
|
|
|
# Specifies a gem dependency with the given +name+ and +requirements+. You
|
|
|
|
# may also supply +options+ following the +requirements+
|
2014-09-13 23:30:02 -04:00
|
|
|
#
|
|
|
|
# +options+ include:
|
|
|
|
#
|
|
|
|
# require: ::
|
|
|
|
# RubyGems does not provide any autorequire features so requires in a gem
|
|
|
|
# dependencies file are recorded but ignored.
|
|
|
|
#
|
|
|
|
# In bundler the require: option overrides the file to require during
|
|
|
|
# Bundler.require. By default the name of the dependency is required in
|
|
|
|
# Bundler. A single file or an Array of files may be given.
|
|
|
|
#
|
|
|
|
# To disable requiring any file give +false+:
|
|
|
|
#
|
|
|
|
# gem 'rake', require: false
|
|
|
|
#
|
|
|
|
# group: ::
|
|
|
|
# Place the dependencies in the given dependency group. A single group or
|
|
|
|
# an Array of groups may be given.
|
|
|
|
#
|
|
|
|
# See also #group
|
|
|
|
#
|
|
|
|
# platform: ::
|
|
|
|
# Only install the dependency on the given platform. A single platform or
|
|
|
|
# an Array of platforms may be given.
|
|
|
|
#
|
|
|
|
# See #platform for a list of platforms available.
|
|
|
|
#
|
|
|
|
# path: ::
|
|
|
|
# Install this dependency from an unpacked gem in the given directory.
|
|
|
|
#
|
|
|
|
# gem 'modified_gem', path: 'vendor/modified_gem'
|
|
|
|
#
|
|
|
|
# git: ::
|
|
|
|
# Install this dependency from a git repository:
|
|
|
|
#
|
|
|
|
# gem 'private_gem', git: git@my.company.example:private_gem.git'
|
|
|
|
#
|
|
|
|
# gist: ::
|
|
|
|
# Install this dependency from the gist ID:
|
|
|
|
#
|
|
|
|
# gem 'bang', gist: '1232884'
|
|
|
|
#
|
|
|
|
# github: ::
|
|
|
|
# Install this dependency from a github git repository:
|
|
|
|
#
|
|
|
|
# gem 'private_gem', github: 'my_company/private_gem'
|
|
|
|
#
|
|
|
|
# submodules: ::
|
|
|
|
# Set to +true+ to include submodules when fetching the git repository for
|
|
|
|
# git:, gist: and github: dependencies.
|
|
|
|
#
|
|
|
|
# ref: ::
|
|
|
|
# Use the given commit name or SHA for git:, gist: and github:
|
|
|
|
# dependencies.
|
|
|
|
#
|
|
|
|
# branch: ::
|
|
|
|
# Use the given branch for git:, gist: and github: dependencies.
|
|
|
|
#
|
|
|
|
# tag: ::
|
|
|
|
# Use the given tag for git:, gist: and github: dependencies.
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem(name, *requirements)
|
2013-10-16 22:08:53 -04:00
|
|
|
options = requirements.pop if requirements.last.kind_of?(Hash)
|
|
|
|
options ||= {}
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
options[:git] = @current_repository if @current_repository
|
|
|
|
|
|
|
|
source_set = false
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
source_set ||= gem_path name, options
|
|
|
|
source_set ||= gem_git name, options
|
|
|
|
source_set ||= gem_git_source name, options
|
2016-02-01 07:43:26 -05:00
|
|
|
source_set ||= gem_source name, options
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
duplicate = @dependencies.include? name
|
|
|
|
|
|
|
|
@dependencies[name] =
|
2018-11-21 05:20:47 -05:00
|
|
|
if requirements.empty? and not source_set
|
2015-02-27 08:00:45 -05:00
|
|
|
Gem::Requirement.default
|
2018-11-21 05:20:47 -05:00
|
|
|
elsif source_set
|
2015-02-27 08:00:45 -05:00
|
|
|
Gem::Requirement.source_set
|
2014-09-13 23:30:02 -04:00
|
|
|
else
|
2015-02-27 08:00:45 -05:00
|
|
|
Gem::Requirement.create requirements
|
2014-09-13 23:30:02 -04:00
|
|
|
end
|
2013-11-10 12:51:40 -05:00
|
|
|
|
|
|
|
return unless gem_platforms options
|
|
|
|
|
|
|
|
groups = gem_group name, options
|
|
|
|
|
|
|
|
return unless (groups & @without_groups).empty?
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
pin_gem_source name, :default unless source_set
|
2013-10-17 20:41:36 -04:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
gem_requires name, options
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if duplicate
|
2014-09-13 23:30:02 -04:00
|
|
|
warn <<-WARNING
|
|
|
|
Gem dependencies file #{@path} requires #{name} more than once.
|
|
|
|
WARNING
|
|
|
|
end
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
@set.gem name, *requirements
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
##
|
|
|
|
# Handles the git: option from +options+ for gem +name+.
|
|
|
|
#
|
2015-09-08 18:46:43 -04:00
|
|
|
# Returns +true+ if the gist or git option was handled.
|
2013-11-18 19:34:13 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem_git(name, options) # :nodoc:
|
|
|
|
if gist = options.delete(:gist)
|
2013-11-18 19:34:13 -05:00
|
|
|
options[:git] = "https://gist.github.com/#{gist}.git"
|
|
|
|
end
|
|
|
|
|
|
|
|
return unless repository = options.delete(:git)
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
pin_gem_source name, :git, repository
|
2013-11-18 19:34:13 -05:00
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
reference = gem_git_reference options
|
2013-11-18 19:34:13 -05:00
|
|
|
|
|
|
|
submodules = options.delete :submodules
|
|
|
|
|
|
|
|
@git_set.add_git_gem name, repository, reference, submodules
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
##
|
|
|
|
# Handles the git options from +options+ for git gem.
|
|
|
|
#
|
|
|
|
# Returns reference for the git gem.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem_git_reference(options) # :nodoc:
|
2016-02-01 07:43:26 -05:00
|
|
|
ref = options.delete :ref
|
|
|
|
branch = options.delete :branch
|
|
|
|
tag = options.delete :tag
|
|
|
|
|
|
|
|
reference = nil
|
|
|
|
reference ||= ref
|
|
|
|
reference ||= branch
|
|
|
|
reference ||= tag
|
|
|
|
reference ||= 'master'
|
|
|
|
|
|
|
|
if ref && branch
|
|
|
|
warn <<-WARNING
|
|
|
|
Gem dependencies file #{@path} includes git reference for both ref and branch but only ref is used.
|
|
|
|
WARNING
|
|
|
|
end
|
2019-02-14 07:59:03 -05:00
|
|
|
if (ref || branch) && tag
|
2016-02-01 07:43:26 -05:00
|
|
|
warn <<-WARNING
|
|
|
|
Gem dependencies file #{@path} includes git reference for both ref/branch and tag but only ref/branch is used.
|
|
|
|
WARNING
|
|
|
|
end
|
|
|
|
|
|
|
|
reference
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
private :gem_git
|
|
|
|
|
|
|
|
##
|
2014-09-13 23:30:02 -04:00
|
|
|
# Handles a git gem option from +options+ for gem +name+ for a git source
|
|
|
|
# registered through git_source.
|
2013-11-18 19:34:13 -05:00
|
|
|
#
|
2014-09-13 23:30:02 -04:00
|
|
|
# Returns +true+ if the custom source option was handled.
|
2013-11-18 19:34:13 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem_git_source(name, options) # :nodoc:
|
2014-09-13 23:30:02 -04:00
|
|
|
return unless git_source = (@git_sources.keys & options.keys).last
|
2013-11-18 19:34:13 -05:00
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
source_callback = @git_sources[git_source]
|
|
|
|
source_param = options.delete git_source
|
|
|
|
|
|
|
|
git_url = source_callback.call source_param
|
|
|
|
|
|
|
|
options[:git] = git_url
|
2013-11-18 19:34:13 -05:00
|
|
|
|
|
|
|
gem_git name, options
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
private :gem_git_source
|
2013-11-21 18:27:30 -05:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
##
|
|
|
|
# Handles the :group and :groups +options+ for the gem with the given
|
|
|
|
# +name+.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem_group(name, options) # :nodoc:
|
2013-10-18 17:56:18 -04:00
|
|
|
g = options.delete :group
|
2019-02-14 07:59:03 -05:00
|
|
|
all_groups = g ? Array(g) : []
|
2013-10-17 20:41:36 -04:00
|
|
|
|
|
|
|
groups = options.delete :groups
|
|
|
|
all_groups |= groups if groups
|
|
|
|
|
|
|
|
all_groups |= @current_groups if @current_groups
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
all_groups
|
|
|
|
end
|
|
|
|
|
|
|
|
private :gem_group
|
|
|
|
|
|
|
|
##
|
|
|
|
# Handles the path: option from +options+ for gem +name+.
|
|
|
|
#
|
|
|
|
# Returns +true+ if the path option was handled.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem_path(name, options) # :nodoc:
|
2013-11-10 12:51:40 -05:00
|
|
|
return unless directory = options.delete(:path)
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
pin_gem_source name, :path, directory
|
2013-11-10 12:51:40 -05:00
|
|
|
|
|
|
|
@vendor_set.add_vendor_gem name, directory
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private :gem_path
|
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
##
|
|
|
|
# Handles the source: option from +options+ for gem +name+.
|
|
|
|
#
|
|
|
|
# Returns +true+ if the source option was handled.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem_source(name, options) # :nodoc:
|
2016-02-01 07:43:26 -05:00
|
|
|
return unless source = options.delete(:source)
|
|
|
|
|
|
|
|
pin_gem_source name, :source, source
|
|
|
|
|
|
|
|
@source_set.add_source_gem name, source
|
|
|
|
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
private :gem_source
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
##
|
|
|
|
# Handles the platforms: option from +options+. Returns true if the
|
|
|
|
# platform matches the current platform.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem_platforms(options) # :nodoc:
|
2014-09-13 23:30:02 -04:00
|
|
|
platform_names = Array(options.delete :platform)
|
|
|
|
platform_names.concat Array(options.delete :platforms)
|
|
|
|
platform_names.concat @current_platforms if @current_platforms
|
2013-11-10 12:51:40 -05:00
|
|
|
|
|
|
|
return true if platform_names.empty?
|
|
|
|
|
|
|
|
platform_names.any? do |platform_name|
|
|
|
|
raise ArgumentError, "unknown platform #{platform_name.inspect}" unless
|
|
|
|
platform = PLATFORM_MAP[platform_name]
|
|
|
|
|
|
|
|
next false unless Gem::Platform.match platform
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if engines = ENGINE_MAP[platform_name]
|
2013-11-10 12:51:40 -05:00
|
|
|
next false unless engines.include? Gem.ruby_engine
|
|
|
|
end
|
|
|
|
|
|
|
|
case WINDOWS[platform_name]
|
|
|
|
when :only then
|
|
|
|
next false unless Gem.win_platform?
|
|
|
|
when :never then
|
|
|
|
next false if Gem.win_platform?
|
2013-10-16 22:08:53 -04:00
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
VERSION_MAP[platform_name].satisfied_by? Gem.ruby_version
|
2013-10-16 22:08:53 -04:00
|
|
|
end
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
private :gem_platforms
|
|
|
|
|
|
|
|
##
|
2014-09-13 23:30:02 -04:00
|
|
|
# Records the require: option from +options+ and adds those files, or the
|
2013-11-10 12:51:40 -05:00
|
|
|
# default file to the require list for +name+.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gem_requires(name, options) # :nodoc:
|
|
|
|
if options.include? :require
|
|
|
|
if requires = options.delete(:require)
|
2013-11-21 18:27:30 -05:00
|
|
|
@requires[name].concat Array requires
|
2013-11-10 12:51:40 -05:00
|
|
|
end
|
|
|
|
else
|
|
|
|
@requires[name] << name
|
|
|
|
end
|
2016-02-01 07:43:26 -05:00
|
|
|
raise ArgumentError, "Unhandled gem options #{options.inspect}" unless options.empty?
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
private :gem_requires
|
|
|
|
|
2013-11-21 18:27:30 -05:00
|
|
|
##
|
|
|
|
# :category: Gem Dependencies DSL
|
|
|
|
#
|
|
|
|
# Block form for specifying gems from a git +repository+.
|
2014-09-13 23:30:02 -04:00
|
|
|
#
|
|
|
|
# git 'https://github.com/rails/rails.git' do
|
|
|
|
# gem 'activesupport'
|
|
|
|
# gem 'activerecord'
|
|
|
|
# end
|
2013-11-21 18:27:30 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def git(repository)
|
2013-11-18 19:34:13 -05:00
|
|
|
@current_repository = repository
|
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
ensure
|
|
|
|
@current_repository = nil
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
##
|
|
|
|
# Defines a custom git source that uses +name+ to expand git repositories
|
|
|
|
# for use in gems built from git repositories. You must provide a block
|
|
|
|
# that accepts a git repository name for expansion.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def git_source(name, &callback)
|
2014-09-13 23:30:02 -04:00
|
|
|
@git_sources[name] = callback
|
|
|
|
end
|
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
##
|
|
|
|
# Returns the basename of the file the dependencies were loaded from
|
|
|
|
|
|
|
|
def gem_deps_file # :nodoc:
|
|
|
|
File.basename @path
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
##
|
|
|
|
# :category: Gem Dependencies DSL
|
2013-11-18 19:34:13 -05:00
|
|
|
#
|
|
|
|
# Loads dependencies from a gemspec file.
|
2014-09-13 23:30:02 -04:00
|
|
|
#
|
|
|
|
# +options+ include:
|
|
|
|
#
|
|
|
|
# name: ::
|
|
|
|
# The name portion of the gemspec file. Defaults to searching for any
|
|
|
|
# gemspec file in the current directory.
|
|
|
|
#
|
|
|
|
# gemspec name: 'my_gem'
|
|
|
|
#
|
|
|
|
# path: ::
|
|
|
|
# The path the gemspec lives in. Defaults to the current directory:
|
|
|
|
#
|
|
|
|
# gemspec 'my_gem', path: 'gemspecs', name: 'my_gem'
|
|
|
|
#
|
|
|
|
# development_group: ::
|
|
|
|
# The group to add development dependencies to. By default this is
|
|
|
|
# :development. Only one group may be specified.
|
2013-11-18 19:34:13 -05:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def gemspec(options = {})
|
2013-11-18 19:34:13 -05:00
|
|
|
name = options.delete(:name) || '{,*}'
|
|
|
|
path = options.delete(:path) || '.'
|
|
|
|
development_group = options.delete(:development_group) || :development
|
|
|
|
|
|
|
|
spec = find_gemspec name, path
|
|
|
|
|
|
|
|
groups = gem_group spec.name, {}
|
|
|
|
|
2014-10-01 04:30:21 -04:00
|
|
|
self_dep = Gem::Dependency.new spec.name, spec.version
|
|
|
|
|
|
|
|
add_dependencies groups, [self_dep]
|
2013-11-18 19:34:13 -05:00
|
|
|
add_dependencies groups, spec.runtime_dependencies
|
|
|
|
|
2015-02-27 08:00:45 -05:00
|
|
|
@dependencies[spec.name] = Gem::Requirement.source_set
|
2014-10-01 04:30:21 -04:00
|
|
|
|
|
|
|
spec.dependencies.each do |dep|
|
|
|
|
@dependencies[dep.name] = dep.requirement
|
|
|
|
end
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
groups << development_group
|
|
|
|
|
|
|
|
add_dependencies groups, spec.development_dependencies
|
|
|
|
|
2016-02-01 07:43:26 -05:00
|
|
|
@vendor_set.add_vendor_gem spec.name, path
|
2013-11-18 19:34:13 -05:00
|
|
|
gem_requires spec.name, options
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# :category: Gem Dependencies DSL
|
2014-09-13 23:30:02 -04:00
|
|
|
#
|
2013-10-16 22:08:53 -04:00
|
|
|
# Block form for placing a dependency in the given +groups+.
|
2014-09-13 23:30:02 -04:00
|
|
|
#
|
|
|
|
# group :development do
|
|
|
|
# gem 'debugger'
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# group :development, :test do
|
|
|
|
# gem 'minitest'
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# Groups can be excluded at install time using `gem install -g --without
|
|
|
|
# development`. See `gem help install` and `gem help gem_dependencies` for
|
|
|
|
# further details.
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def group(*groups)
|
2013-10-16 22:08:53 -04:00
|
|
|
@current_groups = groups
|
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
ensure
|
|
|
|
@current_groups = nil
|
|
|
|
end
|
|
|
|
|
2013-12-07 20:22:39 -05:00
|
|
|
##
|
|
|
|
# Pins the gem +name+ to the given +source+. Adding a gem with the same
|
|
|
|
# name from a different +source+ will raise an exception.
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def pin_gem_source(name, type = :default, source = nil)
|
2013-12-07 20:22:39 -05:00
|
|
|
source_description =
|
|
|
|
case type
|
|
|
|
when :default then '(default)'
|
|
|
|
when :path then "path: #{source}"
|
|
|
|
when :git then "git: #{source}"
|
2016-02-01 07:43:26 -05:00
|
|
|
when :source then "source: #{source}"
|
2013-12-07 20:22:39 -05:00
|
|
|
else '(unknown)'
|
|
|
|
end
|
|
|
|
|
|
|
|
raise ArgumentError,
|
|
|
|
"duplicate source #{source_description} for gem #{name}" if
|
|
|
|
@gem_sources.fetch(name, source) != source
|
|
|
|
|
|
|
|
@gem_sources[name] = source
|
|
|
|
end
|
|
|
|
|
|
|
|
private :pin_gem_source
|
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
##
|
|
|
|
# :category: Gem Dependencies DSL
|
2013-11-21 18:27:30 -05:00
|
|
|
#
|
2014-09-13 23:30:02 -04:00
|
|
|
# Block form for restricting gems to a set of platforms.
|
|
|
|
#
|
|
|
|
# The gem dependencies platform is different from Gem::Platform. A platform
|
|
|
|
# gem.deps.rb platform matches on the ruby engine, the ruby version and
|
|
|
|
# whether or not windows is allowed.
|
|
|
|
#
|
|
|
|
# :ruby, :ruby_XY ::
|
|
|
|
# Matches non-windows, non-jruby implementations where X and Y can be used
|
|
|
|
# to match releases in the 1.8, 1.9, 2.0 or 2.1 series.
|
|
|
|
#
|
|
|
|
# :mri, :mri_XY ::
|
|
|
|
# Matches non-windows C Ruby (Matz Ruby) or only the 1.8, 1.9, 2.0 or
|
|
|
|
# 2.1 series.
|
|
|
|
#
|
|
|
|
# :mingw, :mingw_XY ::
|
|
|
|
# Matches 32 bit C Ruby on MinGW or only the 1.8, 1.9, 2.0 or 2.1 series.
|
|
|
|
#
|
|
|
|
# :x64_mingw, :x64_mingw_XY ::
|
|
|
|
# Matches 64 bit C Ruby on MinGW or only the 1.8, 1.9, 2.0 or 2.1 series.
|
|
|
|
#
|
|
|
|
# :mswin, :mswin_XY ::
|
|
|
|
# Matches 32 bit C Ruby on Microsoft Windows or only the 1.8, 1.9, 2.0 or
|
|
|
|
# 2.1 series.
|
|
|
|
#
|
|
|
|
# :mswin64, :mswin64_XY ::
|
|
|
|
# Matches 64 bit C Ruby on Microsoft Windows or only the 1.8, 1.9, 2.0 or
|
|
|
|
# 2.1 series.
|
|
|
|
#
|
|
|
|
# :jruby, :jruby_XY ::
|
|
|
|
# Matches JRuby or JRuby in 1.8 or 1.9 mode.
|
|
|
|
#
|
|
|
|
# :maglev ::
|
|
|
|
# Matches Maglev
|
|
|
|
#
|
|
|
|
# :rbx ::
|
|
|
|
# Matches non-windows Rubinius
|
|
|
|
#
|
|
|
|
# NOTE: There is inconsistency in what environment a platform matches. You
|
|
|
|
# may need to read the source to know the exact details.
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def platform(*platforms)
|
2014-09-13 23:30:02 -04:00
|
|
|
@current_platforms = platforms
|
2013-11-10 12:51:40 -05:00
|
|
|
|
|
|
|
yield
|
|
|
|
|
|
|
|
ensure
|
2014-09-13 23:30:02 -04:00
|
|
|
@current_platforms = nil
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
##
|
|
|
|
# :category: Gem Dependencies DSL
|
2013-11-21 18:27:30 -05:00
|
|
|
#
|
2014-09-13 23:30:02 -04:00
|
|
|
# Block form for restricting gems to a particular set of platforms. See
|
|
|
|
# #platform.
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
alias :platforms :platform
|
|
|
|
|
2013-10-16 22:08:53 -04:00
|
|
|
##
|
|
|
|
# :category: Gem Dependencies DSL
|
2014-09-13 23:30:02 -04:00
|
|
|
#
|
|
|
|
# Restricts this gem dependencies file to the given ruby +version+.
|
|
|
|
#
|
|
|
|
# You may also provide +engine:+ and +engine_version:+ options to restrict
|
|
|
|
# this gem dependencies file to a particular ruby engine and its engine
|
|
|
|
# version. This matching is performed by using the RUBY_ENGINE and
|
|
|
|
# engine_specific VERSION constants. (For JRuby, JRUBY_VERSION).
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def ruby(version, options = {})
|
2013-11-10 12:51:40 -05:00
|
|
|
engine = options[:engine]
|
|
|
|
engine_version = options[:engine_version]
|
|
|
|
|
|
|
|
raise ArgumentError,
|
2017-10-07 21:32:18 -04:00
|
|
|
'You must specify engine_version along with the Ruby engine' if
|
2013-11-10 12:51:40 -05:00
|
|
|
engine and not engine_version
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
return true if @installing
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
unless RUBY_VERSION == version
|
2013-11-10 12:51:40 -05:00
|
|
|
message = "Your Ruby version is #{RUBY_VERSION}, " +
|
|
|
|
"but your #{gem_deps_file} requires #{version}"
|
|
|
|
|
|
|
|
raise Gem::RubyVersionMismatch, message
|
|
|
|
end
|
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if engine and engine != Gem.ruby_engine
|
2017-10-07 21:32:18 -04:00
|
|
|
message = "Your Ruby engine is #{Gem.ruby_engine}, " +
|
2013-11-10 12:51:40 -05:00
|
|
|
"but your #{gem_deps_file} requires #{engine}"
|
|
|
|
|
|
|
|
raise Gem::RubyVersionMismatch, message
|
|
|
|
end
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if engine_version
|
2013-11-10 12:51:40 -05:00
|
|
|
my_engine_version = Object.const_get "#{Gem.ruby_engine.upcase}_VERSION"
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
if engine_version != my_engine_version
|
2013-11-10 12:51:40 -05:00
|
|
|
message =
|
2017-10-07 21:32:18 -04:00
|
|
|
"Your Ruby engine version is #{Gem.ruby_engine} #{my_engine_version}, " +
|
2013-11-10 12:51:40 -05:00
|
|
|
"but your #{gem_deps_file} requires #{engine} #{engine_version}"
|
|
|
|
|
|
|
|
raise Gem::RubyVersionMismatch, message
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return true
|
2013-10-16 22:08:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# :category: Gem Dependencies DSL
|
2013-11-10 12:51:40 -05:00
|
|
|
#
|
2014-09-13 23:30:02 -04:00
|
|
|
# Sets +url+ as a source for gems for this dependency API. RubyGems uses
|
|
|
|
# the default configured sources if no source was given. If a source is set
|
|
|
|
# only that source is used.
|
|
|
|
#
|
|
|
|
# This method differs in behavior from Bundler:
|
|
|
|
#
|
|
|
|
# * The +:gemcutter+, # +:rubygems+ and +:rubyforge+ sources are not
|
|
|
|
# supported as they are deprecated in bundler.
|
|
|
|
# * The +prepend:+ option is not supported. If you wish to order sources
|
|
|
|
# then list them in your preferred order.
|
2013-10-16 22:08:53 -04:00
|
|
|
|
2018-11-21 05:20:47 -05:00
|
|
|
def source(url)
|
2013-11-10 12:51:40 -05:00
|
|
|
Gem.sources.clear if @default_sources
|
|
|
|
|
|
|
|
@default_sources = false
|
|
|
|
|
|
|
|
Gem.sources << url
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|