diff --git a/lib/comfpile/artefact.rb b/lib/comfpile/artefact.rb index 37ed45f..f76d193 100644 --- a/lib/comfpile/artefact.rb +++ b/lib/comfpile/artefact.rb @@ -47,7 +47,7 @@ module Comfpile # Meta-States exist: # - in_progress/completed: Anything but/Only succeeded, skipped, failed - def initialize(core, engine, stage, target, **opts) + def initialize(core, engine, stage, target, context, **opts) raise ArgumentError, "Unknown options supplied!" unless opts.empty? @core = core @@ -55,8 +55,7 @@ module Comfpile @stage = stage @target = target - - @age = Time.at(0) + @context = @core.sanitize_context context @parent_artefact = nil @@ -136,26 +135,26 @@ module Comfpile }) end - def parent_artefact(stage, target) - @parent_artefact = require_artefact(stage, target) + def parent_artefact(stage, target, context = @context) + @parent_artefact = require_artefact(stage, target, context) end - def include_artefact(stage, target, **opts) - artefact = require_artefact(stage, target, **opts) + def include_artefact(stage, target, context = @context, **opts) + artefact = require_artefact(stage, target, context, **opts) @included_artefacts << artefact artefact end - def require_artefact(stage, target, **opts) - artefact = reference_artefact(stage, target, required: true, **opts) + def require_artefact(stage, target, context = @context, **opts) + artefact = reference_artefact(stage, target, context, required: true, **opts) @required_artefacts << artefact artefact end - def reference_artefact(stage, target, required: false) - artefact = craft_artefact(stage, target) + def reference_artefact(stage, target, context = @context, required: false) + artefact = craft_artefact(stage, target, context) wait_on(artefact) if required @@ -207,12 +206,12 @@ module Comfpile # found that can craft this, else returns the # created or looked-up artefact. # - def craft_artefact(stage, target) - @core.craft_artefact(stage, target) + def craft_artefact(stage, target, context = @context) + @core.craft_artefact(stage, target, context) end - def find_artefact(stage, target) - @core.find_artefact(stage, target) + def find_artefact(stage, target, context = @context) + @core.find_artefact(stage, target, context) end def waitlist_empty? diff --git a/lib/comfpile/artefact_engine.rb b/lib/comfpile/artefact_engine.rb index 5f83db9..aedf3c5 100644 --- a/lib/comfpile/artefact_engine.rb +++ b/lib/comfpile/artefact_engine.rb @@ -15,7 +15,9 @@ module Comfpile @recipes = [] end - def craft(stage, target) + def craft(stage, target, context) + context = @core.sanitize_context context + @recipes.each do |recipe| match = target @@ -32,7 +34,7 @@ module Comfpile end end - new_artefact = Artefact.new(@core, self, stage, target) + new_artefact = Artefact.new(@core, self, stage, target, context) item = recipe[:block].call(match, new_artefact) diff --git a/lib/comfpile/engines/config_engine.rb b/lib/comfpile/engines/config_engine.rb index 7c76013..ef7b911 100644 --- a/lib/comfpile/engines/config_engine.rb +++ b/lib/comfpile/engines/config_engine.rb @@ -61,10 +61,10 @@ module Comfpile end - def craft(stage, target) + def craft(stage, target, context) return unless stage == :config_file - ConfigArtefact.new(@core, self, stage, target) + ConfigArtefact.new(@core, self, stage, target, context) end end end \ No newline at end of file diff --git a/lib/comfpile/engines/filesource_engine.rb b/lib/comfpile/engines/filesource_engine.rb index 81d8482..b126072 100644 --- a/lib/comfpile/engines/filesource_engine.rb +++ b/lib/comfpile/engines/filesource_engine.rb @@ -32,14 +32,14 @@ module Comfpile @root_path = options[:root_path] end - def craft(stage, target) + def craft(stage, target, context) return nil unless stage == :sourcefile full_path = File.join(@root_path, target) return nil unless File.exists? full_path - FilesourceArtefact.new(@core, self, stage, target, + FilesourceArtefact.new(@core, self, stage, target, context, file: full_path); end end diff --git a/lib/comfpile/engines/parser_engine.rb b/lib/comfpile/engines/parser_engine.rb index 3893d5f..26f4836 100644 --- a/lib/comfpile/engines/parser_engine.rb +++ b/lib/comfpile/engines/parser_engine.rb @@ -205,28 +205,28 @@ module Comfpile raise ArgumentError, "Missing regex parsing array!" unless @search_regexes.is_a? Array end - def generate_parser_artefact(stage, target) + def generate_parser_artefact(stage, target, context) match = @input_file_regex.match target return nil if match.nil? - ParserArtefact.new(@core, self, stage, target, + ParserArtefact.new(@core, self, stage, target, context, search_regexes: @search_regexes) end - def generate_dependency_analysis_artefact(stage, target, **opts) + def generate_dependency_analysis_artefact(stage, target, context, **opts) match = @input_file_regex.match target return nil if match.nil? - DependencyAnalysisArtefact.new(@core, self, stage, target, **opts) + DependencyAnalysisArtefact.new(@core, self, stage, target, context, **opts) end - def craft(stage, target) + def craft(stage, target, context) case stage when :parsed - generate_parser_artefact(stage, target) + generate_parser_artefact(stage, target, context) when /^dependency_analysis(?:_(.+))?$/ traverse = $1&.split('_') - generate_dependency_analysis_artefact(stage, target, traverse: traverse) + generate_dependency_analysis_artefact(stage, target, context, traverse: traverse) else nil end