| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-19 17:57:36 -05:00
										 |  |  | require "extend/ENV" | 
					
						
							| 
									
										
										
										
											2015-11-13 16:43:43 +01:00
										 |  |  | require "build_environment" | 
					
						
							| 
									
										
										
										
											2016-08-10 23:19:09 -07:00
										 |  |  | require "utils/shell" | 
					
						
							| 
									
										
										
										
											2019-04-17 18:25:08 +09:00
										 |  |  | require "cli/parser" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  |   def __env_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       usage_banner <<~EOS | 
					
						
							| 
									
										
										
										
											2019-12-12 19:04:01 -05:00
										 |  |  |         `--env` [<options>] [<formula>] | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 18:52:02 +00:00
										 |  |  |         Summarise Homebrew's build environment as a plain list. | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |         If the command's output is sent through a pipe and no shell is specified, | 
					
						
							|  |  |  |         the list is formatted for export to `bash`(1) unless `--plain` is passed. | 
					
						
							|  |  |  |       EOS | 
					
						
							| 
									
										
										
										
											2019-08-06 13:23:19 -04:00
										 |  |  |       flag   "--shell=", | 
					
						
							|  |  |  |              description: "Generate a list of environment variables for the specified shell, " \ | 
					
						
							|  |  |  |                           "or `--shell=auto` to detect the current shell." | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  |       switch "--plain", | 
					
						
							| 
									
										
										
										
											2019-08-20 00:04:14 -04:00
										 |  |  |              description: "Generate plain output even when piped." | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def __env | 
					
						
							| 
									
										
										
										
											2020-07-23 06:25:35 +02:00
										 |  |  |     args = __env_args.parse | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 02:04:50 +02:00
										 |  |  |     ENV.activate_extensions!(env: args.env) | 
					
						
							| 
									
										
										
										
											2020-08-19 10:34:48 -04:00
										 |  |  |     ENV.deps = args.named.to_formulae if superenv?(args.env) | 
					
						
							| 
									
										
										
										
											2020-07-28 02:04:50 +02:00
										 |  |  |     ENV.setup_build_environment | 
					
						
							| 
									
										
										
										
											2014-09-14 01:26:45 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-30 21:29:37 +00:00
										 |  |  |     shell = if args.plain? | 
					
						
							|  |  |  |       nil | 
					
						
							|  |  |  |     elsif args.shell.nil? | 
					
						
							|  |  |  |       :bash unless $stdout.tty? | 
					
						
							|  |  |  |     elsif args.shell == "auto" | 
					
						
							|  |  |  |       Utils::Shell.parent || Utils::Shell.preferred | 
					
						
							|  |  |  |     elsif args.shell | 
					
						
							|  |  |  |       Utils::Shell.from_path(args.shell) | 
					
						
							| 
									
										
										
										
											2016-08-10 23:19:09 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-14 02:26:29 +02:00
										 |  |  |     env_keys = BuildEnvironment.keys(ENV) | 
					
						
							| 
									
										
										
										
											2016-08-10 23:19:09 -07:00
										 |  |  |     if shell.nil? | 
					
						
							| 
									
										
										
										
											2020-08-14 02:26:29 +02:00
										 |  |  |       BuildEnvironment.dump ENV | 
					
						
							| 
									
										
										
										
											2012-03-02 00:59:22 +00:00
										 |  |  |     else | 
					
						
							| 
									
										
										
										
											2018-07-26 10:48:25 +01:00
										 |  |  |       env_keys.each do |key| | 
					
						
							|  |  |  |         puts Utils::Shell.export_value(key, ENV[key], shell) | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2012-03-02 00:59:22 +00:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | end |