diff --git a/Library/Homebrew/cxxstdlib.rb b/Library/Homebrew/cxxstdlib.rb index ead686989c..6fdf97353e 100644 --- a/Library/Homebrew/cxxstdlib.rb +++ b/Library/Homebrew/cxxstdlib.rb @@ -22,7 +22,7 @@ class CxxStdlib def self.create(type, compiler) raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && [:libstdcxx, :libcxx].exclude?(type) - apple_compiler = compiler.to_s.match?(GNU_GCC_REGEXP) ? false : true + apple_compiler = !compiler.to_s.match?(GNU_GCC_REGEXP) CxxStdlib.new(type, compiler, apple_compiler) end diff --git a/Library/Homebrew/extend/module.rb b/Library/Homebrew/extend/module.rb index 8ce9075149..66d0259f41 100644 --- a/Library/Homebrew/extend/module.rb +++ b/Library/Homebrew/extend/module.rb @@ -3,11 +3,8 @@ class Module def attr_rw(*attrs) - file, line, = caller.first.split(":") - line = line.to_i - attrs.each do |attr| - module_eval <<-EOS, file, line + module_eval <<-EOS, __FILE__, __LINE__+1 def #{attr}(val=nil) # def prefix(val=nil) @#{attr} ||= nil # @prefix ||= nil return @#{attr} if val.nil? # return @prefix if val.nil? diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index fad56654d5..6f738cd419 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -78,14 +78,23 @@ HOMEBREW_RELEASES_URL_REGEX = require "fileutils" require "os" -require "os/global" +require "env_config" require "messages" module Homebrew extend FileUtils - DEFAULT_PREFIX ||= HOMEBREW_DEFAULT_PREFIX - DEFAULT_REPOSITORY ||= HOMEBREW_DEFAULT_REPOSITORY + remove_const :DEFAULT_PREFIX if defined?(DEFAULT_PREFIX) + remove_const :DEFAULT_REPOSITORY if defined?(DEFAULT_REPOSITORY) + + DEFAULT_PREFIX, DEFAULT_REPOSITORY = if OS.mac? && Hardware::CPU.arm? + [HOMEBREW_MACOS_ARM_DEFAULT_PREFIX, HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY] + elsif OS.linux? && !EnvConfig.force_homebrew_on_linux? + [HOMEBREW_LINUX_DEFAULT_PREFIX, HOMEBREW_LINUX_DEFAULT_REPOSITORY] + else + [HOMEBREW_DEFAULT_PREFIX, HOMEBREW_DEFAULT_REPOSITORY] + end.freeze + DEFAULT_CELLAR = "#{DEFAULT_PREFIX}/Cellar" DEFAULT_MACOS_CELLAR = "#{HOMEBREW_DEFAULT_PREFIX}/Cellar" DEFAULT_MACOS_ARM_CELLAR = "#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar" @@ -117,8 +126,6 @@ module Homebrew end end -require "env_config" - require "config" require "context" require "extend/pathname" @@ -148,3 +155,6 @@ require "tap" require "tap_constants" require "compat" unless Homebrew::EnvConfig.no_compat? + +# Enables `patchelf.rb` write support. +HOMEBREW_PATCHELF_RB_WRITE = ENV["HOMEBREW_NO_PATCHELF_RB_WRITE"].blank?.freeze diff --git a/Library/Homebrew/os/global.rb b/Library/Homebrew/os/global.rb deleted file mode 100644 index f96f565a4e..0000000000 --- a/Library/Homebrew/os/global.rb +++ /dev/null @@ -1,8 +0,0 @@ -# typed: strict -# frozen_string_literal: true - -if OS.mac? - require "os/mac/global" -elsif OS.linux? - require "os/linux/global" -end diff --git a/Library/Homebrew/os/linux/global.rb b/Library/Homebrew/os/linux/global.rb deleted file mode 100644 index 59b9af9e88..0000000000 --- a/Library/Homebrew/os/linux/global.rb +++ /dev/null @@ -1,17 +0,0 @@ -# typed: false -# frozen_string_literal: true - -require "env_config" - -# Enables `patchelf.rb` write support. -HOMEBREW_PATCHELF_RB_WRITE = ENV["HOMEBREW_NO_PATCHELF_RB_WRITE"].blank?.freeze - -module Homebrew - if EnvConfig.force_homebrew_on_linux? - DEFAULT_PREFIX ||= HOMEBREW_DEFAULT_PREFIX.freeze - DEFAULT_REPOSITORY ||= HOMEBREW_DEFAULT_REPOSITORY.freeze - else - DEFAULT_PREFIX ||= HOMEBREW_LINUX_DEFAULT_PREFIX.freeze - DEFAULT_REPOSITORY ||= HOMEBREW_LINUX_DEFAULT_REPOSITORY.freeze - end -end diff --git a/Library/Homebrew/os/mac/global.rb b/Library/Homebrew/os/mac/global.rb deleted file mode 100644 index 5b66c6347f..0000000000 --- a/Library/Homebrew/os/mac/global.rb +++ /dev/null @@ -1,12 +0,0 @@ -# typed: false -# frozen_string_literal: true - -module Homebrew - if Hardware::CPU.arm? - DEFAULT_PREFIX ||= HOMEBREW_MACOS_ARM_DEFAULT_PREFIX.freeze - DEFAULT_REPOSITORY ||= HOMEBREW_MACOS_ARM_DEFAULT_REPOSITORY.freeze - else - DEFAULT_PREFIX ||= HOMEBREW_DEFAULT_PREFIX.freeze - DEFAULT_REPOSITORY ||= HOMEBREW_DEFAULT_REPOSITORY.freeze - end -end diff --git a/Library/Homebrew/test/dev-cmd/bottle_spec.rb b/Library/Homebrew/test/dev-cmd/bottle_spec.rb index 18360e753d..155b6219bd 100644 --- a/Library/Homebrew/test/dev-cmd/bottle_spec.rb +++ b/Library/Homebrew/test/dev-cmd/bottle_spec.rb @@ -77,64 +77,64 @@ describe Homebrew do let(:hello_hash_big_sur) { JSON.parse stub_hash( - "name": "hello", - "version": "1.0", - "path": "/home/hello.rb", - "cellar": "any_skip_relocation", - "os": "big_sur", - "filename": "hello-1.0.big_sur.bottle.tar.gz", - "local_filename": "hello--1.0.big_sur.bottle.tar.gz", - "sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", + name: "hello", + version: "1.0", + path: "/home/hello.rb", + cellar: "any_skip_relocation", + os: "big_sur", + filename: "hello-1.0.big_sur.bottle.tar.gz", + local_filename: "hello--1.0.big_sur.bottle.tar.gz", + sha256: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", ) } let(:hello_hash_catalina) { JSON.parse stub_hash( - "name": "hello", - "version": "1.0", - "path": "/home/hello.rb", - "cellar": "any_skip_relocation", - "os": "catalina", - "filename": "hello-1.0.catalina.bottle.tar.gz", - "local_filename": "hello--1.0.catalina.bottle.tar.gz", - "sha256": "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", + name: "hello", + version: "1.0", + path: "/home/hello.rb", + cellar: "any_skip_relocation", + os: "catalina", + filename: "hello-1.0.catalina.bottle.tar.gz", + local_filename: "hello--1.0.catalina.bottle.tar.gz", + sha256: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", ) } let(:unzip_hash_big_sur) { JSON.parse stub_hash( - "name": "unzip", - "version": "2.0", - "path": "/home/unzip.rb", - "cellar": "any_skip_relocation", - "os": "big_sur", - "filename": "unzip-2.0.big_sur.bottle.tar.gz", - "local_filename": "unzip--2.0.big_sur.bottle.tar.gz", - "sha256": "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72", + name: "unzip", + version: "2.0", + path: "/home/unzip.rb", + cellar: "any_skip_relocation", + os: "big_sur", + filename: "unzip-2.0.big_sur.bottle.tar.gz", + local_filename: "unzip--2.0.big_sur.bottle.tar.gz", + sha256: "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72", ) } let(:unzip_hash_catalina) { JSON.parse stub_hash( - "name": "unzip", - "version": "2.0", - "path": "/home/unzip.rb", - "cellar": "any", - "os": "catalina", - "filename": "unzip-2.0.catalina.bottle.tar.gz", - "local_filename": "unzip--2.0.catalina.bottle.tar.gz", - "sha256": "d9cc50eec8ac243148a121049c236cba06af4a0b1156ab397d0a2850aa79c137", + name: "unzip", + version: "2.0", + path: "/home/unzip.rb", + cellar: "any", + os: "catalina", + filename: "unzip-2.0.catalina.bottle.tar.gz", + local_filename: "unzip--2.0.catalina.bottle.tar.gz", + sha256: "d9cc50eec8ac243148a121049c236cba06af4a0b1156ab397d0a2850aa79c137", ) } specify "::parse_json_files" do Tempfile.open("hello--1.0.big_sur.bottle.json") do |f| f.write stub_hash( - "name": "hello", - "version": "1.0", - "path": "/home/hello.rb", - "cellar": "any_skip_relocation", - "os": "big_sur", - "filename": "hello-1.0.big_sur.bottle.tar.gz", - "local_filename": "hello--1.0.big_sur.bottle.tar.gz", - "sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", + name: "hello", + version: "1.0", + path: "/home/hello.rb", + cellar: "any_skip_relocation", + os: "big_sur", + filename: "hello-1.0.big_sur.bottle.tar.gz", + local_filename: "hello--1.0.big_sur.bottle.tar.gz", + sha256: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", ) f.close expect( @@ -275,25 +275,25 @@ describe "brew bottle --merge", :integration_test do before do Pathname("#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json").write stub_hash( - "name": "testball", - "version": "1.0", - "path": "#{core_tap.path}/Formula/testball.rb", - "cellar": "any_skip_relocation", - "os": "big_sur", - "filename": "hello-1.0.big_sur.bottle.tar.gz", - "local_filename": "hello--1.0.big_sur.bottle.tar.gz", - "sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", + name: "testball", + version: "1.0", + path: "#{core_tap.path}/Formula/testball.rb", + cellar: "any_skip_relocation", + os: "big_sur", + filename: "hello-1.0.big_sur.bottle.tar.gz", + local_filename: "hello--1.0.big_sur.bottle.tar.gz", + sha256: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", ) Pathname("#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json").write stub_hash( - "name": "testball", - "version": "1.0", - "path": "#{core_tap.path}/Formula/testball.rb", - "cellar": "any_skip_relocation", - "os": "catalina", - "filename": "testball-1.0.catalina.bottle.tar.gz", - "local_filename": "testball--1.0.catalina.bottle.tar.gz", - "sha256": "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", + name: "testball", + version: "1.0", + path: "#{core_tap.path}/Formula/testball.rb", + cellar: "any_skip_relocation", + os: "catalina", + filename: "testball-1.0.catalina.bottle.tar.gz", + local_filename: "testball--1.0.catalina.bottle.tar.gz", + sha256: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", ) end diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index e301c1b694..df359a9f52 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -17,6 +17,7 @@ describe Utils::Analytics do end it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do + allow(Homebrew).to receive(:default_prefix?).and_return(true) expect(described_class.os_arch_prefix_ci).not_to include(described_class.custom_prefix_label) end