| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "extend/ENV" | 
					
						
							|  |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2012-08-29 11:21:15 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   extend T::Sig | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 12:03:48 +02:00
										 |  |  |   sig { returns(CLI::Parser) } | 
					
						
							| 
									
										
										
										
											2019-01-22 01:41:45 +05:30
										 |  |  |   def sh_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       description <<~EOS | 
					
						
							| 
									
										
										
										
											2021-01-24 12:38:32 -05:00
										 |  |  |         Enter an interactive shell for Homebrew's build environment. Use years-battle-hardened | 
					
						
							| 
									
										
										
										
											2020-08-25 14:45:09 +00:00
										 |  |  |         build logic to help your `./configure && make && make install` | 
					
						
							|  |  |  |         and even your `gem install` succeed. Especially handy if you run Homebrew | 
					
						
							| 
									
										
										
										
											2019-01-22 01:41:45 +05:30
										 |  |  |         in an Xcode-only configuration since it adds tools like `make` to your `PATH` | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |         which build systems would not find otherwise. | 
					
						
							| 
									
										
										
										
											2019-01-22 01:41:45 +05:30
										 |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2019-08-06 13:23:19 -04:00
										 |  |  |       flag   "--env=", | 
					
						
							| 
									
										
										
										
											2019-08-06 14:20:27 -04:00
										 |  |  |              description: "Use the standard `PATH` instead of superenv's when `std` is passed." | 
					
						
							| 
									
										
										
										
											2020-08-25 14:45:09 +00:00
										 |  |  |       flag   "-c=", "--cmd=", | 
					
						
							|  |  |  |              description: "Execute commands in a non-interactive shell." | 
					
						
							| 
									
										
										
										
											2020-11-12 10:40:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-15 15:04:02 -05:00
										 |  |  |       named_args :file, max: 1
 | 
					
						
							| 
									
										
										
										
											2019-01-22 01:41:45 +05:30
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-29 11:21:15 -04:00
										 |  |  |   def sh | 
					
						
							| 
									
										
										
										
											2020-07-23 06:25:35 +02:00
										 |  |  |     args = sh_args.parse | 
					
						
							| 
									
										
										
										
											2019-12-13 15:39:55 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 02:04:50 +02:00
										 |  |  |     ENV.activate_extensions!(env: args.env) | 
					
						
							| 
									
										
										
										
											2013-08-19 12:32:56 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-15 14:19:45 +00:00
										 |  |  |     ENV.deps = Formula.installed.select { |f| f.keg_only? && f.opt_prefix.directory? } if superenv?(args.env) | 
					
						
							| 
									
										
										
										
											2020-07-28 02:04:50 +02:00
										 |  |  |     ENV.setup_build_environment | 
					
						
							|  |  |  |     if superenv?(args.env) | 
					
						
							| 
									
										
										
										
											2017-03-05 21:45:15 -05:00
										 |  |  |       # superenv stopped adding brew's bin but generally users will want it | 
					
						
							| 
									
										
										
										
											2017-04-28 12:39:00 +02:00
										 |  |  |       ENV["PATH"] = PATH.new(ENV["PATH"]).insert(1, HOMEBREW_PREFIX/"bin") | 
					
						
							| 
									
										
										
										
											2012-09-23 21:06:09 -04:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-08-25 14:45:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ENV["VERBOSE"] = "1" if args.verbose? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if args.cmd.present? | 
					
						
							|  |  |  |       safe_system(ENV["SHELL"], "-c", args.cmd) | 
					
						
							|  |  |  |     elsif args.named.present? | 
					
						
							| 
									
										
										
										
											2020-08-27 16:48:33 +01:00
										 |  |  |       safe_system(ENV["SHELL"], args.named.first) | 
					
						
							| 
									
										
										
										
											2017-10-29 17:23:03 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2020-08-25 14:45:09 +00:00
										 |  |  |       subshell = if ENV["SHELL"].include?("zsh") | 
					
						
							| 
									
										
										
										
											2020-11-22 21:38:22 -05:00
										 |  |  |         "PS1='brew %B%F{green}%~%f%b$ ' #{ENV["SHELL"]} -d -f" | 
					
						
							|  |  |  |       elsif ENV["SHELL"].include?("bash") | 
					
						
							|  |  |  |         "PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{ENV["SHELL"]} --noprofile --norc" | 
					
						
							| 
									
										
										
										
											2020-08-25 14:45:09 +00:00
										 |  |  |       else | 
					
						
							|  |  |  |         "PS1=\"brew \\[\\033[1;32m\\]\\w\\[\\033[0m\\]$ \" #{ENV["SHELL"]}" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |       puts <<~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. | 
					
						
							|  |  |  |         When done, type `exit`. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  |       $stdout.flush | 
					
						
							|  |  |  |       safe_system subshell | 
					
						
							| 
									
										
										
										
											2017-10-29 17:23:03 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-08-29 11:21:15 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | end |