cocoapods-spm 0.1.4 → 0.1.6

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: 922b55ffd54350ec1e1be78c273b0078acfcdf7bca7f29c87281367507ffcf13
4
- data.tar.gz: 9e0d2e7202e2d5486d92e039aae84b0caeb690b7c6e8c73a3b57110177ec8b14
3
+ metadata.gz: e1e1e2bd492fb8080c1d1d0ab60b4abe580d3540559ba11085b0b2a93826de54
4
+ data.tar.gz: 1a30fc92b2e7cdc5082f6fea26635f55345a9ae08d835450e66041028b862036
5
5
  SHA512:
6
- metadata.gz: c02a69fa12d098b6103d3eccb6dbf5b19ba50473b8c23913b6e5f17c9fd067c7fac3539c9a84264ba9a614c20771c4f641c0640a6c63a862aa2c5d7fc6e35154
7
- data.tar.gz: 5bafa557cfb91f192eaf0923e5e86503a490442104f102abd69a5b1e458395fcb1980394e0d4a65a567dd80f93bff1034ea118f37e09d2cf038dd8e83eaa4597
6
+ metadata.gz: f7941760c3ec1e4be209ba35108e80db527218f6862f1fd4ffa87cbfde60688bd9e1aa735193f2018abd77593d0e8c47bfe652a60c577391a758cff7b47c8ccb
7
+ data.tar.gz: 21df8075d35796d309ed868cbfe7f07b53c57c325c3e3a298b7eabab3239d658805a54d291ed6f9fdf3bc06605210940f55f636c6e362e1932e828e72ad77985
@@ -0,0 +1,31 @@
1
+ module Pod
2
+ class Command
3
+ class Spm < Command
4
+ class Clean < Spm
5
+ self.summary = "Clean caches"
6
+ def self.options
7
+ [
8
+ ["--all", "Clean all"],
9
+ ["--macros", "Clean macros"],
10
+ ["--packages", "Clean packages"],
11
+ ].concat(super)
12
+ end
13
+
14
+ def initialize(argv)
15
+ super
16
+ @clean_all = argv.flag?("all")
17
+ @clean_macros = argv.flag?("macros")
18
+ @clean_pkgs = argv.flag?("packages")
19
+ end
20
+
21
+ def run
22
+ to_clean = []
23
+ to_clean << spm_config.pkg_root_dir if @clean_pkgs
24
+ to_clean << spm_config.macro_root_dir if @clean_macros
25
+ to_clean << spm_config.root_dir if @clean_all
26
+ to_clean.each { |dir| dir.rmtree if dir.exist? }
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ module Pod
2
+ class Command
3
+ class Spm < Command
4
+ def self.bind_command(cls)
5
+ Class.new(Spm) do
6
+ define_method(:cls) { cls }
7
+
8
+ self.summary = "[Deprecated] #{cls.summary}"
9
+
10
+ def self.options
11
+ cls.options
12
+ end
13
+
14
+ def initialize(argv)
15
+ name = self.class.name.demodulize.downcase
16
+ warn "[DEPRECATION] `pod spm #{name}` is deprecated. Please use `pod spm macro #{name}` instead.".yellow
17
+ @_binded = cls.new(argv)
18
+ super
19
+ end
20
+
21
+ def validate!
22
+ @_binded.validate!
23
+ end
24
+
25
+ def run
26
+ @_binded.run
27
+ end
28
+ end
29
+ end
30
+
31
+ Fetch = bind_command(Macro::Fetch)
32
+ Prebuild = bind_command(Macro::Prebuild)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,33 @@
1
+ require "cocoapods-spm/macro/fetcher"
2
+
3
+ module Pod
4
+ class Command
5
+ class Spm < Command
6
+ class Macro < Spm
7
+ class Fetch < Macro
8
+ self.summary = "Fetch macros"
9
+ def self.options
10
+ [
11
+ ["--all", "Prebuild all macros"],
12
+ ["--macros=foo", "Macros to prebuild, separated by comma (,)"],
13
+ ].concat(super)
14
+ end
15
+
16
+ def initialize(argv)
17
+ super
18
+ update_cli_config(
19
+ all: argv.flag?("all"),
20
+ macros: argv.option("macros", "").split(",")
21
+ )
22
+ end
23
+
24
+ def run
25
+ spm_config.macros.each do |name|
26
+ SPM::MacroFetcher.new(name: name, can_cache: true).run
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ require "cocoapods-spm/macro/prebuilder"
2
+
3
+ module Pod
4
+ class Command
5
+ class Spm < Command
6
+ class Macro < Spm
7
+ class Prebuild < Macro
8
+ self.summary = "Prebuild macros"
9
+ def self.options
10
+ [
11
+ ["--all", "Prebuild all macros"],
12
+ ["--macros=foo", "Macros to prebuild, separated by comma (,)"],
13
+ ["--config=foo", "Config (debug/release) to prebuild macros"],
14
+ ].concat(super)
15
+ end
16
+
17
+ def initialize(argv)
18
+ super
19
+ update_cli_config(
20
+ all: argv.flag?("all"),
21
+ macros: argv.option("macros", "").split(","),
22
+ config: argv.option("config"),
23
+ dont_prebuild_macros: false,
24
+ dont_prebuild_macros_if_exist: false
25
+ )
26
+ end
27
+
28
+ def run
29
+ spm_config.macros.each do |name|
30
+ SPM::MacroPrebuilder.new(name: name).run
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,14 @@
1
+ require "cocoapods-spm/command/macro/fetch"
2
+ require "cocoapods-spm/command/macro/prebuild"
3
+ require "cocoapods-spm/command/macro/deprecated"
4
+
5
+ module Pod
6
+ class Command
7
+ class Spm < Command
8
+ class Macro < Spm
9
+ self.summary = "Working with macros"
10
+ self.abstract_command = true
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,5 +1,5 @@
1
- require "cocoapods-spm/command/prebuild"
2
- require "cocoapods-spm/command/fetch"
1
+ require "cocoapods-spm/command/macro"
2
+ require "cocoapods-spm/command/clean"
3
3
 
