Class: PPL::Command::Build
- Inherits:
-
PPL::Command
- Object
- CLAide::Command
- PPL::Command
- PPL::Command::Build
- Defined in:
- lib/pod-pipeline/command/build.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_headers ⇒ Object
- #combine_binarys(local_dependency, pod_dependency) ⇒ Object
- #copy_bundles(local_dependency, pod_dependency) ⇒ Object
-
#initialize(argv) ⇒ Build
constructor
A new instance of Build.
- #merge_bundles ⇒ Object
- #reset_dir ⇒ Object
- #run ⇒ Object
Methods inherited from PPL::Command
#argv_extension, ensure_not_root_or_allowed!, git_version, options_extension, options_extension_hash, run, verify_minimum_git_version!, verify_xcode_license_approved!
Constructor Details
#initialize(argv) ⇒ Build
Returns a new instance of Build.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pod-pipeline/command/build.rb', line 31 def initialize(argv) @path = argv.arguments! @output = argv.option('output', '').split(',').first @configuration = argv.option('configuration', '').split(',').first @archs = argv.option('arch', '').split(',') @combines = argv.option('combine', '').split(',') @combine_ignore = argv.option('combine-ignore', '').split(',') @bundle_merge = argv.option('bundle-merge', '').split(',').first @projectPath = @path.count.zero? ? Pathname.pwd.to_s : @path.first @output = @output ? @output : @projectPath super end |
Class Method Details
.options ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/pod-pipeline/command/build.rb', line 20 def self. [ ['--output=./', '项目构建的输出目录。(默认使用项目根目录)'], ['--configuration=Release', '项目构建的环境。(默认为Release)'], ['--arch=arm64,armv7,x86_64', '项目构建的架构。(默认为 arm64,armv7,x86_64)'], ['--combine=local,pod', '项目构建后合并依赖库的二进制文件,local为本地依赖库,pod为CocoaPods依赖库。(默认为 不合并)'], ['--combine-ignore=name1,name2', '项目构建后合并依赖库的二进制文件,标注不想合并的内容。'], ['--bundle-merge=merge', '是否合并所有资源包,参数为合并后的资源包名。(默认为 不合并)'], ].concat(super) end |
Instance Method Details
#add_headers ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/pod-pipeline/command/build.rb', line 98 def add_headers header_stands = "#{@output}/Example/Pods/Headers/Public/#{@podspec.name}/*.h" Dir[header_stands].each do |header_stand| if File.ftype(header_stand).eql? 'link' header_file = "#{File.dirname(header_stand)}/#{File.readlink(header_stand)}" if File.ftype(header_file).eql? 'file' header_file_basename = File.basename(header_file) if !(File.exist? "#{@framework_headers_path}/#{header_file_basename}") puts header_file_basename FileUtils.cp(header_file, @framework_headers_path) end end end end header_files = "#{@build_path}/**/#{@podspec.name}.framework/Headers/*.h" Dir[header_files].each do |header_file| if File.ftype(header_file).eql? 'file' header_file_basename = File.basename(header_file) if !(File.exist? "#{@framework_headers_path}/#{header_file_basename}") puts header_file_basename FileUtils.cp(header_file, @framework_headers_path) end end end end |
#combine_binarys(local_dependency, pod_dependency) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/pod-pipeline/command/build.rb', line 124 def combine_binarys(local_dependency, pod_dependency) binary = "#{@framework_path}/#{@podspec.name}" #添加 构建生成的二进制文件 inputs = [] inputs << "#{@build_path}/*/**/lib#{@podspec.name}.a" inputs << "#{@build_path}/*/**/*.framework/#{@podspec.name}" if local_dependency #添加 本地依赖的二进制文件 inputs << "#{@output}/#{@podspec.name}/Libraries/**/*.a" inputs << "#{@output}/#{@podspec.name}/Frameworks/**/*.framework/*" end if pod_dependency #添加 Pod依赖库构建生成的二进制文件 inputs << "#{@build_path}/*/**/lib*.a"; inputs << "#{@build_path}/*/**/*.framework/*"; #添加 Pod依赖库预先构建的二进制文件 inputs << "#{@output}/Example/Pods/**/*SDK/*.framework/*" #添加 Pod依赖库本地依赖的二进制文件 inputs << "#{@output}/Example/Pods/**/Libraries/**/*.a" inputs << "#{@output}/Example/Pods/**/Frameworks/**/*.framework/*" end Binary.combine(binary, inputs, @combine_ignore) Binary.thin(binary, @archs) end |
#copy_bundles(local_dependency, pod_dependency) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/pod-pipeline/command/build.rb', line 150 def copy_bundles(local_dependency, pod_dependency) #添加 构建生成的资源包 inputs = ["#{@build_path}/**/#{@podspec.name}/*.bundle"] if local_dependency #添加 本地依赖的资源包 inputs << "#{@output}/#{@podspec.name}/Libraries/**/*.bundle" inputs << "#{@output}/#{@podspec.name}/Frameworks/**/*.bundle" end if pod_dependency #添加 Pod依赖库构建生成的资源包 inputs << "#{@build_path}/*/**/*.bundle" #添加 Pod依赖库预先构建的资源包 inputs << "#{@output}/Example/Pods/**/*SDK/*.bundle" #添加 Pod依赖库本地依赖的资源包 inputs << "#{@output}/Example/Pods/**/Libraries/**/*.bundle" inputs << "#{@output}/Example/Pods/**/Frameworks/**/*.bundle" end Bundle.cp(inputs, @build_path, @combine_ignore) end |
#merge_bundles ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/pod-pipeline/command/build.rb', line 171 def merge_bundles #初始化资源文件夹 bundle_path = "#{@build_path}/#{@bundle_merge}" Dir.reset(bundle_path) #合并资源文件 Dir["#{@build_path}/*.bundle/*"].each do |asset| `cp -fr "#{asset}" "#{bundle_path}"` end #删除bundle Dir["#{@build_path}/*.bundle/"].each do |bundle| `rm -fr "#{bundle}"` end #将资源文件夹命名为 .bundle 格式 `mv "#{bundle_path}" "#{bundle_path}.bundle"` end |
#reset_dir ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/pod-pipeline/command/build.rb', line 87 def reset_dir #初始化 构建目录 @build_path = "#{@output}/#{@podspec.name}-#{@podspec.version}" Dir.reset(@build_path) #初始化 Framework目录 @framework_path = "#{@build_path}/#{@podspec.name}.framework" Dir.reset(@framework_path) @framework_headers_path = "#{@framework_path}/Headers" Dir.reset(@framework_headers_path) end |
#run ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/pod-pipeline/command/build.rb', line 46 def run PPL::Scanner.new(@projectPath, ["all"]).run @podspec = PPL::Scanner.linter.spec @workspace = PPL::Scanner.workspace puts "Pod: #{@podspec}" puts "Workspace: #{@workspace.path}" if !@archs puts "无需构建" return end #初始化 构建目录 reset_dir #构建 puts "\n[构建 #{@configuration} 环境的 #{@archs.join(", ")} 架构项目]" @archs.each do |arch| XCodebuild.build(@workspace.path, @podspec.name, arch, @configuration, @build_path) end #添加头文件 puts "\n[添加Framework头文件]" add_headers #合并二进制文件 puts "\n[合并 #{@combines.join(", ")} 的二进制文件]" combine_binarys(@combines.include?('local'), @combines.include?('pod')) #拷贝资源包 puts "\n[拷贝 #{@combines.join(", ")} 的资源包 到输出目录]" copy_bundles(@combines.include?('local'), @combines.include?('pod')) #合并资源包 if @bundle_merge puts "\n[合并的资源包内容 到 #{@bundle_merge}.bundle]" merge_bundles end end |