Class: XCCache::SPM::Package::Umbrella

Inherits:
XCCache::SPM::Package show all
Includes:
Config::Mixin, UmbrellaBuildMixin, UmbrellaCachemapMixin, UmbrellaDescsMixin, UmbrellaManifestMixin, UmbrellaVizMixin, UmbrellaXCConfigsMixin
Defined in:
lib/xccache/spm/pkg/umbrella.rb

Instance Attribute Summary

Attributes inherited from XCCache::SPM::Package

#root_dir

Instance Method Summary collapse

Methods included from UmbrellaXCConfigsMixin

#gen_xcconfigs

Methods included from UmbrellaVizMixin

#gen_cachemap_viz

Methods included from UmbrellaManifestMixin

#manifest_pkg_dependencies, #manifest_platforms, #manifest_products_to_targets_json, #manifest_targets_json, #write_manifest

Methods included from UmbrellaBuildMixin

#build, #targets_to_build

Methods included from UmbrellaDescsMixin

#binary_targets, #dependency_targets_of_products, #desc_of, #gen_metadata, #targets_of_products, #xccache_desc

Methods included from UmbrellaCachemapMixin

#sync_cachemap

Methods included from Config::Mixin

#config

Methods inherited from XCCache::SPM::Package

#build, #build_target, #resolve

Methods included from Cacheable

#__cacheable_module_name, #cacheable, included

Constructor Details

#initialize(options = {}) ⇒ Umbrella

Returns a new instance of Umbrella.



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

def initialize(options = {})
  super
  @descs = []
  @descs_by_name = {}
  @dependency_targets_by_products = {}
end

Instance Method Details

#createObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/xccache/spm/pkg/umbrella.rb', line 45

def create
  UI.info("Creating umbrella package")
  # Initially, write json with the original data in lockfile (without cache)
  write_manifest(no_cache: true)
  # Create dummy sources dirs prefixed with `.` so that they do not show up in Xcode
  config.project_targets.each do |target|
    dir = Dir.prepare(root_dir / ".Sources" / "#{target.name}.xccache")
    (dir / "dummy.swift").write("")
  end
end


56
57
58
59
60
61
# File 'lib/xccache/spm/pkg/umbrella.rb', line 56

def create_symlinks_for_convenience
  # Symlinks for convenience
  (root_dir / "binaries").symlink_to(root_dir.parent / "binaries")
  (root_dir / ".build").symlink_to(root_dir.parent / ".build")
  (root_dir / ".build/checkouts").symlink_to(root_dir.parent / "checkouts")
end


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/xccache/spm/pkg/umbrella.rb', line 72

def create_symlinks_to_artifacts
  # Clean up symlinks beforehand
  config.spm_binaries_dir.glob("*/*.{xcframework,macro}").each do |p|
    p.rmtree if p.symlink?
  end

  binary_targets.each do |target|
    dst_path = config.spm_binaries_dir / target.name / "#{target.name}.xcframework"
    # For local xcframework, just symlink to the path
    # Zip frameworks (either of local or remote pkgs) are unzipped in the build artifacts
    target.local_binary_path.symlink_to(dst_path) if target.local_binary_path&.extname == ".xcframework"
    config.spm_artifacts_dir.glob("#{target.full_name}/*.xcframework").each do |p|
      p.symlink_to(dst_path)
    end
  end
end


63
64
65
66
67
68
69
70
# File 'lib/xccache/spm/pkg/umbrella.rb', line 63

def create_symlinks_to_local_pkgs
  pkg_desc.dependencies.select(&:local?).each do |dep|
    # For metadata generation
    dep.path.symlink_to(root_dir / ".build/checkouts/#{dep.slug}")
    # For convenience, synced group under `xccache.config` group in xcodeproj
    dep.path.symlink_to(Config.instance.spm_local_pkgs_dir / dep.slug)
  end
end

#prepare(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/xccache/spm/pkg/umbrella.rb', line 27

def prepare(options = {})
  create
  resolve unless options[:skip_resolving_dependencies]
  create_symlinks_for_convenience
  create_symlinks_to_local_pkgs
  
  resolve_recursive_dependencies
  create_symlinks_to_artifacts
  sync_cachemap(sdks: options[:sdks])
end

#resolve_recursive_dependenciesObject



38
39
40
41
42
43
# File 'lib/xccache/spm/pkg/umbrella.rb', line 38

def resolve_recursive_dependencies
  UI.section("Resolving recursive dependencies")
  @descs.each do |desc|
    @dependency_targets_by_products.merge!(desc.resolve_recursive_dependencies.transform_keys(&:full_name))
  end
end