From b0b521001e1b93646a32a5705b05fe53ed0cdae7 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 5 Jul 2021 21:45:01 +0100 Subject: [PATCH 1/4] extend/ENV/super: allow `O{1,0}` to accept a block This makes `ENV.O{1,0}` behave like `ENV.deparallelize`. This should also allow us to build libgcrypt's jitter entropy collector, which we currently disable because it interacts poorly with our compiler shims. See #11201. --- Library/Homebrew/extend/ENV/super.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index e2ce2e6262..03af1e7b6a 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -338,8 +338,12 @@ module Superenv end %w[O1 O0].each do |opt| - define_method opt do - send(:[]=, "HOMEBREW_OPTIMIZATION_LEVEL", opt) + define_method opt do |&block| + if block + with_env(HOMEBREW_OPTIMIZATION_LEVEL: opt) { block.call } + else + send(:[]=, "HOMEBREW_OPTIMIZATION_LEVEL", opt) + end end end end From b37e574ad383c7ceb2385220e8bdf341258c75e4 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Thu, 8 Jul 2021 09:19:11 +0100 Subject: [PATCH 2/4] Fix `typecheck` error --- Library/Homebrew/extend/ENV/super.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 03af1e7b6a..7b91b1657d 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -339,7 +339,7 @@ module Superenv %w[O1 O0].each do |opt| define_method opt do |&block| - if block + if T.must(block) with_env(HOMEBREW_OPTIMIZATION_LEVEL: opt) { block.call } else send(:[]=, "HOMEBREW_OPTIMIZATION_LEVEL", opt) From ebeb9e7e90c2e293e0fc3201da8ed1d903b3239d Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Thu, 8 Jul 2021 10:56:36 +0100 Subject: [PATCH 3/4] Define `O1` and `O0` methods separately --- Library/Homebrew/extend/ENV/super.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 7b91b1657d..cf54fec0ce 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -337,15 +337,25 @@ module Superenv append_to_cccfg "O" end - %w[O1 O0].each do |opt| - define_method opt do |&block| - if T.must(block) - with_env(HOMEBREW_OPTIMIZATION_LEVEL: opt) { block.call } - else - send(:[]=, "HOMEBREW_OPTIMIZATION_LEVEL", opt) - end + # rubocop: disable Naming/MethodName + sig { params(block: T.nilable(T.proc.void)).void } + def O0(&block) + if block + with_env(HOMEBREW_OPTIMIZATION_LEVEL: "O0", &block) + else + self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O0" end end + + sig { params(block: T.nilable(T.proc.void)).void } + def O1(&block) + if block + with_env(HOMEBREW_OPTIMIZATION_LEVEL: "O1", &block) + else + self["HOMEBREW_OPTIMIZATION_LEVEL"] = "O1" + end + end + # rubocop: enable Naming/MethodName end require "extend/os/extend/ENV/super" From 2599cccc81782e45517dae03ba093f2d74f22f7f Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Thu, 8 Jul 2021 19:16:39 +0100 Subject: [PATCH 4/4] Add comment for in-source style exception --- Library/Homebrew/extend/ENV/super.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index cf54fec0ce..5534cc8b00 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -338,6 +338,7 @@ module Superenv end # rubocop: disable Naming/MethodName + # Fixes style error `Naming/MethodName: Use snake_case for method names.` sig { params(block: T.nilable(T.proc.void)).void } def O0(&block) if block