| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | require 'formula' | 
					
						
							| 
									
										
										
										
											2010-11-14 03:52:59 +00:00
										 |  |  | require 'blacklist' | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | module Homebrew extend self | 
					
						
							|  |  |  |   def create | 
					
						
							|  |  |  |     if ARGV.include? '--macports' | 
					
						
							|  |  |  |       exec "open", "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}" | 
					
						
							|  |  |  |     elsif ARGV.include? '--fink' | 
					
						
							|  |  |  |       exec "open", "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}" | 
					
						
							|  |  |  |     elsif ARGV.named.empty? | 
					
						
							|  |  |  |       raise UsageError | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2011-04-05 08:31:05 -07:00
										 |  |  |       HOMEBREW_CACHE.mkpath | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       paths = ARGV.named.map do |url| | 
					
						
							|  |  |  |         fc = FormulaCreator.new | 
					
						
							|  |  |  |         fc.url = url | 
					
						
							|  |  |  |         fc.mode = if ARGV.include? '--cmake' | 
					
						
							|  |  |  |           :cmake | 
					
						
							|  |  |  |         elsif ARGV.include? '--autotools' | 
					
						
							|  |  |  |           :autotools | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-31 17:57:20 -06:00
										 |  |  |         if fc.name.nil? or fc.name.to_s.strip.empty? | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |           path = Pathname.new url | 
					
						
							|  |  |  |           print "Formula name [#{path.stem}]: " | 
					
						
							|  |  |  |           fc.name = __gets || path.stem | 
					
						
							| 
									
										
										
										
											2011-03-27 22:14:16 +02:00
										 |  |  |           fc.path = Formula.path fc.name | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         unless ARGV.force? | 
					
						
							|  |  |  |           if msg = blacklisted?(fc.name) | 
					
						
							| 
									
										
										
										
											2010-11-14 03:52:59 +00:00
										 |  |  |             raise "#{fc.name} is blacklisted for creation.\n#{msg}\nIf you really want to create this formula use --force." | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |           end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           if Formula.aliases.include? fc.name | 
					
						
							| 
									
										
										
										
											2011-05-07 19:29:54 -05:00
										 |  |  |             realname = Formula.canonical_name fc.name | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |             raise <<-EOS.undent
 | 
					
						
							|  |  |  |               The formula #{realname} is already aliased to #{fc.name} | 
					
						
							|  |  |  |               Please check that you are not creating a duplicate. | 
					
						
							|  |  |  |               To force creation use --force. | 
					
						
							|  |  |  |               EOS | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |         fc.generate | 
					
						
							|  |  |  |         fc.path | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2011-04-05 08:37:59 -07:00
										 |  |  |       puts "Please `brew audit "+paths.collect{|p|p.basename(".rb")}*" "+"` before submitting, thanks." | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       exec_editor *paths | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def __gets | 
					
						
							|  |  |  |     gots = $stdin.gets.chomp | 
					
						
							|  |  |  |     if gots.empty? then nil else gots end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FormulaCreator | 
					
						
							|  |  |  |   attr :url | 
					
						
							| 
									
										
										
										
											2012-03-07 18:52:21 +01:00
										 |  |  |   attr :sha1 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   attr :name, true | 
					
						
							| 
									
										
										
										
											2011-03-27 22:14:16 +02:00
										 |  |  |   attr :path, true | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   attr :mode, true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def url= url | 
					
						
							|  |  |  |     @url = url | 
					
						
							|  |  |  |     path = Pathname.new url | 
					
						
							|  |  |  |     /(.*?)[-_.]?#{path.version}/.match path.basename | 
					
						
							|  |  |  |     @name = $1 | 
					
						
							| 
									
										
										
										
											2012-01-31 17:57:20 -06:00
										 |  |  |     @path = Formula.path $1 unless $1.nil? | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def version | 
					
						
							|  |  |  |     Pathname.new(url).version | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def generate | 
					
						
							|  |  |  |     raise "#{path} already exists" if path.exist? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     require 'digest' | 
					
						
							|  |  |  |     require 'erb' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if version.nil? | 
					
						
							|  |  |  |       opoo "Version cannot be determined from URL." | 
					
						
							|  |  |  |       puts "You'll need to add an explicit 'version' to the formula." | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       puts "Version detected as #{version}." | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-13 12:52:41 +00:00
										 |  |  |     unless ARGV.include? "--no-fetch" and version | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       strategy = detect_download_strategy url | 
					
						
							| 
									
										
										
										
											2012-03-07 18:52:21 +01:00
										 |  |  |       @sha1 = strategy.new(url, name, version, nil).fetch.sha1 if strategy == CurlDownloadStrategy | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     path.write ERB.new(template, nil, '>').result(binding) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def template; <<-EOS.undent
 | 
					
						
							|  |  |  |     require 'formula' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-01 13:25:10 +00:00
										 |  |  |     # Documentation: https://github.com/mxcl/homebrew/wiki/Formula-Cookbook | 
					
						
							|  |  |  |     # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST! | 
					
						
							| 
									
										
										
										
											2012-02-29 02:00:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-09 21:11:03 -08:00
										 |  |  |     class #{Formula.class_s name} < Formula | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       homepage '' | 
					
						
							| 
									
										
										
										
											2012-02-06 17:19:54 -06:00
										 |  |  |       url '#{url}' | 
					
						
							| 
									
										
										
										
											2012-03-07 18:52:21 +01:00
										 |  |  |       sha1 '#{sha1}' | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     <% if  mode == :cmake %> | 
					
						
							| 
									
										
										
										
											2011-11-29 16:08:02 -06:00
										 |  |  |       depends_on 'cmake' => :build | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     <% elsif  mode == nil %> | 
					
						
							| 
									
										
										
										
											2011-11-29 16:08:02 -06:00
										 |  |  |       # depends_on 'cmake' => :build | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     <% end  %> | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def install | 
					
						
							| 
									
										
										
										
											2012-03-01 13:25:10 +00:00
										 |  |  |         # ENV.x11 # if your formula requires any X11 headers | 
					
						
							|  |  |  |         # ENV.j1  # if your formula's build system can't parallelize | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     <% if  mode == :cmake %> | 
					
						
							| 
									
										
										
										
											2012-05-22 22:32:16 -05:00
										 |  |  |         system "cmake", ".", *std_cmake_args | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     <% elsif  mode == :autotools %> | 
					
						
							|  |  |  |         system "./configure", "--disable-debug", "--disable-dependency-tracking", | 
					
						
							|  |  |  |                               "--prefix=\#{prefix}" | 
					
						
							|  |  |  |     <% else  %> | 
					
						
							|  |  |  |         system "./configure", "--disable-debug", "--disable-dependency-tracking", | 
					
						
							|  |  |  |                               "--prefix=\#{prefix}" | 
					
						
							| 
									
										
										
										
											2012-05-22 22:32:16 -05:00
										 |  |  |         # system "cmake", ".", *std_cmake_args | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     <% end  %> | 
					
						
							| 
									
										
										
										
											2012-03-01 13:25:10 +00:00
										 |  |  |         system "make install" # if this fails, try separate make/make install steps | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2011-08-25 00:52:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       def test | 
					
						
							| 
									
										
										
										
											2012-03-01 13:25:10 +00:00
										 |  |  |         # This test will fail and we won't accept that! It's enough to just replace | 
					
						
							|  |  |  |         # "false" with the main program this formula installs, but it'd be nice if you | 
					
						
							|  |  |  |         # were more thorough. Run the test with `brew test #{name}`. | 
					
						
							| 
									
										
										
										
											2011-09-20 03:38:30 +01:00
										 |  |  |         system "false" | 
					
						
							| 
									
										
										
										
											2011-08-25 00:52:12 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |     EOS | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |