Class: Litbuild::BlueprintLibrary

Inherits:
Object
  • Object
show all
Defined in:
lib/litbuild/blueprint_library.rb

Overview

BlueprintLibrary initializes and sets configuration parameters for blueprints, and provides a common access point for blueprints and parameters. It always loads blueprints from the *current working directory* and uses config parameters from *the environment*.

Constant Summary collapse

REQUIRED_PARAMS =
%w[DOCUMENT_DIR LOGFILE_DIR PATCH_DIR
SCRIPT_DIR TARFILE_DIR WORK_SITE].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logfile_namer_class:) ⇒ BlueprintLibrary

Returns a new instance of BlueprintLibrary.



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/litbuild/blueprint_library.rb', line 19

def initialize(logfile_namer_class:)
  @blueprints = {}
  Blueprint.descendants.each do |blueprint_type|
    load_blueprints_of_type(blueprint_type)
  end
  @parameters = resolve_parameter_values
  log_namer = logfile_namer_class.new(@parameters['LOGFILE_DIR'])
  @blueprints.each_value do |bp|
    bp.prepare(parameters: @parameters,
               logfile_namer: log_namer,
               library: self)
  end
end

Instance Attribute Details

#blueprintsObject (readonly)

Returns the value of attribute blueprints.



17
18
19
# File 'lib/litbuild/blueprint_library.rb', line 17

def blueprints
  @blueprints
end

#parametersObject (readonly)

Returns the value of attribute parameters.



17
18
19
# File 'lib/litbuild/blueprint_library.rb', line 17

def parameters
  @parameters
end

Instance Method Details

#blueprint_for(target:) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/litbuild/blueprint_library.rb', line 33

def blueprint_for(target:)
  name, phase = split_name_and_phase(target: target)
  bp = blueprints[name]
  unless bp
    raise(UnknownBlueprint, "Blueprint #{name} not found in library")
  end

  bp.for_phase(phase)
end

#dependencies_for(blueprint) ⇒ Object

Convert the dependency declarations found in a ‘depends-on` directive to actual blueprints. See the `Dependencies` section of doc/blueprints.txt for details on how this works.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/litbuild/blueprint_library.rb', line 46

def dependencies_for(blueprint)
  dep_names = blueprint.deduped_dependency_names
  dep_names.map do |dep|
    if dep.match?(/::/) # Explicit phase specified
      blueprint_for(target: dep)
    else
      bp = blueprint_for(target: dep)
      if bp.phases&.include?(blueprint.active_phase)
        bp.for_phase(blueprint.active_phase)
      else
        bp
      end
    end
  end
end