Improved recipe.spec reader.

master
Luka Vandervelden 2019-08-02 23:58:42 +02:00
parent e0ce1ddd2a
commit c2843858ee
3 changed files with 19 additions and 17 deletions

View File

@ -179,13 +179,7 @@ class Package::Context
end
def read_recipe(filename : String)
specs = Specs.parse filename
if specs.nil?
raise Exception.new "file could not be parsed"
end
Recipe.new self, specs
Recipe.new self, filename
end
end

View File

@ -3,7 +3,7 @@ class Package::Package
getter recipe : Recipe
getter automatic : Bool
def initialize(@recipe, @automatic = false)
def initialize(@recipe, @automatic = false, @fake_root_directory = nil)
end
macro inherit(attribute)
@ -33,8 +33,10 @@ class Package::Package
property files : Array(String)?
property file_patterns : Array(Regex)?
@fake_root_directory : String?
def fake_root_directory
"#{@recipe.working_directory}/root-#{name}"
@fake_root_directory || "#{recipe.working_directory}/root-#{name}"
end
def to_s

View File

@ -121,14 +121,20 @@ class Package::Recipe
def self.new(context, name, version)
instance = Recipe.allocate.tap &.initialize(context, name, version)
instance.packages << Package.new instance
instance.packages << Package.new instance, false, instance.fake_root_directory
instance
end
def initialize(@context, specs : Specs)
name : String? = nil
version : String? = nil
def initialize(@context, filename : String)
specs = Specs.parse filename, {
"pkg" => fake_root_directory
}
raise "Could not parse `#{filename}`" if specs.nil?
@name = "" # Needed to avoid build-time errors.
@version = "" # Same.
specs.assignments.each do |key, value|
case key
@ -192,10 +198,10 @@ class Package::Recipe
@version = version
end
def self.new(context, specs : Specs)
instance = Recipe.allocate.tap &.initialize(context, specs)
def self.new(context, filename : String)
instance = Recipe.allocate.tap &.initialize(context, filename)
instance.packages << Package.new instance
instance.packages << Package.new instance, false, instance.fake_root_directory
instance
end
@ -209,7 +215,7 @@ class Package::Recipe
end
def fake_root_directory
@packages[0].fake_root_directory
"#{working_directory}/root"
end
def dirname