Skip to content

Commit

Permalink
update:swift支持
Browse files Browse the repository at this point in the history
  • Loading branch information
iOSer-su350380433 committed Nov 2, 2020
1 parent 18a9ef8 commit 62f2134
Show file tree
Hide file tree
Showing 24 changed files with 594 additions and 123 deletions.
2 changes: 1 addition & 1 deletion cocoapods-imy-bin/cocoapods-imy-bin.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
spec.homepage = 'https://github.com/su350380433/cocaopods-imy-bin'
spec.license = 'MIT'

spec.files = Dir["lib/**/*.rb","spec/**/*.rb"] + %w{README.md LICENSE.txt }
spec.files = Dir["lib/**/*.rb","spec/**/*.rb","lib/**/*.plist"] + %w{README.md LICENSE.txt }

#spec.files = `git ls-files`.split($/)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
Expand Down
12 changes: 7 additions & 5 deletions cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/auto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def self.options
['--all-make', '对该组件的依赖库,全部制作为二进制组件'],
['--configuration', 'Build the specified configuration (e.g. Release ). Defaults to Debug'],
['--env', "该组件上传的环境 %w[dev debug_iphoneos release_iphoneos]"]
]
].concat(Pod::Command::Gen.options).concat(super).uniq
end

def initialize(argv)
Expand All @@ -41,6 +41,7 @@ def initialize(argv)
@verbose = argv.flag?('verbose',true)

@config = argv.option('configuration', 'Debug')
@additional_args = argv.remainder!

super
end
Expand All @@ -56,7 +57,8 @@ def run
sources_sepc.uniq.each do |spec|
begin
fail_push_specs << spec unless CBin::Upload::Helper.new(spec,@code_dependencies,@sources).upload
rescue
rescue Object => exception
UI.puts exception
fail_push_specs << spec
end
end
Expand Down Expand Up @@ -86,15 +88,15 @@ def run
end

#制作二进制包
# `pod bin archive --verbose --code-dependencies --no-clean --sources=https://gitlab.xxx.com/iOS/imyspecs.git,https://cdn.cocoapods.org/ --use-libraries`

def run_archive
argvs = [
"--sources=#{sources_option(@code_dependencies, @sources)},https:\/\/cdn.cocoapods.org",
"--use-libraries",
"--verbose"
@additional_args
]

argvs << spec_file if spec_file
argvs.delete(Array.new)

unless @clean
argvs += ['--no-clean']
Expand Down
23 changes: 16 additions & 7 deletions cocoapods-imy-bin/lib/cocoapods-imy-bin/command/bin/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ def initialize(argv)

def run
# 清除之前的缓存
temp = File.join(@local_build_dir, @platform.to_s)
FileUtils.rm_r(temp) if File.exist? temp
if File.exist?(CBin::Config::Builder.instance.zip_dir)
FileUtils.rm_r(CBin::Config::Builder.instance.zip_dir)
end
# temp = File.join(@local_build_dir, @platform.to_s)
# FileUtils.rm_r(temp) if File.exist? temp
# if File.exist?(CBin::Config::Builder.instance.zip_dir)
# FileUtils.rm_rf(Dir.glob("#{CBin::Config::Builder.instance.zip_dir}/*"))
# end

sources_spec = []
Dir.chdir(CBin::Config::Builder.instance.local_psec_dir) do
Expand Down Expand Up @@ -107,6 +107,7 @@ def build(make_binary_specs)
# 获取没有制作二进制版本的spec集合
sources_sepc << spec
end

fail_build_specs = []
sources_sepc.uniq.each do |spec|
begin
Expand Down Expand Up @@ -146,9 +147,17 @@ def build(make_binary_specs)
private

def library_exist(spec)
File.exist?(File.join(@local_build_dir, "lib#{spec.name}.a"))
File.exist?(File.join(@local_build_dir, "lib#{spec.name}.a")) || is_framework(spec)
end
# 使用了user_framework 会有#{@spec.name}.framework
# 未使用的 需要判断文件
def is_framework(spec)
res = File.exist?(File.join(@local_build_dir, "#{spec.name}.framework"))
unless res
res = File.exist?(File.join(CBin::Config::Builder.instance.xcode_BuildProductsPath_dir, "#{spec.name}","Swift Compatibility Header"))
end
res
end


end
end
Expand Down
2 changes: 1 addition & 1 deletion cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def template_hash
'configuration_env' => { description: '编译环境', default: 'dev', selection: %w[dev debug_iphoneos release_iphoneos] },
'code_repo_url' => { description: '源码私有源 Git 地址', default: '[email protected]:su350380433/example_spec_source.git' },
'binary_repo_url' => { description: '二进制私有源 Git 地址', default: '[email protected]:su350380433/example_spec_bin_dev.git' },
'binary_download_url' => { description: '二进制下载地址,内部会依次传入组件名称与版本,替换字符串中的 %s ', default: 'http://localhost:8080/frameworks/%s/%s.zip' },
'binary_download_url' => { description: '二进制下载地址,内部会依次传入组件名称与版本,替换字符串中的 %s ', default: 'http://localhost:8080/frameworks/%s/%s/zip' },
# 'binary_type' => { description: '二进制打包类型', default: 'framework', selection: %w[framework library] },
'download_file_type' => { description: '下载二进制文件类型', default: 'zip', selection: %w[zip tgz tar tbz txz dmg] }
}
Expand Down
41 changes: 39 additions & 2 deletions cocoapods-imy-bin/lib/cocoapods-imy-bin/config/config_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def self.instance

def initialize
load_build_config
# clean
end

# 加载配置项
Expand All @@ -35,6 +36,13 @@ def load_build_config

end

def clean
#清除之前的缓存
FileUtils.rm_rf(Dir.glob("#{zip_dir}/*")) if File.exist?(zip_dir)
FileUtils.rm_rf(Dir.glob("#{binary_json_dir}/*")) if File.exist?(binary_json_dir)
FileUtils.rm_rf(Dir.glob("#{local_psec_dir}/*")) if File.exist?(local_psec_dir)
end

# 制作二进制打包 工程目录
def gen_name
'bin-archive'
Expand All @@ -49,10 +57,19 @@ def gen_dir
end
end


def framework_name(spec)
"#{spec.name}.framework"
end

def framework_name_version(spec)
"#{spec.name}.framework_#{spec.version}"
end

def framework_zip_file(spec)
File.join(zip_dir_name, framework_name_version(spec))
end

def framework_file(spec)
File.join(zip_dir_name, framework_name(spec))
end
Expand Down Expand Up @@ -110,7 +127,8 @@ def binary_json_dir
#编译target名,如 seeyou
def target_name
@target_name ||= begin
Pod::Config.instance.podfile.root_target_definitions.first.children.first.to_s.split('-').last
target_name_str = Pod::Config.instance.podfile.root_target_definitions.first.children.first.to_s
target_name_str[5,target_name_str.length]
end
end

Expand All @@ -129,6 +147,7 @@ def xcode_build_name
if @xcode_build_name.nil? || Dir.exist?(@xcode_build_name)
@xcode_build_name = "xcode-build/Build/Intermediates.noindex/ArchiveIntermediates/#{target_name}/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/"
end
puts @xcode_build_name
@xcode_build_name
end
end
Expand All @@ -146,7 +165,25 @@ def xcode_build_dir
end
end
end

#完整的xcodebuild BuildProductsPath输出路径,
def xcode_BuildProductsPath_dir
@xcode_BuildProductsPath_dir ||= begin
temp_xcode_BuildProductsPath_dir = "xcode-build/Build/Intermediates.noindex/ArchiveIntermediates/#{target_name}/BuildProductsPath/"
full_path = File.join(root_dir, temp_xcode_BuildProductsPath_dir)

if (File.exist?(full_path))
Dir.chdir(full_path) do
iphoneos = Dir.glob('*-iphoneos')
if iphoneos.length > 0
full_path = File.join(full_path,iphoneos.first)
else
UI.warn "====== 找不到 *-iphoneos @xcode_BuildProductsPath_dir = #{@xcode_BuildProductsPath_dir}"
end
end
end
Pathname.new(full_path)
end
end


#处理编译产物后存储根目录,会存放spec、 json、zip的父目录,默认是工程的同级目录下,"#{basename}-build-temp"
Expand Down
2 changes: 1 addition & 1 deletion cocoapods-imy-bin/lib/cocoapods-imy-bin/gem_version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

module CBin
VERSION = '0.2.9'
VERSION = '0.3.0.12'
end

module Pod
Expand Down
1 change: 1 addition & 0 deletions cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
require 'cocoapods-imy-bin/helpers/spec_creator'
require 'cocoapods-imy-bin/helpers/spec_files_helper'
require 'cocoapods-imy-bin/helpers/spec_source_creator'
require 'cocoapods-imy-bin/helpers/build_utils'
Binary file not shown.
22 changes: 15 additions & 7 deletions cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ def build

build_static_framework
unless @skip_archive
build_static_library
zip_static_framework if @zip &&= @framework_output
zip_static_library
unless CBin::Build::Utils.is_framework(@spec)
build_static_library
zip_static_library
else
zip_static_framework
end
end

end
Expand Down Expand Up @@ -71,15 +74,15 @@ def build_static_library
end

def zip_static_framework
Dir.chdir(zip_dir) do
output_name = "#{framework_name}.zip"
Dir.chdir(File.join(workspace_directory,@framework_path.root_path)) do
output_name = File.join(zip_dir, framework_name_zip)
unless File.exist?(framework_name)
raise Informative, "没有需要压缩的 framework 文件:#{framework_name}"
UI.puts "没有需要压缩的 framework 文件:#{framework_name}"
return
end

UI.puts "Compressing #{framework_name} into #{output_name}"
`zip --symlinks -r #{output_name} #{framework_name}`

end
end

Expand Down Expand Up @@ -114,6 +117,10 @@ def framework_name
CBin::Config::Builder.instance.framework_name(@spec)
end

def framework_name_zip
CBin::Config::Builder.instance.framework_name_version(@spec) + ".zip"
end

def library_name
CBin::Config::Builder.instance.library_name(@spec)
end
Expand All @@ -130,6 +137,7 @@ def gen_name
CBin::Config::Builder.instance.gen_dir
end


def spec_file
@spec_file ||= begin
if @podspec
Expand Down
63 changes: 63 additions & 0 deletions cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/build_utils.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require 'yaml'
require 'cocoapods-imy-bin/config/config'

module CBin
class Build

class Utils

def Utils.is_framework(spec)
if Utils.uses_frameworks?
return true
end

return Utils.is_swift_module(spec)
end

def Utils.is_swift_module(spec)

is_framework = false
dir = File.join(CBin::Config::Builder.instance.gen_dir, CBin::Config::Builder.instance.target_name)
#auto 走这里
if File.exist?(dir)
Dir.chdir(dir) do
public_headers = Array.new
spec_header_dir = "./Headers/Public/#{spec.name}"

unless File.exist?(spec_header_dir)
spec_header_dir = "./Pods/Headers/Public/#{spec.name}"
end
return false unless File.exist?(spec_header_dir)

is_framework = File.exist?(File.join(spec_header_dir, "#{spec.name}-umbrella.h"))
end
end

if $ARGV[1] == "local"
is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_build_dir, "#{spec.name}.framework"))
unless is_framework
is_framework = File.exist?(File.join(CBin::Config::Builder.instance.xcode_BuildProductsPath_dir, "#{spec.name}","Swift Compatibility Header"))
end
end

is_framework
end

def Utils.uses_frameworks?
uses_frameworks = false
Pod::Config.instance.podfile.target_definitions.each do |key,value|
if key != "Pods"
uses_frameworks = value.uses_frameworks?
if uses_frameworks
break ;
end
end
end

return uses_frameworks
end

end

end
end
27 changes: 25 additions & 2 deletions cocoapods-imy-bin/lib/cocoapods-imy-bin/helpers/framework.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Framework
attr_reader :resources_path
attr_reader :root_path
attr_reader :versions_path
attr_reader :swift_module_path
attr_reader :fwk_path

def initialize(name, platform)
@name = name
Expand All @@ -22,8 +24,24 @@ def make
end

def delete_resources
Pathname.new(@resources_path).rmtree
(Pathname.new(@fwk_path) + Pathname.new('Resources')).delete
Pathname.new(@resources_path).rmtree if File.exist? (@resources_path)
(Pathname.new(@fwk_path) + Pathname.new('Resources')).delete if File.exist?(Pathname.new(@fwk_path) + Pathname.new('Resources'))
end

def remove_current_version
FileUtils.rm_f(File.join(@fwk_path,@name))
FileUtils.rm_f(File.join(@fwk_path,"Headers"))
FileUtils.rm_f(File.join(@fwk_path,"Resources"))

FileUtils.cp_r("#{@versions_path}/.", @fwk_path)
# FileUtils.remove_dir(@versions_path)
FileUtils.remove_dir("#{@fwk_path}/Versions")

# current_version_path = @versions_path + Pathname.new('../Current')
# `ln -sf A #{current_version_path}`
# `ln -sf Versions/Current/Headers #{@fwk_path}/`
# `ln -sf Versions/Current/Resources #{@fwk_path}/`
# `ln -sf Versions/Current/#{@name} #{@fwk_path}/`
end

private
Expand All @@ -36,11 +54,16 @@ def make_current_version
`ln -sf Versions/Current/#{@name} #{@fwk_path}/`
end



def make_framework
@fwk_path = @root_path + Pathname.new(@name + '.framework')
@fwk_path.mkdir unless @fwk_path.exist?

@module_map_path = @fwk_path + Pathname.new('Modules')
@swift_module_path = @module_map_path + Pathname.new(@name + '.swiftmodule')


@versions_path = @fwk_path + Pathname.new('Versions/A')
end

Expand Down
Loading

0 comments on commit 62f2134

Please sign in to comment.