Class: XCCache::SPM::Package::Description

Inherits:
BaseObject show all
Includes:
Cacheable
Defined in:
lib/xccache/spm/desc/desc.rb

Constant Summary

Constants inherited from BaseObject

BaseObject::ATTRS

Instance Attribute Summary

Attributes inherited from HashRepresentable

#path, #raw

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Cacheable

#__cacheable_module_name, #cacheable, included

Methods inherited from BaseObject

#cast_to, #display_name, #fetch, #full_name, #inspect, #name, #pkg_desc_of, #pkg_name, #pkg_slug, #src_dir, #to_s

Methods included from Config::Mixin

#config

Methods inherited from JSONRepresentable

#load, #save

Methods inherited from HashRepresentable

#[], #[]=, #initialize, #load, #merge!, #reload, #save

Constructor Details

This class inherits a constructor from XCCache::HashRepresentable

Class Method Details

.combine_descs(descs) ⇒ Object



94
95
96
97
98
# File 'lib/xccache/spm/desc/desc.rb', line 94

def self.combine_descs(descs)
  descs_by_name = descs.flat_map { |d| [[d.name, d], [d.pkg_slug, d]] }.to_h
  descs.each { |d| d.retrieve_pkg_desc = proc { |name| descs_by_name[name] } }
  descs_by_name
end

.descs_in_metadata_dir(dir) ⇒ Object



9
10
11
12
# File 'lib/xccache/spm/desc/desc.rb', line 9

def self.(dir)
  descs = dir.glob("*.json").map { |p| Description.new(p) }
  [descs, combine_descs(descs)]
end

Instance Method Details

#binary_targetsObject



42
43
44
# File 'lib/xccache/spm/desc/desc.rb', line 42

def binary_targets
  @binary_targets ||= targets.select(&:binary?)
end

#dependenciesObject



26
27
28
# File 'lib/xccache/spm/desc/desc.rb', line 26

def dependencies
  @dependencies ||= fetch("dependencies", Dependency)
end

#get_target(name) ⇒ Object



50
51
52
# File 'lib/xccache/spm/desc/desc.rb', line 50

def get_target(name)
  targets.find { |t| t.name == name }
end

#gitObject



90
91
92
# File 'lib/xccache/spm/desc/desc.rb', line 90

def git
  @git ||= Git.new(src_dir) if Dir.git?(src_dir)
end

#has_target?(name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/xccache/spm/desc/desc.rb', line 46

def has_target?(name)
  targets.any? { |t| t.name == name }
end

#local?Boolean

Returns:

  • (Boolean)


60
61
62
63
# File 'lib/xccache/spm/desc/desc.rb', line 60

def local?
  # Workaround: If the pkg dir is under the build checkouts dir -> remote
  !src_dir.to_s.start_with?((config.spm_build_dir / "checkouts").to_s)
end

#metadataObject



18
19
20
# File 'lib/xccache/spm/desc/desc.rb', line 18

def 
  raw["_metadata"] ||= {}
end

#platformsObject



22
23
24
# File 'lib/xccache/spm/desc/desc.rb', line 22

def platforms
  @platforms ||= raw.fetch("platforms", []).to_h { |h| [h["platformName"].to_sym, h["version"]] }
end

#productsObject



34
35
36
# File 'lib/xccache/spm/desc/desc.rb', line 34

def products
  @products ||= fetch("products", Product)
end

#rootObject



14
15
16
# File 'lib/xccache/spm/desc/desc.rb', line 14

def root
  self
end

#targetsObject



38
39
40
# File 'lib/xccache/spm/desc/desc.rb', line 38

def targets
  @targets ||= fetch("targets", Target).map(&:downcast)
end

#targets_of_products(name) ⇒ Object



54
55
56
57
58
# File 'lib/xccache/spm/desc/desc.rb', line 54

def targets_of_products(name)
  matched_products = products.select { |p| p.name == name }
  matched_products
    .flat_map { |p| targets.select { |t| p.target_names.include?(t.name) } }
end

#traverseObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/xccache/spm/desc/desc.rb', line 65

def traverse
  nodes, edges, parents = [], [], {}
  to_visit = targets.dup
  visited = Set.new
  until to_visit.empty?
    cur = to_visit.pop
    next if visited.include?(cur)

    visited << cur
    nodes << cur
    yield cur if block_given?

    # For macro impl, we don't need their dependencies, just the tool binary
    # So, no need to care about swift-syntax dependencies
    next if cur.macro?
    cur.direct_dependency_targets.each do |t|
      to_visit << t
      edges << [cur, t]
      parents[t] ||= []
      parents[t] << cur
    end
  end
  [nodes, edges, parents]
end

#uniform_dependenciesObject



30
31
32
# File 'lib/xccache/spm/desc/desc.rb', line 30

def uniform_dependencies
  dependencies.filter_map(&:pkg_desc)
end