xcocoapods 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +6303 -0
  3. data/LICENSE +28 -0
  4. data/README.md +80 -0
  5. data/bin/pod +56 -0
  6. data/bin/sandbox-pod +168 -0
  7. data/lib/cocoapods.rb +73 -0
  8. data/lib/cocoapods/command.rb +175 -0
  9. data/lib/cocoapods/command/cache.rb +28 -0
  10. data/lib/cocoapods/command/cache/clean.rb +90 -0
  11. data/lib/cocoapods/command/cache/list.rb +69 -0
  12. data/lib/cocoapods/command/env.rb +66 -0
  13. data/lib/cocoapods/command/init.rb +128 -0
  14. data/lib/cocoapods/command/install.rb +45 -0
  15. data/lib/cocoapods/command/ipc.rb +19 -0
  16. data/lib/cocoapods/command/ipc/list.rb +40 -0
  17. data/lib/cocoapods/command/ipc/podfile.rb +31 -0
  18. data/lib/cocoapods/command/ipc/podfile_json.rb +30 -0
  19. data/lib/cocoapods/command/ipc/repl.rb +51 -0
  20. data/lib/cocoapods/command/ipc/spec.rb +29 -0
  21. data/lib/cocoapods/command/ipc/update_search_index.rb +24 -0
  22. data/lib/cocoapods/command/lib.rb +11 -0
  23. data/lib/cocoapods/command/lib/create.rb +105 -0
  24. data/lib/cocoapods/command/lib/lint.rb +121 -0
  25. data/lib/cocoapods/command/list.rb +39 -0
  26. data/lib/cocoapods/command/options/project_directory.rb +36 -0
  27. data/lib/cocoapods/command/options/repo_update.rb +34 -0
  28. data/lib/cocoapods/command/outdated.rb +140 -0
  29. data/lib/cocoapods/command/repo.rb +29 -0
  30. data/lib/cocoapods/command/repo/add.rb +103 -0
  31. data/lib/cocoapods/command/repo/lint.rb +82 -0
  32. data/lib/cocoapods/command/repo/list.rb +93 -0
  33. data/lib/cocoapods/command/repo/push.rb +281 -0
  34. data/lib/cocoapods/command/repo/remove.rb +36 -0
  35. data/lib/cocoapods/command/repo/update.rb +28 -0
  36. data/lib/cocoapods/command/setup.rb +103 -0
  37. data/lib/cocoapods/command/spec.rb +112 -0
  38. data/lib/cocoapods/command/spec/cat.rb +51 -0
  39. data/lib/cocoapods/command/spec/create.rb +283 -0
  40. data/lib/cocoapods/command/spec/edit.rb +87 -0
  41. data/lib/cocoapods/command/spec/env_spec.rb +53 -0
  42. data/lib/cocoapods/command/spec/lint.rb +137 -0
  43. data/lib/cocoapods/command/spec/which.rb +43 -0
  44. data/lib/cocoapods/command/update.rb +101 -0
  45. data/lib/cocoapods/config.rb +347 -0
  46. data/lib/cocoapods/core_overrides.rb +1 -0
  47. data/lib/cocoapods/downloader.rb +190 -0
  48. data/lib/cocoapods/downloader/cache.rb +233 -0
  49. data/lib/cocoapods/downloader/request.rb +86 -0
  50. data/lib/cocoapods/downloader/response.rb +16 -0
  51. data/lib/cocoapods/executable.rb +222 -0
  52. data/lib/cocoapods/external_sources.rb +57 -0
  53. data/lib/cocoapods/external_sources/abstract_external_source.rb +205 -0
  54. data/lib/cocoapods/external_sources/downloader_source.rb +30 -0
  55. data/lib/cocoapods/external_sources/path_source.rb +55 -0
  56. data/lib/cocoapods/external_sources/podspec_source.rb +54 -0
  57. data/lib/cocoapods/gem_version.rb +5 -0
  58. data/lib/cocoapods/generator/acknowledgements.rb +107 -0
  59. data/lib/cocoapods/generator/acknowledgements/markdown.rb +44 -0
  60. data/lib/cocoapods/generator/acknowledgements/plist.rb +94 -0
  61. data/lib/cocoapods/generator/app_target_helper.rb +244 -0
  62. data/lib/cocoapods/generator/bridge_support.rb +22 -0
  63. data/lib/cocoapods/generator/constant.rb +19 -0
  64. data/lib/cocoapods/generator/copy_resources_script.rb +230 -0
  65. data/lib/cocoapods/generator/dummy_source.rb +31 -0
  66. data/lib/cocoapods/generator/embed_frameworks_script.rb +215 -0
  67. data/lib/cocoapods/generator/header.rb +103 -0
  68. data/lib/cocoapods/generator/info_plist_file.rb +116 -0
  69. data/lib/cocoapods/generator/module_map.rb +99 -0
  70. data/lib/cocoapods/generator/prefix_header.rb +60 -0
  71. data/lib/cocoapods/generator/umbrella_header.rb +46 -0
  72. data/lib/cocoapods/hooks_manager.rb +132 -0
  73. data/lib/cocoapods/installer.rb +703 -0
  74. data/lib/cocoapods/installer/analyzer.rb +972 -0
  75. data/lib/cocoapods/installer/analyzer/analysis_result.rb +87 -0
  76. data/lib/cocoapods/installer/analyzer/locking_dependency_analyzer.rb +98 -0
  77. data/lib/cocoapods/installer/analyzer/pod_variant.rb +67 -0
  78. data/lib/cocoapods/installer/analyzer/pod_variant_set.rb +157 -0
  79. data/lib/cocoapods/installer/analyzer/podfile_dependency_cache.rb +54 -0
  80. data/lib/cocoapods/installer/analyzer/sandbox_analyzer.rb +240 -0
  81. data/lib/cocoapods/installer/analyzer/specs_state.rb +84 -0
  82. data/lib/cocoapods/installer/analyzer/target_inspection_result.rb +53 -0
  83. data/lib/cocoapods/installer/analyzer/target_inspector.rb +260 -0
  84. data/lib/cocoapods/installer/installation_options.rb +158 -0
  85. data/lib/cocoapods/installer/pod_source_installer.rb +202 -0
  86. data/lib/cocoapods/installer/pod_source_preparer.rb +77 -0
  87. data/lib/cocoapods/installer/podfile_validator.rb +139 -0
  88. data/lib/cocoapods/installer/post_install_hooks_context.rb +132 -0
  89. data/lib/cocoapods/installer/pre_install_hooks_context.rb +51 -0
  90. data/lib/cocoapods/installer/source_provider_hooks_context.rb +34 -0
  91. data/lib/cocoapods/installer/user_project_integrator.rb +250 -0
  92. data/lib/cocoapods/installer/user_project_integrator/target_integrator.rb +463 -0
  93. data/lib/cocoapods/installer/user_project_integrator/target_integrator/xcconfig_integrator.rb +146 -0
  94. data/lib/cocoapods/installer/xcode.rb +8 -0
  95. data/lib/cocoapods/installer/xcode/pods_project_generator.rb +416 -0
  96. data/lib/cocoapods/installer/xcode/pods_project_generator/aggregate_target_installer.rb +181 -0
  97. data/lib/cocoapods/installer/xcode/pods_project_generator/app_host_installer.rb +84 -0
  98. data/lib/cocoapods/installer/xcode/pods_project_generator/file_references_installer.rb +334 -0
  99. data/lib/cocoapods/installer/xcode/pods_project_generator/pod_target_installer.rb +777 -0
  100. data/lib/cocoapods/installer/xcode/pods_project_generator/pod_target_integrator.rb +116 -0
  101. data/lib/cocoapods/installer/xcode/pods_project_generator/target_installation_result.rb +86 -0
  102. data/lib/cocoapods/installer/xcode/pods_project_generator/target_installer.rb +256 -0
  103. data/lib/cocoapods/installer/xcode/pods_project_generator/target_installer_helper.rb +68 -0
  104. data/lib/cocoapods/installer/xcode/target_validator.rb +147 -0
  105. data/lib/cocoapods/open-uri.rb +33 -0
  106. data/lib/cocoapods/project.rb +414 -0
  107. data/lib/cocoapods/resolver.rb +585 -0
  108. data/lib/cocoapods/resolver/lazy_specification.rb +79 -0
  109. data/lib/cocoapods/sandbox.rb +404 -0
  110. data/lib/cocoapods/sandbox/file_accessor.rb +444 -0
  111. data/lib/cocoapods/sandbox/headers_store.rb +146 -0
  112. data/lib/cocoapods/sandbox/path_list.rb +220 -0
  113. data/lib/cocoapods/sandbox/pod_dir_cleaner.rb +85 -0
  114. data/lib/cocoapods/sandbox/podspec_finder.rb +23 -0
  115. data/lib/cocoapods/sources_manager.rb +157 -0
  116. data/lib/cocoapods/target.rb +261 -0
  117. data/lib/cocoapods/target/aggregate_target.rb +338 -0
  118. data/lib/cocoapods/target/build_settings.rb +1075 -0
  119. data/lib/cocoapods/target/pod_target.rb +559 -0
  120. data/lib/cocoapods/user_interface.rb +459 -0
  121. data/lib/cocoapods/user_interface/error_report.rb +187 -0
  122. data/lib/cocoapods/user_interface/inspector_reporter.rb +109 -0
  123. data/lib/cocoapods/validator.rb +981 -0
  124. metadata +533 -0
