| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "rubocops/extend/formula" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module RuboCop | 
					
						
							|  |  |  |   module Cop | 
					
						
							|  |  |  |     module FormulaAudit | 
					
						
							|  |  |  |       # This cop audits `uses_from_macos` dependencies in formulae | 
					
						
							|  |  |  |       class UsesFromMacos < FormulaCop | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |         # Generate with: | 
					
						
							|  |  |  |         # brew ruby -e 'puts Formula.select {|f| f.keg_only_reason&.provided_by_macos? }.map(&:name).sort.join("\n")' | 
					
						
							|  |  |  |         # Not done at runtime as its too slow and RuboCop doesn't have access. | 
					
						
							|  |  |  |         PROVIDED_BY_MACOS_FORMULAE = %w[
 | 
					
						
							|  |  |  |           apr | 
					
						
							|  |  |  |           bc | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           bison | 
					
						
							|  |  |  |           bzip2 | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           cups | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           curl | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           dyld-headers | 
					
						
							| 
									
										
										
										
											2020-06-15 23:50:54 +02:00
										 |  |  |           ed | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           expat | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           file-formula | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           flex | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           gcore | 
					
						
							|  |  |  |           gnu-getopt | 
					
						
							| 
									
										
										
										
											2020-04-07 12:16:17 +01:00
										 |  |  |           icu4c | 
					
						
							|  |  |  |           krb5 | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           libarchive | 
					
						
							| 
									
										
										
										
											2020-04-07 12:16:17 +01:00
										 |  |  |           libedit | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           libffi | 
					
						
							| 
									
										
										
										
											2020-04-18 21:39:39 +10:00
										 |  |  |           libiconv | 
					
						
							| 
									
										
										
										
											2020-04-07 12:16:17 +01:00
										 |  |  |           libpcap | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           libressl | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           libxml2 | 
					
						
							|  |  |  |           libxslt | 
					
						
							| 
									
										
										
										
											2020-04-07 12:16:17 +01:00
										 |  |  |           llvm | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           lsof | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           m4 | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           ncompress | 
					
						
							| 
									
										
										
										
											2020-04-07 15:04:23 +01:00
										 |  |  |           ncurses | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           net-snmp | 
					
						
							| 
									
										
										
										
											2020-04-07 12:16:17 +01:00
										 |  |  |           openldap | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           openlibm | 
					
						
							|  |  |  |           pod2man | 
					
						
							|  |  |  |           rpcgen | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           ruby | 
					
						
							|  |  |  |           sqlite | 
					
						
							| 
									
										
										
										
											2020-04-07 15:04:23 +01:00
										 |  |  |           ssh-copy-id | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           swift | 
					
						
							| 
									
										
										
										
											2020-04-07 12:16:17 +01:00
										 |  |  |           tcl-tk | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           texinfo | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           unifdef | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |           unzip | 
					
						
							| 
									
										
										
										
											2020-04-07 12:16:17 +01:00
										 |  |  |           zip | 
					
						
							| 
									
										
										
										
											2020-04-07 15:04:23 +01:00
										 |  |  |           zlib | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |         ].freeze | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |         # These formulae aren't keg_only :provided_by_macos but are provided by | 
					
						
							|  |  |  |         # macOS (or very similarly e.g. OpenSSL where system provides LibreSSL) | 
					
						
							|  |  |  |         # TODO: consider making some of these keg-only. | 
					
						
							|  |  |  |         ALLOWED_USES_FROM_MACOS_DEPS = (PROVIDED_BY_MACOS_FORMULAE + %w[
 | 
					
						
							|  |  |  |           bash | 
					
						
							|  |  |  |           expect | 
					
						
							|  |  |  |           groff | 
					
						
							| 
									
										
										
										
											2020-04-20 10:38:06 -07:00
										 |  |  |           gzip | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           openssl | 
					
						
							|  |  |  |           openssl@1.1
 | 
					
						
							|  |  |  |           perl | 
					
						
							|  |  |  |           php | 
					
						
							|  |  |  |           python | 
					
						
							|  |  |  |           python@3
 | 
					
						
							| 
									
										
										
										
											2020-04-20 10:38:06 -07:00
										 |  |  |           rsync | 
					
						
							| 
									
										
										
										
											2020-04-20 10:36:42 +01:00
										 |  |  |           vim | 
					
						
							|  |  |  |           xz | 
					
						
							|  |  |  |           zsh | 
					
						
							|  |  |  |         ]).freeze | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-05 15:22:06 +01:00
										 |  |  |         def audit_formula(_node, _class_node, _parent_class_node, body_node) | 
					
						
							|  |  |  |           find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method| | 
					
						
							|  |  |  |             dep = if parameters(method).first.class == RuboCop::AST::StrNode | 
					
						
							|  |  |  |               parameters(method).first | 
					
						
							|  |  |  |             elsif parameters(method).first.class == RuboCop::AST::HashNode | 
					
						
							|  |  |  |               parameters(method).first.keys.first | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             next if ALLOWED_USES_FROM_MACOS_DEPS.include?(string_content(dep)) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             problem "`uses_from_macos` should only be used for macOS dependencies, not #{string_content(dep)}." | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |