global.rb 4.25 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

Markus Reiter's avatar
Markus Reiter committed
12
13
14
15
16
require "rbconfig"

RUBY_PATH = Pathname.new(RbConfig.ruby).freeze
RUBY_BIN = RUBY_PATH.dirname.freeze

17
require_relative "load_path"
Markus Reiter's avatar
Markus Reiter committed
18

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

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

42
43
require "utils/sorbet"

Mike McQuaid's avatar
Mike McQuaid committed
44
45
46
47
48
49
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"]
50
HOMEBREW_REQUIRED_RUBY_VERSION = ENV["HOMEBREW_REQUIRED_RUBY_VERSION"]
51

52
HOMEBREW_PRODUCT = ENV["HOMEBREW_PRODUCT"]
Mike McQuaid's avatar
Mike McQuaid committed
53
HOMEBREW_VERSION = ENV["HOMEBREW_VERSION"]
54
HOMEBREW_WWW = "https://brew.sh"
55

56
HOMEBREW_USER_AGENT_CURL = ENV["HOMEBREW_USER_AGENT_CURL"]
57
HOMEBREW_USER_AGENT_RUBY =
58
  "#{ENV["HOMEBREW_USER_AGENT"]} ruby/#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
59
60
HOMEBREW_USER_AGENT_FAKE_SAFARI =
  "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) AppleWebKit/602.4.8 " \
61
  "(KHTML, like Gecko) Version/10.0.3 Safari/602.4.8"
62

63
HOMEBREW_DEFAULT_PREFIX = "/usr/local"
64
HOMEBREW_DEFAULT_REPOSITORY = "#{HOMEBREW_DEFAULT_PREFIX}/Homebrew"
Mike McQuaid's avatar
Mike McQuaid committed
65
HOMEBREW_MACOS_ARM_DEFAULT_PREFIX = "/opt/homebrew"
66
HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY = HOMEBREW_MACOS_ARM_DEFAULT_PREFIX
Mike McQuaid's avatar
Mike McQuaid committed
67
HOMEBREW_LINUX_DEFAULT_PREFIX = "/home/linuxbrew/.linuxbrew"
68
HOMEBREW_LINUX_DEFAULT_REPOSITORY = "#{HOMEBREW_LINUX_DEFAULT_PREFIX}/Homebrew"
69

Markus Reiter's avatar
Markus Reiter committed
70
71
72
73
74
75
76
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
HOMEBREW_RELEASES_URL_REGEX =
  %r{https://github\.com/([\w-]+)/([\w-]+)?/releases/download/(.+)}.freeze

77
require "fileutils"
Markus Reiter's avatar
Markus Reiter committed
78
79

require "os"
80
require "os/global"
Markus Reiter's avatar
Markus Reiter committed
81
require "messages"
Mike McQuaid's avatar
Mike McQuaid committed
82

83
module Homebrew
84
  extend FileUtils
85

86
  DEFAULT_PREFIX ||= HOMEBREW_DEFAULT_PREFIX
87
  DEFAULT_REPOSITORY ||= HOMEBREW_DEFAULT_REPOSITORY
88
  DEFAULT_CELLAR = "#{DEFAULT_PREFIX}/Cellar"
89
90
91
  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"
92

93
  class << self
94
    attr_writer :failed, :raise_deprecation_exceptions, :auditing
95

Jonathan Chang's avatar
Jonathan Chang committed
96
    def default_prefix?(prefix = HOMEBREW_PREFIX)
97
98
99
      prefix.to_s == DEFAULT_PREFIX
    end

100
    def failed?
Mike McQuaid's avatar
Mike McQuaid committed
101
      @failed ||= false
102
103
104
      @failed == true
    end

105
106
107
108
    def messages
      @messages ||= Messages.new
    end

109
110
111
    def raise_deprecation_exceptions?
      @raise_deprecation_exceptions == true
    end
112
113
114
115

    def auditing?
      @auditing == true
    end
116
  end
117
118
end

Markus Reiter's avatar
Markus Reiter committed
119
120
121
122
123
124
125
126
require "env_config"

require "config"
require "context"
require "extend/pathname"
require "extend/predicable"
require "extend/module"
require "cli/args"
127

Mike McQuaid's avatar
Mike McQuaid committed
128
require "PATH"
129

130
ENV["HOMEBREW_PATH"] ||= ENV["PATH"]
Markus Reiter's avatar
Markus Reiter committed
131
ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
132
133
134
  Pathname.new(p).expand_path
rescue
  nil
135
end.compact.freeze
Xu Cheng's avatar
Xu Cheng committed
136

Mike McQuaid's avatar
Mike McQuaid committed
137
138
139
140
require "set"

require "extend/string"

141
require "system_command"
Mike McQuaid's avatar
Mike McQuaid committed
142
143
144
145
146
147
148
require "exceptions"
require "utils"

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

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