feat: ✨ port artefact context to other functions
This commit is contained in:
parent
1878186c4f
commit
fe23382dcc
5 changed files with 29 additions and 28 deletions
|
@ -47,7 +47,7 @@ module Comfpile
|
||||||
# Meta-States exist:
|
# Meta-States exist:
|
||||||
# - in_progress/completed: Anything but/Only succeeded, skipped, failed
|
# - 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?
|
raise ArgumentError, "Unknown options supplied!" unless opts.empty?
|
||||||
|
|
||||||
@core = core
|
@core = core
|
||||||
|
@ -55,8 +55,7 @@ module Comfpile
|
||||||
|
|
||||||
@stage = stage
|
@stage = stage
|
||||||
@target = target
|
@target = target
|
||||||
|
@context = @core.sanitize_context context
|
||||||
@age = Time.at(0)
|
|
||||||
|
|
||||||
@parent_artefact = nil
|
@parent_artefact = nil
|
||||||
|
|
||||||
|
@ -136,26 +135,26 @@ module Comfpile
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
def parent_artefact(stage, target)
|
def parent_artefact(stage, target, context = @context)
|
||||||
@parent_artefact = require_artefact(stage, target)
|
@parent_artefact = require_artefact(stage, target, context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_artefact(stage, target, **opts)
|
def include_artefact(stage, target, context = @context, **opts)
|
||||||
artefact = require_artefact(stage, target, **opts)
|
artefact = require_artefact(stage, target, context, **opts)
|
||||||
@included_artefacts << artefact
|
@included_artefacts << artefact
|
||||||
|
|
||||||
artefact
|
artefact
|
||||||
end
|
end
|
||||||
|
|
||||||
def require_artefact(stage, target, **opts)
|
def require_artefact(stage, target, context = @context, **opts)
|
||||||
artefact = reference_artefact(stage, target, required: true, **opts)
|
artefact = reference_artefact(stage, target, context, required: true, **opts)
|
||||||
@required_artefacts << artefact
|
@required_artefacts << artefact
|
||||||
|
|
||||||
artefact
|
artefact
|
||||||
end
|
end
|
||||||
|
|
||||||
def reference_artefact(stage, target, required: false)
|
def reference_artefact(stage, target, context = @context, required: false)
|
||||||
artefact = craft_artefact(stage, target)
|
artefact = craft_artefact(stage, target, context)
|
||||||
|
|
||||||
wait_on(artefact) if required
|
wait_on(artefact) if required
|
||||||
|
|
||||||
|
@ -207,12 +206,12 @@ module Comfpile
|
||||||
# found that can craft this, else returns the
|
# found that can craft this, else returns the
|
||||||
# created or looked-up artefact.
|
# created or looked-up artefact.
|
||||||
#
|
#
|
||||||
def craft_artefact(stage, target)
|
def craft_artefact(stage, target, context = @context)
|
||||||
@core.craft_artefact(stage, target)
|
@core.craft_artefact(stage, target, context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_artefact(stage, target)
|
def find_artefact(stage, target, context = @context)
|
||||||
@core.find_artefact(stage, target)
|
@core.find_artefact(stage, target, context)
|
||||||
end
|
end
|
||||||
|
|
||||||
def waitlist_empty?
|
def waitlist_empty?
|
||||||
|
|
|
@ -15,7 +15,9 @@ module Comfpile
|
||||||
@recipes = []
|
@recipes = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def craft(stage, target)
|
def craft(stage, target, context)
|
||||||
|
context = @core.sanitize_context context
|
||||||
|
|
||||||
@recipes.each do |recipe|
|
@recipes.each do |recipe|
|
||||||
match = target
|
match = target
|
||||||
|
|
||||||
|
@ -32,7 +34,7 @@ module Comfpile
|
||||||
end
|
end
|
||||||
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)
|
item = recipe[:block].call(match, new_artefact)
|
||||||
|
|
||||||
|
|
|
@ -61,10 +61,10 @@ module Comfpile
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def craft(stage, target)
|
def craft(stage, target, context)
|
||||||
return unless stage == :config_file
|
return unless stage == :config_file
|
||||||
|
|
||||||
ConfigArtefact.new(@core, self, stage, target)
|
ConfigArtefact.new(@core, self, stage, target, context)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -32,14 +32,14 @@ module Comfpile
|
||||||
@root_path = options[:root_path]
|
@root_path = options[:root_path]
|
||||||
end
|
end
|
||||||
|
|
||||||
def craft(stage, target)
|
def craft(stage, target, context)
|
||||||
return nil unless stage == :sourcefile
|
return nil unless stage == :sourcefile
|
||||||
|
|
||||||
full_path = File.join(@root_path, target)
|
full_path = File.join(@root_path, target)
|
||||||
|
|
||||||
return nil unless File.exists? full_path
|
return nil unless File.exists? full_path
|
||||||
|
|
||||||
FilesourceArtefact.new(@core, self, stage, target,
|
FilesourceArtefact.new(@core, self, stage, target, context,
|
||||||
file: full_path);
|
file: full_path);
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -205,28 +205,28 @@ module Comfpile
|
||||||
raise ArgumentError, "Missing regex parsing array!" unless @search_regexes.is_a? Array
|
raise ArgumentError, "Missing regex parsing array!" unless @search_regexes.is_a? Array
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_parser_artefact(stage, target)
|
def generate_parser_artefact(stage, target, context)
|
||||||
match = @input_file_regex.match target
|
match = @input_file_regex.match target
|
||||||
return nil if match.nil?
|
return nil if match.nil?
|
||||||
|
|
||||||
ParserArtefact.new(@core, self, stage, target,
|
ParserArtefact.new(@core, self, stage, target, context,
|
||||||
search_regexes: @search_regexes)
|
search_regexes: @search_regexes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_dependency_analysis_artefact(stage, target, **opts)
|
def generate_dependency_analysis_artefact(stage, target, context, **opts)
|
||||||
match = @input_file_regex.match target
|
match = @input_file_regex.match target
|
||||||
return nil if match.nil?
|
return nil if match.nil?
|
||||||
|
|
||||||
DependencyAnalysisArtefact.new(@core, self, stage, target, **opts)
|
DependencyAnalysisArtefact.new(@core, self, stage, target, context, **opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def craft(stage, target)
|
def craft(stage, target, context)
|
||||||
case stage
|
case stage
|
||||||
when :parsed
|
when :parsed
|
||||||
generate_parser_artefact(stage, target)
|
generate_parser_artefact(stage, target, context)
|
||||||
when /^dependency_analysis(?:_(.+))?$/
|
when /^dependency_analysis(?:_(.+))?$/
|
||||||
traverse = $1&.split('_')
|
traverse = $1&.split('_')
|
||||||
generate_dependency_analysis_artefact(stage, target, traverse: traverse)
|
generate_dependency_analysis_artefact(stage, target, context, traverse: traverse)
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue