brew-gem 0.8.2 → 1.1.0

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
- SHA1:
3
- metadata.gz: 3b51e0ed7462440fcd09a45ae0120112e88082ee
4
- data.tar.gz: d4554cffc8bbe17b4089da5aaf802ea3124b5463
2
+ SHA256:
3
+ metadata.gz: df6562ae148c6903c357d09a1c8a1f6c97f0e1fa8d769c0a31af29310c171652
4
+ data.tar.gz: f5cea024787571e2d1d80796df0d29343e902b1b2fc656a0a5bfceacfd7c2fea
5
5
  SHA512:
6
- metadata.gz: 7f87ccaf6353b0f84f8c43ef867b1505c8afe65e329f943cdc886dc8c052fca93cc26d25418c630c4b13e28a4207f461d0a4a1d8a4dda2304b0838e1c521cf90
7
- data.tar.gz: 918856f384cba1e280ce4b5b0c66dc8cadb5b7be3b776b436cfe15554584fa1e931c4723b4775c3f6064d823169088fa61509f0c2b82f50499a9157c2e29a2cb
6
+ metadata.gz: 7f96bd1a41356ee2ce572c1206a5f490c003ea9ecfd10eea82ac8e041297b5784d479b384ce073169f6d2f344e792a26240cfa9f0250980ba1a0d9f59471ff5f
7
+ data.tar.gz: a38fef07e4db35059c41363f20061a4fe28843f513e508752d148b2f1f1dc157e85087c67fe3468c45c64a1f03a7866c0b380bf33f50c0e1723bc006ec6e92bb
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.3.1
1
+ 2.3.6
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,41 @@
1
+ #### v1.1.0
2
+
3
+ * Allow arguments after `--` to be passed to `gem install`
4
+
5
+ > https://github.com/sportngin/brew-gem/pull/67
6
+
7
+ #### v1.0.0
8
+
9
+ * Fix homebrew ruby path (thanks Kaleb Lape)
10
+
11
+ > https://github.com/sportngin/brew-gem/pull/59
12
+
13
+ * Fix old ruby gem flags (thanks JuPlutonic)
14
+
15
+ > https://github.com/sportngin/brew-gem/pull/57/
16
+
17
+ #### v0.9.0
18
+
19
+ * Fix compatibility with latest homebrew
20
+
21
+ > Nick Sieger: https://github.com/sportngin/brew-gem/pull/54
22
+
23
+ #### v0.8.4
24
+
25
+ * Install with homebrew ruby by default, if present
26
+
27
+ > Nick Sieger: Emma Sax, Andy Fleener, Unknown User: https://github.com/sportngin/brew-gem/pull/53
28
+
29
+ * Fix gem exe used by RubyGemsDownloadStrategy
30
+
31
+ > Nick Sieger: Andy Fleener, Unknown User: https://github.com/sportngin/brew-gem/pull/51
32
+
33
+ #### v0.8.3
34
+
35
+ * Add --disable-gems to generated binstubs
36
+
37
+ > Nick Sieger: https://github.com/sportngin/brew-gem/pull/49
38
+
1
39
  #### v0.8.2
2
40
 
3
41
  * Fix sandbox permissions with gem spec cache
data/lib/brew/gem/cli.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'erb'
2
2
  require 'tempfile'
3
+ require 'shellwords'
3
4
 
4
5
  module Brew::Gem::CLI
5
6
  module_function
@@ -14,6 +15,49 @@ module Brew::Gem::CLI
14
15
  "help" => "This message"
15
16
  }
16
17
 
18
+ HOMEBREW_RUBY_FLAG = "--homebrew-ruby"
19
+ SYSTEM_RUBY_FLAG = "--system-ruby"
20
+ RUBY_FLAGS = [HOMEBREW_RUBY_FLAG, SYSTEM_RUBY_FLAG]
21
+
22
+ class Arguments
23
+ attr_reader :ruby_flag
24
+
25
+ def initialize(args)
26
+ @ruby_flag = args.select {|a| RUBY_FLAGS.include?(a) }.last
27
+ @args = args.reject {|a| RUBY_FLAGS.include?(a) }
28
+ @args_without_flags = @args.reject {|a| a.start_with?('-') }
29
+ end
30
+
31
+ def command
32
+ @args_without_flags[0]
33
+ end
34
+
35
+ def gem
36
+ @args_without_flags[1]
37
+ end
38
+
39
+ def supplied_version
40
+ @args_without_flags[2]
41
+ end
42
+
43
+ def flags
44
+ @flags ||= @args.reject {|a| a == gem || a == supplied_version }
45
+ end
46
+
47
+ def to_gem_args
48
+ if start = flags.index('--')
49
+ flags[start..-1]
50
+ else
51
+ []
52
+ end
53
+ end
54
+
55
+ def to_brew_args
56
+ stop_index = (flags.index('--') || 0) - 1
57
+ flags[0..stop_index]
58
+ end
59
+ end
60
+
17
61
  def help_msg
