Class: XCCache::SPM::Package
- Inherits:
-
Object
- Object
- XCCache::SPM::Package
show all
- Includes:
- Cacheable, Config::Mixin, Proxy::Mixin
- 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/pkg/proxy.rb,
lib/xccache/spm/desc/target.rb,
lib/xccache/spm/desc/product.rb,
lib/xccache/spm/desc/target/macro.rb,
lib/xccache/spm/desc/target/binary.rb,
lib/xccache/spm/pkg/proxy_executable.rb
Direct Known Subclasses
Proxy
Defined Under Namespace
Classes: BaseObject, BinaryTarget, Dependency, Description, MacroTarget, Product, Proxy, Target
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Cacheable
#__cacheable_module_name, #cacheable, included
#xccache_proxy
#config
Constructor Details
#initialize(options = {}) ⇒ Package
Returns a new instance of Package.
19
20
21
|
# File 'lib/xccache/spm/pkg/base.rb', line 19
def initialize(options = {})
@root_dir = Pathname(options[:root_dir] || ".").expand_path
end
|
Instance Attribute Details
#root_dir ⇒ Object
Returns the value of attribute root_dir.
17
18
19
|
# File 'lib/xccache/spm/pkg/base.rb', line 17
def root_dir
@root_dir
end
|
Instance Method Details
#build(options = {}) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/xccache/spm/pkg/base.rb', line 23
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/xccache/spm/pkg/base.rb', line 38
def build_target(target: nil, sdks: nil, config: nil, out_dir: nil, **options)
target_pkg_desc = pkg_desc_of_target(
target,
ensure_exist: true,
)
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]
ext = target.macro? ? ".macro" : ".xcframework"
basename = options[:checksum] ? "#{target.name}-#{target.checksum}" : target.name
binary_path = out_dir / "#{basename}#{ext}"
Dir.create_tmpdir do |tmpdir|
cls = target.macro? ? Macro : XCFramework
cls.new(
name: target.name,
pkg_dir: root_dir,
config: config,
sdks: sdks,
path: binary_path,
tmpdir: tmpdir,
pkg_desc: target_pkg_desc,
library_evolution: options[:library_evolution],
).build(**options)
end
return if (symlinks_dir = options[:symlinks_dir]).nil?
binary_path.symlink_to(symlinks_dir / target.name / "#{target.name}#{ext}")
end
|
#get_target(name) ⇒ Object
85
86
87
|
# File 'lib/xccache/spm/pkg/base.rb', line 85
def get_target(name)
pkg_desc_of_target(name)&.get_target(name)
end
|
#pkg_desc_of_target(name, **options) ⇒ Object
78
79
80
81
82
83
|
# File 'lib/xccache/spm/pkg/base.rb', line 78
def pkg_desc_of_target(name, **options)
resolve
desc = descs.find { |d| d.has_target?(name) }
raise GeneralError, "Cannot find package with the given target #{name}" if options[:ensure_exist] && desc.nil?
desc
end
|
#resolve ⇒ Object
72
73
74
75
76
|
# File 'lib/xccache/spm/pkg/base.rb', line 72
def resolve
return if @resolved
xccache_proxy.run("resolve --pkg #{root_dir} --metadata #{metadata_dir}")
@resolved = true
end
|