cocoapods-catalyst-support 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: fd48335575749960d7bd44d134e7baee612a6fb0f57f7b88b6269d3d5e9aac06
4
+ data.tar.gz: 95b1c1d1271bf1db00e1db8aedcbcd0ea1859f4e5029212466b201fb1c9d2091
5
+ SHA512:
6
+ metadata.gz: b51011609358a8ba97e54141b055b8e527df4de5209bf2d2dee06bbd31aebc87ccf9151c28be70f86399befc9acf8829bccfd0fdaff8389fe6a8c93595a23dd5
7
+ data.tar.gz: 21dcca268aebf42676ab90b27d3f02300f9c087179b47ccba8e62065b0ac0a601516fa31f738c5851867ec096c759408b2453059753e0fbfabb7ff52276d43e0
@@ -0,0 +1,18 @@
1
+ require 'cocoapods-catalyst-support/gem_version'
2
+ require 'cocoapods'
3
+
4
+ require 'cocoapods-catalyst-support/utils'
5
+ require 'cocoapods-catalyst-support/catalyst_configuration'
6
+
7
+ require 'cocoapods-catalyst-support/pod_dependency'
8
+ require 'cocoapods-catalyst-support/os_platform'
9
+
10
+ require 'cocoapods-catalyst-support/xcodeproj/abstract_target'
11
+ require 'cocoapods-catalyst-support/xcodeproj/native_target'
12
+ require 'cocoapods-catalyst-support/xcodeproj/target_dependency'
13
+
14
+ require 'cocoapods-catalyst-support/pod/pod_target'
15
+ require 'cocoapods-catalyst-support/pod/podfile'
16
+ require 'cocoapods-catalyst-support/pod/installer'
17
+
18
+ include CocoapodsCatalystSupport
@@ -0,0 +1,35 @@
1
+ require_relative 'utils'
2
+
3
+ module CocoapodsCatalystSupport
4
+
5
+ class CatalystConfiguration
6
+
7
+ attr_reader :ios_dependencies
8
+ attr_reader :mac_dependencies
9
+
10
+ def initialize
11
+ @ios_dependencies = Set.new
12
+ @mac_dependencies = Set.new
13
+ end
14
+
15
+ def ios name
16
+ mac_dependencies.delete name
17
+ ios_dependencies << name
18
+ end
19
+
20
+ def macos name
21
+ ios_dependencies.delete name
22
+ mac_dependencies << name
23
+ end
24
+
25
+ def verbose!
26
+ $verbose = true
27
+ end
28
+
29
+ end
30
+
31
+ end
32
+
33
+ module Pod
34
+ $catalyst_configuration = CocoapodsCatalystSupport::CatalystConfiguration.new
35
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-catalyst-support/command/catalyst'
@@ -0,0 +1,37 @@
1
+ require 'colorize'
2
+
3
+ module Pod
4
+ class Command
5
+ # This is an example of a cocoapods plugin adding a top-level subcommand
6
+ # to the 'pod' command.
7
+ #
8
+ # You can also create subcommands of existing or new commands. Say you
9
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
10
+ # (e.g. `pod list deprecated`), there are a few things that would need
11
+ # to change.
12
+ #
13
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
14
+ # the class to exist in the the Pod::Command::List namespace
15
+ # - change this class to extend from `List` instead of `Command`. This
16
+ # tells the plugin system that it is a subcommand of `list`.
17
+ # - edit `lib/cocoapods_plugins.rb` to require this file
18
+ #
19
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
20
+ # in the `plugins.json` file, once your plugin is released.
21
+ #
22
+ class Catalyst < Command
23
+ self.summary = 'Configure your catalyst dependencies'
24
+
25
+ self.description = <<-DESC
26
+ This plugin will set up your Podfile and create the necessary variables to configure your macCatalyst App.
27
+ See list of subcommands:
28
+ - `init`: Set up your Podfile to use `cocoapods-catalyst-support`
29
+ - `run`: Configure your catalyst dependencies
30
+ - `validate`: Validate your catalyst configuration
31
+ DESC
32
+
33
+ self.abstract_command = true
34
+ self.default_subcommand = 'run'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,18 @@
1
+ require 'cocoapods-catalyst-support/command_helpers'
2
+
3
+ include CocoapodsCatalystSupport
4
+
5
+ module Pod
6
+ class Command
7
+ class Catalyst
8
+ class Init < Catalyst
9
+ self.summary = 'Set up your Podfile to use `cocoapods-catalyst-support`'
10
+ self.arguments = []
11
+
12
+ def run
13
+ configure_podfile
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,13 @@
1
+ module Pod
2
+ class Command
3
+ class Catalyst
4
+ class Run < Catalyst
5
+ self.summary = 'Configure your catalyst dependencies.'
6
+ self.arguments = []
7
+ def run
8
+ system 'pod install'
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ require 'colorize'
2
+ require 'cocoapods-catalyst-support/command_helpers'
3
+
4
+ include CocoapodsCatalystSupport
5
+
6
+ module Pod
7
+ class Command
8
+ class Catalyst
9
+
10
+ class Validate < Catalyst
11
+
12
+ self.summary = 'Validate your catalyst configuration.'
13
+
14
+ self.description = <<-DESC
15
+ Verify that the catalyst configuration you've given in your Podfile is valid and follows the guidelines.
16
+ Note that this doesn't verify your configuration is correct but it's valid.
17
+ DESC
18
+
19
+ self.arguments = []
20
+
21
+ def run
22
+ begin
23
+ validate_podfile
24
+ rescue ValidationError => e
25
+ puts e.message
26
+ else
27
+ puts "Congratulations! Your catalyst configuration is valid.".green
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,123 @@
1
+ require 'colorize'
2
+ require_relative 'utils'
3
+
4
+ module CocoapodsCatalystSupport
5
+
6
+ class ValidationError < StandardError
7
+ end
8
+
9
+ Podfile = String
10
+
11
+ class Podfile
12
+ def pods
13
+ lookup 'pod'
14
+ end
15
+
16
+ def ios_pods
17
+ lookup 'ios'
18
+ end
19
+
20
+ def mac_pods
21
+ lookup 'macos'
22
+ end
23
+
24
+ def validate
25
+ errors = []
26
+ ios_failures = ios_pods.filter do |pod| !pods.include? pod end
27
+ unless ios_failures.empty?
28
+ errors << "- Unrecognized dependencies for iOS:\n#{ios_failures.map do |pod| " + #{pod}" end.join("\n") }".red
29
+ end
30
+
31
+ mac_failures = mac_pods.filter do |pod| !pods.include? pod end
32
+ unless mac_failures.empty?
33
+ errors << "- Unrecognized dependencies for macOS:\n#{mac_failures.map do |pod| " + #{pod}" end.join("\n") }".red
34
+ end
35
+
36
+ return errors
37
+ end
38
+
39
+ @private
40
+ def lookup key
41
+ results = scan(/^[\s]*#{key}\s+[('|")][\S]*[('|")]/).map do |match|
42
+ match.gsub!('/\s+/', ' ' )
43
+ pod_name = match.split(' ')[1]
44
+ pod_name.gsub! /[('|")]/, ''
45
+ pod_name
46
+ end
47
+ return results
48
+ end
49
+ end
50
+
51
+ def configure_podfile
52
+ podfile = File.read('Podfile')
53
+
54
+ unless podfile.include? "require 'cocoapods-catalyst-support'"
55
+ podfile = "require 'cocoapods-catalyst-support'\n\n" + podfile
56
+ end
57
+
58
+ config = ''
59
+ unless podfile.match(/catalyst_configuration\s+do/)
60
+ config += "\n# Configure your macCatalyst dependencies\n"
61
+ config += "catalyst_configuration do\n"
62
+ config += "\t# Uncomment the next line for a verbose output\n\t# verbose!\n\n"
63
+ config += "\t# ios '<pod_name>' # This dependency will only be available for iOS\n"
64
+ config += "\t# macos '<pod_name>' # This dependency will only be available for macOS\nend\n"
65
+ end
66
+
67
+ is_catalyst_configured = podfile.match(/post_install[\S\s]+installer[\S\s]configure_catalyst/)
68
+ changed = !(is_catalyst_configured && config.empty?)
69
+ unless podfile.match /post_install\s+do/
70
+ podfile += config
71
+ podfile += "\n# Configure your macCatalyst App\npost_install do |installer|\n\tinstaller.configure_catalyst\nend\n"
72
+ else
73
+ configure_line = (podfile.include? 'configure_catalyst') ? "" : "\n\tinstaller.configure_catalyst\n"
74
+ post_install_line = podfile.filter_lines do |line| line.include? 'post_install' end.first
75
+
76
+ if config.empty?
77
+ new_post_install_line = post_install_line + configure_line
78
+ else
79
+ new_post_install_line = "#{config}\n\n" + post_install_line + configure_line
80
+ end
81
+
82
+ podfile.gsub! post_install_line, new_post_install_line
83
+ end
84
+
85
+ unless podfile.nil?
86
+ File.open('Podfile', "w") { |file| file << podfile }
87
+ end
88
+
89
+ if changed
90
+ puts 'Done! Checkout your Podfile to start configuring your macCatalyst dependencies'
91
+ else
92
+ puts 'It seems your Podfile is ready. Go ahead and start configuring your macCatalyst dependencies'
93
+ end
94
+ end
95
+
96
+ def validate_podfile
97
+ podfile = File.read('Podfile')
98
+ errors = []
99
+
100
+ unless podfile.match(/require\s+[('|")]cocoapods-catalyst-support[('|")]/)
101
+ errors << "- Are you missing `require cocoapods-catalyst-support` in your Podfile".red
102
+ end
103
+
104
+ unless podfile.match(/catalyst_configuration\s+do/)
105
+ errors << "- Are you missing `require cocoapods-catalyst-support` in your Podfile".red
106
+ end
107
+
108
+ unless podfile.match(/post_install[\S\s]+installer[\S\s]configure_catalyst/)
109
+ errors << "- Are you calling `configure_catalyst` from `post_install` phase?".red
110
+ end
111
+
112
+ pod_errors = podfile.validate
113
+ unless pod_errors.empty?
114
+ errors << "#{pod_errors.reduce('') do |acc, s| "#{acc}\n#{s}" end }"
115
+ end
116
+
117
+ unless errors.empty?
118
+ raise ValidationError.new "Your catalyst configuration seems to have some errors:\n#{errors.join}"
119
+ end
120
+
121
+ end
122
+
123
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsCatalystSupport
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+ module CocoapodsCatalystSupport
2
+
3
+ class OSPlatform
4
+ attr_reader :name
5
+ attr_reader :sdk
6
+ attr_reader :sdk_root
7
+ attr_reader :filter
8
+
9
+ def self.ios
10
+ OSPlatform.new :ios, 'iphone*', 'iPhoneOS', 'ios'
11
+ end
12
+
13
+ def self.macos
14
+ OSPlatform.new :macos, 'macosx*', 'MacOS', 'maccatalyst'
15
+ end
16
+
17
+ def self.watchos
18
+ OSPlatform.new :watchos, 'watchos*', 'WatchOS', 'watchos'
19
+ end
20
+
21
+ def self.tvos
22
+ OSPlatform.new :tvos, 'appletvos*', 'AppleTVOS', 'tvos'
23
+ end
24
+
25
+ private
26
+ def initialize(name, sdk, sdk_root, filter)
27
+ @name = name
28
+ @sdk = sdk
29
+ @sdk_root = sdk_root
30
+ @filter = filter
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,122 @@
1
+ require 'colorize'
2
+
3
+ module Pod
4
+
5
+ class Installer
6
+
7
+ def configure_catalyst
8
+ catalyst_pods_to_remove = $catalyst_configuration.ios_dependencies
9
+ if !catalyst_pods_to_remove.empty?
10
+ remove_dependencies catalyst_pods_to_remove, OSPlatform.macos, OSPlatform.ios
11
+ end
12
+
13
+ ios_pods_to_remove = $catalyst_configuration.mac_dependencies
14
+ if !ios_pods_to_remove.empty?
15
+ remove_dependencies ios_pods_to_remove, OSPlatform.ios, OSPlatform.macos
16
+ end
17
+
18
+ unless ios_pods_to_remove.empty? && catalyst_pods_to_remove.empty?
19
+ puts "Catalyst => Done! Your Catalyst dependencies are ready to go".green
20
+ else
21
+ puts "Catalyst => Nothing to configure"
22
+ end
23
+ end
24
+
25
+ private
26
+ def remove_dependencies pod_names_to_remove, remove_platform, keep_platform
27
+
28
+ loggs "\n#### Configuring #{remove_platform.name} dependencies ####\n"
29
+
30
+ ###### Variable definition ######
31
+ all_pods = podfile.dependencies.flat_map do |d| [d.name, d.to_root_dependency.name] end.to_set.to_a.map do |s| s.sub('/', '') end
32
+ pod_names_to_remove = podfile.dependencies.filter do |d| pod_names_to_remove.include? d.name end.flat_map do |d| [d.name, d.to_root_dependency.name] end.map do |s| s.sub('/', '') end
33
+ pod_names_to_keep = all_pods.filter do |name| !pod_names_to_remove.include? name end
34
+ $verbose = (defined? podfile.debug) ? podfile.debug : $verbose
35
+
36
+ pod_names_to_keep = recursive_dependencies(pod_names_to_keep)
37
+ pod_targets_to_keep = pod_targets.filter do |pod| pod_names_to_keep.include? pod.module_name end # PodTarget
38
+
39
+ pod_names_to_remove = recursive_dependencies(pod_names_to_remove).filter do |name| !pod_names_to_keep.include? name end
40
+ pod_targets_to_remove = pod_targets.filter do |pod| pod_names_to_remove.include? pod.module_name end # PodTarget
41
+
42
+ loggs "\n#### Unsupported Libraries ####\n#{pod_names_to_remove}\n"
43
+
44
+ targets_to_remove = pods_project.targets.filter do |target| pod_names_to_remove.include?(target.module_name) end.filter do |target| target.platform_name == OSPlatform.ios.name end # AbstractTarget
45
+ pods_targets = pods_project.targets.filter do |target| target.name.start_with? "Pods-" end.filter do |target| target.platform_name == OSPlatform.ios.name end # AbstractTarget
46
+ targets_to_keep = pods_project.targets.filter do |target| !targets_to_remove.include?(target) && !pods_targets.include?(target) end.filter do |target| target.platform_name == OSPlatform.ios.name end # AbstractTarget
47
+
48
+ ###### Determine which dependencies should be removed ######
49
+ dependencies_to_keep = targets_to_keep.reduce([]) do |dependencies, target| dependencies + target.other_linker_flags_dependencies end
50
+ dependencies_to_keep = dependencies_to_keep + targets_to_keep.flat_map do |target| target.to_dependency end + pod_targets_to_keep.flat_map do |pod| pod.vendor_products + pod.frameworks end
51
+
52
+ dependencies_to_remove = targets_to_remove.reduce([]) do |dependencies, target| dependencies + target.other_linker_flags_dependencies end
53
+ dependencies_to_remove = dependencies_to_remove + targets_to_remove.flat_map do |target| target.to_dependency end + pod_targets_to_remove.flat_map do |pod| pod.vendor_products + pod.frameworks end
54
+ dependencies_to_remove = dependencies_to_remove.filter do |d| !dependencies_to_keep.include? d end
55
+
56
+ ###### CATALYST NOT SUPPORTED LINKS ######
57
+ unsupported_links = dependencies_to_remove.map do |d| d.link end.to_set.to_a
58
+
59
+ loggs "\n#### Unsupported dependencies ####\n"
60
+ loggs "#{dependencies_to_remove.map do |d| d.name end.to_set.to_a }\n\n"
61
+
62
+ ###### CATALYST NOT SUPPORTED FRAMEWORKS AND RESOURCES
63
+ frameworks_to_uninstall = dependencies_to_remove.filter do |d| d.type == :framework || d.type == :weak_framework end.map do |d| "#{d.name}.framework" end
64
+ resources_to_uninstall = pod_targets_to_remove.flat_map do |pod| pod.resources end.to_set.to_a
65
+
66
+ loggs "#### Frameworks not to be included in the Archive ####\n"
67
+ loggs "#{frameworks_to_uninstall}\n\n"
68
+
69
+ loggs "#### Resources not to be included in the Archive ####\n"
70
+ loggs "#{resources_to_uninstall}\n\n"
71
+
72
+ ###### OTHER LINKER FLAGS -> to iphone* ######
73
+ loggs "#### Flagging unsupported libraries ####"
74
+ pods_project.targets.filter do |target| target.platform_name == OSPlatform.ios.name end.each do |target| target.flag_libraries unsupported_links, keep_platform end
75
+
76
+ ###### BUILD_PHASES AND DEPENDENCIES -> PLATFORM_FILTER 'ios' ######
77
+ loggs "\n#### Filtering build phases ####"
78
+ targets_to_remove.filter do |target|
79
+ pods_project.native_targets.include? target
80
+ end.each do |target|
81
+ loggs "\tTarget: #{target.name}"
82
+ target.add_platform_filter_to_build_phases keep_platform
83
+ target.add_platform_filter_to_dependencies keep_platform
84
+ end
85
+
86
+ loggs "\n#### Filtering dependencies ####"
87
+ targets_to_remove.filter do |target|
88
+ !pods_project.native_targets.include? target
89
+ end.each do |target|
90
+ loggs "\tTarget: #{target.name}"
91
+ target.add_platform_filter_to_dependencies keep_platform
92
+ end
93
+
94
+ ###### FRAMEWORKS AND RESOURCES SCRIPT -> if [ "$SDKROOT" != "MacOS" ]; then #######
95
+ loggs "\n#### Changing frameworks and resources script ####"
96
+ pods_targets.each do |target|
97
+ loggs "\tTarget: #{target.name}"
98
+ loggs "\t\t-Uninstalling frameworks"
99
+ target.uninstall_frameworks frameworks_to_uninstall, remove_platform
100
+
101
+ loggs "\t\t-Uninstalling resources"
102
+ target.uninstall_resources resources_to_uninstall, remove_platform
103
+ end
104
+ end
105
+
106
+ def recursive_dependencies to_filter_names
107
+ targets = pods_project.targets
108
+ targets_to_remove = pods_project.targets.filter do |target| to_filter_names.include? target.module_name end
109
+ dependencies = targets_to_remove.flat_map do |target| target.dependencies end
110
+ dependencies_names = dependencies.map do |d| d.module_name end
111
+
112
+ if dependencies.empty?
113
+ return to_filter_names + dependencies_names
114
+ else
115
+ return to_filter_names + recursive_dependencies(dependencies_names)
116
+ end
117
+
118
+ end
119
+
120
+ end
121
+
122
+ end
@@ -0,0 +1,34 @@
1
+ module Pod
2
+ class PodTarget
3
+
4
+ #build_settings[:debug].other_ldflags
5
+ include CocoapodsCatalystSupport::TargetUtils
6
+
7
+ def resources
8
+ resources = file_accessors.flat_map do |accessor| accessor.resources end.map do |path| "#{path.basename}" end
9
+ bundles = file_accessors.flat_map do |accessor| accessor.resource_bundles end.flat_map do |dic| dic.keys end.map do |s| s + ".bundle" end
10
+ return resources + bundles
11
+ end
12
+
13
+ def vendor_products
14
+ return file_accessors.flat_map do |accessor|
15
+ accessor.vendored_frameworks + accessor.vendored_libraries
16
+ end.map do |s| s.basename
17
+ end.map do |s|
18
+ name = "#{s}"
19
+ if name.include? "framework"
20
+ PodDependency.newFramework name.sub(".framework", "").sub(".xcframework", "")
21
+ else
22
+ PodDependency.newLibrary name.sub("lib", "").sub(".a", "")
23
+ end
24
+ end
25
+ end
26
+
27
+ def frameworks
28
+ return file_accessors.flat_map do |accessor|
29
+ accessor.spec_consumer.frameworks.map do |name| PodDependency.newFramework name end + accessor.spec_consumer.libraries.map do |name| PodDependency.newLibrary name end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ require 'cocoapods-catalyst-support/catalyst_configuration.rb'
2
+
3
+ module Pod
4
+ class Podfile
5
+ module DSL
6
+ def catalyst_configuration &block
7
+ $catalyst_configuration.instance_eval &block
8
+ end
9
+
10
+ def debug!
11
+ $verbose = true
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,46 @@
1
+ module CocoapodsCatalystSupport
2
+
3
+ class PodDependency
4
+ attr_reader :name
5
+ attr_reader :type
6
+
7
+ def link
8
+ case type
9
+ when :weak_framework
10
+ return "-weak_framework \"#{name}\""
11
+ when :library
12
+ return "-l\"#{name}\""
13
+ else
14
+ return "-framework \"#{name}\""
15
+ end
16
+ end
17
+
18
+ def self.newWeakFramework name
19
+ return PodDependency.new(name, :weak_framework)
20
+ end
21
+
22
+ def self.newFramework name
23
+ return PodDependency.new(name, :framework)
24
+ end
25
+
26
+ def self.newLibrary name
27
+ return PodDependency.new(name, :library)
28
+ end
29
+
30
+ def ==(other)
31
+ (name == other.name) && (type == other.type)
32
+ end
33
+
34
+ def eql?(other)
35
+ self == other
36
+ end
37
+
38
+ private
39
+ def initialize(name, type)
40
+ @name = name
41
+ @type = type
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,31 @@
1
+ class String
2
+ def filter_lines
3
+ lines = []
4
+ each_line do |line|
5
+ if yield line
6
+ lines = lines + [line]
7
+ end
8
+ end
9
+ return lines
10
+ end
11
+ end
12
+
13
+ module CocoapodsCatalystSupport
14
+
15
+ $verbose = false
16
+
17
+ def loggs string
18
+ if $verbose
19
+ puts string
20
+ end
21
+ return
22
+ end
23
+
24
+ module TargetUtils
25
+ def module_name
26
+ string = name.clone.gsub! /(-(iOS([0-9]+(\.[0-9])?)*|library|framework))*$/, ''
27
+ return string.nil? ? name : string
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,69 @@
1
+ module Xcodeproj::Project::Object
2
+ class AbstractTarget
3
+
4
+ include CocoapodsCatalystSupport::TargetUtils
5
+
6
+ ###### STEP 2 ######
7
+ # In all targets (aggregates + native), filter dependencies
8
+ def add_platform_filter_to_dependencies platform
9
+ loggs "\t\t- Filtering dependencies"
10
+ dependencies.each do |dependency|
11
+ dependency.platform_filter = platform.name.to_s
12
+ end
13
+ end
14
+
15
+ ###### STEP 3 ######
16
+ # If any unsupported library, then flag as platform-dependant for every build configuration
17
+ def flag_libraries libraries, platform
18
+ loggs "\tTarget: #{name}"
19
+ build_configurations.filter do |config| !config.base_configuration_reference.nil?
20
+ end.each do |config|
21
+ loggs "\t\tScheme: #{config.name}"
22
+ xcconfig_path = config.base_configuration_reference.real_path
23
+ xcconfig = File.read(xcconfig_path)
24
+
25
+ changed = false
26
+ libraries.each do |framework|
27
+ if xcconfig.include? framework
28
+ xcconfig.gsub!(framework, '')
29
+ unless xcconfig.include? "OTHER_LDFLAGS[sdk=#{platform.sdk}]"
30
+ changed = true
31
+ xcconfig += "\nOTHER_LDFLAGS[sdk=#{platform.sdk}] = $(inherited) -ObjC "
32
+ end
33
+ xcconfig += framework + ' '
34
+ end
35
+ end
36
+
37
+ File.open(xcconfig_path, "w") { |file| file << xcconfig }
38
+ loggs "\t\t\t#{changed ? "Succeded" : "Nothing to flag"}"
39
+ end
40
+ end
41
+
42
+ def to_dependency
43
+ # We return both as we don't know if build as library or framework
44
+ return [PodDependency.newFramework(module_name), PodDependency.newLibrary(name)]
45
+ end
46
+
47
+ # Dependencies contained in Other Linker Flags
48
+ def other_linker_flags_dependencies
49
+ config = build_configurations.filter do |config| not config.base_configuration_reference.nil? end.first
50
+ other_ldflags = config.resolve_build_setting 'OTHER_LDFLAGS'
51
+
52
+ if other_ldflags.nil?
53
+ return []
54
+ end
55
+
56
+ if other_ldflags.class == String
57
+ other_ldflags = other_ldflags.split ' '
58
+ end
59
+
60
+ libraries = other_ldflags.filter do |flag| flag.start_with? '-l' end.map do |flag| flag.gsub! /(["|\-l]*)/, '' end.map do |name| PodDependency.newLibrary name end
61
+ mixed_frameworks = other_ldflags.filter do |flag| !flag.start_with? '-l' end
62
+
63
+ weak_frameworks = mixed_frameworks.length.times.filter do |i| mixed_frameworks[i].include? 'weak_framework' end.map do |i| PodDependency.newWeakFramework(mixed_frameworks[i+1].gsub! '"', '') end
64
+ frameworks = mixed_frameworks.length.times.select do |i| mixed_frameworks[i].match /^([^{weak_}]*)framework$/ end.map do |i| PodDependency.newFramework(mixed_frameworks[i+1].gsub! '"', '') end
65
+
66
+ return libraries + frameworks + weak_frameworks
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,92 @@
1
+ module Xcodeproj::Project::Object
2
+
3
+ class PBXNativeTarget
4
+
5
+ ###### STEP 4 ######
6
+ # In "Pods-" targets, modify "*frameworks.sh" to not install unsupported frameworks for SDK
7
+ def uninstall_frameworks frameworks, platform
8
+ uninstall frameworks, "#{name}-frameworks.sh", platform.sdk_root
9
+ end
10
+
11
+ ###### STEP 5 ######
12
+ # In "Pods-" targets, modify "*resources.sh" to not install unsupported resources for SDK
13
+ def uninstall_resources resources, platform
14
+ uninstall resources, "#{name}-resources.sh", platform.sdk_root
15
+ end
16
+
17
+ def support_files_folder
18
+ build_configurations.filter do |config| not config.base_configuration_reference.nil? end.first.base_configuration_reference.real_path.parent
19
+ end
20
+
21
+ @private
22
+ def uninstall keys, file_name, sdk_root
23
+ configurations = build_configurations.map do |b| b.name end
24
+ keys = keys.to_set.to_a
25
+ loggs "\t\t\tUninstalling for configurations: #{configurations}"
26
+ if support_files_folder.nil?
27
+ loggs "\t\t\tNothing to uninstall"
28
+ return
29
+ end
30
+
31
+ script_path = support_files_folder.join file_name
32
+ if !script_path.exist?
33
+ loggs "\t\t\tNothing to uninstall"
34
+ return
35
+ end
36
+
37
+ script = File.read(script_path)
38
+ snippets = script.scan(/if \[\[ \"\$CONFIGURATION\" [\S\s]*?(?=fi\n)fi/)
39
+ archs_condition = "[[ \"$SDKROOT\" != *\"#{sdk_root}\"* ]]"
40
+ file_condition_format = 'if [ -d "%s" ]; then'
41
+ changed = false
42
+
43
+ snippets.each do |snippet|
44
+ new_snippet = snippet.clone
45
+ should_uninstall = configurations.map do |string| snippet.include? string end.reduce(false) do |total, condition| total = total || condition end
46
+ keys.each do |key|
47
+ lines_to_replace = snippet.filter_lines do |line| line.include? "#{key}" end.to_set.to_a
48
+ unless lines_to_replace.empty?
49
+ changed = true
50
+ lines_to_replace.each do |line|
51
+ if should_uninstall
52
+ new_snippet.gsub! line, "\tif #{archs_condition}; then \n\t#{line}\tfi\n"
53
+ elsif file_name.include? 'resources'
54
+ path = line.scan(/[^(install_resource| |")].*[^*("|\n)]/).first
55
+ file_condition = file_condition_format % path
56
+ new_snippet.gsub! line, "\t#{file_condition} \n\t#{line}\tfi\n"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ script.gsub! snippet, new_snippet
62
+ end
63
+
64
+ if changed
65
+ File.open(script_path, "w") { |file| file << script }
66
+ end
67
+ loggs "\t\t\t#{changed ? "Succeded" : "Nothing to uninstall"}"
68
+ end
69
+
70
+ ###### STEP 1 ######
71
+ # In native target's build phases, add platform filter to:
72
+ # - Resources
73
+ # - Compile Sources
74
+ # - Frameworks
75
+ # - Headers
76
+ def add_platform_filter_to_build_phases platform
77
+ loggs "\t\t- Filtering resources"
78
+ resources_build_phase.files.to_a.map do |build_file| build_file.platform_filter = platform.filter end
79
+
80
+ loggs "\t\t- Filtering compile sources"
81
+ source_build_phase.files.to_a.map do |build_file| build_file.platform_filter = platform.filter end
82
+
83
+ loggs "\t\t- Filtering frameworks"
84
+ frameworks_build_phase.files.to_a.map do |build_file| build_file.platform_filter = platform.filter end
85
+
86
+ loggs "\t\t- Filtering headers"
87
+ headers_build_phase.files.to_a.map do |build_file| build_file.platform_filter = platform.filter end
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,5 @@
1
+ module Xcodeproj::Project::Object
2
+ class PBXTargetDependency
3
+ include CocoapodsCatalystSupport::TargetUtils
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'cocoapods-catalyst-support/command'
2
+ require 'cocoapods-catalyst-support/command/catalyst/init'
3
+ require 'cocoapods-catalyst-support/command/catalyst/validate'
4
+ require 'cocoapods-catalyst-support/command/catalyst/run'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-catalyst-support
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - fermoya
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cocoapods
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: Helps you configure your Catalyst dependencies.
70
+ email:
71
+ - fmdr.ct@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/cocoapods-catalyst-support.rb
77
+ - lib/cocoapods-catalyst-support/catalyst_configuration.rb
78
+ - lib/cocoapods-catalyst-support/command.rb
79
+ - lib/cocoapods-catalyst-support/command/catalyst.rb
80
+ - lib/cocoapods-catalyst-support/command/catalyst/init.rb
81
+ - lib/cocoapods-catalyst-support/command/catalyst/run.rb
82
+ - lib/cocoapods-catalyst-support/command/catalyst/validate.rb
83
+ - lib/cocoapods-catalyst-support/command_helpers.rb
84
+ - lib/cocoapods-catalyst-support/gem_version.rb
85
+ - lib/cocoapods-catalyst-support/os_platform.rb
86
+ - lib/cocoapods-catalyst-support/pod/installer.rb
87
+ - lib/cocoapods-catalyst-support/pod/pod_target.rb
88
+ - lib/cocoapods-catalyst-support/pod/podfile.rb
89
+ - lib/cocoapods-catalyst-support/pod_dependency.rb
90
+ - lib/cocoapods-catalyst-support/utils.rb
91
+ - lib/cocoapods-catalyst-support/xcodeproj/abstract_target.rb
92
+ - lib/cocoapods-catalyst-support/xcodeproj/native_target.rb
93
+ - lib/cocoapods-catalyst-support/xcodeproj/target_dependency.rb
94
+ - lib/cocoapods_plugin.rb
95
+ homepage: https://github.com/fermoya/CatalystPodSupport
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '2.6'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.0.3
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Many libraries you may use for iOS won't compile for your macCatalyst App,
118
+ thus, making porting your App to the Mac world more difficult than initially expected.
119
+ This is due to those libraries not being compiled for `x86_64`. `cocoapods-catalyst-support`
120
+ helps you configure which libraries you'll be using for iOS and which for macCatalyst.
121
+ test_files: []