-
Notifications
You must be signed in to change notification settings - Fork 25
/
theme-check.rb
98 lines (81 loc) · 2.76 KB
/
theme-check.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# frozen_string_literal: true
require 'formula'
require 'fileutils'
class ThemeCheck < Formula
module RubyBin
def ruby_bin
Formula["ruby"].opt_bin
end
end
class RubyGemsDownloadStrategy < AbstractDownloadStrategy
include RubyBin
def fetch(_timeout: nil, **_options)
ohai("Fetching theme-check from gem source")
cache.cd do
ENV['GEM_SPEC_CACHE'] = "#{cache}/gem_spec_cache"
system("#{ruby_bin}/gem", "fetch", "theme-check", "--version", gem_version)
end
end
def cached_location
Pathname.new("#{cache}/theme-check-#{gem_version}.gem")
end
def cache
@cache ||= HOMEBREW_CACHE
end
def gem_version
return @version if defined?(@version) && @version
@version = @resource.version if defined?(@resource)
raise "Unable to determine version; did Homebrew change?" unless @version
@version
end
def clear_cache
cached_location.unlink if cached_location.exist?
end
end
include RubyBin
url "theme-check", using: RubyGemsDownloadStrategy
version "1.15.0"
sha256 '2e95953f20dc57bee88a3c025bfa575f69a123a0be8353066a3e4bbc06e80249'
depends_on "ruby"
def install
# set GEM_HOME and GEM_PATH to make sure we package all the dependent gems
# together without accidently picking up other gems on the gem path since
# they might not be there if, say, we change to a different rvm gemset
ENV['GEM_HOME'] = prefix.to_s
ENV['GEM_PATH'] = prefix.to_s
# Use /usr/local/bin at the front of the path instead of Homebrew shims,
# which mess with Ruby's own compiler config when building native extensions
if defined?(HOMEBREW_SHIMS_PATH)
ENV['PATH'] = ENV['PATH'].sub(HOMEBREW_SHIMS_PATH.to_s, '/usr/local/bin')
end
system(
"#{ruby_bin}/gem",
"install",
cached_download,
"--no-document",
"--no-wrapper",
"--no-user-install",
"--install-dir", prefix,
"--bindir", bin
)
raise "gem install 'theme-check' failed with status #{$CHILD_STATUS.exitstatus}" unless $CHILD_STATUS.success?
bin.rmtree if bin.exist?
bin.mkpath
brew_gem_prefix = "#{prefix}/gems/theme-check-#{version}"
gemspec = Gem::Specification.load("#{prefix}/specifications/theme-check-#{version}.gemspec")
ruby_libs = Dir.glob("#{prefix}/gems/*/lib")
gemspec.executables.each do |exe|
file = Pathname.new("#{brew_gem_prefix}/#{gemspec.bindir}/#{exe}")
(bin + file.basename).open('w') do |f|
f << <<~RUBY
#!#{ruby_bin}/ruby --disable-gems
ENV['GEM_HOME']="#{prefix}"
ENV['GEM_PATH']="#{prefix}"
require 'rubygems'
$:.unshift(#{ruby_libs.map(&:inspect).join(',')})
load "#{file}"
RUBY
end
end
end
end