diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2017-08-01 16:46:44 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2017-08-01 16:46:44 -0500 |
commit | e89296991ffdb384ecdb5263cd6e1825c9b26d4b (patch) | |
tree | 03e2870b996e037b2ba6c6dbbf887b24de8ed58a | |
parent | c5a1f1a7bbb0a0b88cc448bbf8d6b16f2945d363 (diff) | |
download | bundler-seg-definition-from-lockfile.tar.gz |
Make static gemfiles opt-inseg-definition-from-lockfile
-rw-r--r-- | lib/bundler/definition.rb | 12 | ||||
-rw-r--r-- | lib/bundler/dsl.rb | 9 | ||||
-rw-r--r-- | lib/bundler/lockfile_generator.rb | 9 |
3 files changed, 26 insertions, 4 deletions
diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 157492c4fb..634b2201f6 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -21,6 +21,12 @@ module Bundler :gemfiles ) + attr_writer :static_gemfile + + def static_gemfile? + @static_gemfile + end + # Given a gemfile and lockfile creates a Bundler definition # # @param gemfile [Pathname] Path to Gemfile @@ -49,11 +55,12 @@ module Bundler aggregate = sources.delete(parsed_lockfile.aggregate_source) sources = SourceList.from_sources(sources) aggregate.remotes.each {|r| sources.global_rubygems_source = r } if aggregate - return Definition.new(parsed_lockfile, parsed_lockfile.dependencies.values, sources, {}, parsed_lockfile.ruby_version, parsed_lockfile.optional_groups, parsed_lockfile.gemfiles.keys) + definition = Definition.new(parsed_lockfile, parsed_lockfile.dependencies.values, sources, {}, parsed_lockfile.ruby_version, parsed_lockfile.optional_groups, parsed_lockfile.gemfiles.keys) + definition.static_gemfile = true end end - Dsl.evaluate(gemfile, parsed_lockfile, unlock) + definition || Dsl.evaluate(gemfile, parsed_lockfile, unlock) end # @@ -85,6 +92,7 @@ module Bundler @specs = nil @ruby_version = ruby_version @gemfiles = gemfiles + @static_gemfile = false @locked_gems = lockfile @lockfile = lockfile && lockfile.lockfile diff --git a/lib/bundler/dsl.rb b/lib/bundler/dsl.rb index 679c66e711..fe6d56510d 100644 --- a/lib/bundler/dsl.rb +++ b/lib/bundler/dsl.rb @@ -35,6 +35,7 @@ module Bundler @gemspecs = [] @gemfile = nil @gemfiles = [] + @dynamic = true add_git_sources end @@ -215,7 +216,9 @@ module Bundler end def to_definition(lockfile, unlock) - Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version, @optional_groups, @gemfiles) + Definition.new(lockfile, @dependencies, @sources, unlock, @ruby_version, @optional_groups, @gemfiles).tap do |definition| + definition.static_gemfile = !@dynamic + end end def group(*args, &blk) @@ -261,6 +264,10 @@ module Bundler # Pass on end + def _static_gemfile!(static = true) + @dynamic = !static + end + def method_missing(name, *args) raise GemfileError, "Undefined local variable or method `#{name}' for Gemfile" end diff --git a/lib/bundler/lockfile_generator.rb b/lib/bundler/lockfile_generator.rb index 7fb7255ad7..34e092e212 100644 --- a/lib/bundler/lockfile_generator.rb +++ b/lib/bundler/lockfile_generator.rb @@ -29,6 +29,10 @@ module Bundler private + def static? + definition.static_gemfile? + end + def add_sources definition.send(:sources).lock_sources.each_with_index do |source, idx| out << "\n" unless idx.zero? @@ -62,6 +66,7 @@ module Bundler handled = [] definition.dependencies.sort_by(&:to_s).each do |dep| next if handled.include?(dep.name) + handled << dep.name out << " #{dep.name}" unless dep.requirement.none? reqs = dep.requirement.requirements.map {|o, v| "#{o} #{v}" }.sort.reverse @@ -69,16 +74,18 @@ module Bundler end out << "!" if dep.source out << "\n" + next unless static? add_value(dep.options_to_lock, 4) - handled << dep.name end end def add_optional_groups + return unless static? add_section("OPTIONAL GROUPS", definition.optional_groups) end def add_gemfiles + return unless static? return unless SharedHelpers.md5_available? gemfiles = {} definition.gemfiles.each do |file| |