cocoapods-fy-bin 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +22 -0
  3. data/README.md +1 -0
  4. data/lib/cocoapods-fy-bin/command/bin/archive.rb +202 -0
  5. data/lib/cocoapods-fy-bin/command/bin/auto.rb +204 -0
  6. data/lib/cocoapods-fy-bin/command/bin/code.rb +232 -0
  7. data/lib/cocoapods-fy-bin/command/bin/imy.rb +46 -0
  8. data/lib/cocoapods-fy-bin/command/bin/init.rb +69 -0
  9. data/lib/cocoapods-fy-bin/command/bin/initHotKey.rb +70 -0
  10. data/lib/cocoapods-fy-bin/command/bin/install.rb +44 -0
  11. data/lib/cocoapods-fy-bin/command/bin/lib/lint.rb +69 -0
  12. data/lib/cocoapods-fy-bin/command/bin/repo/update.rb +43 -0
  13. data/lib/cocoapods-fy-bin/command/bin/spec/create.rb +73 -0
  14. data/lib/cocoapods-fy-bin/command/bin/spec/push.rb +114 -0
  15. data/lib/cocoapods-fy-bin/command/bin/update.rb +154 -0
  16. data/lib/cocoapods-fy-bin/command/bin.rb +59 -0
  17. data/lib/cocoapods-fy-bin/command.rb +2 -0
  18. data/lib/cocoapods-fy-bin/config/config.rb +137 -0
  19. data/lib/cocoapods-fy-bin/config/config_asker.rb +57 -0
  20. data/lib/cocoapods-fy-bin/config/config_builder.rb +228 -0
  21. data/lib/cocoapods-fy-bin/config/config_hot_key.rb +103 -0
  22. data/lib/cocoapods-fy-bin/config/config_hot_key_asker.rb +57 -0
  23. data/lib/cocoapods-fy-bin/gem_version.rb +10 -0
  24. data/lib/cocoapods-fy-bin/helpers/build_helper.rb +164 -0
  25. data/lib/cocoapods-fy-bin/helpers/build_utils.rb +63 -0
  26. data/lib/cocoapods-fy-bin/helpers/framework.rb +94 -0
  27. data/lib/cocoapods-fy-bin/helpers/framework_builder.rb +419 -0
  28. data/lib/cocoapods-fy-bin/helpers/library.rb +54 -0
  29. data/lib/cocoapods-fy-bin/helpers/library_builder.rb +91 -0
  30. data/lib/cocoapods-fy-bin/helpers/sources_helper.rb +36 -0
  31. data/lib/cocoapods-fy-bin/helpers/spec_creator.rb +170 -0
  32. data/lib/cocoapods-fy-bin/helpers/spec_files_helper.rb +77 -0
  33. data/lib/cocoapods-fy-bin/helpers/spec_source_creator.rb +229 -0
  34. data/lib/cocoapods-fy-bin/helpers/upload_helper.rb +97 -0
  35. data/lib/cocoapods-fy-bin/helpers.rb +5 -0
  36. data/lib/cocoapods-fy-bin/native/acknowledgements.rb +27 -0
  37. data/lib/cocoapods-fy-bin/native/analyzer.rb +55 -0
  38. data/lib/cocoapods-fy-bin/native/file_accessor.rb +28 -0
  39. data/lib/cocoapods-fy-bin/native/installation_options.rb +25 -0
  40. data/lib/cocoapods-fy-bin/native/installer.rb +204 -0
  41. data/lib/cocoapods-fy-bin/native/linter.rb +26 -0
  42. data/lib/cocoapods-fy-bin/native/path_source.rb +33 -0
  43. data/lib/cocoapods-fy-bin/native/pod_source_installer.rb +19 -0
  44. data/lib/cocoapods-fy-bin/native/pod_target_installer.rb +94 -0
  45. data/lib/cocoapods-fy-bin/native/podfile.rb +91 -0
  46. data/lib/cocoapods-fy-bin/native/podfile_env.rb +37 -0
  47. data/lib/cocoapods-fy-bin/native/podfile_generator.rb +199 -0
  48. data/lib/cocoapods-fy-bin/native/podspec_finder.rb +25 -0
  49. data/lib/cocoapods-fy-bin/native/resolver.rb +238 -0
  50. data/lib/cocoapods-fy-bin/native/sandbox_analyzer.rb +34 -0
  51. data/lib/cocoapods-fy-bin/native/source.rb +35 -0
  52. data/lib/cocoapods-fy-bin/native/sources_manager.rb +20 -0
  53. data/lib/cocoapods-fy-bin/native/specification.rb +31 -0
  54. data/lib/cocoapods-fy-bin/native/target_validator.rb +41 -0
  55. data/lib/cocoapods-fy-bin/native/validator.rb +40 -0
  56. data/lib/cocoapods-fy-bin/native.rb +23 -0
  57. data/lib/cocoapods-fy-bin/source_provider_hook.rb +55 -0
  58. data/lib/cocoapods-fy-bin.rb +2 -0
  59. data/lib/cocoapods_plugin.rb +3 -0
  60. data/spec/command/bin_spec.rb +12 -0
  61. data/spec/spec_helper.rb +50 -0
  62. metadata +177 -0
@@ -0,0 +1,25 @@
1
+
2
+ require 'cocoapods'
3
+
4
+ module Pod
5
+ class Installer
6
+ class InstallationOptions
7
+ def self.env_option(key, default = true)
8
+ option key, ENV[key.to_s].nil? ? default : ENV[key.to_s] == 'true'
9
+ end
10
+
11
+ # 不同 source 存在相同 spec 名时,默认不警告
12
+ defaults.delete('warn_for_multiple_pod_sources')
13
+ env_option :warn_for_multiple_pod_sources, false
14
+
15
+ # 是否警告不安全 source (如 http )
16
+ env_option :warn_for_unsecure_source, false
17
+
18
+ # 是否多线程执行 install_pod_sources
19
+ env_option :install_with_multi_threads, true
20
+
21
+ # 是否多进程执行 update_repositories
22
+ env_option :update_source_with_multi_processes, true
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,204 @@
1
+ require 'cocoapods/installer/project_cache/target_metadata.rb'
2
+ require 'parallel'
3
+ require 'cocoapods'
4
+ require 'xcodeproj'
5
+ require 'cocoapods-fy-bin/native/pod_source_installer'
6
+
7
+ module Pod
8
+ class Installer
9
+ attr_reader :removed_frameworks
10
+ attr_reader :clean_white_list
11
+
12
+ def cache_descriptors
13
+ @cache_descriptors ||= begin
14
+ cache = Downloader::Cache.new(Config.instance.cache_root + 'Pods')
15
+ cache_descriptors = cache.cache_descriptors_per_pod
16
+ end
17
+ end
18
+ # 清除项目中不使用二进制的二进制库 工程目录/Pods/组件名称
19
+ def clean_local_cache
20
+ podfile = Pod::Config.instance.podfile
21
+ title_options = { verbose_prefix: '-> '.red }
22
+ root_specs.sort_by(&:name).each do |spec|
23
+ pod_dir = Pod::Config.instance.sandbox.pod_dir(spec.root.name)
24
+ framework_file = pod_dir + "#{spec.root.name}.framework"
25
+ # 如果framework存在 但不使用二进制 则删除framework
26
+ if pod_dir.exist? && framework_file.exist? && (podfile.use_binaries_selector.nil? || !podfile.use_binaries_selector.call(spec)) && !clean_white_list.include?(spec.root.name)
27
+ title = "Remove Binary Framework #{spec.name} #{spec.version}"
28
+ UI.titled_section(title.red, title_options) do
29
+ @removed_frameworks << spec.root.name
30
+ begin
31
+ FileUtils.rm_rf(pod_dir)
32
+ rescue => err
33
+ puts err
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ # 清除本地资源 /Users/dengrui/Library/Caches/CocoaPods/Pods/Release/
41
+ def clean_pod_cache
42
+ clean_white_list = ['Bugly', 'LookinServer']
43
+ podfile = Pod::Config.instance.podfile
44
+ root_specs.sort_by(&:name).each do |spec|
45
+ descriptors = cache_descriptors[spec.root.name]
46
+ if !descriptors.nil?
47
+ descriptors = descriptors.select { |d| d[:version] == spec.version}
48
+ descriptors.each do |d|
49
+ # pod cache 文件名由文件内容的 sha1 组成,由于生成时使用的是 podspec,获取时使用的是 podspec.json 导致生成的目录名不一致
50
+ # Downloader::Request slug
51
+ # cache_descriptors_per_pod 表明,specs_dir 中都是以 .json 形式保存 spec
52
+ slug = d[:slug].dirname + "#{spec.version}-#{spec.checksum[0, 5]}"
53
+ puts slug
54
+ framework_file = slug + "#{spec.root.name}.framework"
55
+ puts framework_file
56
+ if framework_file.exist? && (podfile.use_binaries_selector.nil? || !podfile.use_binaries_selector.call(spec)) && !clean_white_list.include?(spec.root.name)
57
+ begin
58
+ FileUtils.rm(d[:spec_file])
59
+ FileUtils.rm_rf(slug)
60
+ rescue => err
61
+ puts err
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ alias old_create_pod_installer create_pod_installer
70
+ def create_pod_installer(pod_name)
71
+ installer = old_create_pod_installer(pod_name)
72
+ installer.installation_options = installation_options
73
+ installer
74
+ end
75
+
76
+ alias old_install_pod_sources install_pod_sources
77
+ def install_pod_sources
78
+ @clean_white_list = ['Bugly', 'LookinServer']
79
+ @removed_frameworks = Array.new
80
+ podfile = Pod::Config.instance.podfile
81
+ # 如果不是全局使用 则删除不在列表内的framework二进制缓存
82
+ if !podfile.use_binaries?
83
+ clean_local_cache
84
+ clean_pod_cache
85
+ end
86
+
87
+ if installation_options.install_with_multi_threads
88
+ if Pod.match_version?('~> 1.4.0')
89
+ install_pod_sources_for_version_in_1_4_0
90
+ elsif Pod.match_version?('~> 1.5')
91
+ install_pod_sources_for_version_above_1_5_0
92
+ else
93
+ old_install_pod_sources
94
+ end
95
+ else
96
+ old_install_pod_sources
97
+ end
98
+ end
99
+
100
+ # rewrite install_pod_sources
101
+ def install_pod_sources_for_version_in_1_4_0
102
+ @installed_specs = []
103
+ pods_to_install = sandbox_state.added | sandbox_state.changed
104
+ title_options = { verbose_prefix: '-> '.green }
105
+ Parallel.each(root_specs.sort_by(&:name), in_threads: 4) do |spec|
106
+ if pods_to_install.include?(spec.name)
107
+ if sandbox_state.changed.include?(spec.name) && sandbox.manifest
108
+ previous = sandbox.manifest.version(spec.name)
109
+ title = "Installing #{spec.name} #{spec.version} (was #{previous})"
110
+ else
111
+ title = "Installing #{spec}"
112
+ end
113
+ UI.titled_section(title.green, title_options) do
114
+ install_source_of_pod(spec.name)
115
+ end
116
+ else
117
+ UI.titled_section("Using #{spec}", title_options) do
118
+ create_pod_installer(spec.name)
119
+ end
120
+ end
121
+ end
122
+ end
123
+
124
+ def install_pod_sources_for_version_above_1_5_0
125
+ @installed_specs = []
126
+ pods_to_install = sandbox_state.added | sandbox_state.changed | removed_frameworks
127
+ title_options = { verbose_prefix: '-> '.green }
128
+ # 多进程下载,多线程时 log 会显著交叉,多进程好点,但是多进程需要利用文件锁对 cache 进行保护
129
+ # in_processes: 10
130
+ Parallel.each(root_specs.sort_by(&:name), in_threads: 4) do |spec|
131
+ if pods_to_install.include?(spec.name)
132
+ if sandbox_state.changed.include?(spec.name) && sandbox.manifest
133
+ current_version = spec.version
134
+ previous_version = sandbox.manifest.version(spec.name)
135
+ has_changed_version = current_version != previous_version
136
+ current_repo = analysis_result.specs_by_source.detect do |key, values|
137
+ break key if values.map(&:name).include?(spec.name)
138
+ end
139
+ current_repo &&= current_repo.url || current_repo.name
140
+ previous_spec_repo = sandbox.manifest.spec_repo(spec.name)
141
+ has_changed_repo = !previous_spec_repo.nil? && current_repo && (current_repo != previous_spec_repo)
142
+ title = "Installing #{spec.name} #{spec.version}"
143
+ if has_changed_version && has_changed_repo
144
+ title += " (was #{previous_version} and source changed to `#{current_repo}` from `#{previous_spec_repo}`)"
145
+ end
146
+ if has_changed_version && !has_changed_repo
147
+ title += " (was #{previous_version})"
148
+ end
149
+ if !has_changed_version && has_changed_repo
150
+ title += " (source changed to `#{current_repo}` from `#{previous_spec_repo}`)"
151
+ end
152
+ else
153
+ title = "Installing #{spec}"
154
+ end
155
+ UI.titled_section(title.green, title_options) do
156
+ install_source_of_pod(spec.name)
157
+ end
158
+ else
159
+ UI.titled_section("Using #{spec}", title_options) do
160
+ create_pod_installer(spec.name)
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ alias old_write_lockfiles write_lockfiles
167
+ def write_lockfiles
168
+ old_write_lockfiles
169
+ if File.exist?('Podfile_local')
170
+
171
+ project = Xcodeproj::Project.open(config.sandbox.project_path)
172
+ #获取主group
173
+ group = project.main_group
174
+ group.set_source_tree('SOURCE_ROOT')
175
+ #向group中添加 文件引用
176
+ file_ref = group.new_reference(config.sandbox.root + '../Podfile_local')
177
+ #podfile_local排序
178
+ podfile_local_group = group.children.last
179
+ group.children.pop
180
+ group.children.unshift(podfile_local_group)
181
+ #保存
182
+ project.save
183
+ end
184
+ end
185
+ end
186
+
187
+ module Downloader
188
+ class Cache
189
+ # 多线程锁
190
+ @@lock = Mutex.new
191
+
192
+ # 后面如果要切到进程的话,可以在 cache root 里面新建一个文件
193
+ # 利用这个文件 lock
194
+ # https://stackoverflow.com/questions/23748648/using-fileflock-as-ruby-global-lock-mutex-for-processes
195
+
196
+ # rmtree 在多进程情况下可能 Directory not empty @ dir_s_rmdir 错误
197
+ # old_ensure_matching_version 会移除不是同一个 CocoaPods 版本的组件缓存
198
+ alias old_ensure_matching_version ensure_matching_version
199
+ def ensure_matching_version
200
+ @@lock.synchronize { old_ensure_matching_version }
201
+ end
202
+ end
203
+ end
204
+ end
@@ -0,0 +1,26 @@
1
+
2
+
3
+ require 'cocoapods-fy-bin/native/specification'
4
+
5
+ module Pod
6
+ class Specification
7
+ class Linter
8
+ # !@group Lint steps
9
+
10
+ # Checks that the spec's root name matches the filename.
11
+ #
12
+ # @return [void]
13
+ #
14
+ def validate_root_name
15
+ if spec.root.name && file
16
+ acceptable_names = Specification::VALID_EXTNAME.map { |extname| "#{spec.root.name}#{extname}" }
17
+ names_match = acceptable_names.include?(file.basename.to_s)
18
+ unless names_match
19
+ results.add_error('name', 'The name of the spec should match the ' \
20
+ 'name of the file.')
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,33 @@
1
+
2
+
3
+ require 'cocoapods-fy-bin/native/specification'
4
+
5
+ module Pod
6
+ module ExternalSources
7
+ # Provides support for fetching a specification file from a path local to
8
+ # the machine running the installation.
9
+ #
10
+ class PathSource < AbstractExternalSource
11
+ def normalized_podspec_path(declared_path)
12
+ extension = File.extname(declared_path)
13
+
14
+ if extension == '.podspec' || extension == '.json'
15
+ path_with_ext = declared_path
16
+ else
17
+ # 默认先从 binary podspec 找起,因为 binary podspec 的 subspec 可能比 code podspec 多
18
+ # 这里可能出现 code subspec 和 binary subspec 对应不上的情况,导致 lint 失败
19
+ # 所以不要在 code podspec 同一目录下保留 binary podspec
20
+ path_with_ext = Specification::VALID_EXTNAME
21
+ .map { |extname| "#{declared_path}/#{name}#{extname}" }
22
+ .find { |file| File.exist?(file) } || "#{declared_path}/#{name}.podspec"
23
+ end
24
+
25
+ UI.message "获取的 podspec 路径为 `#{path_with_ext}`"
26
+
27
+ podfile_dir = File.dirname(podfile_path || '')
28
+
29
+ File.expand_path(path_with_ext, podfile_dir)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,19 @@
1
+
2
+
3
+ require 'cocoapods-fy-bin/native/installation_options'
4
+
5
+ module Pod
6
+ class Installer
7
+ class PodSourceInstaller
8
+ attr_accessor :installation_options
9
+
10
+ alias old_verify_source_is_secure verify_source_is_secure
11
+ def verify_source_is_secure(root_spec)
12
+ # http source 默认不警告
13
+ if installation_options.warn_for_unsecure_source?
14
+ old_verify_source_is_secure(root_spec)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,94 @@
1
+ module Pod
2
+ class Installer
3
+ class Xcode
4
+ class PodsProjectGenerator
5
+ # Creates the target for the Pods libraries in the Pods project and the
6
+ # relative support files.
7
+ #
8
+ class PodTargetInstaller < TargetInstaller
9
+ require 'cocoapods/installer/xcode/pods_project_generator/app_host_installer'
10
+
11
+ # Adds a shell script phase, intended only for library targets that contain swift,
12
+ # to copy the ObjC compatibility header (the -Swift.h file that the swift compiler generates)
13
+ # to the built products directory. Additionally, the script phase copies the module map, appending a `.Swift`
14
+ # submodule that references the (moved) compatibility header. Since the module map has been moved, the umbrella header
15
+ # is _also_ copied, so that it is sitting next to the module map. This is necessary for a successful archive build.
16
+ #
17
+ # @param [PBXNativeTarget] native_target
18
+ # the native target to add the Swift static library script phase into.
19
+ #
20
+ # @return [Void]
21
+ #
22
+ alias old_add_swift_library_compatibility_header_phase add_swift_library_compatibility_header_phase
23
+
24
+ def add_swift_library_compatibility_header_phase(native_target)
25
+ UI.warn("========= swift add_swift_library_compatibility_header_phase")
26
+ if $ARGV[1] == "auto"
27
+ UI.warn("========= auto swift add_swift_library_compatibility_header_phase")
28
+
29
+ if custom_module_map
30
+ raise Informative, 'Using Swift static libraries with custom module maps is currently not supported. ' \
31
+ "Please build `#{target.label}` as a framework or remove the custom module map."
32
+ end
33
+
34
+ build_phase = native_target.new_shell_script_build_phase('Copy generated compatibility header')
35
+
36
+ relative_module_map_path = target.module_map_path.relative_path_from(target.sandbox.root)
37
+ relative_umbrella_header_path = target.umbrella_header_path.relative_path_from(target.sandbox.root)
38
+
39
+ build_phase.shell_script = <<-SH.strip_heredoc
40
+ COMPATIBILITY_HEADER_PATH="${BUILT_PRODUCTS_DIR}/Swift Compatibility Header/${PRODUCT_MODULE_NAME}-Swift.h"
41
+ MODULE_MAP_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.modulemap"
42
+
43
+ ditto "${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}-Swift.h" "${COMPATIBILITY_HEADER_PATH}"
44
+ ditto "${PODS_ROOT}/#{relative_module_map_path}" "${MODULE_MAP_PATH}"
45
+ ditto "${PODS_ROOT}/#{relative_umbrella_header_path}" "${BUILT_PRODUCTS_DIR}"
46
+
47
+ COPY_PATH="${PODS_CONFIGURATION_BUILD_DIR}/${PRODUCT_MODULE_NAME}"
48
+ UMBRELLA_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}-umbrella.h"
49
+ SWIFTMODULE_PATH="${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.swiftmodule"
50
+
51
+ ditto "${MODULE_MAP_PATH}" "${PODS_CONFIGURATION_BUILD_DIR}/${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}.modulemap"
52
+ ditto "${COMPATIBILITY_HEADER_PATH}" "${COPY_PATH}/Swift Compatibility Header/${PRODUCT_MODULE_NAME}-Swift.h"
53
+ ditto "${COMPATIBILITY_HEADER_PATH}" "${COPY_PATH}"
54
+ ditto "${UMBRELLA_PATH}" "${COPY_PATH}"
55
+ ditto "${SWIFTMODULE_PATH}" "${COPY_PATH}/${PRODUCT_MODULE_NAME}.swiftmodule"
56
+ ditto "${SWIFTMODULE_PATH}" "${COPY_PATH}/${PRODUCT_MODULE_NAME}.swiftmodule"
57
+
58
+ if [ ${PRODUCT_MODULE_NAME} != ${PRODUCT_NAME} ] ; then
59
+ ditto "${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}-umbrella.h" "${COPY_PATH}"
60
+ ditto "${COPY_PATH}" "${PODS_CONFIGURATION_BUILD_DIR}/${PRODUCT_NAME}"
61
+ fi
62
+
63
+ MODULE_MAP_SEARCH_PATH = "${PODS_CONFIGURATION_BUILD_DIR}/${PRODUCT_MODULE_NAME}/${PRODUCT_MODULE_NAME}.modulemap"
64
+
65
+ if [${MODULE_MAP_PATH} != ${MODULE_MAP_SEARCH_PATH}] ; then
66
+ printf "\\n\\nmodule ${PRODUCT_MODULE_NAME}.Swift {\\n header \\"${COPY_PATH}/Swift Compatibility Header/${PRODUCT_MODULE_NAME}-Swift.h\\"\\n requires objc\\n}\\n" >> "${MODULE_MAP_SEARCH_PATH}"
67
+ fi
68
+
69
+ printf "\\n\\nmodule ${PRODUCT_MODULE_NAME}.Swift {\\n header \\"${COMPATIBILITY_HEADER_PATH}\\"\\n requires objc\\n}\\n" >> "${MODULE_MAP_PATH}"
70
+
71
+ SH
72
+ build_phase.input_paths = %W(
73
+ ${DERIVED_SOURCES_DIR}/${PRODUCT_MODULE_NAME}-Swift.h
74
+ ${PODS_ROOT}/#{relative_module_map_path}
75
+ ${PODS_ROOT}/#{relative_umbrella_header_path}
76
+ )
77
+ build_phase.output_paths = %W(
78
+ ${BUILT_PRODUCTS_DIR}/${PRODUCT_MODULE_NAME}.modulemap
79
+ ${BUILT_PRODUCTS_DIR}/#{relative_umbrella_header_path.basename}
80
+ ${BUILT_PRODUCTS_DIR}/Swift\ Compatibility\ Header/${PRODUCT_MODULE_NAME}-Swift.h
81
+ )
82
+ else
83
+ UI.warn("========= null swift add_swift_library_compatibility_header_phase")
84
+ old_add_swift_library_compatibility_header_phase(native_target)
85
+ end
86
+
87
+ end
88
+
89
+ #-----------------------------------------------------------------------#
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,91 @@
1
+
2
+
3
+ require 'cocoapods'
4
+ require 'cocoapods-fy-bin/native/podfile_env'
5
+
6
+ module Pod
7
+ class Podfile
8
+ # TREAT_DEVELOPMENTS_AS_NORMAL = 'treat_developments_as_normal'.freeze
9
+
10
+ module DSL
11
+ def allow_prerelease!
12
+ set_internal_hash_value(ALLOW_PRERELEASE, true)
13
+ end
14
+
15
+ def use_binaries!(flag = true)
16
+ set_internal_hash_value(USE_BINARIES, flag)
17
+ end
18
+
19
+ def use_binaries_with_spec_selector!(&block)
20
+ raise Informative, '必须提供选择需要二进制组件的 block !' unless block_given?
21
+
22
+ set_internal_hash_value(USE_BINARIES_SELECTOR, block)
23
+ end
24
+
25
+ def set_use_source_pods(pods)
26
+ hash_pods_use_source = get_internal_hash_value(USE_SOURCE_PODS) || []
27
+ hash_pods_use_source += Array(pods)
28
+ set_internal_hash_value(USE_SOURCE_PODS, hash_pods_use_source)
29
+ end
30
+
31
+ # 0 dev
32
+ # 1 debug_iphoneos
33
+ # 2 release_iphoneos
34
+ # 需要在podfile_env 先定义 CONFIGURATION_ENV
35
+ def set_configuration_env(env = "dev")
36
+ set_internal_hash_value(CONFIGURATION_ENV, env)
37
+ end
38
+ end
39
+
40
+ alias old_plugins plugins
41
+ def plugins
42
+ if ENV[USE_PLUGINS]
43
+ env_plugins = ENV[USE_PLUGINS].split(',').each_with_object({}) do |name, result|
44
+ result[name] = {}
45
+ end
46
+ env_plugins.merge!(old_plugins)
47
+ else
48
+ old_plugins
49
+ end
50
+ end
51
+
52
+ def use_binaries_selector
53
+ get_internal_hash_value(USE_BINARIES_SELECTOR, nil)
54
+ end
55
+
56
+ def allow_prerelease?
57
+ get_internal_hash_value(ALLOW_PRERELEASE, false) || ENV[ALLOW_PRERELEASE] == 'true'
58
+ end
59
+
60
+ def use_binaries?
61
+ get_internal_hash_value(USE_BINARIES, false) || ENV[USE_BINARIES] == 'true'
62
+ end
63
+
64
+ def use_source_pods
65
+ get_internal_hash_value(USE_SOURCE_PODS, []) + String(ENV[USE_SOURCE_PODS]).split('|').uniq
66
+ end
67
+
68
+ def configuration_env
69
+ get_internal_hash_value(CONFIGURATION_ENV, "dev") || ENV[CONFIGURATION_ENV] == "dev"
70
+ end
71
+
72
+ private
73
+
74
+ def valid_bin_plugin
75
+ unless plugins.keys.include?('cocoapods-fy-bin')
76
+ raise Pod::Informative, 'You should add `plugin \'cocoapods-fy-bin\'` before using its DSL'
77
+ end
78
+ end
79
+
80
+ # set_hash_value 有 key 限制
81
+ def set_internal_hash_value(key, value)
82
+ valid_bin_plugin
83
+
84
+ internal_hash[key] = value
85
+ end
86
+
87
+ def get_internal_hash_value(key, default = nil)
88
+ internal_hash.fetch(key, default)
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,37 @@
1
+
2
+
3
+ module Pod
4
+ class Podfile
5
+ USE_BINARIES = 'use_binaries'
6
+ USE_SOURCE_PODS = 'use_source_pods'
7
+ USE_BINARIES_SELECTOR = 'use_binaries_selector'
8
+ ALLOW_PRERELEASE = 'allow_prerelease'
9
+ USE_PLUGINS = 'use_plugins'
10
+ CONFIGURATION_ENV = 'configuration_env'
11
+
12
+ module ENVExecutor
13
+ def execute_with_bin_plugin(&block)
14
+ execute_with_key(USE_PLUGINS, -> { 'cocoapods-fy-bin' }, &block)
15
+ end
16
+
17
+ def execute_with_allow_prerelease(allow_prerelease, &block)
18
+ execute_with_key(ALLOW_PRERELEASE, -> { allow_prerelease ? 'true' : 'false' }, &block)
19
+ end
20
+
21
+ def execute_with_use_binaries(use_binaries, &block)
22
+ execute_with_key(USE_BINARIES, -> { use_binaries ? 'true' : 'false' }, &block)
23
+ end
24
+
25
+ def execute_with_key(key, value_returner)
26
+ origin_value = ENV[key]
27
+ ENV[key] = value_returner.call
28
+
29
+ yield if block_given?
30
+
31
+ ENV[key] = origin_value
32
+ end
33
+ end
34
+
35
+ extend ENVExecutor
36
+ end
37
+ end