From 999623b45d0661ba5eb15ecbfd31709e91955195 Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Wed, 10 Aug 2022 22:51:44 +0800 Subject: [PATCH 1/2] ENV/super: add Python's `libexec/"bin"` directory when applicable When Homebrew/homebrew-core#107517 is merged, builds will no longer be able to find `python@3.9` as `python3`. This is also what is likely to happen to `python@3.10` when we add a `python@3.11`. This is likely to break many builds, so let's make sure they can keep finding a `python3` for formulae that don't have a dependency on the latest Python3. This is arguably something we should've done earlier: it also means that builds that go looking for an unversioned `python` end up finding our Python3 (whenever present in the build environment) instead of, say, `/usr/bin/python` which is typically Python2. --- Library/Homebrew/extend/ENV/super.rb | 4 +++- Library/Homebrew/extend/os/linux/extend/ENV/super.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index c89a4604c5..2e996d46db 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -125,8 +125,10 @@ module Superenv sig { returns(T::Array[Pathname]) } def homebrew_extra_paths - [] + deps.select { |d| d.name.match? Version.formula_optionally_versioned_regex(:python) } + .map { |d| d.opt_libexec/"bin" } end + alias generic_homebrew_extra_paths homebrew_extra_paths sig { returns(T.nilable(PATH)) } def determine_path diff --git a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb index 8dd6f95c8d..1281a12038 100644 --- a/Library/Homebrew/extend/os/linux/extend/ENV/super.rb +++ b/Library/Homebrew/extend/os/linux/extend/ENV/super.rb @@ -27,7 +27,7 @@ module Superenv end def homebrew_extra_paths - paths = [] + paths = generic_homebrew_extra_paths paths += %w[binutils make].map do |f| bin = Formulary.factory(f).opt_bin bin if bin.directory? From 8064a39c18d4425a5f1c1999bbea5359414e45fc Mon Sep 17 00:00:00 2001 From: Carlo Cabrera <30379873+carlocab@users.noreply.github.com> Date: Mon, 15 Aug 2022 18:18:21 +0800 Subject: [PATCH 2/2] Prefer newer versions of Python Some formulae declare multiple Python dependencies, and they can appear in any order in the `deps` array. Let's make sure to prefer the newest one when adding their `libexec/"bin"` directory to `PATH`. --- Library/Homebrew/extend/ENV/super.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 2e996d46db..bc2d51121d 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -125,7 +125,10 @@ module Superenv sig { returns(T::Array[Pathname]) } def homebrew_extra_paths + # Reverse sort by version so that we prefer the newest when there are multiple. deps.select { |d| d.name.match? Version.formula_optionally_versioned_regex(:python) } + .sort_by(&:version) + .reverse .map { |d| d.opt_libexec/"bin" } end alias generic_homebrew_extra_paths homebrew_extra_paths