4
4
  module Pod
5
5
  class Command
@@ -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
@@ -58,19 +58,23 @@ module Pod
58
58
  end
59
59
 
60
60
  def macro_root_dir
61
- root_dir # To be updated: rootdir / "macros"
61
+ @macro_root_dir ||= prepare_dir(root_dir / "macros")
62
62
  end
63
63
 
64
64
  def macro_downloaded_root_dir
65
65
  macro_root_dir / ".downloaded"
66
66
  end
67
67
 
68
+ def macro_prebuilt_root_dir
69
+ macro_root_dir / ".prebuilt"
70
+ end
71
+
68
72
  def macro_downloaded_sandbox
69
73
  @macro_downloaded_sandbox ||= Sandbox.new(macro_downloaded_root_dir)
70
74
  end
71
75
 
72
76
  def pkg_umbrella_dir
73
- @pkg_umbrella_dir ||= prepare_dir(root_dir / ".umbrella")
77
+ @pkg_umbrella_dir ||= prepare_dir(pkg_root_dir / ".umbrella")
74
78
  end
75
79
 
76
80
  def pkg_checkouts_dir
@@ -18,7 +18,7 @@ module Pod
18
18
  macro = requirements[0].delete(:macro) if requirements.first.is_a?(Hash)
19
19
  macro ||= {}
20
20
  unless macro.empty?
21
- requirements[0][:path] = prepare_macro_pod_dir(name, macro)
21
+ requirements[0][:path] = prepare_macro_pod_dir(name, macro).to_s
22
22
  macro_pods[name] = macro
23
23
  end
24
24
  origin_pod(name, *requirements)
@@ -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)
@@ -67,8 +71,7 @@ module Pod
67
71
  end
68
72
  HEREDOC
69
73
 
70
- path = Pathname(".spm.pods/#{name}")
71
- (path / ".prebuilt").mkpath
74
+ path = Pod::SPM::Config.instance.macro_root_dir / name
72
75
  (path / "Sources").mkpath
73
76
  (path / "#{name}.podspec").write(podspec_content)
74
77
  path
@@ -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
@@ -0,0 +1,13 @@
1
+ module Pod
2
+ module IOUtils
3
+ def self.symlink(src, dst)
4
+ # NOTE: File operations are case-insensitive (foo.json and Foo.json are identical)
5
+ return if File.identical?(src, dst)
6
+
7
+ src = Pathname.new(src) unless src.is_a?(Pathname)
8
+ dst = Pathname.new(dst) unless dst.is_a?(Pathname)
9
+ dst.delete if dst.exist?
10
+ File.symlink(src.absolute? ? src : src.realpath, dst)
11
+ end
12
+ end
13
+ 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
@@ -7,22 +7,21 @@ module Pod
7
7
  class UpdateSettings < Hook
8
8
  def run
9
9
  update_macro_plugin_flags
10
- update_modulemap_flags
11
- update_swift_include_paths
12
- update_linker_flags
10
+ update_packages_flags
13
11
  end
14
12
 
15
13
  private
16
14
 
17
15
  def macro_plugin_flag_by_config
16
+ path_prefix = "${PODS_ROOT}/../#{spm_config.macro_prebuilt_root_dir}"
18
17
  @macro_plugin_flag_by_config ||= begin
19
18
  hash = user_build_configurations.keys.to_h do |config|
20
19
  flags = macro_pods.keys.map do |name|
21
20
  metadata = MacroMetadata.for_pod(name)
22
21
  impl_module_name = metadata.macro_impl_name
23
22
  plugin_executable_path =
24
- "${PODS_ROOT}/../.spm.pods/#{name}/.prebuilt/#{config.to_s.downcase}/" \
25
- "#{impl_module_name}##{impl_module_name}"
23
+ "#{path_prefix}/#{name}/" \
24
+ "#{impl_module_name}-#{config.to_s.downcase}##{impl_module_name}"
26
25
  "-load-plugin-executable \"#{plugin_executable_path}\""
27
26
  end.join(" ")
28
27
  [config, flags]
@@ -42,27 +41,20 @@ module Pod
42
41
  )
43
42
  end
44
43
 
45
- def update_modulemap_flags
46
- perform_settings_update(
47
- update_targets: lambda do |target, _, _|
48
- {
49
- "OTHER_SWIFT_FLAGS" => modulemap_args_for_target(target, prefix: "-Xcc"),
50
- "OTHER_CFLAGS" => modulemap_args_for_target(target),
51
- }
52
- end
53
- )
54
- end
55
-
56
- def update_linker_flags
44
+ def update_packages_flags
57
45
  return if @spm_resolver.result.spm_pkgs.empty?
58
46
 
59
- # For packages to work in the main target
60
47
  perform_settings_update(
61
48
  update_targets: lambda do |target, _, _|
62
49
  {
63
- "OTHER_LDFLAGS" => linker_flags_for(target),
50
+ "SOURCE_PACKAGES_CHECKOUTS_DIR" => "${BUILD_ROOT}/../../SourcePackages/checkouts",
64
51
  "FRAMEWORK_SEARCH_PATHS" => "\"${PODS_CONFIGURATION_BUILD_DIR}/PackageFrameworks\"",
65
52
  "LIBRARY_SEARCH_PATHS" => "\"${PODS_CONFIGURATION_BUILD_DIR}\"",
53
+ "SWIFT_INCLUDE_PATHS" => "$(PODS_CONFIGURATION_BUILD_DIR)",
54
+ "OTHER_SWIFT_FLAGS" => modulemap_args_for_target(target, prefix: "-Xcc"),
55
+ "OTHER_CFLAGS" => modulemap_args_for_target(target),
56
+ "HEADER_SEARCH_PATHS" => header_search_paths_for(target),
57
+ "OTHER_LDFLAGS" => linker_flags_for(target),
66
58
  }
67
59
  end
68
60
  )
@@ -74,16 +66,6 @@ module Pod
74
66
  @spm_resolver.result.linker_flags_for(target)
75
67
  end
76
68
 
77
- def update_swift_include_paths
78
- return if @spm_resolver.result.spm_pkgs.empty? && spm_config.all_macros.empty?
79
-
80
- perform_settings_update(
81
- update_targets: lambda do |_, _, _|
82
- { "SWIFT_INCLUDE_PATHS" => "$(PODS_CONFIGURATION_BUILD_DIR)" }
83
- end
84
- )
85
- end
86
-
87
69
  def modulemap_args_for_target(target, prefix: nil)
88
70
  @spm_resolver
89
71
  .result
@@ -92,6 +74,14 @@ module Pod
92
74
  .map { |v| prefix.nil? ? v : "#{prefix} #{v}" }
93
75
  .join(" ")
94
76
  end
77
+
78
+ def header_search_paths_for(target)
79
+ @spm_resolver
80
+ .result
81
+ .spm_targets_for(target)
82
+ .filter_map(&:header_search_path_arg)
83
+ .join(" ")
84
+ end
95
85
  end
96
86
  end
97
87
  end
@@ -26,7 +26,7 @@ module Pod
26
26
  end
27
27
 
28
28
  def macro_prebuilt_dir
29
- macro_dir / ".prebuilt"
29
+ spm_config.macro_prebuilt_root_dir / name
30
30
  end
31
31
 
32
32
  def metadata_path
@@ -47,7 +47,8 @@ module Pod
47
47
 
48
48
  config = spm_config.macro_config
49
49
  impl_module_name = @metadata.macro_impl_name
50
- return if spm_config.dont_prebuild_macros_if_exist? && (macro_prebuilt_dir / config / impl_module_name).exist?
50
+ prebuilt_binary = macro_prebuilt_dir / "#{impl_module_name}-#{config}"
51
+ return if spm_config.dont_prebuild_macros_if_exist? && prebuilt_binary.exist?
51
52
 
52
53
  UI.section "Building macro implementation: #{impl_module_name} (#{config})...".green do
53
54
  Dir.chdir(macro_downloaded_dir) do
@@ -55,10 +56,10 @@ module Pod
55
56
  end
56
57
  end
57
58
 
58
- (macro_prebuilt_dir / config).mkpath
59
+ prebuilt_binary.parent.mkpath
59
60
  FileUtils.copy_entry(
60
61
  macro_downloaded_dir / ".build" / config / impl_module_name,
61
- macro_prebuilt_dir / config / impl_module_name
62
+ prebuilt_binary
62
63
  )
63
64
  end
64
65
  end
@@ -1,3 +1,6 @@
1
+ require "cocoapods-spm/compatibility/all"
2
+ require "cocoapods-spm/helpers/io"
3
+ require "cocoapods-spm/helpers/patch"
1
4
  require "cocoapods-spm/config"
2
5
  require "cocoapods-spm/executables"
3
6
  require "cocoapods-spm/def/target_definition"
@@ -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
@@ -56,10 +56,15 @@ module Pod
56
56
  end
57
57
 
58
58
  def create_symlinks_to_local_pkgs
59
- @spm_pkgs.select(&:local?).each do |pkg|
60
- dst_dir = spm_config.pkg_checkouts_dir / pkg.slug
61
- dst_dir.delete if dst_dir.exist?
62
- File.symlink(pkg.absolute_path, dst_dir)
59
+ local_spm_pkgs = @spm_pkgs.select(&:local?)
60
+ symlinks = local_spm_pkgs.to_h { |p| [p.slug, p.absolute_path] }
61
+ local_spm_pkgs.each do |pkg|
62
+ pkg_desc = Swift::PackageDescription.from_dir(pkg.absolute_path)
63
+ pkg_desc.dependencies.select(&:local?).each { |d| symlinks[d.slug] = d.path }
64
+ end
65
+
66
+ symlinks.each do |slug, src_dir|
67
+ IOUtils.symlink(src_dir, spm_config.pkg_checkouts_dir / slug)
63
68
  end
64
69
  end
65
70
  end
@@ -0,0 +1,27 @@
1
+ require "cocoapods-spm/swift/package/base"
2
+
3
+ module Pod
4
+ module Swift
5
+ class PackageDescription
6
+ class Dependency < PackageDescriptionBaseObject
7
+ def local?
8
+ raw.key?("fileSystem")
9
+ end
10
+
11
+ def slug
12
+ hash["identity"]
13
+ end
14
+
15
+ def path
16
+ hash["path"]
17
+ end
18
+
19
+ private
20
+
21
+ def hash
22
+ raw.values.flatten[0] || {}
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -4,9 +4,15 @@ module Pod
4
4
  module Swift
5
5
  class PackageDescription < PackageDescriptionBaseObject
6
6
  include SPM::Config::Mixin
7
+ autoload :Dependency, "cocoapods-spm/swift/package/dependency"
7
8
  autoload :Target, "cocoapods-spm/swift/package/target"
8
9
  autoload :Product, "cocoapods-spm/swift/package/product"
9
10
 
11
+ def self.from_dir(dir)
12
+ raw = `swift package dump-package --package-path #{dir.shellescape}`
13
+ from_s(raw)
14
+ end
15
+
10
16
  def src_dir
11
17
  @src_dir ||= begin
12
18
  path = raw.fetch("packageKind", {}).fetch("root", [])[0]
@@ -14,6 +20,10 @@ module Pod
14
20
  end
15
21
  end
16
22
 
23
+ def checkouts_dir
24
+ src_dir.parent
25
+ end
26
+
17
27
  def artifacts_dir
18
28
  spm_config.pkg_artifacts_dir / slug
19
29
  end
@@ -22,12 +32,16 @@ module Pod
22
32
  src_dir.nil? ? name : src_dir.basename.to_s
23
33
  end
24
34
 
35
+ def dependencies
36
+ @dependencies ||= convert_field("dependencies", Dependency)
37
+ end
38
+
25
39
  def targets
26
- @targets ||= raw.fetch("targets", []).flat_map { |h| Target.new(h, parent: self) }
40
+ @targets ||= convert_field("targets", Target)
27
41
  end
28
42
 
29
43
  def products
30
- @products ||= raw.fetch("products", []).flat_map { |h| Product.new(h, parent: nil) }
44
+ @products ||= convert_field("products", Product)
31
45
  end
32
46
 
33
47
  def targets_of_product(name)
@@ -51,6 +65,12 @@ module Pod
51
65
  pkg = pod_config.podfile.spm_pkgs.find { |t| t.name == name }
52
66
  @use_default_xcode_linking = pkg&.use_default_xcode_linking?
53
67
  end
68
+
69
+ private
70
+
71
+ def convert_field(name, type)
72
+ raw.fetch(name, []).flat_map { |h| type.new(h, parent: self) }
73
+ end
54
74
  end
55
75
  end
56
76
  end
@@ -12,18 +12,21 @@ 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)
21
22
  until to_visit.empty?
22
23
  target = to_visit.pop
23
24
  res << target
24
- to_visit += target.resolve_dependencies(@pkg_desc_cache)
25
+ # Exclude macros as they wont be linked to the project's binary
26
+ # https://github.com/trinhngocthuyen/cocoapods-spm/issues/107
27
+ to_visit += target.resolve_dependencies(@pkg_desc_cache, platform: platform).reject(&:macro?)
25
28
  end
