From c2843858ee8cc952c24ae68c42d4e3cbf8fe6312 Mon Sep 17 00:00:00 2001 From: Luka Vandervelden Date: Fri, 2 Aug 2019 23:58:42 +0200 Subject: [PATCH] Improved recipe.spec reader. --- src/context.cr | 8 +------- src/package.cr | 6 ++++-- src/recipe.cr | 22 ++++++++++++++-------- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/context.cr b/src/context.cr index 975ecd5..7601a7a 100644 --- a/src/context.cr +++ b/src/context.cr @@ -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 diff --git a/src/package.cr b/src/package.cr index dceb678..acf9731 100644 --- a/src/package.cr +++ b/src/package.cr @@ -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 diff --git a/src/recipe.cr b/src/recipe.cr index 6583c8b..ea13160 100644 --- a/src/recipe.cr +++ b/src/recipe.cr @@ -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