feat: port artefact context to other functions

This commit is contained in:
David Bailey 2023-04-20 09:49:54 +02:00
parent 1878186c4f
commit fe23382dcc
5 changed files with 29 additions and 28 deletions

View file

@ -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?

View file

@ -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)

View file

@ -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

View file

@ -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

View file

@ -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