bundler-patch 1.0.0 → 1.1.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6495ba38818fc8260c56a2e76557c240c915bc1f
4
- data.tar.gz: e1bd0b9ad6de5ea1747a55d3d272fbc0844dd6f7
3
+ metadata.gz: 4d0a7b1ce6bd99140213082d130de098b65c45ce
4
+ data.tar.gz: f81ba6fbfecf3be917095c265e9cfe38929e49ec
5
5
  SHA512:
6
- metadata.gz: 9e5c2bab2b14e99942d719bcb95c70719067c7226718a504aa4cbc285dce1c5b34a9c307bbea2b483f0602b8d31f237ef07731677230da77d67f0787eb9515ee
7
- data.tar.gz: a1d304cc5094b3d2b1604e5d55777b32f707beeaf80723752c9da000cb65a170b5a43ea7d202757968c9773612d39f604b15612d9df8d17235be4935e5affc1c
6
+ metadata.gz: 75aaf7bd3c7c80d6cd88c43604071277df983c0716ac4de46094f8aaa1bf41f9161769ab1e2320c99ec00f50b8ef54c75d8cfd68ab868304fda6c20ee5ebbc48
7
+ data.tar.gz: bbfebaa7bd031e39ab1a5313233e256b2f6d2b3b8f6e0071afe14d15a25abca02ae9976eac90bbbe2656f488495af8df369c0e894ea26cbb933ebee357b3db96
@@ -1 +1 @@
1
- 2.3.3
1
+ 2.3.4
@@ -4,26 +4,48 @@ before_install:
4
4
  - for dir in $(echo $GEM_PATH | tr ':' ' '); do gem uninstall -i $dir bundler -a -x; done
5
5
  - gem install bundler -v $BUNDLER_TEST_VERSION
6
6
  - bundle --version
7
+ - rvm use 2.1.10 --install --binary --fuzzy
8
+ - gem update --system
9
+ - rvm use $RVM_VER --install --binary --fuzzy
10
+ - gem update --system
7
11
 
8
12
  script: bundle exec rake test:all
9
13
 
10
14
  matrix:
11
15
  include:
12
- - rvm: 2.3.4
13
- env: BUNDLER_TEST_VERSION=1.9.10
14
- - rvm: 2.3.4
15
- env: BUNDLER_TEST_VERSION=1.10.5
16
- - rvm: 2.3.4
17
- env: BUNDLER_TEST_VERSION=1.11.2
18
- - rvm: 2.3.4
19
- env: BUNDLER_TEST_VERSION=1.12.5
20
- - rvm: 2.3.4
21
- env: BUNDLER_TEST_VERSION=1.13.6
22
- - rvm: 2.3.4
23
- env: BUNDLER_TEST_VERSION=1.14.6
24
- - rvm: 2.1.10
25
- env: BUNDLER_TEST_VERSION=1.15.0
26
- - rvm: 2.2.7
27
- env: BUNDLER_TEST_VERSION=1.15.0
28
- - rvm: 2.3.4
29
- env: BUNDLER_TEST_VERSION=1.15.0
16
+ env:
17
+ - RVM_VER=2.3.4
18
+ - BUNDLER_TEST_VERSION=1.9.10
19
+ - BP_DEBUG=1
20
+ env:
21
+ - RVM_VER=2.3.4
22
+ - BUNDLER_TEST_VERSION=1.10.5
23
+ - BP_DEBUG=1
24
+ env:
25
+ - RVM_VER=2.3.4
26
+ - BUNDLER_TEST_VERSION=1.11.2
27
+ - BP_DEBUG=1
28
+ env:
29
+ - RVM_VER=2.3.4
30
+ - BUNDLER_TEST_VERSION=1.12.5
31
+ - BP_DEBUG=1
32
+ env:
33
+ - RVM_VER=2.3.4
34
+ - BUNDLER_TEST_VERSION=1.13.6
35
+ - BP_DEBUG=1
36
+ env:
37
+ - RVM_VER=2.3.4
38
+ - BUNDLER_TEST_VERSION=1.14.6
39
+ - BP_DEBUG=1
40
+ # env:
41
+ # - RVM_VER=2.1.10
42
+ # - BUNDLER_TEST_VERSION=1.15.1
43
+ # - BP_DEBUG=1
44
+ env:
45
+ - RVM_VER=2.2.7
46
+ - BUNDLER_TEST_VERSION=1.15.1
47
+ - BP_DEBUG=1
48
+ env:
49
+ - RVM_VER=2.3.4
50
+ - BUNDLER_TEST_VERSION=1.15.1
51
+ - BP_DEBUG=1
@@ -19,11 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.executables = ['bundler-patch']
20
20
  spec.require_paths = ['lib']
