require "cocoapods" require 'pathname' require_relative 'spec_helper.rb' require_relative 'xcodeproj.rb' module QCloudHive module HivePod class << self @@podspecs = nil end def HivePod.sources() Pod::Config::instance.sources_manager.aggregate.sources end def HivePod.configPostInstaller(installer) installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['ENABLE_BITCODE'] = Config.bitcodeEnable ? "YES" : "NO" end end end def HivePod.search(name) sources.each { |source| podspec = source.search(name) if podspec != nil return podspec end } return nil end def HivePod.findPodspecs(path) podspecs = [] path = Pathname(path) path.entries.each { |entry| if (entry.extname == '.podspec' || entry.to_s.end_with?('.podspec.json')) if path.basename.to_path == "Local Podspecs" next end podspecs.push(path.join(entry)) end } if podspecs.count != 0 return podspecs else path.entries.each { |entry| next if entry.to_path == "." next if entry.to_path == ".." next if entry.to_path == ".git" next if entry.to_path == ".repo" if File.directory?(path.join(entry)) subpath = path.join(entry) ps = findPodspecs(subpath) podspecs = podspecs + ps end } end return podspecs end def HivePod.podspecs if @@podspecs.nil? podspecs = findPodspecs(Config.projectRootDirectory) if not podspecs.nil? @@podspecs = podspecs.map { |specPath| name = nil basenamestr = specPath.basename.to_s extenname = specPath.extname if extenname == ".json" extenname = ".podspec.json" end if extenname.length>0 && basenamestr.end_with?(extenname) name = basenamestr[0,basenamestr.length - extenname.length] end HiveSpec.new(name, specPath) } end end return @@podspecs end def HivePod.installDependencies(target, podfilePath) Config.setup() Config.loadShareConfig L.info("target is nil #{target}") if target.nil? or target == "nil" return end Config.setup xcodeProject = QCloudHive.xcodeprojectByPath(Pathname.new(podfilePath).parent.to_s) if xcodeProject.nil? ERROR "该Podfile文件没有对应的Xcode工程 #{podfilePath}" end if xcodeProject.hiveSpecModules.nil? puts "nil!!!" end xcodeProject.hiveSpecModules.each { |spec| # local spec if not spec.path.nil? relativePath = Pathname.new(spec.path).dirname.relative_path_from(Pathname.new(podfilePath).parent) target.store_pod(spec.name,:path=>relativePath.to_s) elsif Config.buildFromCommit && (not spec.commit.nil?) target.store_pod(spec.name,:git=>spec.sourceURL, :commit=>spec.commit) else target.store_pod(spec.name,:git=>spec.sourceURL, :branch=>spec.branch) end } xcodeProject.saveHiveModulesConfig L.info("Config #{Config}") L.info("Config use frameworks #{Config.useFrameworks}") if Config.useFrameworks target.use_frameworks! L.info("Target use frameworks") end L.info "save projects" end end end