class Litbuild::Package

Constants

BUILD_STAGES
NONE
STAGE_DEFAULTS
STAGE_DIRECTIVES

Public Class Methods

directory_name() click to toggle source
# File lib/litbuild/package.rb, line 15
def self.directory_name
  'packages'
end
new(text:) click to toggle source
Calls superclass method Litbuild::Blueprint::new
# File lib/litbuild/package.rb, line 19
def initialize(text:)
  super
  if phases?
    phases.each do |p|
      synthesize_default_commands(@phase_directives[p], @phase_grafs[p])
    end
  else
    synthesize_default_commands(@base_directives, @base_grafs)
  end
end

Public Instance Methods

accept(visitor:) click to toggle source
Calls superclass method Litbuild::Blueprint#accept
# File lib/litbuild/package.rb, line 30
def accept(visitor:)
  super
  visitor.visit_package(package: self)
end
build_commands(stage) click to toggle source
# File lib/litbuild/package.rb, line 65
def build_commands(stage)
  commands = directives["#{stage}-commands"]
  return [] if commands == [NONE]

  commands
end
build_dir() click to toggle source
# File lib/litbuild/package.rb, line 57
def build_dir
  value('build-dir')
end
header_text() click to toggle source
# File lib/litbuild/package.rb, line 76
def header_text
  name
end
in_tree() click to toggle source
# File lib/litbuild/package.rb, line 43
def in_tree
  in_tree_files = self['in-tree-sources'] || []
  in_tree_files.map(&:split)
end
in_tree_packages() click to toggle source
# File lib/litbuild/package.rb, line 48
def in_tree_packages
  in_tree.map { |name, version, _path| "#{name}-#{version}.tar" }
end
name_and_version() click to toggle source
# File lib/litbuild/package.rb, line 61
def name_and_version
  "#{name}-#{version}"
end
patch_files() click to toggle source
# File lib/litbuild/package.rb, line 52
def patch_files
  patches = self['patches'] || []
  patches.map { |basename| "#{name_and_version}-#{basename}.patch" }
end
pkgusr_name() click to toggle source
# File lib/litbuild/package.rb, line 72
def pkgusr_name
  value('package-user')['name'].first
end
tar_files_needed() click to toggle source
# File lib/litbuild/package.rb, line 39
def tar_files_needed
  ["#{name_and_version}.tar"] + in_tree_packages
end
url(url_type) click to toggle source

Return the URL directive of the specified type, or `(unknown)` if there is none.

# File lib/litbuild/package.rb, line 83
def url(url_type)
  directives["#{url_type}-url"]&.first || '(unknown)'
end
version() click to toggle source
# File lib/litbuild/package.rb, line 35
def version
  self['version'].first
end

Private Instance Methods

add_to_narrative(grafs, to_add) click to toggle source

We have default commands to add to the narrative. Where do they go?

The logic here is a little thorny (see comments embeddeed in this method for a description). For any occasion where it does not have a pleasing result, the blueprint can simply be written to have explicit directives rather than using defaults.

# File lib/litbuild/package.rb, line 108
def add_to_narrative(grafs, to_add)
  # *install* always goes at the end.
  stages_to_consider = STAGE_DIRECTIVES.reverse
  stg = stages_to_consider.shift
  grafs << { stg => to_add[stg] } if to_add.key?(stg)

  # For other stages...
  until stages_to_consider.empty?
    stg = stages_to_consider.shift
    next unless to_add.key?(stg)

    # if there is a previous stage *and* directives for that stage
    # are present in the narrative, the default version goes right
    # *after* the *last* of those directives;
    previous_stage = stages_to_consider[0]
    if previous_stage
      last_idx = grafs.rindex do |graf|
        graf.respond_to?(:key) && graf.key?(previous_stage)
      end
      if last_idx
        grafs.insert(last_idx + 1, stg => to_add[stg])
        next
      end
    end

    # otherwise, the default version goes right *before* the *first
    # directive of the next stage* (which will always be present).
    next_stage = STAGE_DIRECTIVES[STAGE_DIRECTIVES.index(stg) + 1]
    first_idx = grafs.index do |graf|
      graf.respond_to?(:key) && graf.key?(next_stage)
    end
    grafs.insert(first_idx, stg => to_add[stg])
  end
end
synthesize_default_commands(directives, grafs) click to toggle source

This is called from the constructor, be careful if modifying it.

# File lib/litbuild/package.rb, line 90
def synthesize_default_commands(directives, grafs)
  to_add = {}
  STAGE_DIRECTIVES.each do |sdir|
    unless directives.include?(sdir)
      directives[sdir] = [STAGE_DEFAULTS[sdir]]
      to_add[sdir] = [STAGE_DEFAULTS[sdir]]
    end
  end
  add_to_narrative(grafs, to_add) unless to_add.empty?
end