21
21
 
22
- spec.add_dependency 'bundler-advise', '~> 1.1', '>= 1.1.2'
22
+ spec.add_dependency 'bundler-advise', '~> 1.1', '>= 1.1.5'
23
23
  spec.add_dependency 'slop', '~> 3.0'
24
24
  spec.add_dependency 'bundler', '~> 1.7'
25
25
 
26
- spec.add_development_dependency 'bundler-fixture', '~> 1.3', '>= 1.3.2'
26
+ spec.add_development_dependency 'bundler-fixture', '~> 1.6'
27
27
  spec.add_development_dependency 'pry'
28
28
  spec.add_development_dependency 'rake', '~> 10.0'
29
29
  spec.add_development_dependency 'rspec', '~> 3.5'
@@ -5,6 +5,7 @@ module Bundler
5
5
  end
6
6
  end
7
7
 
8
+ require 'bundler/patch/target_bundle'
8
9
  require 'bundler/patch/updater'
9
10
  require 'bundler/patch/gemfile'
10
11
  require 'bundler/patch/ruby_version'
@@ -63,7 +63,8 @@ module Bundler::Patch
63
63
  end.map do |_, all|
64
64
  all.sort.last
65
65
  end
66
- Gemfile.new(gem_name: all_gem_names.first, patched_versions: highest_minor_patched)
66
+ Gemfile.new(target_bundle: @options[:target] || TargetBundle.new,
67
+ gem_name: all_gem_names.first, patched_versions: highest_minor_patched)
67
68
  end
68
69
  end
69
70
 
@@ -2,10 +2,13 @@ require 'bundler'
2
2
  require 'bundler/vendor/thor/lib/thor'
3
3
  require 'bundler/advise'
4
4
  require 'slop'
5
+ require 'open3'
5
6
 
6
7
  module Bundler::Patch
7
8
  class CLI
8
9
  def self.execute
10
+ original_command = ARGV.join(' ')
11
+
9
12
  opts = Slop.parse! do
10
13
  banner "Bundler Patch Version #{Bundler::Patch::VERSION}\nUsage: bundle patch [options] [gems-to-update]\n\nbundler-patch attempts to update gems conservatively.\n"
11
14
  on '-m', '--minor', 'Prefer update to the latest minor.patch version.'
@@ -17,8 +20,11 @@ module Bundler::Patch
17
20
  on '-d=', '--ruby-advisory-db-path=', 'Optional path for ruby advisory db. `gems` dir will be appended to this path.'
18
21
  on '-r', '--ruby', 'Update Ruby version in related files.'
19
22
  on '--rubies=', 'Supported Ruby versions. Comma delimited or multiple switches.', as: Array, delimiter: ','
23
+ on '-g=', '--gemfile=', 'Optional Gemfile to execute against. Defaults to Gemfile in current directory.'
24
+ on '--use_target_ruby', 'Optionally attempt to use Ruby version of target bundle specified in --gemfile.'
20
25
  on '-h', 'Show this help'
21
26
  on '--help', 'Show README.md'
27
+
22
28
  # will be stripped in help display and normalized to hyphenated options
23
29
  on '--vulnerable_gems_only'
24
30
  on '--advisory_db_path='
@@ -30,6 +36,7 @@ module Bundler::Patch
30
36
 
31
37
  options = opts.to_hash
32
38
  options[:gems_to_update] = ARGV
39
+ options[:original_command] = original_command
33
40
  STDERR.puts options.inspect if ENV['DEBUG']
34
41
 
35
42
  show_help(opts) if options[:h]
@@ -58,11 +65,23 @@ module Bundler::Patch
58
65
 
59
66
  normalize_options(options)
60
67
 
61
- return list(options) if options[:list]
68
+ process_gemfile_option(options)
69
+
70
+ if options[:use_target_ruby] # TODO: && different_ruby_found
71
+ tb = options[:target]
72
+ ruby = tb.ruby_bin_exe
73
+ tb.install_bundler_patch_in_target
74
+ bundler_patch = File.join(tb.ruby_bin, 'bundler-patch') # uses 'latest' bundler-patch, which can work after we've installed ours.
75
+ full_command = "#{ruby} #{bundler_patch} #{options[:original_command].gsub(/use_target_ruby/, '')}"
76
+ result = shell_command(full_command)
77
+ puts result[:stdout] unless ENV['BP_DEBUG']
78
+ else
79
+ return list(options) if options[:list]
62
80
 
63
- patch_ruby(options[:rubies]) if options[:ruby]
81
+ patch_ruby(options) if options[:ruby]
64
82
 
65
- patch_gems(options)
83
+ patch_gems(options)
84
+ end
66
85
  end
67
86
 
68
87
  def normalize_options(options)
@@ -78,6 +97,19 @@ module Bundler::Patch
78
97
 
79
98
  private
80
99
 
100
+ def process_gemfile_option(options)
101
+ # copy/pasta from Bundler
102
+ custom_gemfile = options[:gemfile] || Bundler.settings[:gemfile]
103
+ if custom_gemfile && !custom_gemfile.empty?
104
+ ENV['BUNDLE_GEMFILE'] = File.expand_path(custom_gemfile)
105
+ dir, gemfile = [File.dirname(custom_gemfile), File.basename(custom_gemfile)]
106
+ target_bundle = TargetBundle.new(dir: dir, gemfile: gemfile)
107
+ options[:target] = target_bundle
108
+ else
109
+ options[:target] = TargetBundle.new
110
+ end
111
+ end
112
+
81
113
  def list(options)
82
114
  gem_patches = AdvisoryConsolidator.new(options).vulnerable_gems
83
115
 
@@ -91,8 +123,9 @@ module Bundler::Patch
91
123
  end
92
124
  end
93
125
 
94
- def patch_ruby(supported)
95
- RubyVersion.new(patched_versions: supported).update
126
+ def patch_ruby(options)
127
+ supported = options[:rubies]
128
+ RubyVersion.new(target_bundle: options[:target], patched_versions: supported).update
96
129
  end
97
130
 
98
131
  def patch_gems(options)
@@ -138,12 +171,28 @@ module Bundler::Patch
138
171
  # update => true is very important, otherwise without any Gemfile changes, the installer
139
172
  # may end up concluding everything can be resolved locally, nothing is changing,
140
173
  # and then nothing is done. lib/bundler/cli/update.rb also hard-codes this.
141
- Bundler::Installer.install(Bundler.root, prep.bundler_def, {'update' => true})
174
+ Bundler::Installer.install(options[:target].dir, prep.bundler_def, {'update' => true})
142
175
  Bundler.load.cache if Bundler.app_cache.exist?
143
176
  end
144
177
  end
145
178
  end
146
179
 
180
+ def shell_command(command)
181
+ stdout, stderr, status = Open3.capture3(command)
182
+ if ENV['BP_DEBUG']
183
+ puts "-command: #{command}"
184
+ puts "--stdout:#{indent(stdout)}"
185
+ puts "--stderr:#{indent(stderr)}"
186
+ end
187
+ {stdout: stdout,
188
+ stderr: stderr,
189
+ status: status}
190
+ end
191
+
192
+ def indent(s)
193
+ s.split("\n").map { |ln| " #{ln}" }.join("\n")
194
+ end
195
+
147
196
  if __FILE__ == $0
148
197
  Bundler::Patch::CLI.execute
149
198
  end
@@ -2,11 +2,11 @@ module Bundler::Patch
2
2
  class Gemfile < UpdateSpec
3
3
  attr_reader :gem_name
4
4
 