26
- @recursive_targets_cache[product_name] = res.uniq(&:name)
29
+ @recursive_targets_cache[platform][product_name] = res.uniq(&:name)
27
30
  end
28
31
 
29
32
  def pkg_desc_of(name)
@@ -38,17 +41,17 @@ module Pod
38
41
  @src_dir.glob("*").each do |dir|
39
42
  next if dir.glob("Package*.swift").empty?
40
43
 
41
- raw = Dir.chdir(dir) { `swift package dump-package` }
42
- pkg_desc = PackageDescription.from_s(raw)
43
- write_data = lambda do |name|
44
- @pkg_desc_cache[name] = pkg_desc
45
- (@json_dir / "#{name}.json").write(raw) unless @json_dir.nil?
46
- end
47
-
48
- pkg_name = pkg_desc.name
49
- pkg_slug = dir.basename.to_s
50
- write_data.call(pkg_name)
51
- write_data.call(pkg_slug) unless pkg_name == pkg_slug
44
+ pkg_desc = PackageDescription.from_dir(dir)
45
+ name = pkg_desc.name
46
+ slug = dir.basename.to_s
47
+ @pkg_desc_cache[name] = pkg_desc
48
+ @pkg_desc_cache[slug] = pkg_desc
49
+ next if @json_dir.nil?
50
+
51
+ json_path = @json_dir / "#{name}.json"
52
+ slug_json_path = @json_dir / "#{slug}.json"
53
+ json_path.write(pkg_desc.raw.to_json)
54
+ IOUtils.symlink(json_path, slug_json_path) unless name == slug
52
55
  end
53
56
  end
54
57
  end
@@ -28,18 +28,66 @@ module Pod
28
28
  @product_name || name
29
29
  end
30
30
 
31
+ def sources_path
32
+ @sources_path ||= begin
33
+ path = raw["path"] || "Sources/#{name}"
34
+ root.src_dir / path
35
+ end
36
+ end
37
+
38
+ def header_search_path_arg
39
+ return nil if public_headers_path.nil?
40
+
41
+ path = public_headers_path.to_s.sub(root.checkouts_dir.to_s, "${SOURCE_PACKAGES_CHECKOUTS_DIR}")
42
+ "\"#{path}\""
43
+ end
44
+
31
45
  def public_headers_path
32
- raw["publicHeadersPath"]
46
+ res = sources_path / raw["publicHeadersPath"] if raw.key?("publicHeadersPath")
47
+ res = implicit_public_headers if res.nil?
48
+ res
49
+ end
50
+
51
+ def implicit_public_headers
52
+ path = sources_path / "include"
53
+ path unless path.glob("**/*.h*").empty?
54
+ end
55
+
56
+ def use_generated_modulemap?
57
+ return false if public_headers_path.nil?
58
+
59
+ # If there exists module.modulemap, it'll be auto picked up during compilation
60
+ true if public_headers_path.glob("module.modulemap").empty?
33
61
  end
34
62
 
35
63
  def clang_modulemap_arg
36
- return nil if public_headers_path.nil?
64
+ return nil unless use_generated_modulemap?
37
65
 
38
66
  "-fmodule-map-file=\"${GENERATED_MODULEMAP_DIR}/#{name}.modulemap\""
39
67
  end
40
68
 
41
69
  def resources
42
- raw.fetch("resources", []).flat_map { |h| Resources.new(h, parent: self) }
70
+ res = raw.fetch("resources", []).flat_map { |h| Resources.new(h, parent: self) }
71
+ res = implicit_resources if res.empty?
72
+ res
73
+ end
74
+
75
+ def implicit_resources
76
+ target_sources_path = raw["path"] || "Sources/#{name}"
77
+ target_sources_path = root.src_dir / target_sources_path
78
+
79
+ # Refer to the following link for the implicit resources
80
+ # https://developer.apple.com/documentation/xcode/bundling-resources-with-a-swift-package#Add-resource-files
81
+ patterns = [
82
+ "*.xcassets",
83
+ "*.xib",
84
+ "*.storyboard",
85
+ "*.xcdatamodeld",
86
+ "*.lproj",
87
+ ]
88
+ return [] if patterns.all? { |p| target_sources_path.glob(p).empty? }
89
+
90
+ [Resources.new({}, parent: self)]
43
91
  end
44
92
 
45
93
  def linker_flags
@@ -48,18 +96,19 @@ module Pod
48
96
 
49
97
  case binary_basename
50
98
  when /(\S+)\.framework/ then ["-framework \"#{$1}\""]
51
- when /lib(\S+)\.a/ then ["-library \"#{$1}\""]
52
- when /(\S+\.a)/ then ["\"${PODS_CONFIGURATION_BUILD_DIR}/#{$1}\""]
99
+ when /lib(\S+)\.(a|dylib)/ then ["-l\"#{$1}\""]
100
+ when /(\S+\.(a|dylib))/ then ["\"${PODS_CONFIGURATION_BUILD_DIR}/#{$1}\""]
53
101
  else []
54
102
  end
55
103
  end
56
104
 
57
- def resolve_dependencies(pkg_desc_cache)
105
+ def resolve_dependencies(pkg_desc_cache, platform: nil)
58
106
  raw.fetch("dependencies", []).flat_map do |hash|
59
107
  type = ["byName", "target", "product"].find { |k| hash.key?(k) }
60
108
  if type.nil?
61
109
  raise Informative, "Unexpected dependency type. Must be either `byName`, `target`, or `product`."
62
110
  end
111
+ next [] unless match_platform?(hash[type][-1], platform)
63
112
 
64
113
  name = hash[type][0]
65
114
  pkg_name = hash.key?("product") ? hash["product"][1] : self.pkg_name
@@ -78,11 +127,21 @@ module Pod
78
127
  "${BUILT_PRODUCTS_DIR}/PackageFrameworks/#{framework_name}.framework"
79
128
  end
80
129
 
130
+ def xcframework
131
+ @xcframework ||= begin
132
+ path = (root.artifacts_dir / name).glob("*.xcframework")[0]
133
+ Xcode::XCFramework.new(name, path.realpath) unless path.nil?
134
+ end
135
+ end
136
+
81
137
  def binary_basename
82
138
  return nil unless binary?
83
139
 
84
140
  @binary_basename ||= begin
85
- paths = (root.artifacts_dir / name).glob("*.xcframework/*/*.{a,framework}")
141
+ xcframework_dir ||= (root.artifacts_dir / name).glob("*.xcframework")[0]
142
+ xcframework_dir ||= root.src_dir / raw["path"] if raw.key?("path")
143
+ paths = xcframework_dir.glob("*/*.{a,framework}")
144
+ UI.warn "Cannot detect binary_basename for #{name}" if paths.empty?
86
145
  paths[0].basename.to_s unless paths.empty?
87
146
  end
88
147
  end
@@ -90,6 +149,17 @@ module Pod
90
149
  def use_default_xcode_linking?
91
150
  root.use_default_xcode_linking?
92
151
  end
152
+
153
+ private
154
+
155
+ def match_platform?(condition, platform)
156
+ # Consider matching if there's no condition
157
+ return true if condition.nil? || !condition.key?("platformNames")
158
+
159
+ # macos is called osx in Cocoapods.
160
+ platform_name = platform.to_s == 'osx' ? 'macos' : platform.to_s
161
+ condition["platformNames"].include?(platform_name)
162
+ end
93
163
  end
94
164
  end
95
165
  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.4
4
+ version: 0.1.6
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-04-25 00:00:00.000000000 Z
11
+ date: 2024-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -32,9 +32,14 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - lib/cocoapods-spm.rb
35
- - lib/cocoapods-spm/command/fetch.rb
36
- - lib/cocoapods-spm/command/prebuild.rb
35
+ - lib/cocoapods-spm/command/clean.rb
36
+ - lib/cocoapods-spm/command/macro.rb
37
+ - lib/cocoapods-spm/command/macro/deprecated.rb
38
+ - lib/cocoapods-spm/command/macro/fetch.rb
39
+ - lib/cocoapods-spm/command/macro/prebuild.rb
37
40
  - lib/cocoapods-spm/command/spm.rb
41
+ - lib/cocoapods-spm/compatibility/all.rb
42
+ - lib/cocoapods-spm/compatibility/rb26.rb
38
43
  - lib/cocoapods-spm/config.rb
39
44
  - lib/cocoapods-spm/config/pod.rb
40
45
  - lib/cocoapods-spm/config/project.rb
@@ -46,6 +51,7 @@ files:
46
51
  - lib/cocoapods-spm/def/target_definition.rb
47
52
  - lib/cocoapods-spm/def/xcodeproj.rb
48
53
  - lib/cocoapods-spm/executables.rb
54
+ - lib/cocoapods-spm/helpers/io.rb
49
55
  - lib/cocoapods-spm/helpers/patch.rb
50
56
  - lib/cocoapods-spm/hooks/base.rb
51
57
  - lib/cocoapods-spm/hooks/helpers/update_script.rb
@@ -67,6 +73,7 @@ files:
67
73
  - lib/cocoapods-spm/resolver/umbrella_package.rb
68
74
  - lib/cocoapods-spm/resolver/validator.rb
69
75
  - lib/cocoapods-spm/swift/package/base.rb
76
+ - lib/cocoapods-spm/swift/package/dependency.rb
70
77
  - lib/cocoapods-spm/swift/package/description.rb
71
78
  - lib/cocoapods-spm/swift/package/product.rb
72
79
  - lib/cocoapods-spm/swift/package/project_packages.rb
@@ -1,31 +0,0 @@
1
- require "cocoapods-spm/macro/fetcher"
2
-
3
- module Pod
4
- class Command
5
- class Spm < Command
6
- class Fetch < Spm
7
- self.summary = "Fetch macros"
8
- def self.options
9
- [
10
- ["--all", "Prebuild all macros"],
11
- ["--macros=foo", "Macros to prebuild, separated by comma (,)"],
12
- ].concat(super)
13
- end
14
-
15
- def initialize(argv)
16
- super
17
- update_cli_config(
18
- all: argv.flag?("all"),
19
- macros: argv.option("macros", "").split(",")
20
- )
21
- end
22
-
23
- def run
24
- spm_config.macros.each do |name|
25
- SPM::MacroFetcher.new(name: name, can_cache: true).run
26
- end
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,35 +0,0 @@
1
- require "cocoapods-spm/macro/prebuilder"
2
-
3
- module Pod
4
- class Command
5
- class Spm < Command
6
- class Prebuild < Spm
7
- self.summary = "Prebuild macros"
8
- def self.options
9
- [
10
- ["--all", "Prebuild all macros"],
11
- ["--macros=foo", "Macros to prebuild, separated by comma (,)"],
12
- ["--config=foo", "Config (debug/release) to prebuild macros"],
13
- ].concat(super)
14
- end
15
-
16
- def initialize(argv)
17
- super
18
- update_cli_config(
19
- all: argv.flag?("all"),
20
- macros: argv.option("macros", "").split(","),
21
- config: argv.option("config"),
22
- dont_prebuild_macros: false,
23
- dont_prebuild_macros_if_exist: false
24
- )
25
- end
26
-
27
- def run
28
- spm_config.macros.each do |name|
29
- SPM::MacroPrebuilder.new(name: name).run
30
- end
31
- end
32
- end
33
- end
34
- end
35
- end