mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Add Go language module, resources
This introduces a new GoResource category of resource. GoResources have a specialized stage method which allows a resource to stage itself into a gopath. The new Go language module provides a one-liner to stage all GoResources present in the formula.
This commit is contained in:
parent
aec47d8a19
commit
4743fc1662
@ -660,12 +660,16 @@ class Formula
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Define a named resource using a SoftwareSpec style block
|
# Define a named resource using a SoftwareSpec style block
|
||||||
def resource name, &block
|
def resource name, klass=Resource, &block
|
||||||
specs.each do |spec|
|
specs.each do |spec|
|
||||||
spec.resource(name, &block) unless spec.resource_defined?(name)
|
spec.resource(name, klass, &block) unless spec.resource_defined?(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def go_resource name, &block
|
||||||
|
resource name, Resource::Go, &block
|
||||||
|
end
|
||||||
|
|
||||||
def depends_on dep
|
def depends_on dep
|
||||||
specs.each { |spec| spec.depends_on(dep) }
|
specs.each { |spec| spec.depends_on(dep) }
|
||||||
end
|
end
|
||||||
|
14
Library/Homebrew/language/go.rb
Normal file
14
Library/Homebrew/language/go.rb
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
require "resource"
|
||||||
|
|
||||||
|
module Language
|
||||||
|
module Go
|
||||||
|
# Given a set of resources, stages them to a gopath for
|
||||||
|
# building go software.
|
||||||
|
# The resource names should be the import name of the package,
|
||||||
|
# e.g. `resource "github.com/foo/bar"`
|
||||||
|
def self.stage_deps resources, target
|
||||||
|
godeps = resources.grep(Resource::Go)
|
||||||
|
godeps.each {|resource| resource.stage target}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -130,4 +130,10 @@ class Resource
|
|||||||
raise TypeError, "version '#{val.inspect}' should be a string"
|
raise TypeError, "version '#{val.inspect}' should be a string"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Go < Resource
|
||||||
|
def stage target
|
||||||
|
super(target/name)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -69,10 +69,10 @@ class SoftwareSpec
|
|||||||
resources.has_key?(name)
|
resources.has_key?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def resource name, &block
|
def resource name, klass=Resource, &block
|
||||||
if block_given?
|
if block_given?
|
||||||
raise DuplicateResourceError.new(name) if resource_defined?(name)
|
raise DuplicateResourceError.new(name) if resource_defined?(name)
|
||||||
res = Resource.new(name, &block)
|
res = klass.new(name, &block)
|
||||||
resources[name] = res
|
resources[name] = res
|
||||||
dependency_collector.add(res)
|
dependency_collector.add(res)
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user