18
62
  (["Please specify a gem name (e.g. brew gem command <name>)"] +
19
63
  COMMANDS.map {|name, desc| " #{name} - #{desc}"}).join("\n")
@@ -31,31 +75,36 @@ module Brew::Gem::CLI
31
75
  end
32
76
 
33
77
  def process_args(args)
34
- abort help_msg unless args[0]
35
- abort "unknown command: #{args[0]}\n#{help_msg}" unless COMMANDS.keys.include?(args[0])
78
+ arguments = Arguments.new(args)
79
+ command = arguments.command
80
+ abort help_msg unless command
81
+ abort "unknown command: #{command}\n#{help_msg}" unless COMMANDS.keys.include?(command)
36
82
 
37
- if args[0] == 'help'
83
+ if command == 'help'
38
84
  STDERR.puts help_msg
39
85
  exit 0
40
86
  end
41
87
 
42
- args[0..3]
88
+ arguments
89
+ end
90
+
91
+ def homebrew_prefix
92
+ ENV['HOMEBREW_PREFIX'] || `brew --prefix`.chomp
43
93
  end
44
94
 
45
- def expand_formula(name, version, use_homebrew_ruby=false)
95
+ def expand_formula(name, version, use_homebrew_ruby = false, gem_arguments = [])
46
96
  klass = 'Gem' + name.capitalize.gsub(/[-_.\s]([a-zA-Z0-9])/) { $1.upcase }.gsub('+', 'x')
47
97
  user_gemrc = "#{ENV['HOME']}/.gemrc"
48
- homebrew_prefix = ENV['HOMEBREW_PREFIX'] || `brew --prefix`.chomp
49
98
  template_file = File.expand_path('../formula.rb.erb', __FILE__)
50
99
  template = ERB.new(File.read(template_file))
51
100
  template.result(binding)
52
101
  end
53
102
 
54
- def with_temp_formula(name, version, use_homebrew_ruby)
103
+ def with_temp_formula(name, version, use_homebrew_ruby, gem_arguments)
55
104
  filename = File.join Dir.tmpdir, "gem-#{name}.rb"
56
105
 
57
106
  open(filename, 'w') do |f|
58
- f.puts expand_formula(name, version, use_homebrew_ruby)
107
+ f.puts expand_formula(name, version, use_homebrew_ruby, gem_arguments)
59
108
  end
60
109
 
61
110
  yield filename
@@ -63,24 +112,21 @@ module Brew::Gem::CLI
63
112
  File.unlink filename
64
113
  end
65
114
 
66
- def run(args = ARGV)
67
- command, name, supplied_version, homebrew_ruby = process_args(args)
68
- homebrew_ruby_flag = "--homebrew-ruby"
69
- if supplied_version == homebrew_ruby_flag
70
- supplied_version = nil
71
- homebrew_ruby = homebrew_ruby_flag
72
- end
73
-
74
- use_homebrew_ruby = homebrew_ruby == homebrew_ruby_flag
75
-
76
- version = fetch_version(name, supplied_version)
115
+ def homebrew_ruby?(ruby_flag)
116
+ File.exist?("#{homebrew_prefix}/opt/ruby") &&
117
+ ruby_flag.nil? || ruby_flag == HOMEBREW_RUBY_FLAG
118
+ end
77
119
 
78
- with_temp_formula(name, version, use_homebrew_ruby) do |filename|
79
- case command
120
+ def run(args = ARGV)
121
+ arguments = process_args(args)
122
+ name = arguments.gem
123
+ version = fetch_version(name, arguments.supplied_version)
124
+ with_temp_formula(name, version, homebrew_ruby?(arguments.ruby_flag), arguments.to_gem_args) do |filename|
125
+ case arguments.command
80
126
  when "formula"
81
127
  $stdout.puts File.read(filename)
82
128
  else
83
- system "brew #{command} #{filename}"
129
+ system "brew #{arguments.to_brew_args.shelljoin} --formula #{filename}"
84
130
  exit $?.exitstatus unless $?.success?
85
131
  end
86
132
  end
@@ -3,17 +3,39 @@
3
3
  require 'formula'
4
4
  require 'fileutils'
5
5
 
6
+ USE_HOMEBREW_RUBY = <%= use_homebrew_ruby ? "true" : "false" %>
7
+ GEM_ARGUMENTS = <%= gem_arguments.inspect %>
8
+
9
+ module RubyBin
10
+ def ruby_bin
11
+ USE_HOMEBREW_RUBY ? Formula["ruby"].opt_bin: "/usr/bin"
12
+ end
13
+ end
14
+
6
15
  class RubyGemsDownloadStrategy < AbstractDownloadStrategy
