| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | require 'formula' | 
					
						
							| 
									
										
										
										
											2010-11-14 03:52:59 +00:00
										 |  |  | require 'blacklist' | 
					
						
							| 
									
										
										
										
											2014-02-22 20:17:04 -05:00
										 |  |  | require 'digest' | 
					
						
							|  |  |  | require 'erb' | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   # Create a formula from a tarball URL | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   def create | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # Allow searching MacPorts or Fink. | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     if ARGV.include? '--macports' | 
					
						
							| 
									
										
										
										
											2012-12-27 23:34:29 -06:00
										 |  |  |       exec_browser "http://www.macports.org/ports.php?by=name&substr=#{ARGV.next}" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     elsif ARGV.include? '--fink' | 
					
						
							| 
									
										
										
										
											2012-12-27 23:34:29 -06:00
										 |  |  |       exec_browser "http://pdb.finkproject.org/pdb/browse.php?summary=#{ARGV.next}" | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     raise UsageError if ARGV.named.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Ensure that the cache exists so we can fetch the tarball | 
					
						
							|  |  |  |     HOMEBREW_CACHE.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     url = ARGV.named.first # Pull the first (and only) url from ARGV | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     version = ARGV.next if ARGV.include? '--set-version' | 
					
						
							|  |  |  |     name = ARGV.next if ARGV.include? '--set-name' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fc = FormulaCreator.new | 
					
						
							|  |  |  |     fc.name = name | 
					
						
							|  |  |  |     fc.version = version | 
					
						
							|  |  |  |     fc.url = url | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     fc.mode = if ARGV.include? '--cmake' | 
					
						
							|  |  |  |       :cmake | 
					
						
							|  |  |  |     elsif ARGV.include? '--autotools' | 
					
						
							|  |  |  |       :autotools | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-07-17 19:40:44 -05:00
										 |  |  |     if fc.name.nil? || fc.name.strip.empty? | 
					
						
							|  |  |  |       stem = Pathname.new(url).stem | 
					
						
							|  |  |  |       print "Formula name [#{stem}]: " | 
					
						
							|  |  |  |       fc.name = __gets || stem | 
					
						
							|  |  |  |       fc.path = Formula.path(fc.name) | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     # Don't allow blacklisted formula, or names that shadow aliases, | 
					
						
							|  |  |  |     # unless --force is specified. | 
					
						
							|  |  |  |     unless ARGV.force? | 
					
						
							|  |  |  |       if msg = blacklisted?(fc.name) | 
					
						
							|  |  |  |         raise "#{fc.name} is blacklisted for creation.\n#{msg}\nIf you really want to create this formula use --force." | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       if Formula.aliases.include? fc.name | 
					
						
							| 
									
										
										
										
											2014-06-22 15:00:15 -05:00
										 |  |  |         realname = Formulary.canonical_name(fc.name) | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07: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 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     fc.generate! | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     puts "Please `brew audit #{fc.name}` before submitting, thanks." | 
					
						
							|  |  |  |     exec_editor fc.path | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def __gets | 
					
						
							|  |  |  |     gots = $stdin.gets.chomp | 
					
						
							|  |  |  |     if gots.empty? then nil else gots end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class FormulaCreator | 
					
						
							| 
									
										
										
										
											2013-02-17 22:52:39 -06:00
										 |  |  |   attr_reader :url, :sha1 | 
					
						
							|  |  |  |   attr_accessor :name, :version, :path, :mode | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def url= url | 
					
						
							|  |  |  |     @url = url | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     path = Pathname.new(url) | 
					
						
							|  |  |  |     if @name.nil? | 
					
						
							| 
									
										
										
										
											2013-10-25 21:06:17 +01:00
										 |  |  |       %r{github.com/\S+/(\S+)/archive/}.match url | 
					
						
							|  |  |  |       @name ||= $1 | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |       /(.*?)[-_.]?#{path.version}/.match path.basename | 
					
						
							| 
									
										
										
										
											2013-10-25 21:06:17 +01:00
										 |  |  |       @name ||= $1 | 
					
						
							|  |  |  |       @path = Formula.path @name unless @name.nil? | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     else | 
					
						
							|  |  |  |       @path = Formula.path name | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-08-02 04:44:14 +07:00
										 |  |  |     if @version | 
					
						
							|  |  |  |       @version = Version.new(@version) | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |       @version = Pathname.new(url).version | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-22 20:17:04 -05:00
										 |  |  |   def fetch? | 
					
						
							|  |  |  |     !ARGV.include?("--no-fetch") | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |   def generate! | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     raise "#{path} already exists" if path.exist? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if version.nil? | 
					
						
							|  |  |  |       opoo "Version cannot be determined from URL." | 
					
						
							|  |  |  |       puts "You'll need to add an explicit 'version' to the formula." | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-22 20:17:04 -05:00
										 |  |  |     if fetch? && version | 
					
						
							| 
									
										
										
										
											2013-09-23 21:39:19 -05:00
										 |  |  |       r = Resource.new | 
					
						
							|  |  |  |       r.url, r.version, r.owner = url, version, self | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:41 -05:00
										 |  |  |       @sha1 = r.fetch.sha1 if r.download_strategy == CurlDownloadStrategy | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     path.write ERB.new(template, nil, '>').result(binding) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def template; <<-EOS.undent
 | 
					
						
							| 
									
										
										
										
											2014-01-07 08:10:31 +00:00
										 |  |  |     require "formula" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-12-14 18:13:11 +00:00
										 |  |  |     # Documentation: https://github.com/Homebrew/homebrew/wiki/Formula-Cookbook | 
					
						
							| 
									
										
										
										
											2013-10-30 13:20:48 -07:00
										 |  |  |     #                #{HOMEBREW_CONTRIB}/example-formula.rb | 
					
						
							| 
									
										
										
										
											2012-03-01 13:25:10 +00:00
										 |  |  |     # PLEASE REMOVE ALL GENERATED COMMENTS BEFORE SUBMITTING YOUR PULL REQUEST! | 
					
						
							| 
									
										
										
										
											2012-02-29 02:00:33 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-22 20:17:04 -05:00
										 |  |  |     class #{Formulary.class_s(name)} < Formula | 
					
						
							| 
									
										
										
										
											2014-01-07 08:10:31 +00:00
										 |  |  |       homepage "" | 
					
						
							|  |  |  |       url "#{url}" | 
					
						
							| 
									
										
										
										
											2013-09-16 16:12:25 -05:00
										 |  |  |     <% unless  version.nil? or version.detected_from_url? %> | 
					
						
							| 
									
										
										
										
											2014-01-07 08:10:31 +00:00
										 |  |  |       version "#{version}" | 
					
						
							| 
									
										
										
										
											2012-08-22 19:42:01 -07:00
										 |  |  |     <% end  %> | 
					
						
							| 
									
										
										
										
											2014-01-07 08:10:31 +00:00
										 |  |  |       sha1 "#{sha1}" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     <% if  mode == :cmake %> | 
					
						
							| 
									
										
										
										
											2014-01-07 08:10:31 +00:00
										 |  |  |       depends_on "cmake" => :build | 
					
						
							| 
									
										
										
										
											2013-06-26 18:47:00 -05:00
										 |  |  |     <% elsif  mode.nil? %> | 
					
						
							| 
									
										
										
										
											2014-01-07 08:10:31 +00:00
										 |  |  |       # depends_on "cmake" => :build | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     <% end  %> | 
					
						
							| 
									
										
										
										
											2012-08-09 11:00:35 -05:00
										 |  |  |       depends_on :x11 # if your formula requires any X11/XQuartz components | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       def install | 
					
						
							| 
									
										
										
										
											2013-12-24 15:37:59 -05:00
										 |  |  |         # ENV.deparallelize  # if your formula fails when building in parallel | 
					
						
							| 
									
										
										
										
											2012-03-01 13:25:10 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 %> | 
					
						
							| 
									
										
										
										
											2013-09-05 22:54:32 -07:00
										 |  |  |         # Remove unrecognized options if warned by configure | 
					
						
							|  |  |  |         system "./configure", "--disable-debug", | 
					
						
							|  |  |  |                               "--disable-dependency-tracking", | 
					
						
							|  |  |  |                               "--disable-silent-rules", | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |                               "--prefix=\#{prefix}" | 
					
						
							|  |  |  |     <% else  %> | 
					
						
							| 
									
										
										
										
											2013-09-05 22:54:32 -07:00
										 |  |  |         # Remove unrecognized options if warned by configure | 
					
						
							|  |  |  |         system "./configure", "--disable-debug", | 
					
						
							|  |  |  |                               "--disable-dependency-tracking", | 
					
						
							|  |  |  |                               "--disable-silent-rules", | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |                               "--prefix=\#{prefix}" | 
					
						
							| 
									
										
										
										
											2012-05-22 22:32:16 -05:00
										 |  |  |         # system "cmake", ".", *std_cmake_args | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |     <% end  %> | 
					
						
							| 
									
										
										
										
											2013-04-03 11:24:45 -07: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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-23 08:42:34 +00:00
										 |  |  |       test do | 
					
						
							|  |  |  |         # `test do` will create, run in and delete a temporary directory. | 
					
						
							|  |  |  |         # | 
					
						
							| 
									
										
										
										
											2014-01-07 12:53:09 +01: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 | 
					
						
							| 
									
										
										
										
											2014-06-02 22:30:22 +02:00
										 |  |  |         # were more thorough. Run the test with `brew test #{name}`. Options passed | 
					
						
							|  |  |  |         # to `brew install` such as `--HEAD` also need to be provided to `brew test`. | 
					
						
							| 
									
										
										
										
											2013-10-26 15:39:39 -07:00
										 |  |  |         # | 
					
						
							|  |  |  |         # The installed folder is not in the path, so use the entire path to any | 
					
						
							| 
									
										
										
										
											2014-01-07 08:10:31 +00:00
										 |  |  |         # executables being tested: `system "\#{bin}/program", "do", "something"`. | 
					
						
							| 
									
										
										
										
											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 |