cocoapods-spm 0.1.5 → 0.1.7

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: 815b5b5db4530e4fd685d421cd33fb1cde41b29abfa667aa0ba9d3c1b61f8ef0
4
- data.tar.gz: 6befd92a1d7528b4da4a5f62a1f8676c8bfb8be0dd5cc65d8c134a7df01d5b01
3
+ metadata.gz: c4fe180c87aca4c93c0309f995109ef39507f5e5f82183a1e6e15d247e153a3b
4
+ data.tar.gz: 8f913beccd589a820ec92b4a5ef6af7c0373f3b878cd3e78eac18720e3383b8b
5
5
  SHA512:
6
- metadata.gz: abf5bf865306d931a1fbe53d230d17d80f62a1813a96b199c902c9f7da9dfc7ecbfff44eac5a3c7043ca73f856d66225c94f38d6ca5cf634f3b475d29f4a5476
7
- data.tar.gz: 87e9e3935e947420740e3bdbd2d4c8ca0f36c8ad955a9ab15b2d7756c6bf58dc37aa7a3b9378df75b4db60b30c2e1e1a8b666b19d547cbe5216c907a0f89607a
6
+ metadata.gz: '064788c5e4bbc60ebbcf3bb3f9334c8f30a75d1102c26181299978894e42554f9430adda3d1e7c8b17c9572f146e9a6fa3a0179f20db7be7cf1f95e9c31601b8'
7
+ data.tar.gz: 53adc8060fe965e1ef8566a8fbf1844ac9adbf3adddd93fcab6e52afd4750adb97273379247bbb3d13e5c5492622b2763c9b7e4682ee365cf96f706076ed7180
@@ -0,0 +1 @@
1
+ require_relative "rb26"
@@ -0,0 +1,14 @@
1
+ module Enumerable
2
+ unless method_defined?(:filter_map)
3
+ def filter_map
4
+ return enum_for(:filter_map) unless block_given?
5
+
6
+ result = []
7
+ each do |element|
8
+ value = yield(element)
9
+ result << value if value
10
+ end
11
+ result
12
+ end
13
+ end
14
+ end
@@ -49,6 +49,10 @@ module Pod
49
49
  end
50
50
  end
51
51
 
52
+ def platforms
53
+ @platforms ||= target_definition_list.filter_map { |d| d.platform&.name }.uniq || [:ios]
54
+ end
55
+
52
56
  private
53
57
 
54
58
  def prepare_macro_pod_dir(name, requirement)
@@ -55,6 +55,10 @@ module Pod
55
55
  @linking_opts.fetch(:use_default_xcode_linking, false)
56
56
  end
57
57
 
58
+ def should_exclude_from_target?(target_name)
59
+ @linking_opts.fetch(:exclude_from_targets, []).include?(target_name.delete_prefix('Pods-'))
60
+ end
61
+
58
62
  def linker_flags
59
63
  @linking_opts[:linker_flags] || []
60
64
  end
@@ -33,7 +33,7 @@ module Pod
33
33
 
34
34
  def add_spm_products_to_targets
35
35
  pods_project.targets.each do |target|
36
- @spm_resolver.result.spm_dependencies_by_target[target.name].to_a.each do |dep|
36
+ @spm_resolver.result.spm_dependencies_for(target).each do |dep|
37
37
  pkg_ref = spm_pkg_refs[dep.pkg.name]
38
38
  target_dep_ref = pkg_ref.create_target_dependency_ref(dep.product)
39
39
  target.dependencies << target_dep_ref
@@ -47,7 +47,7 @@ module Pod
47
47
  perform_settings_update(
48
48
  update_targets: lambda do |target, _, _|
49
49
  {
50
- "SOURCE_PACKAGES_CHECKOUTS_DIR" => "${PODS_CONFIGURATION_BUILD_DIR}/../../../SourcePackages/checkouts",
50
+ "SOURCE_PACKAGES_CHECKOUTS_DIR" => "${BUILD_ROOT}/../../SourcePackages/checkouts",
51
51
  "FRAMEWORK_SEARCH_PATHS" => "\"${PODS_CONFIGURATION_BUILD_DIR}/PackageFrameworks\"",
52
52
  "LIBRARY_SEARCH_PATHS" => "\"${PODS_CONFIGURATION_BUILD_DIR}\"",
53
53
  "SWIFT_INCLUDE_PATHS" => "$(PODS_CONFIGURATION_BUILD_DIR)",
@@ -0,0 +1,27 @@
1
+ module Pod
2
+ module SPM
3
+ module MacroConfigMixin
4
+ include Config::Mixin
5
+
6
+ def macro_downloaded_dir
7
+ spm_config.macro_downloaded_root_dir / name
8
+ end
9
+
10
+ def macro_dir
11
+ @macro_dir ||= spm_config.macro_root_dir / name
12
+ end
13
+
14
+ def macro_prebuilt_dir
15
+ spm_config.macro_prebuilt_root_dir / name
16
+ end
17
+
18
+ def metadata_path
19
+ macro_dir / "metadata.json"
20
+ end
21
+
22
+ def metadata
23
+ @metadata ||= MacroMetadata.for_pod(name)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,7 +1,10 @@
1
+ require "cocoapods-spm/macro/metadata"
2
+ require_relative "config"
3
+
1
4
  module Pod
2
5
  module SPM
3
6
  class MacroFetcher
4
- include Config::Mixin
7
+ include MacroConfigMixin
5
8
 
6
9
  attr_reader :name
7
10
 
@@ -13,6 +16,7 @@ module Pod
13
16
  end
14
17
 
15
18
  def run
19
+ UI.puts "Fetching macro #{name}...".magenta
16
20
  download_macro_source
17
21
  macro_dir = spm_config.macro_root_dir / name
18
22
  macro_downloaded_dir = spm_config.macro_downloaded_root_dir / name
@@ -20,6 +24,17 @@ module Pod
20
24
  macro_downloaded_dir / "Sources" / name,
21
25
  macro_dir / "Sources" / name
22
26
  )
27
+ generate_metadata
28
+ end
29
+
30
+ private
31
+
32
+ def generate_metadata
33
+ raise "Package.swift not exist in #{macro_downloaded_dir}" \
34
+ unless (macro_downloaded_dir / "Package.swift").exist?
35
+
36
+ raw = Dir.chdir(macro_downloaded_dir) { `swift package dump-package` }
37
+ metadata_path.write(raw)
23
38
  end
24
39
 
25
40
  def download_macro_source
@@ -4,7 +4,13 @@ module Pod
4
4
  module SPM
5
5
  class MacroMetadata < Swift::PackageDescription
6
6
  def self.for_pod(name)
7
- from_file(Config.instance.macro_root_dir / name / "metadata.json")
7
+ path = Config.instance.macro_root_dir / name / "metadata.json"
8
+ unless path.exist?
9
+ UI.message "Will fetch macro #{name} because its metadata does not exist at #{path}"
10
+ require "cocoapods-spm/macro/fetcher"
11
+ MacroFetcher.new(name: name, can_cache: true).run
12
+ end
13
+ from_file(path)
8
14
  end
9
15
  end
10
16
  end
@@ -1,9 +1,10 @@
1
1
  require "cocoapods-spm/macro/metadata"
2
+ require_relative "config"
2
3
 
3
4
  module Pod
4
5
  module SPM
5
6
  class MacroPrebuilder
6
- include Config::Mixin
7
+ include MacroConfigMixin
7
8
  include Executables
8
9
 
9
10
  attr_reader :name
@@ -13,40 +14,14 @@ module Pod
13
14
  end
14
15
 
15
16
  def run
16
- generate_metadata
17
17
  prebuild_macro_impl
18
18
  end
19
19
 
20
- def macro_downloaded_dir
21
- spm_config.macro_downloaded_root_dir / name
22
- end
23
-
24
- def macro_dir
25
- @macro_dir ||= spm_config.macro_root_dir / name
26
- end
27
-
28
- def macro_prebuilt_dir
29
- spm_config.macro_prebuilt_root_dir / name
30
- end
31
-
32
- def metadata_path
33
- macro_dir / "metadata.json"
34
- end
35
-
36
- def generate_metadata
37
- raise "Package.swift not exist in #{macro_downloaded_dir}" \
38
- unless (macro_downloaded_dir / "Package.swift").exist?
39
-
40
- raw = Dir.chdir(macro_downloaded_dir) { `swift package dump-package` }
41
- metadata_path.write(raw)
42
- @metadata = MacroMetadata.from_s(raw)
43
- end
44
-
45
20
  def prebuild_macro_impl
46
21
  return if spm_config.dont_prebuild_macros?
47
22
 
48
23
  config = spm_config.macro_config
49
- impl_module_name = @metadata.macro_impl_name
24
+ impl_module_name = metadata.macro_impl_name
50
25
  prebuilt_binary = macro_prebuilt_dir / "#{impl_module_name}-#{config}"
51
26
  return if spm_config.dont_prebuild_macros_if_exist? && prebuilt_binary.exist?
52
27
 
@@ -1,3 +1,4 @@
1
+ require "cocoapods-spm/compatibility/all"
1
2
  require "cocoapods-spm/helpers/io"
2
3
  require "cocoapods-spm/helpers/patch"
3
4
  require "cocoapods-spm/config"
@@ -28,7 +28,9 @@ module Pod
28
28
  @result.spm_dependencies_by_target.values.flatten.uniq(&:product).each do |dep|
29
29
  next if dep.pkg.use_default_xcode_linking?
30
30
 
31
- project_pkgs.resolve_recursive_targets_of(dep.pkg.name, dep.product)
31
+ @podfile.platforms.each do |platform|
32
+ project_pkgs.resolve_recursive_targets_of(dep.pkg.name, dep.product, platform: platform)
33
+ end
32
34
  end
33
35
  end
34
36
  end
@@ -31,12 +31,15 @@ module Pod
31
31
  end
32
32
 
33
33
  def spm_dependencies_for(target)
34
- @spm_dependencies_by_target[target.to_s].to_a
34
+ filtered_dependencies = @spm_dependencies_by_target[spec_name_of(target)]&.reject do |dep|
35
+ dep.pkg&.should_exclude_from_target?(target.name)
36
+ end
37
+ filtered_dependencies.to_a
35
38
  end
36
39
 
37
40
  def spm_targets_for(target, exclude_default_xcode_linking: true)
38
41
  targets = spm_dependencies_for(target).flat_map do |d|
39
- project_pkgs.resolve_recursive_targets_of(d.pkg.name, d.product)
42
+ project_pkgs.resolve_recursive_targets_of(d.pkg.name, d.product, platform: target.platform.name)
40
43
  end.uniq(&:name)
41
44
  return targets.reject(&:use_default_xcode_linking?) if exclude_default_xcode_linking
42
45
 
@@ -49,6 +52,21 @@ module Pod
49
52
  spm_pkgs_for(target).flat_map(&:linker_flags)
50
53
  ).uniq
51
54
  end
55
+
56
+ private
57
+
58
+ def spec_name_of(target)
59
+ # In case of multi-platforms, the target name might contains the platform (ex. Logger-iOS, Logger-macOS)
60
+ # We need to strip the platform suffix out
61
+ return target.name if @spm_dependencies_by_target.key?(target.name)
62
+ return target.root_spec.name if target.is_a?(Pod::PodTarget)
63
+ return target.name if target.is_a?(Pod::AggregateTarget)
64
+
65
+ cmps = target.name.split("-")
66
+ return cmps[...-1].join("-") if ["iOS", "macOS", "watchOS", "tvOS"].include?(cmps[-1])
67
+
68
+ target.name
69
+ end
52
70
  end
53
71
  end
54
72
  end
@@ -16,7 +16,7 @@ module Pod
16
16
  private
17
17
 
18
18
  def resolve_spm_pkgs
19
- @result.spm_pkgs = @podfile.target_definition_list.flat_map(&:spm_pkgs).uniq
19
+ @result.spm_pkgs = @podfile.target_definition_list.flat_map(&:spm_pkgs).uniq(&:name)
20
20
  end
21
21
 
22
22
  def resolve_spm_dependencies_by_target
@@ -5,7 +5,7 @@ module Pod
5
5
 
6
6
  def initialize(podfile)
7
7
  @podfile = podfile
8
- @spm_pkgs = @podfile.target_definition_list.flat_map(&:spm_pkgs).uniq
8
+ @spm_pkgs = @podfile.target_definition_list.flat_map(&:spm_pkgs).uniq(&:name)
9
9
  end
10
10
 
11
11
  def prepare
@@ -12,9 +12,10 @@ module Pod
12
12
  load
13
13
  end
14
14
 
15
- def resolve_recursive_targets_of(pkg_name, product_name)
15
+ def resolve_recursive_targets_of(pkg_name, product_name, platform: nil)
16
16
  @recursive_targets_cache ||= {}
17
- return @recursive_targets_cache[product_name] if @recursive_targets_cache.key(product_name)
17
+ @recursive_targets_cache[platform] ||= {}
18
+ return @recursive_targets_cache[platform][product_name] if @recursive_targets_cache[platform].key(product_name)
18
19
 
19
20
  res = []
20
21
  to_visit = pkg_desc_of(pkg_name).targets_of_product(product_name)
@@ -23,9 +24,9 @@ module Pod
23
24
  res << target
24
25
  # Exclude macros as they wont be linked to the project's binary
25
26
  # https://github.com/trinhngocthuyen/cocoapods-spm/issues/107
26
- to_visit += target.resolve_dependencies(@pkg_desc_cache).reject(&:macro?)
27
+ to_visit += target.resolve_dependencies(@pkg_desc_cache, platform: platform).reject(&:macro?)
27
28
  end
28
- @recursive_targets_cache[product_name] = res.uniq(&:name)
29
+ @recursive_targets_cache[platform][product_name] = res.uniq(&:name)
29
30
  end
30
31
 
31
32
  def pkg_desc_of(name)
@@ -35,11 +35,15 @@ module Pod
35
35
  end