@@ -0,0 +1,30 @@
1
+ module Pod
2
+ module ExternalSources
3
+ # Provides support for fetching a specification file from a source handled
4
+ # by the downloader. Supports all the options of the downloader
5
+ #
6
+ # @note The podspec must be in the root of the repository and should have a
7
+ # name matching the one of the dependency.
8
+ #
9
+ class DownloaderSource < AbstractExternalSource
10
+ # @see AbstractExternalSource#fetch
11
+ #
12
+ def fetch(sandbox)
13
+ pre_download(sandbox)
14
+ end
15
+
16
+ # @see AbstractExternalSource#description
17
+ #
18
+ def description
19
+ strategy = Downloader.strategy_from_options(params)
20
+ options = params.dup
21
+ url = options.delete(strategy)
22
+ result = "from `#{url}`"
23
+ options.each do |key, value|
24
+ result << ", #{key} `#{value}`"
25
+ end
26
+ result
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,55 @@
1
+ module Pod
2
+ module ExternalSources
3
+ # Provides support for fetching a specification file from a path local to
4
+ # the machine running the installation.
5
+ #
6
+ class PathSource < AbstractExternalSource
7
+ # @see AbstractExternalSource#fetch
8
+ #
9
+ def fetch(sandbox)
10
+ title = "Fetching podspec for `#{name}` #{description}"
11
+ UI.titled_section(title, :verbose_prefix => '-> ') do
12
+ podspec = podspec_path
13
+ unless podspec.exist?
14
+ raise Informative, "No podspec found for `#{name}` in " \
15
+ "`#{declared_path}`"
16
+ end
17
+ store_podspec(sandbox, podspec, podspec.extname == '.json')
18
+ is_absolute = absolute?(declared_path)
19
+ sandbox.store_local_path(name, podspec, is_absolute)
20
+ sandbox.remove_checkout_source(name)
21
+ end
22
+ end
23
+
24
+ # @see AbstractExternalSource#description
25
+ #
26
+ def description
27
+ "from `#{declared_path}`"
28
+ end
29
+
30
+ private
31
+
32
+ # @!group Helpers
33
+
34
+ # @return [String] The path as declared by the user.
35
+ #
36
+ def declared_path
37
+ result = params[:path]
38
+ result.to_s if result
39
+ end
40
+
41
+ # @return [Pathname] The absolute path of the podspec.
42
+ #
43
+ def podspec_path
44
+ path = Pathname(normalized_podspec_path(declared_path))
45
+ path.exist? ? path : Pathname("#{path}.json")
46
+ end
47
+
48
+ # @return [Bool]
49
+ #
50
+ def absolute?(path)
51
+ Pathname(path).absolute? || path.to_s.start_with?('~')
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,54 @@
1
+ module Pod
2
+ module ExternalSources
3
+ # Provides support for fetching a specification file from an URL. Can be
4
+ # http, file, etc.
5
+ #
6
+ class PodspecSource < AbstractExternalSource
7
+ # @see AbstractExternalSource#fetch
8
+ #
9
+ def fetch(sandbox)
10
+ title = "Fetching podspec for `#{name}` #{description}"
11
+ UI.titled_section(title, :verbose_prefix => '-> ') do
12
+ podspec_path = Pathname(podspec_uri)
13
+ is_json = podspec_path.extname == '.json'
14
+ if podspec_path.exist?
15
+ store_podspec(sandbox, podspec_path, is_json)
16
+ else
17
+ require 'cocoapods/open-uri'
18
+ begin
19
+ open(podspec_uri) { |io| store_podspec(sandbox, io.read, is_json) }
20
+ rescue OpenURI::HTTPError => e
21
+ status = e.io.status.join(' ')
22
+ raise Informative, "Failed to fetch podspec for `#{name}` at `#{podspec_uri}`.\n Error: #{status}"
23
+ end
24
+ end
25
+ end
26
+ end
27
+
28
+ # @see AbstractExternalSource#description
29
+ #
30
+ def description
31
+ "from `#{params[:podspec]}`"
32
+ end
33
+
34
+ private
35
+
36
+ # @!group Helpers
37
+
38
+ # @return [String] The uri of the podspec appending the name of the file
39
+ # and expanding it if necessary.
40
+ #
41
+ # @note If the declared path is expanded only if the represents a path
42
+ # relative to the file system.
43
+ #
44
+ def podspec_uri
45
+ declared_path = params[:podspec].to_s
46
+ if declared_path =~ %r{^.+://}
47
+ declared_path
48
+ else
49
+ normalized_podspec_path(declared_path)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,5 @@
1
+ module Pod
2
+ # The version of the CocoaPods command line tool.
3
+ #
4
+ VERSION = '1.5.3'.freeze unless defined? Pod::VERSION
5
+ end
@@ -0,0 +1,107 @@
1
+ module Pod
2
+ module Generator
3
+ class Acknowledgements
4
+ # @return [Array<Class>] The classes of the acknowledgements generator
5
+ # subclasses.
6
+ #
7
+ def self.generators
8
+ [Plist, Markdown]
9
+ end
10
+
11
+ # @return [Array<Sandbox::FileAccessor>] the list of the file accessors
12
+ # for the specs of the target that needs to generate the
13
+ # acknowledgements.
14
+ #
15
+ attr_reader :file_accessors
16
+
17
+ # @param [Array<Sandbox::FileAccessor>] @see file_accessors.
18
+ #
19
+ def initialize(file_accessors)
20
+ @file_accessors = file_accessors
21
+ end
22
+
23
+ #-----------------------------------------------------------------------#
24
+
25
+ # !@group Configuration
26
+
27
+ # @return [String] The title of the acknowledgements file.
28
+ #
29
+ def header_title
30
+ 'Acknowledgements'
31
+ end
32
+
33
+ # @return [String] A text to present before listing the acknowledgements.
34
+ #
35
+ def header_text
36
+ 'This application makes use of the following third party libraries:'
37
+ end
38
+
39
+ # @return [String] The title of the foot notes.
40
+ #
41
+ def footnote_title
42
+ ''
43
+ end
44
+
45
+ # @return [String] the foot notes.
46
+ #
47
+ def footnote_text
48
+ 'Generated by CocoaPods - https://cocoapods.org'
49
+ end
50
+
51
+ #-----------------------------------------------------------------------#
52
+
53
+ private
54
+
55
+ # !@group Private methods
56
+
57
+ # @return [Array<Specification>] The root specifications for which the
58
+ # acknowledgements should be generated.
59
+ #
60
+ def specs
61
+ file_accessors.map { |accessor| accessor.spec.root }.uniq
62
+ end
63
+
64
+ # Returns the text of the license for the given spec.
65
+ #
66
+ # @param [Specification] spec
67
+ # the specification for which license is needed.
68
+ #
69
+ # @return [String] The text of the license.
70
+ # @return [Nil] If not license text could be found.
71
+ #
72
+ def license_text(spec)
73
+ return nil unless spec.license
74
+ text = spec.license[:text]
75
+ unless text
76
+ if license_file = spec.license[:file]
77
+ license_path = file_accessor(spec).root + license_file
78
+ if File.exist?(license_path)
79
+ text = IO.read(license_path)
80
+ else
81
+ UI.warn "Unable to read the license file `#{license_file}` " \
82
+ "for the spec `#{spec}`"
83
+ end
84
+ elsif license_file = file_accessor(spec).license
85
+ text = IO.read(license_file)
86
+ end
87
+ end
88
+ text
89
+ end
90
+
91
+ protected
92
+
93
+ # Returns the file accessor for the given spec.
94
+ #
95
+ # @param [Specification] spec
96
+ # the specification for which the file accessor is needed.
97
+ #
98
+ # @return [Sandbox::FileAccessor] The file accessor.
99
+ #
100
+ def file_accessor(spec)
101
+ file_accessors.find { |accessor| accessor.spec.root == spec }
102
+ end
103
+
104
+ #-----------------------------------------------------------------------#
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,44 @@
1
+ module Pod
2
+ module Generator
3
+ class Markdown < Acknowledgements
4
+ def self.path_from_basepath(path)
5
+ Pathname.new(path.dirname + "#{path.basename}.markdown")
6
+ end
7
+
8
+ def save_as(path)
9
+ file = File.new(path, 'w')
10
+ file.write(licenses)
11
+ file.close
12
+ end
13
+
14
+ # @return [String] The contents of the acknowledgements in Markdown format.
15
+ #
16
+ def generate
17
+ licenses
18
+ end
19
+
20
+ def title_from_string(string, level)
21
+ unless string.empty?
22
+ '#' * level << " #{string}"
23
+ end
24
+ end
25
+
26
+ def string_for_spec(spec)
27
+ if (license_text = license_text(spec))
28
+ "\n" << title_from_string(spec.name, 2) << "\n\n" << license_text << "\n"
29
+ end
30
+ end
31
+
32
+ def licenses
33
+ licenses_string = "#{title_from_string(header_title, 1)}\n#{header_text}\n"
34
+ specs.each do |spec|
35
+ if (license = string_for_spec(spec))
36
+ license = license.force_encoding('UTF-8') if license.respond_to?(:force_encoding)
37
+ licenses_string += license
38
+ end
39
+ end
40
+ licenses_string += "#{title_from_string(footnote_title, 2)}#{footnote_text}\n"
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,94 @@
1
+ require 'stringio'
2
+
3
+ module Pod
4
+ module Generator
5
+ class Plist < Acknowledgements
6
+ def self.path_from_basepath(path)
7
+ Pathname.new(path.dirname + "#{path.basename}.plist")
8
+ end
9
+
10
+ def save_as(path)
11
+ Xcodeproj::Plist.write_to_path(plist, path)
12
+ end
13
+
14
+ # @return [String] The contents of the plist
15
+ #
16
+ def generate
17
+ plist = Nanaimo::Plist.new(plist, :xml)
18
+ contents = StringIO.new
19
+ Nanaimo::Writer::XMLWriter.new(plist, :pretty => true, :output => contents, :strict => false).write
20
+ contents.string
21
+ end
22
+
23
+ def plist
24
+ {
25
+ :Title => plist_title,
26
+ :StringsTable => plist_title,
27
+ :PreferenceSpecifiers => licenses,
28
+ }
29
+ end
30
+
31
+ def plist_title
32
+ 'Acknowledgements'
33
+ end
34
+
35
+ def licenses
36
+ licences_array = [header_hash]
37
+ specs.each do |spec|
38
+ if (hash = hash_for_spec(spec))
39
+ licences_array << hash
40
+ end
41
+ end
42
+ licences_array << footnote_hash
43
+ end
44
+
45
+ def hash_for_spec(spec)
46
+ if (license = license_text(spec))
47
+ hash = {
48
+ :Type => 'PSGroupSpecifier',
49
+ :Title => sanitize_encoding(spec.name),
50
+ :FooterText => sanitize_encoding(license),
51
+ }
52
+ hash[:License] = sanitize_encoding(spec.license[:type]) if spec.license[:type]
53
+
54
+ hash
55
+ end
56
+ end
57
+
58
+ def header_hash
59
+ {
60
+ :Type => 'PSGroupSpecifier',
61
+ :Title => sanitize_encoding(header_title),
62
+ :FooterText => sanitize_encoding(header_text),
63
+ }
64
+ end
65
+
66
+ def footnote_hash
67
+ {
68
+ :Type => 'PSGroupSpecifier',
69
+ :Title => sanitize_encoding(footnote_title),
70
+ :FooterText => sanitize_encoding(footnote_text),
71
+ }
72
+ end
73
+
74
+ #-----------------------------------------------------------------------#
75
+
76
+ private
77
+
78
+ # !@group Private methods
79
+
80
+ # Returns the sanitized text with UTF-8 invalid characters eliminated.
81
+ #
82
+ # @param [String] text
83
+ # the text we want to sanitize.
84
+ #
85
+ # @return [String] The sanitized UTF-8 text.
86
+ #
87
+ def sanitize_encoding(text)
88
+ text.encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '')
89
+ end
90
+
91
+ #-----------------------------------------------------------------------#
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,244 @@
1
+ module Pod
2
+ module Generator
3
+ # Stores the common logic for creating app targets within projects including
4
+ # generating standard import and main files for app hosts.
5
+ #
6
+ module AppTargetHelper
7
+ # Adds a single app target to the given project with the provided name.
8
+ #
9
+ # @param [Project] project
10
+ # the Xcodeproj to generate the target into.
11
+ #
12
+ # @param [Symbol] platform
13
+ # the platform of the target. Can be `:ios` or `:osx`, etc.
14
+ #
15
+ # @param [String] deployment_target
16
+ # the deployment target for the platform.
17
+ #
18
+ # @param [String] name
19
+ # The name to use for the target, defaults to 'App'.
20
+ #
21
+ # @return [PBXNativeTarget] the new target that was created.
22
+ #
23
+ def self.add_app_target(project, platform, deployment_target, name = 'App')
24
+ project.new_target(:application, name, platform, deployment_target)
25
+ end
26
+
27
+ # Creates and links an import file for the given pod target and into the given native target.
28
+ #
29
+ # @param [Project] project
30
+ # the Xcodeproj to generate the target into.
31
+ #
32
+ # @param [PBXNativeTarget] target
33
+ # the native target to link the generated import file into.
34
+ #
35
+ # @param [PodTarget] pod_target
36
+ # the pod target to use for when generating the contents of the import file.
37
+ #
38
+ # @param [Symbol] platform
39
+ # the platform of the target. Can be `:ios` or `:osx`, etc.
40
+ #
41
+ # @param [String] name
42
+ # The name to use for the target, defaults to 'App'.
43
+ #
44
+ # @return [Array<PBXBuildFile>] the created build file references.
45
+ #
46
+ def self.add_app_project_import(project, target, pod_target, platform, name = 'App')
47
+ source_file = AppTargetHelper.create_app_import_source_file(project, pod_target, platform, name)
48
+ group = project[name] || project.new_group(name, name)
49
+ source_file_ref = group.new_file(source_file)
50
+ target.add_file_references([source_file_ref])
51
+ end
52
+
53
+ # Creates and links an empty Swift file for the given target.
54
+ #
55
+ # @param [Project] project
56
+ # the Xcodeproj to generate the target into.
57
+ #
58
+ # @param [PBXNativeTarget] target
59
+ # the native target to link the generated import file into.
60
+ #
61
+ # @param [String] name
62
+ # The name to use for the target, defaults to 'App'.
63
+ #
64
+ # @return [Array<PBXBuildFile>] the created build file references.
65
+ #
66
+ def self.add_empty_swift_file(project, target, name = 'App')
67
+ swift_file = project.path.dirname.+("#{name}/dummy.swift")
68
+ swift_file.parent.mkpath
69
+ File.write(swift_file, '')
70
+ group = project[name] || project.new_group(name, name)
71
+ swift_file_ref = group.new_file(swift_file)
72
+ target.add_file_references([swift_file_ref])
73
+ end
74
+
75
+ # Creates and links a default app host 'main.m' file.
76
+ #
77
+ # @param [Project] project
78
+ # the Xcodeproj to generate the target into.
79
+ #
80
+ # @param [PBXNativeTarget] target
81
+ # the native target to link the generated main file into.
82
+ #
83
+ # @param [Symbol] platform
84
+ # the platform of the target. Can be `:ios` or `:osx`, etc.
85
+ #
86
+ # @param [String] name
87
+ # The name to use for the target, defaults to 'App'.
88
+ #
89
+ # @return [Array<PBXBuildFile>] the created build file references.
90
+ #
91
+ def self.add_app_host_main_file(project, target, platform, name = 'App')
92
+ source_file = AppTargetHelper.create_app_host_main_file(project, platform, name)
93
+ source_file_ref = project.new_group(name, name).new_file(source_file)
94
+ target.add_file_references([source_file_ref])
95
+ end
96
+
97
+ # Adds the xctest framework search paths into the given target.
98
+ #
99
+ # @param [PBXNativeTarget] target
100
+ # the native target to add XCTest into.
101
+ #
102
+ # @return [void]
103
+ #
104
+ def self.add_xctest_search_paths(target)
105
+ target.build_configurations.each do |configuration|
106
+ search_paths = configuration.build_settings['FRAMEWORK_SEARCH_PATHS'] ||= '$(inherited)'
107
+ search_paths << ' "$(PLATFORM_DIR)/Developer/Library/Frameworks"'
108
+ end
109
+ end
110
+
111
+ # Adds the provided swift version into the given target.
112
+ #
113
+ # @param [PBXNativeTarget] target
114
+ # the native target to add the swift version into.
115
+ #
116
+ # @param [String] swift_version
117
+ # the swift version to set to.
118
+ #
119
+ # @return [void]
120
+ #
121
+ def self.add_swift_version(target, swift_version)
122
+ raise 'Cannot set empty Swift version to target.' if swift_version.blank?
123
+ target.build_configurations.each do |configuration|
124
+ configuration.build_settings['SWIFT_VERSION'] = swift_version
125
+ end
126
+ end
127
+
128
+ # Creates a default import file for the given pod target.
129
+ #
130
+ # @param [Project] project
131
+ # the Xcodeproj to generate the target into.
132
+ #
133
+ # @param [PodTarget] pod_target
134
+ # the pod target to use for when generating the contents of the import file.
135
+ #
136
+ # @param [Symbol] platform
137
+ # the platform of the target. Can be `:ios` or `:osx`, etc.
138
+ #
139
+ # @param [String] name
140
+ # The name of the folder to use and save the generated main file.
141
+ #
142
+ # @return [Pathname] the new source file that was generated.
143
+ #
144
+ def self.create_app_import_source_file(project, pod_target, platform, name = 'App')
145
+ language = pod_target.uses_swift? ? :swift : :objc
146
+
147
+ if language == :swift
148
+ source_file = project.path.dirname.+("#{name}/main.swift")
149
+ source_file.parent.mkpath
150
+ import_statement = pod_target.should_build? && pod_target.defines_module? ? "import #{pod_target.product_module_name}\n" : ''
151
+ source_file.open('w') { |f| f << import_statement }
152
+ else
153
+ source_file = project.path.dirname.+("#{name}/main.m")
154
+ source_file.parent.mkpath
155
+ import_statement = if pod_target.should_build? && pod_target.defines_module?
156
+ "@import #{pod_target.product_module_name};\n"
157
+ else
158
+ header_name = "#{pod_target.product_module_name}/#{pod_target.product_module_name}.h"
159
+ if pod_target.sandbox.public_headers.root.+(header_name).file?
160
+ "#import <#{header_name}>\n"
161
+ else
162
+ ''
163
+ end
164
+ end
165
+ source_file.open('w') do |f|
166
+ f << "@import Foundation;\n"
167
+ f << "@import UIKit;\n" if platform == :ios || platform == :tvos
168
+ f << "@import Cocoa;\n" if platform == :osx
169
+ f << "#{import_statement}int main() {}\n"
170
+ end
171
+ end
172
+ source_file
173
+ end
174
+
175
+ # Creates a default app host 'main.m' file.
176
+ #
177
+ # @param [Project] project
178
+ # the Xcodeproj to generate the target into.
179
+ #
180
+ # @param [Symbol] platform
181
+ # the platform of the target. Can be `:ios` or `:osx`.
182
+ #
183
+ # @param [String] name
184
+ # The name of the folder to use and save the generated main file.
185
+ #
186
+ # @return [Pathname] the new source file that was generated.
187
+ #
188
+ def self.create_app_host_main_file(project, platform, name = 'App')
189
+ source_file = project.path.dirname.+("#{name}/main.m")
190
+ source_file.parent.mkpath
191
+ source_file.open('w') do |f|
192
+ case platform
193
+ when :ios, :tvos
194
+ f << IOS_APP_HOST_MAIN_CONTENTS
195
+ when :osx
196
+ f << MACOS_APP_APP_HOST_MAIN_CONTENTS
197
+ end
198
+ end
199
+ source_file
200
+ end
201
+
202
+ IOS_APP_HOST_MAIN_CONTENTS = <<EOS.freeze
203
+ #import <Foundation/Foundation.h>
204
+ #import <UIKit/UIKit.h>
205
+
206
+ @interface CPTestAppHostAppDelegate : UIResponder <UIApplicationDelegate>
207
+
208
+ @property (nonatomic, strong) UIWindow *window;
209
+
210
+ @end
211
+
212
+ @implementation CPTestAppHostAppDelegate
213
+
214
+ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
215
+ {
216
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
217
+ self.window.rootViewController = [UIViewController new];
218
+
219
+ [self.window makeKeyAndVisible];
220
+
221
+ return YES;
222
+ }
223
+
224
+ @end
225
+
226
+ int main(int argc, char *argv[])
227
+ {
228
+ @autoreleasepool
229
+ {
230
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([CPTestAppHostAppDelegate class]));
231
+ }
232
+ }
233
+ EOS
234
+
235
+ MACOS_APP_APP_HOST_MAIN_CONTENTS = <<EOS.freeze
236
+ #import <Cocoa/Cocoa.h>
237
+
238
+ int main(int argc, const char * argv[]) {
239
+ return NSApplicationMain(argc, argv);
240
+ }
241
+ EOS
242
+ end
243
+ end
244
+ end