Class: XCCache::Lockfile

Inherits:
JSONRepresentable show all
Defined in:
lib/xccache/core/lockfile.rb

Defined Under Namespace

Classes: Pkg

Instance Attribute Summary

Attributes inherited from HashRepresentable

#path, #raw

Instance Method Summary collapse

Methods inherited from JSONRepresentable

#load, #save

Methods inherited from HashRepresentable

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

Constructor Details

This class inherits a constructor from XCCache::HashRepresentable

Instance Method Details

#deep_merge!(hash) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/xccache/core/lockfile.rb', line 40

def deep_merge!(hash)
  raw.deep_merge!(
    hash,
    uniq_block: proc { |h| h.is_a?(Hash) ? Pkg.from_h(h).id || h : h },
    sort_block: proc { |x| x.to_s.downcase },
  )
  # After deep_merge, clear property cache
  (instance_variables - %i[@path @raw]).each do |ivar|
    remove_instance_variable(ivar)
  end
end

#hash_for_project(project) ⇒ Object



32
33
34
# File 'lib/xccache/core/lockfile.rb', line 32

def hash_for_project(project)
  raw[project.display_name] ||= {}
end

#known_product_dependenciesObject



64
65
66
# File 'lib/xccache/core/lockfile.rb', line 64

def known_product_dependencies
  raw.empty? ? [] : product_dependencies.reject { |d| File.dirname(d) == "__unknown__" }
end

#local_pkg_slugsObject



60
61
62
# File 'lib/xccache/core/lockfile.rb', line 60

def local_pkg_slugs
  @local_pkg_slugs ||= local_pkgs.map(&:slug).uniq
end

#local_pkgsObject



56
57
58
# File 'lib/xccache/core/lockfile.rb', line 56

def local_pkgs
  @local_pkgs ||= pkgs.select(&:local?).uniq
end

#pkgsObject



52
53
54
# File 'lib/xccache/core/lockfile.rb', line 52

def pkgs
  @pkgs ||= raw.values.flat_map { |h| h["packages"] || [] }.map { |h| Pkg.from_h(h) }
end

#product_dependenciesObject



68
69
70
# File 'lib/xccache/core/lockfile.rb', line 68

def product_dependencies
  @product_dependencies ||= product_dependencies_by_targets.values.flatten.uniq
end

#product_dependencies_by_targetsObject



36
37
38
# File 'lib/xccache/core/lockfile.rb', line 36

def product_dependencies_by_targets
  @product_dependencies_by_targets ||= raw.values.map { |h| h["dependencies"] }.reduce { |acc, h| acc.merge(h) }
end

#targets_dataObject



72
73
74
# File 'lib/xccache/core/lockfile.rb', line 72

def targets_data
  @targets_data ||= product_dependencies_by_targets.transform_keys { |k| "#{k}.xccache" }
end

#verify!Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/xccache/core/lockfile.rb', line 76

def verify!
  known_slugs = pkgs.map(&:slug)
  unknown = product_dependencies.reject { |d| known_slugs.include?(File.dirname(d)) }
  return if unknown.empty?

  UI.error! <<~DESC
    Unknown product dependencies at #{path}:

    #{unknown.sort.map { |d| "#{d}" }.join("\n")}

    Refer to this doc for how to resolve this issue:
      https://github.com/trinhngocthuyen/xccache/blob/main/docs/troubleshooting.md#unknown-product-dependencies
  DESC
end