36
36
  end
37
37
 
38
- def header_search_path_arg
39
- return nil if public_headers_path.nil?
38
+ def public_headers_path_expr
39
+ @public_headers_path_expr ||= public_headers_path.to_s.sub(
40
+ root.checkouts_dir.to_s,
41
+ "${SOURCE_PACKAGES_CHECKOUTS_DIR}"
42
+ )
43
+ end
40
44
 
41
- path = public_headers_path.to_s.sub(root.checkouts_dir.to_s, "${SOURCE_PACKAGES_CHECKOUTS_DIR}")
42
- "\"#{path}\""
45
+ def header_search_path_arg
46
+ "\"#{public_headers_path_expr}\"" unless public_headers_path.nil?
43
47
  end
44
48
 
45
49
  def public_headers_path
@@ -53,17 +57,18 @@ module Pod
53
57
  path unless path.glob("**/*.h*").empty?
54
58
  end
55
59
 
56
- def use_generated_modulemap?
57
- return false if public_headers_path.nil?
60
+ def modulemap_path
61
+ @modulemap_path ||= public_headers_path&.glob("*.modulemap")&.first
62
+ end
63
+
64
+ def clang_modulemap_path_expr
65
+ return "#{public_headers_path_expr}/#{modulemap_path.basename}" unless modulemap_path.nil?
58
66
 
59
- # If there exists module.modulemap, it'll be auto picked up during compilation
60
- true if public_headers_path.glob("module.modulemap").empty?
67
+ "${GENERATED_MODULEMAP_DIR}/#{name}.modulemap" unless binary?
61
68
  end
62
69
 
63
70
  def clang_modulemap_arg
64
- return nil unless use_generated_modulemap?
65
-
66
- "-fmodule-map-file=\"${GENERATED_MODULEMAP_DIR}/#{name}.modulemap\""
71
+ "-fmodule-map-file=\"#{clang_modulemap_path_expr}\"" unless clang_modulemap_path_expr.nil?
67
72
  end
68
73
 
69
74
  def resources
@@ -102,12 +107,13 @@ module Pod
102
107
  end
103
108
  end
104
109
 
105
- def resolve_dependencies(pkg_desc_cache)
110
+ def resolve_dependencies(pkg_desc_cache, platform: nil)
106
111
  raw.fetch("dependencies", []).flat_map do |hash|
107
112
  type = ["byName", "target", "product"].find { |k| hash.key?(k) }
108
113
  if type.nil?
109
114
  raise Informative, "Unexpected dependency type. Must be either `byName`, `target`, or `product`."
110
115
  end
116
+ next [] unless match_platform?(hash[type][-1], platform)
111
117
 
112
118
  name = hash[type][0]
113
119
  pkg_name = hash.key?("product") ? hash["product"][1] : self.pkg_name
@@ -148,6 +154,17 @@ module Pod
148
154
  def use_default_xcode_linking?
149
155
  root.use_default_xcode_linking?
150
156
  end
157
+
158
+ private
159
+
160
+ def match_platform?(condition, platform)
161
+ # Consider matching if there's no condition
162
+ return true if condition.nil? || !condition.key?("platformNames")
163
+
164
+ # macos is called osx in Cocoapods.
165
+ platform_name = platform.to_s == 'osx' ? 'macos' : platform.to_s
166
+ condition["platformNames"].include?(platform_name)
167
+ end
151
168
  end
152
169
  end
153
170
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-spm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thuyen Trinh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-31 00:00:00.000000000 Z
11
+ date: 2024-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -38,6 +38,8 @@ files:
38
38
  - lib/cocoapods-spm/command/macro/fetch.rb
39
39
  - lib/cocoapods-spm/command/macro/prebuild.rb
40
40
  - lib/cocoapods-spm/command/spm.rb
41
+ - lib/cocoapods-spm/compatibility/all.rb
42
+ - lib/cocoapods-spm/compatibility/rb26.rb
41
43
  - lib/cocoapods-spm/config.rb
42
44
  - lib/cocoapods-spm/config/pod.rb
43
45
  - lib/cocoapods-spm/config/project.rb
@@ -57,6 +59,7 @@ files:
57
59
  - lib/cocoapods-spm/hooks/post_integrate/5.update_settings.rb
58
60
  - lib/cocoapods-spm/hooks/post_integrate/6.update_embed_frameworks_script.rb
59
61
  - lib/cocoapods-spm/hooks/post_integrate/7.update_copy_resources_script.rb
62
+ - lib/cocoapods-spm/macro/config.rb
60
63
  - lib/cocoapods-spm/macro/fetcher.rb
61
64
  - lib/cocoapods-spm/macro/metadata.rb
62
65
  - lib/cocoapods-spm/macro/pod_installer.rb