Class: XCCache::SPM::Package

Inherits:
Object
  • Object
show all
Includes:
Cacheable
Defined in:
lib/xccache/spm/desc/dep.rb,
lib/xccache/spm/pkg/base.rb,
lib/xccache/spm/desc/base.rb,
lib/xccache/spm/desc/desc.rb,
lib/xccache/spm/desc/target.rb,
lib/xccache/spm/desc/product.rb,
lib/xccache/spm/pkg/umbrella.rb,
lib/xccache/spm/pkg/umbrella/viz.rb,
lib/xccache/spm/desc/target/macro.rb,
lib/xccache/spm/desc/target/binary.rb,
lib/xccache/spm/pkg/umbrella/build.rb,
lib/xccache/spm/pkg/umbrella/descs.rb,
lib/xccache/spm/pkg/umbrella/cachemap.rb,
lib/xccache/spm/pkg/umbrella/manifest.rb,
lib/xccache/spm/pkg/umbrella/xcconfigs.rb

Direct Known Subclasses

Umbrella

Defined Under Namespace

Modules: UmbrellaBuildMixin, UmbrellaCachemapMixin, UmbrellaDescsMixin, UmbrellaManifestMixin, UmbrellaVizMixin, UmbrellaXCConfigsMixin Classes: BaseObject, BinaryTarget, Dependency, Description, MacroTarget, Product, Target, Umbrella

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cacheable

#__cacheable_module_name, #cacheable, included

Constructor Details

#initialize(options = {}) ⇒ Package

Returns a new instance of Package.



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

def initialize(options = {})
  @root_dir = Pathname(options[:root_dir] || ".").expand_path
  @warn_if_not_direct_target = options.fetch(:warn_if_not_direct_target, true)
end

Instance Attribute Details

#root_dirObject (readonly)

Returns the value of attribute root_dir.



13
14
15
# File 'lib/xccache/spm/pkg/base.rb', line 13

def root_dir
  @root_dir
end

Instance Method Details

#build(options = {}) ⇒ Object

Raises:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/xccache/spm/pkg/base.rb', line 20

def build(options = {})
  validate!
  targets = options.delete(:targets) || []
  raise GeneralError, "No targets were specified" if targets.empty?

  targets.map { |t| t.split("/")[-1] }.each_with_index do |t, i|
    UI.section("\n▶ Building target: #{t} (#{i + 1}/#{targets.count})".bold.magenta) do
      build_target(**options, target: t)
    rescue StandardError => e
      UI.error("Failed to build target: #{t}. Error: #{e}")
      raise e unless Config.instance.ignore_build_errors?
    end
  end
end

#build_target(target: nil, sdks: nil, config: nil, out_dir: nil, **options) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/xccache/spm/pkg/base.rb', line 35

def build_target(target: nil, sdks: nil, config: nil, out_dir: nil, **options)
  target_pkg_desc = pkg_desc_of_target(target, skip_resolving_dependencies: options[:skip_resolving_dependencies])
  if target_pkg_desc.binary_targets.any? { |t| t.name == target }
    return UI.warn("Target #{target} is a binary target -> no need to build")
  end

  target = target_pkg_desc.get_target(target)

  out_dir = Pathname(out_dir || ".")
  out_dir /= target.name if options[:checksum]
  basename = options[:checksum] ? "#{target.name}-#{target.checksum}" : target.name
  basename += target.macro? ? ".macro" : ".xcframework"

  Dir.create_tmpdir do |_tmpdir|
    cls = target.macro? ? Macro : XCFramework
    cls.new(
      name: target.name,
      pkg_dir: root_dir,
      config: config,
      sdks: sdks,
      path: out_dir / basename,
      tmpdir: Dir.create_tmpdir,
      pkg_desc: target_pkg_desc,
      library_evolution: options[:library_evolution],
    ).build(**options)
  end
end

#resolve(force: false) ⇒ Object



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

def resolve(force: false)
  return if @resolved && !force

  UI.section("Resolving package dependencies (package: #{root_dir.basename})", timing: true) do
    Sh.run("swift package resolve --package-path #{root_dir} 2>&1")
  end
  @resolved = true
end