From 3b1e1742c65d974481e1dce133bef7a2f01b1ad4 Mon Sep 17 00:00:00 2001 From: denglibing5 Date: Tue, 13 Aug 2024 10:36:10 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E5=85=BC=E5=AE=B9=20cocoapods-generate=20(?= =?UTF-8?q?2.2.5)=E3=80=81Cocoapods=EF=BC=881.15.2=EF=BC=89=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=E7=BC=96=E8=AF=91=E6=8A=A5=E9=94=99=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/cocoapods-imy-bin/native/pod_source_installer.rb | 5 ++++- .../lib/cocoapods-imy-bin/native/podfile_generator.rb | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/pod_source_installer.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/pod_source_installer.rb index 4d72b0f..5051435 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/pod_source_installer.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/pod_source_installer.rb @@ -4,7 +4,10 @@ module Pod class Installer - class PodSourceInstaller + # Cocoapods新版本(1.15.2)将 PodSourceInstaller 的 + # verify_source_is_secure 等方法迁移到 PodSourceDownloader + # 所以这里需要修改一下 + class PodSourceDownloader attr_accessor :installation_options alias old_verify_source_is_secure verify_source_is_secure diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/podfile_generator.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/podfile_generator.rb index bf066d7..c1b15ca 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/podfile_generator.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/podfile_generator.rb @@ -17,9 +17,11 @@ class PodfileGenerator # # @param [Specification] spec # - alias old_podfile_for_spec podfile_for_spec + # cocoapods-generate (2.2.5)这个插件的版本,将 + # podfile_for_spec 方法改名为 podfile_for_specs + alias old_podfile_for_specs podfile_for_specs - def podfile_for_spec(spec) + def podfile_for_specs(spec) generator = self dir = configuration.gen_dir_for_pod(spec.name) @@ -196,4 +198,3 @@ def podfile_for_spec(spec) end end end - From b1cb9c48244b873079b22727fa00b26c36ee07dd Mon Sep 17 00:00:00 2001 From: denglibing5 Date: Thu, 15 Aug 2024 16:22:52 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E7=BB=A7=E7=BB=AD=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E3=80=81=E8=BF=90=E8=A1=8C=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .vscode/launch.json | 22 +++ cocoapods-imy-bin/Gemfile.lock | 155 ++++++++++-------- cocoapods-imy-bin/cocoapods-imy-bin.gemspec | 2 +- .../lib/cocoapods-imy-bin/config/config.rb | 3 + .../cocoapods-imy-bin/helpers/build_helper.rb | 3 +- .../cocoapods-imy-bin/helpers/build_utils.rb | 2 +- .../helpers/framework_builder.rb | 5 +- .../helpers/spec_source_creator.rb | 6 +- .../native/pod_source_installer.rb | 21 ++- .../native/podfile_generator.rb | 112 +++++++------ .../cocoapods-imy-bin/post_install_hook.rb | 110 +++++++++++++ 11 files changed, 307 insertions(+), 134 deletions(-) create mode 100644 .vscode/launch.json create mode 100755 cocoapods-imy-bin/lib/cocoapods-imy-bin/post_install_hook.rb diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..36f2d2e --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,22 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "rdbg", + "name": "Debug current file with rdbg", + "request": "launch", + "script": "${workspaceFolder}/cocoapods-imy-bin/cocoapods-imy-bin-0.3.1.2", + "cwd": "/Users/denglibing3/HDProject/ITPlayground/Ruby/202407/CocoaPodsDemo/HDPods/HDStaticPod/HDStaticPod", // "program"的工作目录 + "args": ["bin","auto"], + "askParameters": false + }, + { + "type": "rdbg", + "name": "Attach with rdbg", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/cocoapods-imy-bin/Gemfile.lock b/cocoapods-imy-bin/Gemfile.lock index eb72498..31709ef 100644 --- a/cocoapods-imy-bin/Gemfile.lock +++ b/cocoapods-imy-bin/Gemfile.lock @@ -1,116 +1,131 @@ -PATH - remote: ../cocoapods +GEM + remote: https://rubygems.org/ specs: - cocoapods (1.8.4) - activesupport (>= 4.0.2, < 5) + CFPropertyList (3.0.7) + base64 + nkf + rexml + activesupport (7.1.3.4) + base64 + bigdecimal + concurrent-ruby (~> 1.0, >= 1.0.2) + connection_pool (>= 2.2.5) + drb + i18n (>= 1.6, < 2) + minitest (>= 5.1) + mutex_m + tzinfo (~> 2.0) + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + algoliasearch (1.27.5) + httpclient (~> 2.8, >= 2.8.3) + json (>= 1.5.1) + atomos (0.1.3) + bacon (1.2.0) + base64 (0.2.0) + bigdecimal (3.1.8) + claide (1.1.0) + cocoapods (1.15.2) + addressable (~> 2.8) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.8.4) + cocoapods-core (= 1.15.2) cocoapods-deintegrate (>= 1.0.3, < 2.0) - cocoapods-downloader (>= 1.2.2, < 2.0) + cocoapods-downloader (>= 2.1, < 3.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) - cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.4.0, < 2.0) + cocoapods-trunk (>= 1.6.0, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) escape (~> 0.0.4) fourflusher (>= 2.3.0, < 3.0) gh_inspector (~> 1.0) - molinillo (~> 0.6.6) + molinillo (~> 0.8.0) nap (~> 1.0) - ruby-macho (~> 1.4) - xcodeproj (>= 1.11.1, < 2.0) - -PATH - remote: ../xcodeproj - specs: - xcodeproj (1.15.0) - CFPropertyList (>= 2.3.3, < 4.0) - atomos (~> 0.1.3) - claide (>= 1.0.2, < 2.0) - colored2 (~> 3.1) - nanaimo (~> 0.2.6) - -PATH - remote: . - specs: - cocoapods-imy-bin (0.2.0) - cocoapods - cocoapods-generate (= 1.6.0) - parallel - -GEM - remote: https://rubygems.org/ - specs: - CFPropertyList (3.0.2) - activesupport (4.2.11.3) - i18n (~> 0.7) - minitest (~> 5.1) - thread_safe (~> 0.3, >= 0.3.4) - tzinfo (~> 1.1) - algoliasearch (1.27.3) - httpclient (~> 2.8, >= 2.8.3) - json (>= 1.5.1) - atomos (0.1.3) - bacon (1.2.0) - claide (1.0.3) - cocoapods-core (1.8.4) - activesupport (>= 4.0.2, < 6) + ruby-macho (>= 2.3.0, < 3.0) + xcodeproj (>= 1.23.0, < 2.0) + cocoapods-core (1.15.2) + activesupport (>= 5.0, < 8) + addressable (~> 2.8) algoliasearch (~> 1.0) concurrent-ruby (~> 1.1) fuzzy_match (~> 2.0.4) nap (~> 1.0) - cocoapods-deintegrate (1.0.4) - cocoapods-disable-podfile-validations (0.1.1) - cocoapods-downloader (1.3.0) - cocoapods-generate (1.6.0) - cocoapods-disable-podfile-validations (~> 0.1.1) + netrc (~> 0.11) + public_suffix (~> 4.0) + typhoeus (~> 1.0) + cocoapods-deintegrate (1.0.5) + cocoapods-disable-podfile-validations (0.2.0) + cocoapods-downloader (2.1) + cocoapods-generate (2.2.5) + cocoapods-disable-podfile-validations (>= 0.1.1, < 0.3.0) + cocoapods-imy-bin (0.3.1.21) + cocoapods + cocoapods-generate + parallel cocoapods-plugins (1.0.0) nap - cocoapods-search (1.0.0) - cocoapods-stats (1.1.0) - cocoapods-trunk (1.5.0) + cocoapods-search (1.0.1) + cocoapods-trunk (1.6.0) nap (>= 0.8, < 2.0) netrc (~> 0.11) cocoapods-try (1.2.0) colored2 (3.1.2) - concurrent-ruby (1.1.6) + concurrent-ruby (1.3.4) + connection_pool (2.4.1) + drb (2.2.1) escape (0.0.4) + ethon (0.16.0) + ffi (>= 1.15.0) + ffi (1.17.0) fourflusher (2.3.1) fuzzy_match (2.0.4) gh_inspector (1.1.3) httpclient (2.8.3) - i18n (0.9.5) + i18n (1.14.5) concurrent-ruby (~> 1.0) - json (2.3.0) - minitest (5.14.1) + json (2.7.2) + minitest (5.24.1) mocha (1.11.2) mocha-on-bacon (0.2.3) mocha (>= 0.13.0) - molinillo (0.6.6) - nanaimo (0.2.6) + molinillo (0.8.0) + mutex_m (0.2.0) + nanaimo (0.3.0) nap (1.1.0) netrc (0.11.0) - parallel (1.19.1) + nkf (0.2.0) + parallel (1.26.2) prettybacon (0.0.2) bacon (~> 1.2) - ruby-macho (1.4.0) - thread_safe (0.3.6) - tzinfo (1.2.7) - thread_safe (~> 0.1) + public_suffix (4.0.7) + rexml (3.3.5) + strscan + ruby-macho (2.5.1) + strscan (3.1.0) + typhoeus (1.4.1) + ethon (>= 0.9.0) + tzinfo (2.0.6) + concurrent-ruby (~> 1.0) + xcodeproj (1.25.0) + CFPropertyList (>= 2.3.3, < 4.0) + atomos (~> 0.1.3) + claide (>= 1.0.2, < 2.0) + colored2 (~> 3.1) + nanaimo (~> 0.3.0) + rexml (>= 3.3.2, < 4.0) PLATFORMS ruby DEPENDENCIES bacon - cocoapods! - cocoapods-generate (= 1.6.0) - cocoapods-imy-bin! + cocoapods + cocoapods-generate (= 2.2.5) + cocoapods-imy-bin mocha mocha-on-bacon prettybacon - xcodeproj! + xcodeproj BUNDLED WITH 2.1.4 diff --git a/cocoapods-imy-bin/cocoapods-imy-bin.gemspec b/cocoapods-imy-bin/cocoapods-imy-bin.gemspec index e20685b..7becb9e 100755 --- a/cocoapods-imy-bin/cocoapods-imy-bin.gemspec +++ b/cocoapods-imy-bin/cocoapods-imy-bin.gemspec @@ -22,7 +22,7 @@ Gem::Specification.new do |spec| spec.add_dependency 'parallel' spec.add_dependency 'cocoapods' - spec.add_dependency "cocoapods-generate",'~>2.0.1' + spec.add_dependency "cocoapods-generate",'2.2.5' spec.add_development_dependency 'bundler' spec.add_development_dependency 'rake' diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config.rb index 3beb95f..33ee219 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config.rb @@ -3,6 +3,9 @@ require 'cocoapods-imy-bin/native/podfile_env' require 'cocoapods/generate' +# 新增如下一行代码,解决在 pod bin init 初始化提示 Config 错误的问题。 +require 'ostruct' + module CBin class Config def config_file diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_helper.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_helper.rb index c08b7ee..d5079ef 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_helper.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_helper.rb @@ -58,7 +58,8 @@ def build_static_framework @@build_defines = builder.build if @isRootSpec begin @framework_path = builder.lipo_build(@@build_defines) unless @skip_archive - rescue + rescue => e + puts "An error occurred: #{e.message}" @skip_archive = true end end diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_utils.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_utils.rb index 7a29903..d2d834e 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_utils.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_utils.rb @@ -16,7 +16,7 @@ def Utils.is_framework(spec) def Utils.spec_header_dir(spec) - header_dir = "./Headers/Public/#{spec.name}" + header_dir = "./build-arm64/#{spec.name}.framework/Headers" header_dir = "./Pods/Headers/Public/#{spec.name}" unless File.exist?(header_dir) unless File.exist?(header_dir) diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/framework_builder.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/framework_builder.rb index 4147e93..78b98d8 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/framework_builder.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/framework_builder.rb @@ -91,6 +91,7 @@ def static_libs_in_sandbox(build_dir = 'build') def build_static_library_for_ios(output) UI.message "Building ios libraries with archs #{ios_architectures}" + puts "Building ios libraries with archs #{ios_architectures}" static_libs = static_libs_in_sandbox('build') + static_libs_in_sandbox('build-simulator') + @vendored_libraries # if is_debug_model ios_architectures.map do |arch| @@ -106,7 +107,7 @@ def build_static_library_for_ios(output) # if is_debug_model libs = (ios_architectures + ios_architectures_sim) .map do |arch| - library = "build-#{arch}/lib#{@spec.name}.a" + library = "build-#{arch}/#{@spec.name}.framework/#{@spec.name}" library end # else @@ -141,7 +142,7 @@ def ios_architectures # iphone5,iphone5s以下的模拟器 # >x86_64 # iphone6以上的模拟器 - archs = %w[arm64 armv7] + archs = %w[arm64] # archs = %w[x86_64 arm64 armv7s i386] # @vendored_libraries.each do |library| # archs = `lipo -info #{library}`.split & archs diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/spec_source_creator.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/spec_source_creator.rb index 1ffb27e..61deeff 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/spec_source_creator.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/spec_source_creator.rb @@ -117,7 +117,7 @@ def create_from_code_spec @spec.vendored_libraries = binary_vendored_libraries @spec.resources = binary_resources if @spec.attributes_hash.keys.include?("resources") @spec.description = <<-EOF - 「 converted automatically by plugin cocoapods-imy-bin @厦门美柚 - slj 」 + 「 converted automatically by plugin cocoapods-imy-bin 」 #{@spec.description} EOF @@ -183,7 +183,7 @@ def create_framework_from_code_spec @spec = Pod::Specification.from_hash(spec_hash) @spec.description = <<-EOF - 「 converted automatically by plugin cocoapods-imy-bin @厦门美柚 - slj 」 + 「 converted automatically by plugin cocoapods-imy-bin 」 #{@spec.description} EOF @spec @@ -231,4 +231,4 @@ def binary_resources # s.vendored_libraries = "bin_#{s.name}_#{s.version}/*.a" #有图片资源的,要带上 #s.resources = 'bin_#{s.name}_#{s.version}/Resources/*.{json,png,jpg,gif,js,xib,eot,svg,ttf,woff,db,sqlite,mp3,bundle}' -#模板框架end \ No newline at end of file +#模板框架end diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/pod_source_installer.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/pod_source_installer.rb index 5051435..71ed5a7 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/pod_source_installer.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/pod_source_installer.rb @@ -10,13 +10,20 @@ class Installer class PodSourceDownloader attr_accessor :installation_options - alias old_verify_source_is_secure verify_source_is_secure - def verify_source_is_secure(root_spec) - # http source 默认不警告 - if installation_options.warn_for_unsecure_source? - old_verify_source_is_secure(root_spec) - end - end + # alias old_verify_source_is_secure verify_source_is_secure + # def verify_source_is_secure(root_spec) + # # http source 默认不警告 + # if installation_options.warn_for_unsecure_source? + # old_verify_source_is_secure(root_spec) + # end + # end + end + end + + class Installer + # 新增 PodSourceInstaller 的 installation_options 扩展方法 + class PodSourceInstaller + attr_accessor :installation_options end end end diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/podfile_generator.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/podfile_generator.rb index c1b15ca..a6b8317 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/podfile_generator.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/native/podfile_generator.rb @@ -15,19 +15,21 @@ module Generate class PodfileGenerator # @return [Podfile] a podfile suitable for installing the given spec # - # @param [Specification] spec + # @param [Array] specs # # cocoapods-generate (2.2.5)这个插件的版本,将 # podfile_for_spec 方法改名为 podfile_for_specs alias old_podfile_for_specs podfile_for_specs - def podfile_for_specs(spec) + def podfile_for_specs(specs) generator = self - dir = configuration.gen_dir_for_pod(spec.name) + dir = configuration.gen_dir_for_specs(specs) + project_name = configuration.project_name_for_specs(specs) + external_source_pods = configuration.external_source_pods Pod::Podfile.new do - project "#{spec.name}.xcodeproj" - workspace "#{spec.name}.xcworkspace" + project "#{project_name}.xcodeproj" + workspace "#{project_name}.xcworkspace" plugin 'cocoapods-generate' @@ -50,12 +52,17 @@ def podfile_for_specs(spec) self.defined_in_file = dir.join('CocoaPods.podfile.yaml') - test_specs = spec.recursive_subspecs.select(&:test_specification?) - app_specs = if spec.respond_to?(:app_specification?) - spec.recursive_subspecs.select(&:app_specification?) - else - [] - end + test_specs_by_spec = Hash[specs.map do |spec| + [spec, spec.recursive_subspecs.select(&:test_specification?)] + end] + app_specs_by_spec = Hash[specs.map do |spec| + app_specs = if spec.respond_to?(:app_specification?) + spec.recursive_subspecs.select(&:app_specification?) + else + [] + end + [spec, app_specs] + end] # Stick all of the transitive dependencies in an abstract target. # This allows us to force CocoaPods to use the versions / sources / external sources @@ -87,7 +94,7 @@ def podfile_for_specs(spec) # Add platform-specific concrete targets that inherit the # `pod` declaration for the local pod. - spec_platform_names = spec.available_platforms.map(&:string_name).flatten.each.reject do |platform_name| + spec_platform_names = specs.flat_map { |s| s.available_platforms.map(&:string_name) }.uniq.each.reject do |platform_name| !generator.configuration.platforms.nil? && !generator.configuration.platforms.include?(platform_name.downcase) end @@ -101,68 +108,75 @@ def podfile_for_specs(spec) # and the local `pod` declaration # 会导致多个dependencies出现, 注释by slj - inhibit_all_warnings! if generator.inhibit_all_warnings? use_modular_headers! if generator.use_modular_headers? # This is the pod declaration for the local pod, # it will be inherited by the concrete target definitions below - pod_options = generator.dependency_compilation_kwargs(spec.name) - pod_options[:path] = spec.defined_in_file.relative_path_from(dir).to_s - # generator.configuration.podfile.dependencies[0].external_source - + specs.each do |spec| + # This is the pod declaration for the local pod, + # it will be inherited by the concrete target definitions below + pod_options = generator.dependency_compilation_kwargs(spec.name) - { testspecs: test_specs, appspecs: app_specs }.each do |key, specs| - pod_options[key] = specs.map { |s| s.name.sub(%r{^#{Regexp.escape spec.root.name}/}, '') }.sort unless specs.empty? + path = spec.defined_in_file.relative_path_from(dir).to_s + pod_options[:path] = path + { testspecs: test_specs_by_spec[spec], appspecs: app_specs_by_spec[spec] }.each do |key, subspecs| + pod_options[key] = subspecs.map { |s| s.name.sub(%r{^#{Regexp.escape spec.root.name}/}, '') }.sort unless subspecs.blank? + end + pod spec.name, **pod_options end - pod spec.name, **pod_options + specs.each do |spec| - if Pod::Config.instance.podfile - target_definitions['Pods'].instance_exec do - target_definition = nil - Pod::Config.instance.podfile.target_definition_list.each do |target| - if target.label == "Pods-#{spec.name}" - target_definition = target - break + if Pod::Config.instance.podfile + target_definitions['Pods'].instance_exec do + target_definition = nil + Pod::Config.instance.podfile.target_definition_list.each do |target| + if target.label == "Pods-#{spec.name}" + target_definition = target + break + end end - end - # setting modular_headers_for - if(target_definition && target_definition.use_modular_headers_hash.values.any?) - target_definition.use_modular_headers_hash.values.each do |f| - f.each { | pod_name| self.set_use_modular_headers_for_pod(pod_name, true) } + # setting modular_headers_for + if(target_definition && target_definition.use_modular_headers_hash.values.any?) + target_definition.use_modular_headers_hash.values.each do |f| + f.each { | pod_name| self.set_use_modular_headers_for_pod(pod_name, true) } + end end - end - if target_definition - value = target_definition.to_hash['dependencies'] - next if value.blank? - #删除 本地库中的 spec.name,因为本地的./spec.name地址是错的 - value.each do |f| - if f.is_a?(Hash) && f.keys.first == spec.name - value.delete f - break + if target_definition + value = target_definition.to_hash['dependencies'] + next if value.blank? + #删除 本地库中的 spec.name,因为本地的./spec.name地址是错的 + value.each do |f| + if f.is_a?(Hash) && f.keys.first == spec.name + value.delete f + break + end end - end - old_value = self.to_hash['dependencies'].first - value << old_value unless (old_value == nil || value.include?(old_value)) + old_value = self.to_hash['dependencies'].first + value << old_value unless (old_value == nil || value.include?(old_value)) - set_hash_value(%w(dependencies).first, value) + set_hash_value(%w(dependencies).first, value) - value = target_definition.to_hash['configuration_pod_whitelist'] - next if value.blank? - set_hash_value(%w(configuration_pod_whitelist).first, value) + value = target_definition.to_hash['configuration_pod_whitelist'] + next if value.blank? + set_hash_value(%w(configuration_pod_whitelist).first, value) - end + end + end + end end + + # if generator.configuration && generator.configuration.podfile # #变量本地podfile下的dependencies 写入新的验证文件中,指定依赖源 # generator.configuration.podfile.dependencies.each { |dependencies| diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/post_install_hook.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/post_install_hook.rb new file mode 100755 index 0000000..423bcca --- /dev/null +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/post_install_hook.rb @@ -0,0 +1,110 @@ +require 'cocoapods-imy-bin/native/sources_manager' +require 'cocoapods-imy-bin/command/bin/repo/update' +require 'cocoapods/user_interface' +require 'xcodeproj/config/other_linker_flags_parser' +require 'xcodeproj/config' + +module Xcodeproj + class Config + def remove_attr_with_key(key) + unless key == nil + @attributes.delete(key) + end + end + def remove_header_search_path + remove_attr_with_key('HEADER_SEARCH_PATHS') + flags = @attributes['OTHER_CFLAGS'] + if flags + new_flags = '' + skip = false + flags.split(' ').each do |substr| + if skip + skip = false + next + end + if substr == '-isystem' + skip = true + next + end + if new_flags.length > 0 + new_flags += ' ' + end + new_flags += substr + end + if new_flags.length > 0 + @attributes['OTHER_CFLAGS'] = new_flags + else + remove_attr_with_key('OTHER_CFLAGS') + end + end + end + end +end + +module Pod + class Installer + class PostInstallHooksContext + attr_accessor :aggregate_targets + def self.generate(sandbox, pods_project, pod_target_subprojects, aggregate_targets) + context = super + UI.info "[#] generate method of post install hook context override" + context.aggregate_targets = aggregate_targets + context + end + end + end + module ProjectHeaderMap + HooksManager.register('cocoapods-imy-bin', :post_install) do |post_context| + + podfile = Pod::Config.instance.podfile + + + if podfile && podfile.use_hmap? + UI.info "[#] use hmap for this project" + post_context.aggregate_targets.each do |one| + hmap = Hash.new + one.pod_targets.each do |target| + target.public_header_mappings_by_file_accessor.each do |facc, headers| + headers.each do |key, value| + value.each do |path| + pn = Pathname.new(path) + name = pn.basename.to_s + dirname = pn.dirname.to_s + '/' + # construct hmap hash info + path_info = Hash['suffix' => name, 'prefix' => dirname] + # import with quote + hmap[name] = path_info + # import with angle bracket + hmap["#{target.name}/#{name}"] = path_info + end + end + end + end + + unless hmap.empty? + path = "#{post_context.sandbox_root + "/#{one.name}-hmap.json"}" + path_hmap = "#{post_context.sandbox_root + "/#{one.name}.hmap"}" + # write hmap json to file + File.open(path, 'w') { |file| file << hmap.to_json } + # json to hmap + system("hmap convert #{path} #{path_hmap}") + # delete json file + File.delete(path) + + # override xcconfig + one.xcconfigs.each do |config_name, config_file| + # puts "config_file == #{config_file} \n\r" + config_file << Hash['OTHER_CFLAGS' => "#{"-I ${PODS_ROOT}/#{one.name}.hmap"}"] + config_file << Hash['OTHER_SWIFT_FLAGS' => "#{"-Xcc -I${PODS_ROOT}/#{one.name}.hmap"}"] + config_file.remove_header_search_path + xcconfig_path = one.xcconfig_path(config_name) + config_file.save_as(xcconfig_path) + end + + end + end + end + + end + end +end From c34ef277e96add772f0c498970b58cb4bdae422d Mon Sep 17 00:00:00 2001 From: denglibing5 Date: Fri, 16 Aug 2024 22:54:24 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E7=BB=84=E4=BB=B6=E6=89=93=E5=8C=85?= =?UTF-8?q?=E7=9A=84=E8=B7=AF=E5=BE=84=E4=BF=AE=E6=94=B9=E6=88=90=20privat?= =?UTF-8?q?e/var/tmp/imy=5Frelease=20=E8=B7=AF=E5=BE=84=E4=B8=8A=EF=BC=8C?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E8=A7=A3=E5=86=B3=E6=BA=90=E7=A0=81=E8=B0=83?= =?UTF-8?q?=E8=AF=95(pod=20bin=20code=20HDStaticPod)=20=E8=BD=AF=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=EF=BC=88ln=20-s=EF=BC=89=E6=97=A0=E6=B3=95=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E7=94=A8=E6=88=B7=E8=B7=AF=E5=BE=84=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cocoapods-imy-bin/Gemfile | 4 +-- .../cocoapods-imy-bin/command/bin/archive.rb | 34 ++++++++++++++++--- .../lib/cocoapods-imy-bin/command/bin/auto.rb | 3 +- .../lib/cocoapods-imy-bin/command/bin/code.rb | 3 ++ .../config/config_builder.rb | 6 +++- .../helpers/upload_helper.rb | 2 ++ cocoapods-imy-bin/spec/command/bin_spec.rb | 1 - 7 files changed, 44 insertions(+), 9 deletions(-) diff --git a/cocoapods-imy-bin/Gemfile b/cocoapods-imy-bin/Gemfile index e136caa..5f2165d 100755 --- a/cocoapods-imy-bin/Gemfile +++ b/cocoapods-imy-bin/Gemfile @@ -1,4 +1,4 @@ -SKIP_UNRELEASED_VERSIONS = false +SKIP_UNRELEASED_VERSIONS = true # Specify your gem's dependencies in cocoapods-imy-bin.gemspec @@ -23,7 +23,7 @@ group :development do cp_gem 'xcodeproj', 'xcodeproj',path: 'Xcodeproj' cp_gem 'cocoapods-imy-bin', 'cocoapods-imy-bin',path: 'cocoapods-imy-bin' - gem 'cocoapods-generate', '1.6.0' + gem 'cocoapods-generate', '2.2.5' gem 'mocha' gem 'bacon' gem 'mocha-on-bacon' diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/archive.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/archive.rb index 3e652a6..41b08b5 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/archive.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/archive.rb @@ -156,15 +156,22 @@ def generate_project argvs = [ "--sources=#{sources_option(@code_dependencies, @sources)}", "--gen-directory=#{CBin::Config::Builder.instance.gen_dir}", - '--clean', + # '--clean', *@additional_args ] + # 源码路径 + source_dir = Pathname.pwd+@spec.name + + # 打包路径(private/var/tmp/imy_release)路径,解决多个电脑源码调试的问题 + gen_directory = "#{CBin::Config::Builder.instance.gen_dir}" + "/#{@spec.name}" + FileUtils.cp_r(source_dir, gen_directory) + podfile= File.join(Pathname.pwd, "Podfile") if File.exist?(podfile) argvs += ['--use-podfile'] end - + argvs << spec_file if spec_file gen = Pod::Command::Gen.new(CLAide::ARGV.new(argvs)) @@ -184,12 +191,31 @@ def spec_file raise Informative, '当前目录下没有找到可用源码 podspec.' end - spec_file = code_spec_files.first - spec_file + # spec_file = code_spec_files.first + # spec_file + gen_file end end end + def gen_file + spec_file = code_spec_files.first + + # {CBin::Config::Builder.instance.gen_dir: /private/var/tmp/imy_release/HDStaticPod-build-temp/bin-archive + # 使用 split 方法分割字符串,并获取分割后的第一个部分 + name = spec_file.to_path.split('.').first + # 打包路径(private/var/tmp/imy_release)路径,解决多个电脑源码调试的问题 + gen_directory = "#{CBin::Config::Builder.instance.gen_dir}" + "/#{name}" + FileUtils.rm_rf(gen_directory) if File.exist?(gen_directory) + # 确保目标目录存在 + FileUtils.mkdir_p(gen_directory) + # 复制目录及其内容 + gen_directory = "#{gen_directory}" + "/#{spec_file}" + # 复制目录及其内容 + FileUtils.cp_r(spec_file, gen_directory) + + gen_directory + end end diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/auto.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/auto.rb index c994391..6f77932 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/auto.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/auto.rb @@ -57,6 +57,7 @@ def run source_specs = run_archive fail_push_specs = [] + UI.puts "pod bin auto run" source_specs.uniq.each do |spec| begin fail_push_specs << spec unless CBin::Upload::Helper.new(spec,@code_dependencies,@sources).upload @@ -123,7 +124,7 @@ def run_archive argvs += ["--env=#{@env}"] end argvs += ["--configuration=#{@config}"] - + archive = Pod::Command::Bin::Archive.new(CLAide::ARGV.new(argvs)) archive.validate! source_specs = archive.run diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/code.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/code.rb index 010e186..49e7b6e 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/code.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/code.rb @@ -160,6 +160,9 @@ def check(lib_file,dir,basename) def get_lib_path(name) dir = Pathname.new(File.join(Pathname.pwd,"Pods",name)) lib_name = "lib#{name}.a" + unless File.exist?(lib_name) + lib_name = "#{name}" + end lib_path = File.join(dir,lib_name) unless File.exist?(lib_path) diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config_builder.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config_builder.rb index 38aee48..0fabf48 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config_builder.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config_builder.rb @@ -191,7 +191,11 @@ def root_dir @root_dir ||= begin basename = File.basename(Pod::Config.instance.installation_root) parent_dir = File.dirname(Pod::Config.instance.installation_root) - root_name = File.join(parent_dir,"#{basename}-build-temp") + private_dir = '/private/var/tmp/imy_release/' + unless File.exist?(private_dir) + FileUtils.mkdir_p(private_dir) + end + root_name = File.join(private_dir,"#{basename}-build-temp") Dir.mkdir(root_name) unless File.exist?root_name Pathname.new(root_name) end diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/upload_helper.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/upload_helper.rb index c689531..72b3249 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/upload_helper.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/upload_helper.rb @@ -22,6 +22,7 @@ def initialize(spec,code_dependencies,sources) end def upload + puts "upload" Dir.chdir(CBin::Config::Builder.instance.root_dir) do # 创建binary-template.podsepc # 上传二进制文件 @@ -47,6 +48,7 @@ def spec_creator def curl_zip zip_file = "#{CBin::Config::Builder.instance.library_file(@spec)}.zip" res = File.exist?(zip_file) + puts "curl_zip #{zip_file} #{res}" unless res zip_file = CBin::Config::Builder.instance.framework_zip_file(@spec) + ".zip" res = File.exist?(zip_file) diff --git a/cocoapods-imy-bin/spec/command/bin_spec.rb b/cocoapods-imy-bin/spec/command/bin_spec.rb index 3add097..919df19 100755 --- a/cocoapods-imy-bin/spec/command/bin_spec.rb +++ b/cocoapods-imy-bin/spec/command/bin_spec.rb @@ -9,4 +9,3 @@ module Pod end end end - From 14a021be22a7a15c78ae5347f243dee99d5877a6 Mon Sep 17 00:00:00 2001 From: denglibing5 Date: Sat, 17 Aug 2024 15:56:25 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=9A=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=EF=BC=8C=E6=BA=90=E7=A0=81=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/cocoapods-imy-bin/command/bin/code.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/code.rb b/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/code.rb index 49e7b6e..aef53cd 100755 --- a/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/code.rb +++ b/cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/code.rb @@ -83,7 +83,8 @@ def download_source(name) FileUtils.rm_rf(target_path) find_dependency = find_dependency(name) - + # find_dependency.external_source = {:podspec => '/Users/denglibing3/.cocoapods/repos/erduoniba-hdpodrepo/HDStaticPod/0.1.0/HDStaticPod.podspec'} + # find_dependency.requirement.requirements.first[1].version spec = fetch_external_source(find_dependency, @config.podfile,@config.lockfile, @config.sandbox,true ) download_request = Pod::Downloader::Request.new(:name => name, :spec => spec) @@ -118,6 +119,10 @@ def fetch_external_source(dependency ,podfile , lockfile, sandbox,use_lockfile_o def link(lib_file,target_path,basename) dir = (`dwarfdump "#{lib_file}" | grep "AT_comp_dir" | head -1 | cut -d \\" -f2 `) sub_path = "#{basename}/bin-archive/#{basename}" + + # 用于 pod bin code 源码调试,找到打包电脑上的编译代码的路径 + # 需要去掉 Pods 这个路径 + dir = dir.gsub("#{basename}/Pods", "").chomp dir = dir.gsub(sub_path, "").chomp # UI.puts "dir = #{dir}"