From 32463227ac419b3a5cd96dcc5dc29e6945ce93d5 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 28 Feb 2023 15:02:06 +0000 Subject: [PATCH] Deprecate `preferred_shell` and `shell_profile`. I know that we're outside our normal deprecation cycle but: these are totally broken with the API and it doesn't make sense to support them only for non-core formulae. --- Library/Homebrew/dev-cmd/sh.rb | 2 ++ Library/Homebrew/extend/kernel.rb | 6 ++++-- Library/Homebrew/test/utils/shell_spec.rb | 4 ++-- Library/Homebrew/utils/shell.rb | 7 ++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/dev-cmd/sh.rb b/Library/Homebrew/dev-cmd/sh.rb index 71699997fd..b531e6675b 100644 --- a/Library/Homebrew/dev-cmd/sh.rb +++ b/Library/Homebrew/dev-cmd/sh.rb @@ -43,6 +43,8 @@ module Homebrew ENV["VERBOSE"] = "1" if args.verbose? + preferred_shell = Utils::Shell.preferred_path(default: "/bin/bash") + if args.cmd.present? safe_system(preferred_shell, "-c", args.cmd) elsif args.named.present? diff --git a/Library/Homebrew/extend/kernel.rb b/Library/Homebrew/extend/kernel.rb index f48cd57ab8..f2bb0872f2 100644 --- a/Library/Homebrew/extend/kernel.rb +++ b/Library/Homebrew/extend/kernel.rb @@ -218,7 +218,7 @@ module Kernel FileUtils.touch "#{home}/.zshrc" end - Process.wait fork { exec preferred_shell } + Process.wait fork { exec Utils::Shell.preferred_path(default: "/bin/bash") } return if $CHILD_STATUS.success? raise "Aborted due to non-zero exit status (#{$CHILD_STATUS.exitstatus})" if $CHILD_STATUS.exited? @@ -528,11 +528,13 @@ module Kernel sig { returns(String) } def preferred_shell - ENV.fetch("SHELL", "/bin/sh") + odeprecated "preferred_shell" + Utils::Shell.preferred_path(default: "/bin/sh") end sig { returns(String) } def shell_profile + odeprecated "shell_profile" Utils::Shell.profile end diff --git a/Library/Homebrew/test/utils/shell_spec.rb b/Library/Homebrew/test/utils/shell_spec.rb index d83372f85c..2cc2e0a5d8 100644 --- a/Library/Homebrew/test/utils/shell_spec.rb +++ b/Library/Homebrew/test/utils/shell_spec.rb @@ -85,13 +85,13 @@ describe Utils::Shell do it "supports tcsh" do ENV["SHELL"] = "/bin/tcsh" expect(described_class.prepend_path_in_profile(path)) - .to eq("echo 'setenv PATH #{path}:$PATH' >> #{shell_profile}") + .to eq("echo 'setenv PATH #{path}:$PATH' >> #{described_class.profile}") end it "supports Bash" do ENV["SHELL"] = "/bin/bash" expect(described_class.prepend_path_in_profile(path)) - .to eq("echo 'export PATH=\"#{path}:$PATH\"' >> #{shell_profile}") + .to eq("echo 'export PATH=\"#{path}:$PATH\"' >> #{described_class.profile}") end it "supports fish" do diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index b6663255db..4fe444be02 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -18,9 +18,14 @@ module Utils shell_name.to_sym if %w[bash csh fish ksh mksh sh tcsh zsh].include?(shell_name) end + sig { params(default: String).returns(String) } + def preferred_path(default: "") + ENV.fetch("SHELL", default) + end + sig { returns(T.nilable(Symbol)) } def preferred - from_path(ENV.fetch("SHELL", "")) + from_path(preferred_path) end sig { returns(T.nilable(Symbol)) }