2024-03-21 21:41:54 -07:00
|
|
|
# typed: strict
|
2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2024-03-21 21:41:54 -07:00
|
|
|
require "abstract_command"
|
2015-08-03 13:09:07 +01:00
|
|
|
require "extend/ENV"
|
|
|
|
require "formula"
|
2012-08-29 11:21:15 -04:00
|
|
|
|
2014-06-18 22:41:47 -05:00
|
|
|
module Homebrew
|
2024-03-21 21:41:54 -07:00
|
|
|
module DevCmd
|
|
|
|
class Sh < AbstractCommand
|
|
|
|
cmd_args do
|
|
|
|
description <<~EOS
|
|
|
|
Enter an interactive shell for Homebrew's build environment. Use years-battle-hardened
|
|
|
|
build logic to help your `./configure && make && make install`
|
|
|
|
and even your `gem install` succeed. Especially handy if you run Homebrew
|
2025-06-03 11:06:35 -04:00
|
|
|
in an Xcode-only configuration since it adds tools like `make` to your `$PATH`
|
2024-03-21 21:41:54 -07:00
|
|
|
which build systems would not find otherwise.
|
|
|
|
EOS
|
2025-06-29 08:05:23 -07:00
|
|
|
flag "--env=",
|
|
|
|
description: "Use the standard `$PATH` instead of superenv's when `std` is passed."
|
|
|
|
flag "-c=", "--cmd=",
|
|
|
|
description: "Execute commands in a non-interactive shell."
|
2016-09-26 01:44:51 +02:00
|
|
|
|
2024-03-21 21:41:54 -07:00
|
|
|
named_args :file, max: 1
|
|
|
|
end
|
2019-12-13 15:39:55 -05:00
|
|
|
|
2024-03-21 21:41:54 -07:00
|
|
|
sig { override.void }
|
|
|
|
def run
|
|
|
|
ENV.activate_extensions!(env: args.env)
|
2013-08-19 12:32:56 -05:00
|
|
|
|
2024-08-23 05:50:39 +01:00
|
|
|
if superenv?(args.env)
|
2025-06-29 08:05:23 -07:00
|
|
|
ENV.deps = Formula.installed.select do |f|
|
|
|
|
f.keg_only? && f.opt_prefix.directory?
|
|
|
|
end
|
2024-08-23 05:50:39 +01:00
|
|
|
end
|
2024-03-21 21:41:54 -07:00
|
|
|
ENV.setup_build_environment
|
|
|
|
if superenv?(args.env)
|
|
|
|
# superenv stopped adding brew's bin but generally users will want it
|
|
|
|
ENV["PATH"] = PATH.new(ENV.fetch("PATH")).insert(1, HOMEBREW_PREFIX/"bin").to_s
|
|
|
|
end
|
2020-08-25 14:45:09 +00:00
|
|
|
|
2024-03-21 21:41:54 -07:00
|
|
|
ENV["VERBOSE"] = "1" if args.verbose?
|
2020-08-25 14:45:09 +00:00
|
|
|
|
2025-03-24 13:37:25 +00:00
|
|
|
preferred_path = Utils::Shell.preferred_path(default: "/bin/bash")
|
2023-02-28 15:02:06 +00:00
|
|
|
|
2024-03-21 21:41:54 -07:00
|
|
|
if args.cmd.present?
|
2025-03-24 13:37:25 +00:00
|
|
|
safe_system(preferred_path, "-c", args.cmd)
|
2024-03-21 21:41:54 -07:00
|
|
|
elsif args.named.present?
|
2025-03-24 13:37:25 +00:00
|
|
|
safe_system(preferred_path, args.named.first)
|
2024-03-21 21:41:54 -07:00
|
|
|
else
|
2025-03-24 13:37:25 +00:00
|
|
|
notice = unless Homebrew::EnvConfig.no_env_hints?
|
|
|
|
<<~EOS
|
|
|
|
Your shell has been configured to use Homebrew's build environment;
|
|
|
|
this should help you build stuff. Notably though, the system versions of
|
|
|
|
gem and pip will ignore our configuration and insist on using the
|
|
|
|
environment they were built under (mostly). Sadly, scons will also
|
|
|
|
ignore our configuration.
|
|
|
|
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).
|
|
|
|
When done, type `exit`.
|
|
|
|
EOS
|
2024-03-21 21:41:54 -07:00
|
|
|
end
|
2025-03-24 13:37:25 +00:00
|
|
|
system Utils::Shell.shell_with_prompt("brew", preferred_path:, notice:)
|
2024-03-21 21:41:54 -07:00
|
|
|
end
|
2020-08-25 14:45:09 +00:00
|
|
|
end
|
2017-10-29 17:23:03 +00:00
|
|
|
end
|
2012-08-29 11:21:15 -04:00
|
|
|
end
|
|
|
|
end
|