global.rb 3.94 KB
Newer Older
1
# typed: false
2
3
# frozen_string_literal: true

Markus Reiter's avatar
Markus Reiter committed
4
require "English"
5
6
require "json"
require "json/add/exception"
7
8
9
require "pathname"
require "ostruct"
require "pp"
Bo Anderson's avatar
Bo Anderson committed
10
require "forwardable"
Markus Reiter's avatar
Markus Reiter committed
11

12
require_relative "load_path"
Markus Reiter's avatar
Markus Reiter committed
13

14
require "rubygems"
15
16
# Only require "core_ext" here to ensure we're only requiring the minimum of
# what we need.
17
require "active_support/core_ext/object/blank"
Markus Reiter's avatar
Markus Reiter committed
18
require "active_support/core_ext/numeric/time"
19
require "active_support/core_ext/object/try"
20
require "active_support/core_ext/array/access"
21
22
require "active_support/core_ext/string/inflections"
require "active_support/core_ext/array/conversions"
Mike McQuaid's avatar
Mike McQuaid committed
23
24
require "active_support/core_ext/hash/deep_merge"
require "active_support/core_ext/file/atomic"
25
26
27
28
29
30
31
32
33
34

I18n.backend.available_locales # Initialize locales so they can be overwritten.
I18n.backend.store_translations :en, support: { array: { last_word_connector: " and " } }

ActiveSupport::Inflector.inflections(:en) do |inflect|
  inflect.irregular "formula", "formulae"
  inflect.irregular "is", "are"
  inflect.irregular "it", "they"
end

35
36
require "utils/sorbet"

Mike McQuaid's avatar
Mike McQuaid committed
37
38
39
40
41
42
HOMEBREW_BOTTLE_DEFAULT_DOMAIN = ENV["HOMEBREW_BOTTLE_DEFAULT_DOMAIN"]
HOMEBREW_BREW_DEFAULT_GIT_REMOTE = ENV["HOMEBREW_BREW_DEFAULT_GIT_REMOTE"]
HOMEBREW_CORE_DEFAULT_GIT_REMOTE = ENV["HOMEBREW_CORE_DEFAULT_GIT_REMOTE"]
HOMEBREW_DEFAULT_CACHE = ENV["HOMEBREW_DEFAULT_CACHE"]
HOMEBREW_DEFAULT_LOGS = ENV["HOMEBREW_DEFAULT_LOGS"]
HOMEBREW_DEFAULT_TEMP = ENV["HOMEBREW_DEFAULT_TEMP"]
43
HOMEBREW_REQUIRED_RUBY_VERSION = ENV["HOMEBREW_REQUIRED_RUBY_VERSION"]
Mike McQuaid's avatar
Mike McQuaid committed
44
45
require "env_config"

Markus Reiter's avatar
Markus Reiter committed
46
require "config"
47
require "os"
Bo Anderson's avatar
Bo Anderson committed
48
49
50
require "context"
require "extend/pathname"
require "extend/predicable"
51
require "extend/module"
52
require "cli/args"
53
require "messages"
54

55
HOMEBREW_PRODUCT = ENV["HOMEBREW_PRODUCT"]
Mike McQuaid's avatar
Mike McQuaid committed
56
HOMEBREW_VERSION = ENV["HOMEBREW_VERSION"]
57
HOMEBREW_WWW = "https://brew.sh"
58

Mike McQuaid's avatar
Mike McQuaid committed
59
60
require "rbconfig"

61
62
RUBY_PATH = Pathname.new(RbConfig.ruby).freeze
RUBY_BIN = RUBY_PATH.dirname.freeze
Mike McQuaid's avatar
Mike McQuaid committed
63

64
HOMEBREW_USER_AGENT_CURL = ENV["HOMEBREW_USER_AGENT_CURL"]
65
HOMEBREW_USER_AGENT_RUBY =
66
  "#{ENV["HOMEBREW_USER_AGENT"]} ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
67
68
HOMEBREW_USER_AGENT_FAKE_SAFARI =
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 " \
69
  "(KHTML, like Gecko) Version/10.0.3 Safari/602.4.8"
70

71
HOMEBREW_DEFAULT_PREFIX = "/usr/local"
Mike McQuaid's avatar
Mike McQuaid committed
72
73
HOMEBREW_MACOS_ARM_DEFAULT_PREFIX = "/opt/homebrew"
HOMEBREW_LINUX_DEFAULT_PREFIX = "/home/linuxbrew/.linuxbrew"
74

75
require "fileutils"
76
require "os/global"
Mike McQuaid's avatar
Mike McQuaid committed
77

78
module Homebrew
79
  extend FileUtils
80

81
  DEFAULT_PREFIX ||= HOMEBREW_DEFAULT_PREFIX
82
  DEFAULT_CELLAR = "#{DEFAULT_PREFIX}/Cellar"
83
84
85
  DEFAULT_MACOS_CELLAR = "#{HOMEBREW_DEFAULT_PREFIX}/Cellar"
  DEFAULT_MACOS_ARM_CELLAR = "#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar"
  DEFAULT_LINUX_CELLAR = "#{HOMEBREW_LINUX_DEFAULT_PREFIX}/Cellar"
86
  DEFAULT_REPOSITORY = "#{DEFAULT_PREFIX}/Homebrew"
87

88
  class << self
89
    attr_writer :failed, :raise_deprecation_exceptions, :auditing
90

Jonathan Chang's avatar
Jonathan Chang committed
91
    def default_prefix?(prefix = HOMEBREW_PREFIX)
92
93
94
      prefix.to_s == DEFAULT_PREFIX
    end

95
    def failed?
Mike McQuaid's avatar
Mike McQuaid committed
96
      @failed ||= false
97
98
99
      @failed == true
    end

100
101
102
103
    def messages
      @messages ||= Messages.new
    end

104
105
106
    def raise_deprecation_exceptions?
      @raise_deprecation_exceptions == true
    end
107
108
109
110

    def auditing?
      @auditing == true
    end
111
  end
112
113
end

Mike McQuaid's avatar
Mike McQuaid committed
114
115
116
117
HOMEBREW_PULL_API_REGEX =
  %r{https://api\.github\.com/repos/([\w-]+)/([\w-]+)?/pulls/(\d+)}.freeze
HOMEBREW_PULL_OR_COMMIT_URL_REGEX =
  %r[https://github\.com/([\w-]+)/([\w-]+)?/(?:pull/(\d+)|commit/[0-9a-fA-F]{4,40})].freeze
118
119
HOMEBREW_RELEASES_URL_REGEX =
  %r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}.freeze
120

Mike McQuaid's avatar
Mike McQuaid committed
121
require "PATH"
122

123
ENV["HOMEBREW_PATH"] ||= ENV["PATH"]
Markus Reiter's avatar
Markus Reiter committed
124
ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
125
126
127
  Pathname.new(p).expand_path
rescue
  nil
128
end.compact.freeze
Xu Cheng's avatar
Xu Cheng committed
129

Mike McQuaid's avatar
Mike McQuaid committed
130
131
132
133
require "set"

require "extend/string"

134
require "system_command"
Mike McQuaid's avatar
Mike McQuaid committed
135
136
137
138
139
140
141
require "exceptions"
require "utils"

require "official_taps"
require "tap"
require "tap_constants"

Mike McQuaid's avatar
Mike McQuaid committed
142
require "compat" unless Homebrew::EnvConfig.no_compat?