16
+ include RubyBin
17
+
7
18
  def fetch
8
19
  ohai "Fetching <%= name %> from gem source"
9
- HOMEBREW_CACHE.cd do
10
- ENV['GEM_SPEC_CACHE'] = "#{HOMEBREW_CACHE}/gem_spec_cache"
11
- system "gem", "fetch", "<%= name %>", "--version", resource.version
20
+ cache.cd do
21
+ ENV['GEM_SPEC_CACHE'] = "#{cache}/gem_spec_cache"
22
+ system "#{ruby_bin}/gem", "fetch", "<%= name %>", "--version", gem_version
12
23
  end
13
24
  end
14
25
 
15
26
  def cached_location
16
- Pathname.new("#{HOMEBREW_CACHE}/<%= name %>-#{resource.version}.gem")
27
+ Pathname.new("#{cache}/<%= name %>-#{gem_version}.gem")
28
+ end
29
+
30
+ def cache
31
+ @cache ||= HOMEBREW_CACHE
32
+ end
33
+
34
+ def gem_version
35
+ return @version if defined?(@version) && @version
36
+ @version = @resource.version if defined?(@resource)
37
+ raise "Unable to determine version; did Homebrew change?" unless @version
38
+ @version
17
39
  end
18
40
 
19
41
  def clear_cache
@@ -22,8 +44,11 @@ class RubyGemsDownloadStrategy < AbstractDownloadStrategy
22
44
  end
23
45
 
24
46
  class <%= klass %> < Formula
47
+ include RubyBin
48
+
25
49
  url "<%= name %>", :using => RubyGemsDownloadStrategy
26
50
  version "<%= version %>"
51
+ depends_on "ruby"
27
52
 
28
53
  def install
29
54
  # Copy user's RubyGems config to temporary build home.
@@ -38,16 +63,18 @@ class <%= klass %> < Formula
38
63
  ENV['GEM_HOME']="#{prefix}"
39
64
  ENV['GEM_PATH']="#{prefix}"
40
65
 
41
- rubybindir = '<%= use_homebrew_ruby ? "#{homebrew_prefix}/bin" : "/usr/bin" %>'
42
- gem_path = "#{rubybindir}/gem"
43
- ruby_path = "#{rubybindir}/ruby"
44
- system gem_path, "install", cached_download,
45
- "--no-ri",
46
- "--no-rdoc",
66
+ # Use /usr/local/bin at the front of the path instead of Homebrew shims,
67
+ # which mess with Ruby's own compiler config when building native extensions
68
+ if defined?(HOMEBREW_SHIMS_PATH)
69
+ ENV['PATH'] = ENV['PATH'].sub(HOMEBREW_SHIMS_PATH.to_s, '/usr/local/bin')
70
+ end
71
+
72
+ system "#{ruby_bin}/gem", "install", cached_download,
73
+ "--no-document",
47
74
  "--no-wrapper",
48
75
  "--no-user-install",
49
76
  "--install-dir", prefix,
50
- "--bindir", bin
77
+ "--bindir", bin, *GEM_ARGUMENTS
51
78
 
52
79
  raise "gem install '<%= name %>' failed with status #{$?.exitstatus}" unless $?.success?
53
80
 
@@ -74,9 +101,10 @@ class <%= klass %> < Formula
74
101
  file = Pathname.new("#{brew_gem_prefix}/#{gemspec.bindir}/#{exe}")
75
102
  (bin+file.basename).open('w') do |f|
76
103
  f << <<-RUBY
77
- #!#{ruby_path}
104
+ #!#{ruby_bin}/ruby --disable-gems
78
105
  ENV['GEM_HOME']="#{prefix}"
79
106
  ENV['GEM_PATH']="#{prefix}"
107
+ require 'rubygems'
80
108
  $:.unshift(#{ruby_libs.map(&:inspect).join(",")})
81
109
  load "#{file}"
82
110
  RUBY
@@ -1,5 +1,5 @@
1
1
  module Brew
2
2
  module Gem
3
- VERSION = "0.8.2"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brew-gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sieger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-03 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -97,7 +97,7 @@ homepage: https://github.com/sportngin/brew-gem
97
97
  licenses: []
98
98
  metadata:
99
99
  allowed_push_host: https://rubygems.org
100
- post_install_message:
100
+ post_install_message:
101
101
  rdoc_options: []
102
102
  require_paths:
103
103
  - lib
@@ -112,9 +112,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
112
112
  - !ruby/object:Gem::Version
113
113
  version: '0'
114
114
  requirements: []
115
- rubyforge_project:
116
- rubygems_version: 2.6.12
117
- signing_key:
115
+ rubygems_version: 3.0.3
116
+ signing_key:
118
117
  specification_version: 4
119
118
  summary: Generate Homebrew formulas to install standalone ruby gems.
120
119
  test_files: []