xccache 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 31a523d3926f239135aaaebcc8c6cabe18da2a43e251e83edb486b13c22630e9
4
- data.tar.gz: 2997cc54f7b5a4c2395181d29f1042433b4d24d38aef98d8053555d52e4c518c
3
+ metadata.gz: ec431281d554462ef40e31a982b9198f5e0b3e8201fe26d97b29dc776595c9e6
4
+ data.tar.gz: 265f10b7ab38e2d2351e6b5b0e5f337bacbe64499263f4ce736131691646dc83
5
5
  SHA512:
6
- metadata.gz: 3d4d9014951e0e99cbfa57594831872404289522cf4943af250cba55e4b70f00567caa6d882b65d84b8825840aa279e0e6248dabfdc2a3e72ea8febd772ef532
7
- data.tar.gz: d0e4eda645edc09208c1a097eae6959145171975b48bcb778b02f3d0df22d99332fd1a1b326fafbfe425cdec0d9e45d3b07cfe8954482fddfaaf09f9be2d6f7a
6
+ metadata.gz: 50a9eaba6ffeb480fd36688171fb9c97852a500f466b6b95d700dda1a134129b784bc916799a970ec9262f64e74930f497c72adfe95c1ec78f31b5ca9bbf9e9c
7
+ data.tar.gz: 45b141c6b9136dfeacce7129956c2147f8e5a20e2427206509c144ed1ca543b79c7b36c81cd1f6369a97ee639d7ad024030382fc285d261b5fe0a691fdbe5203
@@ -28,28 +28,47 @@ module XCCache
28
28
  end
29
29
 
30
30
  def print_stats
31
- hit, missed, ignored = %i[hit missed ignored].map { |type| get_cache_data(type) }
32
- total_count = cache_data.count
33
- UI.message <<~DESC
34
- -------------------------------------------------------------------
35
- Cache stats
36
- Hit (#{hit.count}/#{total_count}): #{hit.to_s.green.dark}
37
- Missed (#{missed.count}/#{total_count}): #{missed.to_s.yellow.dark}
38
- Ignored (#{ignored.count}/#{total_count}): #{ignored.to_s.dark}
39
- -------------------------------------------------------------------
40
- DESC
31
+ verbose = Config.instance.verbose?
32
+ colors = { :hit => "green", :missed => "yellow" }
33
+ descs = %i[hit missed ignored].to_h do |type|
34
+ colorize = proc { |s| colors.key?(type) ? s.send(colors[type]).dark : s.dark }
35
+ items = get_cache_data(type)
36
+ percent = cache_data.count.positive? ? items.count.to_f / cache_data.count * 100 : 0
37
+ desc = "#{type} #{percent.round}% (#{items.count}/#{cache_data.count})"
38
+ desc = desc.capitalize if verbose
39
+ desc = "#{desc} #{colorize.call(items.to_s)}" if verbose && !items.empty?
40
+ [type, desc]
41
+ end
42
+ if verbose
43
+ UI.info <<~DESC
44
+ -------------------------------------------------------------------
45
+ Cache stats
46
+ #{descs.values.map { |s| "• #{s}" }.join("\n")}
47
+ -------------------------------------------------------------------
48
+ DESC
49
+ else
50
+ UI.info <<~DESC
51
+ -------------------------------------------------------------------
52
+ Cache stats: #{descs.values.join(', ')}
53
+ To see the full stats, use --verbose in the xccache command
54
+ -------------------------------------------------------------------
55
+ DESC
56
+ end
41
57
  end
42
58
 
43
59
  def get_cache_data(type)
44
- cache_data.select { |k, v| v == type && !k.end_with?(".xccache") }.keys
60
+ cache_data.select { |_, v| v == type }.keys
45
61
  end
46
62
 
47
63
  def update_from_graph(graph)
48
- cache_data = graph["cache"].to_h do |k, v|
49
- next [k, :hit] if v
50
- next [k, :ignored] if Config.instance.ignore?(k)
51
- [k, :missed]
52
- end
64
+ cache_data =
65
+ graph["cache"]
66
+ .reject { |k, _| k.end_with?(".xccache") }
67
+ .to_h do |k, v|
68
+ next [k, :hit] if v
69
+ next [k, :ignored] if Config.instance.ignore?(k)
70
+ [k, :missed]
71
+ end
53
72
 
54
73
  deps = graph["deps"]
55
74
  edges = deps.flat_map { |k, xs| xs.map { |v| { :source => k, :target => v } } }
@@ -40,11 +40,11 @@ module XCCache
40
40
  end
41
41
 
42
42
  def spm_local_pkgs_dir
43
- @spm_local_pkgs_dir ||= Dir.prepare(spm_sandbox / "local", clean: true)
43
+ @spm_local_pkgs_dir ||= Dir.prepare(spm_sandbox / "local")
44
44
  end
45
45
 
46
- def spm_xcconfig_dir
47
- @spm_xcconfig_dir ||= Dir.prepare(spm_sandbox / "xcconfigs", clean: true)
46
+ def spm_xcconfigs_dir
47
+ @spm_xcconfigs_dir ||= Dir.prepare(spm_sandbox / "xcconfigs")
48
48
  end
49
49
 
50
50
  def spm_cache_dir
@@ -52,7 +52,7 @@ module XCCache
52
52
  end
53
53
 
54
54
  def spm_binaries_dir
55
- @spm_binaries_dir ||= Dir.prepare(spm_sandbox / "binaries", clean: true)
55
+ @spm_binaries_dir ||= Dir.prepare(spm_sandbox / "binaries")
56
56
  end
57
57
 
58
58
  def spm_build_dir
@@ -10,7 +10,7 @@ module XCCache
10
10
  end
11
11
 
12
12
  def targets_to_build(options)
13
- items = options[:targets] || []
13
+ items = (options[:targets] || []).map { |x| File.basename(x) }
14
14
  items = config.cachemap.missed.map { |x| File.basename(x) } if items.empty?
15
15
  targets = items.map { |x| umbrella_pkg.get_target(x) }
16
16
 
@@ -11,7 +11,7 @@ module XCCache
11
11
 
12
12
  def gen_xcconfigs
13
13
  macros_config_by_targets.each do |target, hash|
14
- xcconfig_path = config.spm_xcconfig_dir / "#{target}.xcconfig"
14
+ xcconfig_path = config.spm_xcconfigs_dir / "#{target}.xcconfig"
15
15
  UI.message("XCConfig of target #{target} at: #{xcconfig_path}")
16
16
  Xcodeproj::Config.new(hash).save_as(xcconfig_path)
17
17
  end
@@ -17,6 +17,7 @@ module XCCache
17
17
 
18
18
  def perform_install
19
19
  verify_projects!
20
+ recreate_config_dirs
20
21
  projects.each { |project| migrate_umbrella_to_proxy(project) }
21
22
  UI.message("Using cache dir: #{config.spm_cache_dir}")
22
23
  config.ensure_file!
@@ -87,7 +88,8 @@ module XCCache
87
88
 
88
89
  def platforms_for_project(project)
89
90
  project
90
- .targets.map { |t| [t.platform_name.to_s, t.deployment_target] }
91
+ .targets.select(&:platform_name)
92
+ .map { |t| [t.platform_name.to_s, t.deployment_target] }
91
93
  .sort.reverse.to_h # sort descendingly -> min value is picked for the hash
92
94
  end
93
95
 
@@ -105,9 +107,9 @@ module XCCache
105
107
  end
106
108
 
107
109
  def inject_xcconfig_to_project(project)
108
- group = project.xccache_config_group.ensure_synced_group(name: "xcconfigs", path: config.spm_xcconfig_dir)
110
+ group = project.xccache_config_group.ensure_synced_group(name: "xcconfigs", path: config.spm_xcconfigs_dir)
109
111
  project.targets.each do |target|
110
- xcconfig_path = config.spm_xcconfig_dir / "#{target.name}.xcconfig"
112
+ xcconfig_path = config.spm_xcconfigs_dir / "#{target.name}.xcconfig"
111
113
  target.build_configurations.each do |build_config|
112
114
  if (existing = build_config.base_configuration_xcconfig)
113
115
  next if existing.path == xcconfig_path
@@ -144,5 +146,14 @@ module XCCache
144
146
  ref.path = "xccache/packages/proxy/Package.swift"
145
147
  end
146
148
  end
149
+
150
+ def recreate_config_dirs
151
+ [
152
+ config.spm_binaries_dir,
153
+ config.spm_local_pkgs_dir,
154
+ config.spm_xcconfigs_dir,
155
+ config.spm_metadata_dir,
156
+ ].each { |p| Dir.prepare(p, clean: true) }
157
+ end
147
158
  end
148
159
  end
@@ -9,12 +9,14 @@ module XCCache
9
9
  @module_name = @name.c99extidentifier
10
10
  @pkg_dir = Pathname(options[:pkg_dir] || ".").expand_path
11
11
  @pkg_desc = options[:pkg_desc]
12
+ @ctx_desc = options[:ctx_desc] # Context desc, could be an umbrella or a standalone pkg
12
13
  @sdks = options[:sdks] || []
13
14
  @sdk = options[:sdk] || @sdks&.first
14
15
  @config = options[:config] || "debug"
15
16
  @path = options[:path]
16
17
  @tmpdir = options[:tmpdir]
17
18
  @library_evolution = options[:library_evolution]
19
+ @sdks.each { |sdk| sdk.version = @ctx_desc.platforms[sdk.platform] } if @ctx_desc
18
20
  end
19
21
 
20
22
  def build(options = {})
@@ -41,7 +43,7 @@ module XCCache
41
43
  def swift_build_args
42
44
  [
43
45
  "--configuration", config,
44
- "--triple", sdk.triple,
46
+ "--triple", sdk.triple(with_version: true),
45
47
  ]
46
48
  end
47
49
 
@@ -19,6 +19,10 @@ module XCCache
19
19
  raw["_metadata"] ||= {}
20
20
  end
21
21
 
22
+ def platforms
23
+ @platforms ||= raw.fetch("platforms", []).to_h { |h| [h["platformName"].to_sym, h["version"]] }
24
+ end
25
+
22
26
  def dependencies
23
27
  @dependencies ||= fetch("dependencies", Dependency)
24
28
  end
@@ -62,6 +62,7 @@ module XCCache
62
62
  path: binary_path,
63
63
  tmpdir: tmpdir,
64
64
  pkg_desc: target_pkg_desc,
65
+ ctx_desc: pkg_desc || target_pkg_desc,
65
66
  library_evolution: options[:library_evolution],
66
67
  ).build(**options)
67
68
  end
@@ -75,6 +76,10 @@ module XCCache
75
76
  @resolved = true
76
77
  end
77
78
 
79
+ def pkg_desc
80
+ descs_by_name[root_dir.basename.to_s]
81
+ end
82
+
78
83
  def pkg_desc_of_target(name, **options)
79
84
  resolve
80
85
  desc = descs.find { |d| d.has_target?(name) }
@@ -30,7 +30,7 @@ module XCCache
30
30
  end
31
31
 
32
32
  def invalidate_cache(sdks: [])
33
- UI.message("Invalidating cache (sdks: #{sdks.map(&:name)})")
33
+ UI.message("Invalidating cache (sdks: #{sdks.map(&:to_s).join(', ')})")
34
34
 
35
35
  config.spm_cache_dir.glob("*/*.{xcframework,macro}").each do |p|
36
36
  cmps = p.basename(".*").to_s.split("-")
@@ -45,7 +45,7 @@ module XCCache
45
45
 
46
46
  # For regular targets, the xcframework must satisfy the sdk constraints (ie. containing all the slices)
47
47
  metadata = XCFramework::Metadata.new(p / "Info.plist")
48
- expected_triples = sdks.map { |sdk| sdk.triple(without_vendor: true) }
48
+ expected_triples = sdks.map { |sdk| sdk.triple(with_vendor: false) }
49
49
  missing_triples = expected_triples - metadata.triples
50
50
  missing_triples.empty? ? accept_cache.call : reject_cache.call
51
51
  end
@@ -33,14 +33,14 @@ module XCCache
33
33
  if use_clang?
34
34
  cmd = ["xcrun", "clang"]
35
35
  cmd << "-x" << "objective-c"
36
- cmd << "-target" << sdk.triple << "-isysroot" << sdk.sdk_path
36
+ cmd << "-target" << sdk.triple(with_version: true) << "-isysroot" << sdk.sdk_path
37
37
  cmd << "-o" << obj_path.to_s
38
38
  cmd << "-c" << source_path
39
39
  else
40
40
  cmd = ["xcrun", "swiftc"]
41
41
  cmd << "-emit-library" << "-emit-object"
42
42
  cmd << "-module-name" << module_name
43
- cmd << "-target" << sdk.triple << "-sdk" << sdk.sdk_path
43
+ cmd << "-target" << sdk.triple(with_version: true) << "-sdk" << sdk.sdk_path
44
44
  cmd << "-o" << obj_path.to_s
45
45
  cmd << source_path
46
46
  end
@@ -3,38 +3,45 @@ require "xccache/core/sh"
3
3
  module XCCache
4
4
  module Swift
5
5
  class Sdk
6
- attr_reader :name
7
-
8
- NAME_TO_TRIPLE = {
9
- :iphonesimulator => "arm64-apple-ios-simulator",
10
- :iphoneos => "arm64-apple-ios",
11
- :macos => "arm64-apple-macos",
12
- :watchos => "arm64-apple-watchos",
13
- :watchsimulator => "arm64-apple-watchos-simulator",
14
- :appletvos => "arm64-apple-tvos",
15
- :appletvsimulator => "arm64-apple-tvos-simulator",
16
- :xros => "arm64-apple-xros",
17
- :xrsimulator => "arm64-apple-xros-simulator",
6
+ attr_reader :name, :arch, :vendor, :platform
7
+ attr_accessor :version
8
+
9
+ NAME_TO_PLATFORM = {
10
+ :iphonesimulator => :ios,
11
+ :iphoneos => :ios,
12
+ :macos => :macos,
13
+ :watchos => :watchos,
14
+ :watchsimulator => :watchos,
15
+ :appletvos => :tvos,
16
+ :appletvsimulator => :tvos,
17
+ :xros => :xros,
18
+ :xrsimulator => :xros,
18
19
  }.freeze
19
20
 
20
- def initialize(name)
21
- @name = name
22
- return if NAME_TO_TRIPLE.key?(name.to_sym)
23
- raise GeneralError, "Unknown sdk: #{name}. Must be one of #{NAME_TO_TRIPLE.keys}"
21
+ def initialize(name, version: nil)
22
+ @name = name.to_sym
23
+ @vendor = "apple"
24
+ @arch = "arm64"
25
+ @platform = NAME_TO_PLATFORM.fetch(@name, @name)
26
+ @version = version
27
+ return if NAME_TO_PLATFORM.key?(@name)
28
+ raise GeneralError, "Unknown sdk: #{@name}. Must be one of #{NAME_TO_PLATFORM.keys}"
24
29
  end
25
30
 
26
31
  def to_s
27
- name
32
+ name.to_s
28
33
  end
29
34
 
30
- def triple(without_vendor: false)
31
- res = NAME_TO_TRIPLE[name.to_sym]
32
- res = res.sub("-apple", "") if without_vendor
33
- res
35
+ def triple(with_vendor: true, with_version: false)
36
+ cmps = [arch]
37
+ cmps << vendor if with_vendor
38
+ cmps << (with_version && version ? "#{platform}#{version}" : platform.to_s)
39
+ cmps << "simulator" if simulator?
40
+ cmps.join("-")
34
41
  end
35
42
 
36
43
  def sdk_name
37
- name == "macos" ? "macosx" : name
44
+ name == :macos ? :macosx : name
38
45
  end
39
46
 
40
47
  def sdk_path
@@ -56,6 +63,10 @@ module XCCache
56
63
  "-I#{developer_usr_lib_path}",
57
64
  ]
58
65
  end
66
+
67
+ def simulator?
68
+ name.to_s.end_with?("simulator")
69
+ end
59
70
  end
60
71
  end
61
72
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xccache
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thuyen Trinh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-06-03 00:00:00.000000000 Z
11
+ date: 2025-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide