diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2017-04-03 20:31:08 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-03 20:31:08 -0700 |
commit | 6eeb145cf2719d91b33a814720425134ad159c00 (patch) | |
tree | 98915bf4d3a0d4b8c816b8071f1bd99f68479b5c | |
parent | 41fa5caa4a75abf71aaf435c77423adf2b3d0306 (diff) | |
parent | f5744b90c2d68250b708f2a7e341a41012a2c478 (diff) | |
download | chef-6eeb145cf2719d91b33a814720425134ad159c00.tar.gz |
Merge pull request #6002 from chef/lcg/fix-rake-bundle-commands
fix and simplify rake bundle:* commands
-rwxr-xr-x | tasks/bin/bundle-platform | 20 | ||||
-rw-r--r-- | tasks/bin/bundle-platform.bat | 2 | ||||
-rw-r--r-- | tasks/bin/bundler_patch.rb | 27 | ||||
-rwxr-xr-x | tasks/bin/gem-version-diff | 37 | ||||
-rw-r--r-- | tasks/bundle.rb | 50 | ||||
-rw-r--r-- | tasks/bundle_util.rb | 110 | ||||
-rw-r--r-- | tasks/dependencies.rb | 1 |
7 files changed, 15 insertions, 232 deletions
diff --git a/tasks/bin/bundle-platform b/tasks/bin/bundle-platform deleted file mode 100755 index aaf433c98d..0000000000 --- a/tasks/bin/bundle-platform +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env ruby -require_relative "bundler_patch" - -platforms = ARGV.shift -platforms = platforms.split(" ").map { |p| Gem::Platform.new(p) } -Gem::Platform.instance_eval { @local = platforms.last } -old_platforms = Gem.platforms -Gem.platforms = platforms -puts "bundle-platform set Gem.platforms to #{Gem.platforms.map { |p| p.to_s }} (was #{old_platforms.map { |p| p.to_s }})" - -desired_version = ARGV.shift.delete("_") - -# The rest of this is a normal bundler binstub -require "pathname" -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../../Gemfile", - Pathname.new(__FILE__).realpath) - -require "rubygems" - -load Gem.bin_path("bundler", "bundle", desired_version) diff --git a/tasks/bin/bundle-platform.bat b/tasks/bin/bundle-platform.bat deleted file mode 100644 index d193eb0c05..0000000000 --- a/tasks/bin/bundle-platform.bat +++ /dev/null @@ -1,2 +0,0 @@ -@ECHO OFF -ruby "%~dpn0" %* diff --git a/tasks/bin/bundler_patch.rb b/tasks/bin/bundler_patch.rb deleted file mode 100644 index 5665e44eca..0000000000 --- a/tasks/bin/bundler_patch.rb +++ /dev/null @@ -1,27 +0,0 @@ -# This is a temporary monkey patch to address https://github.com/bundler/bundler/issues/4896 -# the heart of the fix is line #18 with the addition of: -# && (possibility.activated - existing_node.payload.activated).empty? -# This ensures we do not mis linux platform gems in some scenarios like ffi in kitchen-test. -# There is a permanent fix to bundler (See https://github.com/bundler/bundler/pull/4836) which -# is due to ship in v1.14. Once we adopt that version, we can remove this file - -require "bundler" -require "bundler/vendor/molinillo/lib/molinillo/resolution" - -module Bundler::Molinillo - class Resolver - # A specific resolution from a given {Resolver} - class Resolution - def attempt_to_activate - debug(depth) { "Attempting to activate " + possibility.to_s } - existing_node = activated.vertex_named(name) - if existing_node.payload && (possibility.activated - existing_node.payload.activated).empty? - debug(depth) { "Found existing spec (#{existing_node.payload})" } - attempt_to_activate_existing_spec(existing_node) - else - attempt_to_activate_new_spec - end - end - end - end -end diff --git a/tasks/bin/gem-version-diff b/tasks/bin/gem-version-diff deleted file mode 100755 index 617402d4e6..0000000000 --- a/tasks/bin/gem-version-diff +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env ruby - -require_relative "../../version_policy" - -old_version, new_version = ARGV[0..1] - -require "set" -ENV["BUNDLE_WITHOUT"] = INSTALL_WITHOUT_GROUPS.join(":") -relevant_gems = Set.new -`bundle list`.each_line do |line| - next unless line =~ /^ \* (\S+)/ - relevant_gems.add($1) -end - -old_gems = {} -old_file = `git show #{old_version}:Gemfile.lock` -old_file.each_line do |line| - next unless line =~ /^ (\S+) \(([^\)]+)\)$/ - next unless relevant_gems.include?($1) - old_gems[$1] = $2 -end - -new_gems = {} -new_file = `git show #{new_version}:Gemfile.lock` -new_file.each_line do |line| - next unless line =~ /^ (\S+) \(([^\)]+)\)$/ - next unless relevant_gems.include?($1) - new_gems[$1] = $2 -end - -modified_gems = (old_gems.keys & new_gems.keys).sort.select { |name| new_gems[name] != old_gems[name] }.map { |name| "#{name} - #{new_gems[name]} (was #{old_gems[name]})" } -removed_gems = (old_gems.keys - new_gems.keys).sort.map { |name| "#{name} - #{old_gems[name]}" } -added_gems = (new_gems.keys - old_gems.keys).sort.map { |name| "#{name} - #{new_gems[name]}" } - -puts "MODIFIED:\n#{modified_gems.join("\n")}" if modified_gems.any? -puts "\nADDED:\n#{added_gems.join("\n")}" if added_gems.any? -puts "\nREMOVED:\n#{removed_gems.join("\n")}" if removed_gems.any? diff --git a/tasks/bundle.rb b/tasks/bundle.rb index f530515786..0e9b207932 100644 --- a/tasks/bundle.rb +++ b/tasks/bundle.rb @@ -15,7 +15,6 @@ # limitations under the License. # -require_relative "bundle_util" require_relative "../version_policy" require "fileutils" @@ -23,33 +22,22 @@ desc "Tasks to work with the main Gemfile and Gemfile.<platform>" namespace :bundle do desc "Update Gemfile.lock and all Gemfile.<platform>.locks (or one or more gems via bundle:update gem1 gem2 ...)." task :update, [:args] do |t, rake_args| - extend BundleUtil args = rake_args[:args] || "" - with_bundle_unfrozen do - puts "" - puts "-------------------------------------------------------------------" - puts "Updating Gemfile.lock ..." - puts "-------------------------------------------------------------------" - bundle "update #{args}" - platforms.each do |platform| - bundle "update #{args}", platform: platform - end + Bundler.with_clean_env do + sh "bundle config --local frozen '0'" + sh "bundle update #{args}" + sh "bundle config --local frozen '1'" end end desc "Conservatively update Gemfile.lock and all Gemfile.<platform>.locks" task :install, [:args] do |t, rake_args| - extend BundleUtil args = rake_args[:args] || "" - with_bundle_unfrozen do - puts "" - puts "-------------------------------------------------------------------" - puts "Updating Gemfile.lock ..." - puts "-------------------------------------------------------------------" - bundle "install #{args}" - platforms.each do |platform| - bundle "lock", platform: platform - end + args = rake_args[:args] || "" + Bundler.with_clean_env do + sh "bundle config --local frozen '0'" + sh "bundle install #{args}" + sh "bundle config --local frozen '1'" end end @@ -82,20 +70,12 @@ namespace :bundle do end end -desc "Run bundle with arbitrary args against the given platform; e.g. rake bundle[show]. No platform to run against the main bundle; bundle[show,windows] to run the windows one; bundle[show,*] to run against all non-default platforms." -task :bundle, [:args, :platform] do |t, rake_args| - extend BundleUtil +desc "Run bundle with arbitrary args" +task :bundle, [:args] do |t, rake_args| args = rake_args[:args] || "" - platform = rake_args[:platform] - with_bundle_unfrozen do - if platform == "*" - platforms.each do |platform| - bundle args, platform: platform - end - elsif platform - bundle args, platform: platform - else - bundle args - end + Bundler.with_clean_env do + sh "bundle config --local frozen '0'" + sh "bundle #{args}" + sh "bundle config --local frozen '1'" end end diff --git a/tasks/bundle_util.rb b/tasks/bundle_util.rb deleted file mode 100644 index 67647dd4f0..0000000000 --- a/tasks/bundle_util.rb +++ /dev/null @@ -1,110 +0,0 @@ -require "bundler" -require "shellwords" - -module BundleUtil - PLATFORMS = { "windows" => %w{ruby x86-mingw32} } - - def project_root - File.expand_path("../..", __FILE__) - end - - def bundle_platform - File.join(project_root, "tasks", "bin", "bundle-platform") - end - - # Parse the output of "bundle outdated" and get the list of gems that - # were outdated - def parse_bundle_outdated(bundle_outdated_output) - result = [] - bundle_outdated_output.each_line do |line| - if line =~ /^\s*\* (.+) \(newest ([^,]+), installed ([^,)])*/ - gem_name, newest_version, installed_version = $1, $2, $3 - result << [ line, gem_name ] - end - end - result - end - - def with_bundle_unfrozen(cwd: nil, leave_frozen: false) - bundle "config --delete frozen", cwd: cwd - begin - yield - ensure - bundle "config --local frozen 1", cwd: cwd unless leave_frozen - end - end - - # Run bundle-platform with the given ruby platform(s) - def bundle(args, gemfile: nil, platform: nil, cwd: nil, extract_output: false, delete_gemfile_lock: false) - args = args.split(/\s+/) - if cwd - prefix = "[#{cwd}] " - end - cwd = File.expand_path(cwd || ".", project_root) - Bundler.with_clean_env do - Dir.chdir(cwd) do - gemfile ||= "Gemfile" - gemfile = File.expand_path(gemfile, cwd) - raise "No platform #{platform} (supported: #{PLATFORMS.keys.join(", ")})" if platform && !PLATFORMS[platform] - - # First delete the gemfile.lock - if delete_gemfile_lock - if File.exist?("#{gemfile}.lock") - puts "Deleting #{gemfile}.lock ..." - File.delete("#{gemfile}.lock") - end - end - - # Run the bundle command - ruby_platforms = platform ? PLATFORMS[platform].join(" ") : "ruby" - cmd = Shellwords.join([ - Gem.ruby, - "-S", - bundle_platform, - ruby_platforms, - "_#{desired_bundler_version}_", - *args, - ]) - puts "#{prefix}#{Shellwords.join(["bundle", *args])}#{platform ? " for #{platform} platform" : ""}:" - with_gemfile(gemfile) do - puts "#{prefix}BUNDLE_GEMFILE=#{gemfile}" - puts "#{prefix}> #{cmd}" - if extract_output - `#{cmd}` - else - unless system(bundle_platform, ruby_platforms, "_#{desired_bundler_version}_", *args) - raise "#{bundle_platform} failed: exit code #{$?}" - end - end - end - end - end - end - - def with_gemfile(gemfile) - old_gemfile = ENV["BUNDLE_GEMFILE"] - ENV["BUNDLE_GEMFILE"] = gemfile - begin - yield - ensure - if old_gemfile - ENV["BUNDLE_GEMFILE"] = old_gemfile - else - ENV.delete("BUNDLE_GEMFILE") - end - end - end - - def platforms - PLATFORMS.keys - end - - def desired_bundler_version - @desired_bundler_version ||= begin - omnibus_overrides = File.join(project_root, "omnibus_overrides.rb") - File.readlines(omnibus_overrides).each do |line| - return $1 if line =~ /^override :bundler, version: "(.+)"$/ - end - end - end -end diff --git a/tasks/dependencies.rb b/tasks/dependencies.rb index 6b836b747e..2118644b12 100644 --- a/tasks/dependencies.rb +++ b/tasks/dependencies.rb @@ -15,7 +15,6 @@ # limitations under the License. # -require_relative "bundle_util" require_relative "bundle" require_relative "../version_policy" |