| 
									
										
										
										
											2024-03-21 10:46:51 -07:00
										 |  |  | # typed: strict | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 10:46:51 -07:00
										 |  |  | require "abstract_command" | 
					
						
							| 
									
										
										
										
											2018-02-28 10:39:15 -05:00
										 |  |  | require "cache_store" | 
					
						
							| 
									
										
										
										
											2018-02-28 09:13:17 -08:00
										 |  |  | require "linkage_checker" | 
					
						
							| 
									
										
										
										
											2016-04-17 21:25:11 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2024-03-21 10:46:51 -07:00
										 |  |  |   module DevCmd | 
					
						
							|  |  |  |     class Linkage < AbstractCommand | 
					
						
							|  |  |  |       cmd_args do | 
					
						
							|  |  |  |         description <<~EOS | 
					
						
							|  |  |  |           Check the library links from the given <formula> kegs. If no <formula> are | 
					
						
							|  |  |  |           provided, check all kegs. Raises an error if run on uninstalled formulae. | 
					
						
							|  |  |  |         EOS | 
					
						
							|  |  |  |         switch "--test", | 
					
						
							|  |  |  |                description: "Show only missing libraries and exit with a non-zero status if any missing " \ | 
					
						
							|  |  |  |                             "libraries are found." | 
					
						
							|  |  |  |         switch "--strict", | 
					
						
							|  |  |  |                depends_on:  "--test", | 
					
						
							|  |  |  |                description: "Exit with a non-zero status if any undeclared dependencies with linkage are found." | 
					
						
							|  |  |  |         switch "--reverse", | 
					
						
							|  |  |  |                description: "For every library that a keg references, print its dylib path followed by the " \ | 
					
						
							|  |  |  |                             "binaries that link to it." | 
					
						
							|  |  |  |         switch "--cached", | 
					
						
							| 
									
										
										
										
											2025-06-03 11:06:35 -04:00
										 |  |  |                description: "Print the cached linkage values stored in `$HOMEBREW_CACHE`, set by a previous " \ | 
					
						
							| 
									
										
										
										
											2024-03-21 10:46:51 -07:00
										 |  |  |                             "`brew linkage` run." | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         named_args :installed_formula | 
					
						
							| 
									
										
										
										
											2018-08-03 11:15:58 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-01-16 17:37:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-03-21 10:46:51 -07:00
										 |  |  |       sig { override.void } | 
					
						
							|  |  |  |       def run | 
					
						
							|  |  |  |         CacheStoreDatabase.use(:linkage) do |db| | 
					
						
							|  |  |  |           kegs = if args.named.to_default_kegs.empty? | 
					
						
							|  |  |  |             Formula.installed.filter_map(&:any_installed_keg) | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             args.named.to_default_kegs | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           kegs.each do |keg| | 
					
						
							|  |  |  |             ohai "Checking #{keg.name} linkage" if kegs.size > 1
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             result = LinkageChecker.new(keg, cache_db: db) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if args.test? | 
					
						
							|  |  |  |               result.display_test_output(strict: args.strict?) | 
					
						
							|  |  |  |               Homebrew.failed = true if result.broken_library_linkage?(test: true, strict: args.strict?) | 
					
						
							|  |  |  |             elsif args.reverse? | 
					
						
							|  |  |  |               result.display_reverse_output | 
					
						
							|  |  |  |             else | 
					
						
							|  |  |  |               result.display_normal_output | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2018-02-24 17:32:29 -05:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-17 21:25:11 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2016-04-19 13:55:47 +08:00
										 |  |  | end |