Fix brew style

This commit is contained in:
Mike McQuaid 2021-01-29 09:11:35 +00:00
parent a4761ab570
commit e65e310fd0
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
8 changed files with 74 additions and 103 deletions

View File

@ -22,7 +22,7 @@ class CxxStdlib
def self.create(type, compiler) def self.create(type, compiler)
raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && [:libstdcxx, :libcxx].exclude?(type) 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) CxxStdlib.new(type, compiler, apple_compiler)
end end

View File

@ -3,11 +3,8 @@
class Module class Module
def attr_rw(*attrs) def attr_rw(*attrs)
file, line, = caller.first.split(":")
line = line.to_i
attrs.each do |attr| attrs.each do |attr|
module_eval <<-EOS, file, line module_eval <<-EOS, __FILE__, __LINE__+1
def #{attr}(val=nil) # def prefix(val=nil) def #{attr}(val=nil) # def prefix(val=nil)
@#{attr} ||= nil # @prefix ||= nil @#{attr} ||= nil # @prefix ||= nil
return @#{attr} if val.nil? # return @prefix if val.nil? return @#{attr} if val.nil? # return @prefix if val.nil?

View File

@ -78,14 +78,23 @@ HOMEBREW_RELEASES_URL_REGEX =
require "fileutils" require "fileutils"
require "os" require "os"
require "os/global" require "env_config"
require "messages" require "messages"
module Homebrew module Homebrew
extend FileUtils extend FileUtils
DEFAULT_PREFIX ||= HOMEBREW_DEFAULT_PREFIX remove_const :DEFAULT_PREFIX if defined?(DEFAULT_PREFIX)
DEFAULT_REPOSITORY ||= HOMEBREW_DEFAULT_REPOSITORY 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_CELLAR = "#{DEFAULT_PREFIX}/Cellar"
DEFAULT_MACOS_CELLAR = "#{HOMEBREW_DEFAULT_PREFIX}/Cellar" DEFAULT_MACOS_CELLAR = "#{HOMEBREW_DEFAULT_PREFIX}/Cellar"
DEFAULT_MACOS_ARM_CELLAR = "#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar" DEFAULT_MACOS_ARM_CELLAR = "#{HOMEBREW_MACOS_ARM_DEFAULT_PREFIX}/Cellar"
@ -117,8 +126,6 @@ module Homebrew
end end
end end
require "env_config"
require "config" require "config"
require "context" require "context"
require "extend/pathname" require "extend/pathname"
@ -148,3 +155,6 @@ require "tap"
require "tap_constants" require "tap_constants"
require "compat" unless Homebrew::EnvConfig.no_compat? require "compat" unless Homebrew::EnvConfig.no_compat?
# Enables `patchelf.rb` write support.
HOMEBREW_PATCHELF_RB_WRITE = ENV["HOMEBREW_NO_PATCHELF_RB_WRITE"].blank?.freeze

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -77,64 +77,64 @@ describe Homebrew do
let(:hello_hash_big_sur) { let(:hello_hash_big_sur) {
JSON.parse stub_hash( JSON.parse stub_hash(
"name": "hello", name: "hello",
"version": "1.0", version: "1.0",
"path": "/home/hello.rb", path: "/home/hello.rb",
"cellar": "any_skip_relocation", cellar: "any_skip_relocation",
"os": "big_sur", os: "big_sur",
"filename": "hello-1.0.big_sur.bottle.tar.gz", filename: "hello-1.0.big_sur.bottle.tar.gz",
"local_filename": "hello--1.0.big_sur.bottle.tar.gz", local_filename: "hello--1.0.big_sur.bottle.tar.gz",
"sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", sha256: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f",
) )
} }
let(:hello_hash_catalina) { let(:hello_hash_catalina) {
JSON.parse stub_hash( JSON.parse stub_hash(
"name": "hello", name: "hello",
"version": "1.0", version: "1.0",
"path": "/home/hello.rb", path: "/home/hello.rb",
"cellar": "any_skip_relocation", cellar: "any_skip_relocation",
"os": "catalina", os: "catalina",
"filename": "hello-1.0.catalina.bottle.tar.gz", filename: "hello-1.0.catalina.bottle.tar.gz",
"local_filename": "hello--1.0.catalina.bottle.tar.gz", local_filename: "hello--1.0.catalina.bottle.tar.gz",
"sha256": "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", sha256: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac",
) )
} }
let(:unzip_hash_big_sur) { let(:unzip_hash_big_sur) {
JSON.parse stub_hash( JSON.parse stub_hash(
"name": "unzip", name: "unzip",
"version": "2.0", version: "2.0",
"path": "/home/unzip.rb", path: "/home/unzip.rb",
"cellar": "any_skip_relocation", cellar: "any_skip_relocation",
"os": "big_sur", os: "big_sur",
"filename": "unzip-2.0.big_sur.bottle.tar.gz", filename: "unzip-2.0.big_sur.bottle.tar.gz",
"local_filename": "unzip--2.0.big_sur.bottle.tar.gz", local_filename: "unzip--2.0.big_sur.bottle.tar.gz",
"sha256": "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72", sha256: "16cf230afdfcb6306c208d169549cf8773c831c8653d2c852315a048960d7e72",
) )
} }
let(:unzip_hash_catalina) { let(:unzip_hash_catalina) {
JSON.parse stub_hash( JSON.parse stub_hash(
"name": "unzip", name: "unzip",
"version": "2.0", version: "2.0",
"path": "/home/unzip.rb", path: "/home/unzip.rb",
"cellar": "any", cellar: "any",
"os": "catalina", os: "catalina",
"filename": "unzip-2.0.catalina.bottle.tar.gz", filename: "unzip-2.0.catalina.bottle.tar.gz",
"local_filename": "unzip--2.0.catalina.bottle.tar.gz", local_filename: "unzip--2.0.catalina.bottle.tar.gz",
"sha256": "d9cc50eec8ac243148a121049c236cba06af4a0b1156ab397d0a2850aa79c137", sha256: "d9cc50eec8ac243148a121049c236cba06af4a0b1156ab397d0a2850aa79c137",
) )
} }
specify "::parse_json_files" do specify "::parse_json_files" do
Tempfile.open("hello--1.0.big_sur.bottle.json") do |f| Tempfile.open("hello--1.0.big_sur.bottle.json") do |f|
f.write stub_hash( f.write stub_hash(
"name": "hello", name: "hello",
"version": "1.0", version: "1.0",
"path": "/home/hello.rb", path: "/home/hello.rb",
"cellar": "any_skip_relocation", cellar: "any_skip_relocation",
"os": "big_sur", os: "big_sur",
"filename": "hello-1.0.big_sur.bottle.tar.gz", filename: "hello-1.0.big_sur.bottle.tar.gz",
"local_filename": "hello--1.0.big_sur.bottle.tar.gz", local_filename: "hello--1.0.big_sur.bottle.tar.gz",
"sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", sha256: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f",
) )
f.close f.close
expect( expect(
@ -275,25 +275,25 @@ describe "brew bottle --merge", :integration_test do
before do before do
Pathname("#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json").write stub_hash( Pathname("#{TEST_TMPDIR}/testball-1.0.big_sur.bottle.json").write stub_hash(
"name": "testball", name: "testball",
"version": "1.0", version: "1.0",
"path": "#{core_tap.path}/Formula/testball.rb", path: "#{core_tap.path}/Formula/testball.rb",
"cellar": "any_skip_relocation", cellar: "any_skip_relocation",
"os": "big_sur", os: "big_sur",
"filename": "hello-1.0.big_sur.bottle.tar.gz", filename: "hello-1.0.big_sur.bottle.tar.gz",
"local_filename": "hello--1.0.big_sur.bottle.tar.gz", local_filename: "hello--1.0.big_sur.bottle.tar.gz",
"sha256": "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f", sha256: "a0af7dcbb5c83f6f3f7ecd507c2d352c1a018f894d51ad241ce8492fa598010f",
) )
Pathname("#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json").write stub_hash( Pathname("#{TEST_TMPDIR}/testball-1.0.catalina.bottle.json").write stub_hash(
"name": "testball", name: "testball",
"version": "1.0", version: "1.0",
"path": "#{core_tap.path}/Formula/testball.rb", path: "#{core_tap.path}/Formula/testball.rb",
"cellar": "any_skip_relocation", cellar: "any_skip_relocation",
"os": "catalina", os: "catalina",
"filename": "testball-1.0.catalina.bottle.tar.gz", filename: "testball-1.0.catalina.bottle.tar.gz",
"local_filename": "testball--1.0.catalina.bottle.tar.gz", local_filename: "testball--1.0.catalina.bottle.tar.gz",
"sha256": "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac", sha256: "5334dd344986e46b2aa4f0471cac7b0914bd7de7cb890a34415771788d03f2ac",
) )
end end

View File

@ -17,6 +17,7 @@ describe Utils::Analytics do
end end
it "does not include prefix when HOMEBREW_PREFIX is the default prefix" do 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) expect(described_class.os_arch_prefix_ci).not_to include(described_class.custom_prefix_label)
end end