##Copyright 2023 ByteDance Ltd. and/or its affiliates ##SPDX-License-Identifier: MIT require 'cocoapods' require 'singleton' require 'cocoapods-byte-panglem-beta/gem_version' require 'digest' require "thread" require_relative 'net' require_relative 'config' require_relative 'tool' require_relative 'analyzer' require_relative 'recorder' require_relative 'plugin' module PMPlugin def PMPlugin.action() recoder= PM::Recorder.instance if recoder.is_load_plugin yield(recoder) if block_given? end end def PMPlugin.update() if PM::Recorder.instance.is_auto_update puts "[cocoapods-byte-panglem-beta]checking for updates..." command = 'gem install cocoapods-byte-panglem-beta' stdout, stderr, status = Open3.capture3(command) if status.success? puts "[cocoapods-byte-panglem-beta]update sucess" end end end end class Xcodeproj::Project::Object::XCBuildConfiguration ## 重写属性 attr_accessor :simple_attributes_hash end class Pod::Resolver alias_method :original_search_for, :search_for def search_for(dependency) possibilities = original_search_for(dependency) ##返回不可变数组 PMPlugin.action do |recoder| PM::SpecificationInfo.update Pod::Specification.root_name(dependency.name) , possibilities end possibilities end alias_method :original_specifications_for_dependency, :specifications_for_dependency def specifications_for_dependency(dependency, additional_requirements = []) PMPlugin.action do |recoder| if PM::MapRelations.should_remove_requirements?(Pod::Specification.root_name(dependency.name)) additional_requirements = [] dependency = Pod::Dependency.new(dependency.name) end end original_specifications_for_dependency(dependency, additional_requirements) end end class Pod::Installer::Analyzer alias_method :original_dependencies_for_specs, :dependencies_for_specs def dependencies_for_specs(specs, platform, all_specs) dependent_specs = { :debug => Set.new, :release => Set.new, } if !specs.empty? && !all_specs.empty? specs.each do |s| s.dependencies(platform).each do |dep| temp_name = dep.name if !temp_name.include?("Ads-Global") all_specs[dep.name].each do |spec| if spec.non_library_specification? if s.test_specification? && spec.name == s.consumer(platform).app_host_name && spec.app_specification? # This needs to be handled separately, since we _don't_ want to treat this as a "normal" dependency next end raise Informative, "`#{s}` depends upon `#{spec}`, which is a `#{spec.spec_type}` spec." end dependent_specs.each do |config, set| next unless s.dependency_whitelisted_for_configuration?(dep, config) set << spec end end end end end end Hash[dependent_specs.map { |k, v| [k, (v - specs).group_by(&:root)] }].freeze end alias_method :original_resolve_dependencies, :resolve_dependencies def resolve_dependencies(locked_dependencies) resolver_specs_by_target = original_resolve_dependencies(locked_dependencies) PMPlugin.action do |recoder| resolver_specs_by_target.each do |target, specs| if specs.length > 0 if PM::Recorder.instance.is_release Pod::UserInterface.section "[cocoapods-byte-panglem-beta][info] start trying to update the sdk version (when is_release is yes) " do PM::Analyzer.resolve_release_target target, specs end else Pod::UserInterface.section '[cocoapods-byte-panglem-beta][info] start trying to update the sdk version ' do is_update_finish = PM::Analyzer.resolve_last target, specs if is_update_finish Pod::UserInterface.section '[cocoapods-byte-panglem-beta][info] write Podfile.pangle.lock' do write_lock_file recoder end end end end end end end resolver_specs_by_target end def write_lock_file(recoder) PM::Lockfile.new(recoder.to_hash).write_to_disk(File.expand_path("#{Pod::Config.instance.installation_root}/Podfile.pangle")) end end module Pod class Podfile module DSL def use_pangm_sdk_update!(option = true) current_target_definition.use_pangm_sdk_update!(option) end def pangm_release_target!(option = true) current_target_definition.pangm_release_target!(option) end alias_method :original_plugin, :plugin def plugin(name, options = {}) if name == 'cocoapods-byte-panglem-beta' PM::Recorder.instance.set_plugin_load true case options when Hash PM::Recorder.instance.set_is_debug options[:is_debug] if options.has_key?(:is_debug) PM::Recorder.instance.set_is_auto_update options[:is_auto_update]if options.has_key?(:is_auto_update) end PMPlugin.update end original_plugin(name, options) end # alias_method :original_target, :target # def target(name, options = nil) # relust = original_target(name, options) # result # end alias_method :original_pod, :pod def pod(name = nil, *requirements) ## SDK 场景不需要 PMPlugin.action do |recoder| unless current_target_definition.have_add_dependencys current_target_definition.have_add_dependencys = true pangle_beta = PM::BuildConfig.pangle_sdk_beta current_target_definition.store_pod(pangle_beta, []) end end original_pod(name, *requirements) end end class TargetDefinition ## 媒体线上版本target的标识 attr_reader :pangm_release_target ## 是否已自动加载了库 attr_accessor :have_add_dependencys ## rarget维度的配置信息 attr_reader :pm_build_config def use_pangm_sdk_update!(option) @global_pm_build_config = PM::Recorder.instance.find_global_note option end ## SDK 暂不需要 def pangm_release_target!(option = true) raise ArgumentError, "[cocoapods-byte-panglem] The `pangm_release_target!` configuration item needs to be set in a specific target, do not set it globally" if @label == "Pods" name = String.new("T-") << label case option when true @pm_build_config = PM::Recorder.instance.get_target name @pm_build_config.is_release_target = option @pm_build_config.referenced_target = name when Hash @pm_build_config = PM::Recorder.instance.get_target name @pm_build_config.is_release_target = true @pm_build_config.referenced_target = String.new("T-") << option[:referenced] else raise ArgumentError, "CSJM error: `#{option.inspect}`, should be a true or a target name" end end original_parse_inhibit_warnings = instance_method(:parse_inhibit_warnings) define_method(:parse_inhibit_warnings) do |name, requirements| PMPlugin.action do |recoder| ## 这里去掉adapter 大部分逻辑部分 @pm_build_config = recoder.get_target String.new("T-") << label end original_parse_inhibit_warnings.bind(self).call(name, requirements) end end end end