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
37
38
39
40
41
|
# File 'lib/xccache/spm/pkg/base.rb', line 23
def build(options = {})
validate!
targets = (options.delete(:targets) || []).map { |t| t.split("/")[-1] }
raise GeneralError, "No targets were specified" if targets.empty?
Dir.create_tmpdir do |tmpdir|
targets.each_with_index do |t, i|
target_tmpdir = Dir.prepare(tmpdir / t)
log_dir = Dir.prepare(options[:log_dir] || target_tmpdir)
live_log = LiveLog.new(tee: log_dir / "build_#{t}.log")
live_log.capture("[#{i + 1}/#{targets.count}] Building target: #{t}") do
build_target(**options, target: t, live_log: live_log, tmpdir: target_tmpdir)
end
rescue StandardError => e
UI.error("Error: #{e}\n" + "For details, check out: #{live_log.tee}".yellow.bold)
raise e unless Config.instance.ignore_build_errors?
end
end
end
|
#build_target(target: nil, sdks: nil, config: nil, out_dir: nil, **options) ⇒ Object
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
71
72
73
74
75
|
# File 'lib/xccache/spm/pkg/base.rb', line 43
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}"
cls = target.macro? ? Macro : XCFramework
cls.new(
name: target.name,
pkg_dir: root_dir,
config: config,
sdks: sdks,
path: binary_path,
tmpdir: options[:tmpdir],
pkg_desc: target_pkg_desc,
ctx_desc: pkg_desc || target_pkg_desc,
library_evolution: options[:library_evolution],
live_log: options[:live_log],
).build(**options)
return if (symlinks_dir = options[:symlinks_dir]).nil?
binary_path.symlink_to(symlinks_dir / target.name / "#{target.name}#{ext}")
end
|
#get_target(name) ⇒ Object
94
95
96
|
# File 'lib/xccache/spm/pkg/base.rb', line 94
def get_target(name)
pkg_desc_of_target(name)&.get_target(name)
end
|
#pkg_desc ⇒ Object
83
84
85
|
# File 'lib/xccache/spm/pkg/base.rb', line 83
def pkg_desc
descs_by_name[root_dir.basename.to_s]
end
|
#pkg_desc_of_target(name, **options) ⇒ Object
87
88
89
90
91
92
|
# File 'lib/xccache/spm/pkg/base.rb', line 87
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
77
78
79
80
81
|
# File 'lib/xccache/spm/pkg/base.rb', line 77
def resolve
return if @resolved
xccache_proxy.run("resolve --pkg #{root_dir} --metadata #{metadata_dir}")
@resolved = true
end
|