Class: XCCache::SPM::Package::Proxy

Inherits:
XCCache::SPM::Package show all
Includes:
Mixin
Defined in:
lib/xccache/spm/pkg/proxy.rb,
lib/xccache/spm/pkg/proxy_executable.rb

Defined Under Namespace

Modules: Mixin Classes: Executable

Instance Attribute Summary

Attributes inherited from XCCache::SPM::Package

#root_dir

Instance Method Summary collapse

Methods included from Mixin

#xccache_proxy

Methods inherited from XCCache::SPM::Package

#build, #build_target, #get_target, #initialize, #pkg_desc, #pkg_desc_of_target, #resolve

Methods included from Cacheable

#__cacheable_module_name, #cacheable, included

Methods included from Config::Mixin

#config

Constructor Details

This class inherits a constructor from XCCache::SPM::Package

Instance Method Details

#gen_proxyObject



27
28
29
30
# File 'lib/xccache/spm/pkg/proxy.rb', line 27

def gen_proxy
  xccache_proxy.run("gen-proxy")
  config.cachemap.update_from_graph(graph.reload)
end

#graphObject



54
55
56
# File 'lib/xccache/spm/pkg/proxy.rb', line 54

def graph
  @graph ||= JSONRepresentable.new(root_dir / "graph.json")
end

#invalidate_cache(sdks: []) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/xccache/spm/pkg/proxy.rb', line 32

def invalidate_cache(sdks: [])
  UI.message("Invalidating cache (sdks: #{sdks.map(&:to_s).join(', ')})")

  config.spm_cache_dir.glob("*/*.{xcframework,macro}").each do |p|
    cmps = p.basename(".*").to_s.split("-")
    name, checksum = cmps[...-1].join("-"), cmps[-1]
    p_without_checksum = config.spm_binaries_dir / name / "#{name}#{p.extname}"
    accept_cache = proc { p.symlink_to(p_without_checksum) }
    reject_cache = proc { p_without_checksum.rmtree if p_without_checksum.exist? }
    next reject_cache.call if (target = umbrella.get_target(name)).nil?
    next reject_cache.call if target.checksum != checksum
    # For macro, we just need the tool binary to exist
    next accept_cache.call if target.macro?

    # For regular targets, the xcframework must satisfy the sdk constraints (ie. containing all the slices)
     = XCFramework::.new(p / "Info.plist")
    expected_triples = sdks.map { |sdk| sdk.triple(with_vendor: false) }
    missing_triples = expected_triples - .triples
    missing_triples.empty? ? accept_cache.call : reject_cache.call
  end
end

#prepare(options = {}) ⇒ Object



20
21
22
23
24
25
# File 'lib/xccache/spm/pkg/proxy.rb', line 20

def prepare(options = {})
  xccache_proxy.run("gen-umbrella")
  umbrella.resolve
  invalidate_cache(sdks: options[:sdks])
  gen_proxy
end

#umbrellaObject



16
17
18
# File 'lib/xccache/spm/pkg/proxy.rb', line 16

def umbrella
  @umbrella ||= Package.new(root_dir: config.spm_umbrella_sandbox)
end