| 
									
										
										
										
											2013-09-17 21:25:38 -05:00
										 |  |  | require 'forwardable' | 
					
						
							|  |  |  | require 'resource' | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | require 'checksum' | 
					
						
							|  |  |  | require 'version' | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  | require 'build_options' | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  | require 'dependency_collector' | 
					
						
							| 
									
										
										
										
											2013-10-21 21:25:42 -07:00
										 |  |  | require 'bottles' | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  | require 'patch' | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  | class SoftwareSpec | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:38 -05:00
										 |  |  |   extend Forwardable | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |   attr_reader :name, :owner | 
					
						
							|  |  |  |   attr_reader :build, :resources, :patches | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |   attr_reader :dependency_collector | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   attr_reader :bottle_specification | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:39 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-22 20:17:04 -05:00
										 |  |  |   def_delegators :@resource, :stage, :fetch, :verify_download_integrity | 
					
						
							| 
									
										
										
										
											2014-02-21 00:41:07 -05:00
										 |  |  |   def_delegators :@resource, :cached_download, :clear_cache | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:38 -05:00
										 |  |  |   def_delegators :@resource, :checksum, :mirrors, :specs, :using, :downloader | 
					
						
							| 
									
										
										
										
											2013-09-28 16:37:05 -05:00
										 |  |  |   def_delegators :@resource, :version, :mirror, *Checksum::TYPES | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-23 21:39:19 -05:00
										 |  |  |   def initialize | 
					
						
							|  |  |  |     @resource = Resource.new | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:39 -05:00
										 |  |  |     @resources = {} | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |     @build = BuildOptions.new(ARGV.options_only) | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |     @dependency_collector = DependencyCollector.new | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |     @bottle_specification = BottleSpecification.new | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     @patches = [] | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:39 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def owner= owner | 
					
						
							| 
									
										
										
										
											2013-09-23 21:39:19 -05:00
										 |  |  |     @name = owner.name | 
					
						
							| 
									
										
										
										
											2014-02-27 14:50:22 -06:00
										 |  |  |     @owner = owner | 
					
						
							| 
									
										
										
										
											2013-09-23 21:39:19 -05:00
										 |  |  |     @resource.owner = self | 
					
						
							| 
									
										
										
										
											2013-11-26 18:47:41 -06:00
										 |  |  |     resources.each_value do |r| | 
					
						
							|  |  |  |       r.owner     = self | 
					
						
							|  |  |  |       r.version ||= version | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     patches.each { |p| p.owner = self } | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:39 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-28 16:37:05 -05:00
										 |  |  |   def url val=nil, specs={} | 
					
						
							|  |  |  |     return @resource.url if val.nil? | 
					
						
							|  |  |  |     @resource.url(val, specs) | 
					
						
							|  |  |  |     dependency_collector.add(@resource) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   def bottled? | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |     bottle_specification.tag?(bottle_tag) | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def bottle &block | 
					
						
							|  |  |  |     bottle_specification.instance_eval(&block) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:40 -05:00
										 |  |  |   def resource? name | 
					
						
							|  |  |  |     resources.has_key?(name) | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:39 -05:00
										 |  |  |   def resource name, &block | 
					
						
							|  |  |  |     if block_given? | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:40 -05:00
										 |  |  |       raise DuplicateResourceError.new(name) if resource?(name) | 
					
						
							| 
									
										
										
										
											2014-03-14 23:42:53 -05:00
										 |  |  |       res = Resource.new(name, &block) | 
					
						
							|  |  |  |       resources[name] = res | 
					
						
							|  |  |  |       dependency_collector.add(res) | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:39 -05:00
										 |  |  |     else | 
					
						
							|  |  |  |       resources.fetch(name) { raise ResourceMissingError.new(owner, name) } | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def option name, description=nil | 
					
						
							| 
									
										
										
										
											2013-10-07 00:40:32 -07:00
										 |  |  |     name = 'c++11' if name == :cxx11 | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  |     name = name.to_s if Symbol === name | 
					
						
							|  |  |  |     raise "Option name is required." if name.empty? | 
					
						
							|  |  |  |     raise "Options should not start with dashes." if name[0, 1] == "-" | 
					
						
							|  |  |  |     build.add(name, description) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-21 19:27:24 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def depends_on spec | 
					
						
							|  |  |  |     dep = dependency_collector.add(spec) | 
					
						
							|  |  |  |     build.add_dep_option(dep) if dep | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def deps | 
					
						
							|  |  |  |     dependency_collector.deps | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def requirements | 
					
						
							|  |  |  |     dependency_collector.requirements | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def patch strip=:p1, io=nil, &block | 
					
						
							|  |  |  |     patches << Patch.create(strip, io, &block) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def add_legacy_patches(list) | 
					
						
							|  |  |  |     list = Patch.normalize_legacy_patches(list) | 
					
						
							|  |  |  |     list.each { |p| p.owner = self } | 
					
						
							|  |  |  |     patches.concat(list) | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class HeadSoftwareSpec < SoftwareSpec | 
					
						
							| 
									
										
										
										
											2013-09-23 21:39:19 -05:00
										 |  |  |   def initialize | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |     super | 
					
						
							| 
									
										
										
										
											2013-09-23 21:39:19 -05:00
										 |  |  |     @resource.version = Version.new('HEAD') | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def verify_download_integrity fn | 
					
						
							|  |  |  |     return | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | class Bottle | 
					
						
							|  |  |  |   extend Forwardable | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 10:01:01 -05:00
										 |  |  |   attr_reader :name, :resource, :prefix, :cellar, :revision | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 13:13:06 +00:00
										 |  |  |   def_delegators :resource, :url, :fetch, :verify_download_integrity | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   def_delegators :resource, :downloader, :cached_download, :clear_cache | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   def initialize(f, spec) | 
					
						
							| 
									
										
										
										
											2014-03-13 10:01:01 -05:00
										 |  |  |     @name = f.name | 
					
						
							| 
									
										
										
										
											2014-03-13 13:13:06 +00:00
										 |  |  |     @resource = Resource.new | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |     @resource.owner = f | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     checksum, tag = spec.checksum_for(bottle_tag) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |     @resource.url = bottle_url( | 
					
						
							|  |  |  |       spec.root_url, | 
					
						
							|  |  |  |       :name => f.name, | 
					
						
							|  |  |  |       :version => f.pkg_version, | 
					
						
							|  |  |  |       :revision => spec.revision, | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |       :tag => tag | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |     ) | 
					
						
							| 
									
										
										
										
											2014-03-18 15:47:26 -05:00
										 |  |  |     @resource.download_strategy = CurlBottleDownloadStrategy | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |     @resource.version = f.pkg_version | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |     @resource.checksum = checksum | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |     @prefix = spec.prefix | 
					
						
							|  |  |  |     @cellar = spec.cellar | 
					
						
							|  |  |  |     @revision = spec.revision | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def compatible_cellar? | 
					
						
							|  |  |  |     cellar == :any || cellar == HOMEBREW_CELLAR.to_s | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class BottleSpecification | 
					
						
							|  |  |  |   attr_rw :root_url, :prefix, :cellar, :revision | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |   attr_reader :checksum, :collector | 
					
						
							| 
									
										
										
										
											2013-09-17 21:25:38 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |   def initialize | 
					
						
							|  |  |  |     @revision = 0
 | 
					
						
							|  |  |  |     @prefix = '/usr/local' | 
					
						
							|  |  |  |     @cellar = '/usr/local/Cellar' | 
					
						
							| 
									
										
										
										
											2014-03-05 10:24:33 -06:00
										 |  |  |     @root_url = 'https://downloads.sf.net/project/machomebrew/Bottles' | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:07 -05:00
										 |  |  |     @collector = BottleCollector.new | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |   def tag?(tag) | 
					
						
							|  |  |  |     !!collector.fetch_bottle_for(tag) | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |   # Checksum methods in the DSL's bottle block optionally take | 
					
						
							|  |  |  |   # a Hash, which indicates the platform the checksum applies on. | 
					
						
							|  |  |  |   Checksum::TYPES.each do |cksum| | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:08 -05:00
										 |  |  |     define_method(cksum) do |val| | 
					
						
							|  |  |  |       digest, tag = val.shift | 
					
						
							|  |  |  |       collector.add(Checksum.new(cksum, digest), tag) | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def checksum_for(tag) | 
					
						
							|  |  |  |     collector.fetch_bottle_for(tag) | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-21 21:16:18 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   def checksums | 
					
						
							|  |  |  |     checksums = {} | 
					
						
							| 
									
										
										
										
											2014-04-01 16:03:07 -05:00
										 |  |  |     os_versions = collector.keys | 
					
						
							|  |  |  |     os_versions.map! {|osx| MacOS::Version.from_symbol osx rescue nil }.compact! | 
					
						
							|  |  |  |     os_versions.sort.reverse_each do |os_version| | 
					
						
							|  |  |  |       osx = os_version.to_sym | 
					
						
							|  |  |  |       checksum = collector[osx] | 
					
						
							|  |  |  |       checksums[checksum.hash_type] ||= [] | 
					
						
							|  |  |  |       checksums[checksum.hash_type] << { checksum => osx } | 
					
						
							| 
									
										
										
										
											2013-09-21 21:16:18 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |     checksums | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-09-14 10:16:52 -05:00
										 |  |  | end |