5
- def initialize(target_dir: Dir.pwd,
5
+ def initialize(target_bundle: TargetBundle.new,
6
6
  gem_name:,
7
7
  patched_versions: [])
8
- super(target_file: 'Gemfile',
9
- target_dir: target_dir,
8
+ super(target_file: target_bundle.gemfile,
9
+ target_dir: target_bundle.dir,
10
10
  patched_versions: patched_versions)
11
11
  @gem_name = gem_name
12
12
  end
@@ -32,7 +32,6 @@ module Bundler::Patch
32
32
  #
33
33
  # We'll still instance_eval the gem line though, to properly
34
34
  # handle the various options and possible multiple reqs.
35
- @target_file = 'Gemfile'
36
35
  @regexes = /^\s*gem.*['"]\s*#{@gem_name}\s*['"].*$/
37
36
  file_replace do |match, re|
38
37
  update_to_new_gem_version(match)
@@ -4,21 +4,21 @@ module Bundler::Patch
4
4
 
5
5
  def self.files
6
6
  @files ||= {
7
- '.ruby-version' => [/.*/],
8
- 'Gemfile' => RUBY_VERSION_LINE_REGEXPS,
9
- 'gems.rb' => RUBY_VERSION_LINE_REGEXPS,
7
+ '.ruby-version' => [/.*/]
10
8
  }
11
9
  end
12
10
 
13
- def initialize(target_dir: Dir.pwd, patched_versions: [])
14
- super(target_file: target_file,
15
- target_dir: target_dir,
11
+ def initialize(target_bundle: TargetBundle.new, patched_versions: [])
12
+ super(target_file: target_bundle.gemfile,
13
+ target_dir: target_bundle.dir,
16
14
  regexes: regexes,
17
15
  patched_versions: patched_versions)
18
16
  end
19
17
 
20
18
  def update
21
- self.class.files.each_pair do |file, regexes|
19
+ hash = self.class.files.dup
20
+ hash[@target_file.dup] = RUBY_VERSION_LINE_REGEXPS
21
+ hash.each_pair do |file, regexes|
22
22
  @target_file = file
23
23
  @regexes = regexes
24
24
  file_replace
@@ -0,0 +1,108 @@
1
+ class TargetBundle
2
+ attr_reader :dir, :gemfile
3
+
4
+ def self.bundler_version_or_higher(version)
5
+ version_greater_than_or_equal_to_other(Bundler::VERSION, version)
6
+ end
7
+
8
+ def self.version_greater_than_or_equal_to_other(a, b)
9
+ Gem::Version.new(a) >= Gem::Version.new(b)
10
+ end
11
+
12
+ # TODO: Make gems.rb default in Bundler 2.0.
13
+ def initialize(dir: Dir.pwd, gemfile: 'Gemfile')
14
+ @dir = dir
15
+ @gemfile = gemfile
16
+ end
17
+
18
+ # First, the version of Ruby itself:
19
+ # 1. Look in the Gemfile/lockfile for ruby version
20
+ # 2. Look for a .ruby-version file
21
+ # 3. (An additional flag so user can specify?)
22
+ #
23
+ # Second, look bin path presuming version is in current path.
24
+ def ruby_version
25
+ result = if TargetBundle.bundler_version_or_higher('1.12.0') && File.exist?(lockfile_name)
26
+ lockfile_parser = Bundler::LockfileParser.new(Bundler.read_file(lockfile_name))
27
+ lockfile_parser.ruby_version
28
+ end
29
+
30
+ result ||= if File.exist?(ruby_version_filename)
31
+ File.read('.ruby-version').chomp
32
+ else
33
+ Bundler::Definition.build(gemfile_name, lockfile_name, nil).ruby_version
34
+ end
35
+
36
+ version, patch_level = result.to_s.scan(/(\d+\.\d+\.\d+)(p\d+)*/).first
37
+ patch_level ? "#{version}-#{patch_level}" : version
38
+ end
39
+
40
+ # This is hairy here. All the possible variants will make this mucky, but ... can
41
+ # prolly get close enough in many circumstances.
42
+ def ruby_bin(current_ruby_bin=RbConfig::CONFIG['bindir'], target_ruby_version=self.ruby_version)
43
+ [
44
+ target_ruby_version,
45
+ target_ruby_version.gsub(/-p\d+/, ''),
46
+ "ruby-#{target_ruby_version}",
47
+ "ruby-#{target_ruby_version.gsub(/-p\d+/, '')}"
48
+ ].map do |ruby_ver|
49
+ build_ruby_bin(current_ruby_bin, ruby_ver)
50
+ end.detect do |ruby_ver|
51
+ print "Looking for #{ruby_ver}... " if ENV['BP_DEBUG']
52
+ File.exist?(ruby_ver).tap { |exist| puts(exist ? 'found' : 'not found') if ENV['BP_DEBUG'] }
53
+ end
54
+ end
55
+
56
+ def build_ruby_bin(current_ruby_bin, target_ruby_version)
57
+ current_ruby_bin.split(File::SEPARATOR).reverse.map do |segment|
58
+ if segment =~ /\d+\.\d+\.\d+/
59
+ segment.gsub(/(\d+\.\d+\.\d+)-*(p\d+)*/, target_ruby_version)
60
+ else
61
+ segment
62
+ end
63
+ end.reverse.join(File::SEPARATOR)
64
+ end
65
+
66
+ def ruby_bin_exe
67
+ File.join(ruby_bin, "#{RbConfig::CONFIG['ruby_install_name']}#{RbConfig::CONFIG['EXEEXT']}")
68
+ end
69
+
70
+ # Have to run a separate process in the other Ruby, because Bundler::Settings#path ultimately
71
+ # arrives at RbConfig::CONFIG which is all special data derived from the active runtime.
72
+ # TODO: fix ^^
73
+ def gem_home
74
+ result = shell_command "#{ruby_bin_exe} -C#{@dir} -e 'puts Gem.default_dir'"
75
+ path = result[:stdout].chomp
76
+ expanded_path = Pathname.new(path).expand_path(@dir).to_s
77
+ puts expanded_path if ENV['BP_DEBUG']
78
+ expanded_path
79
+ end
80
+
81
+ # To properly update another bundle, bundler-patch _does_ need to live in the same bundle
82
+ # location because of its _dependencies_ (it's not a self-contained gem), and it can't both
83
+ # act on another bundle location AND find its own dependencies in a separate bundle location.
84
+
85
+ # TODO: gem_home for this purpose does not need to be the local bundle path, can just
86
+ # be in the Ruby "global" gem home, right?
87
+ def install_bundler_patch_in_target
88
+ # cmd = "#{ruby_bin}#{File::SEPARATOR}gem install -V --install-dir #{gem_home} --conservative --no-document --prerelease bundler-patch"
89
+ cmd = "#{ruby_bin}#{File::SEPARATOR}gem install -V --install-dir #{gem_home} --no-document --prerelease bundler-patch"
90
+ shell_command cmd
91
+
92
+ shell_command "ls #{ruby_bin}#{File::SEPARATOR}**"
93
+ end
94
+
95
+ private
96
+
97
+ def ruby_version_filename
98
+ File.join(@dir, '.ruby-version')
99
+ end
100
+
101
+ def gemfile_name
102
+ File.join(@dir, @gemfile)
103
+ end
104
+
105
+ def lockfile_name
106
+ "#{gemfile_name}.lock"
107
+ end
108
+ end
@@ -13,7 +13,7 @@ module Bundler::Patch
13
13
  end
14
14
 
15
15
  def target_path_fn
16
- File.join(@target_dir, @target_file)
16
+ File.expand_path(File.join(@target_dir, @target_file))
17
17
  end
18
18
 
19
19
  def calc_new_version(old_version)
@@ -1,5 +1,5 @@
1
1
  module Bundler
2
2
  module Patch
3
- VERSION = '1.0.0'
3
+ VERSION = '1.1.0.pre1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bundler-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrismo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-22 00:00:00.000000000 Z
11
+ date: 2017-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler-advise
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '1.1'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.1.2
22
+ version: 1.1.5
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '1.1'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.1.2
32
+ version: 1.1.5
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: slop
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -64,20 +64,14 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '1.3'
68
- - - ">="
69
- - !ruby/object:Gem::Version
70
- version: 1.3.2
67
+ version: '1.6'
71
68
  type: :development
72
69
  prerelease: false
73
70
  version_requirements: !ruby/object:Gem::Requirement
74
71
  requirements:
75
72
  - - "~>"
76
73
  - !ruby/object:Gem::Version
77
- version: '1.3'
78
- - - ">="
79
- - !ruby/object:Gem::Version
80
- version: 1.3.2
74
+ version: '1.6'
81
75
  - !ruby/object:Gem::Dependency
82
76
  name: pry
83
77
  requirement: !ruby/object:Gem::Requirement
@@ -149,6 +143,7 @@ files:
149
143
  - lib/bundler/patch/gemfile.rb
150
144
  - lib/bundler/patch/gems_to_patch_reconciler.rb
151
145
  - lib/bundler/patch/ruby_version.rb
146
+ - lib/bundler/patch/target_bundle.rb
152
147
  - lib/bundler/patch/updater.rb
153
148
  - lib/bundler/patch/version.rb
154
149
  homepage: https://github.com/livingsocial/bundler-patch
@@ -166,12 +161,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
161
  version: '0'
167
162
  required_rubygems_version: !ruby/object:Gem::Requirement
168
163
  requirements:
169
- - - ">="
164
+ - - ">"
170
165
  - !ruby/object:Gem::Version
171
- version: '0'
166
+ version: 1.3.1
172
167
  requirements: []
173
168
  rubyforge_project:
174
- rubygems_version: 2.6.8
169
+ rubygems_version: 2.6.12
175
170
  signing_key:
176
171
  specification_version: 4
177
172
  summary: Conservative bundler updates