lib/cocoapods-binary/Prebuild.rb in cocoapods-binary-0.2.2 vs lib/cocoapods-binary/Prebuild.rb in cocoapods-binary-0.3

- old
+ new

@@ -1,41 +1,52 @@ require_relative 'rome/build_framework' +require_relative 'helper/passer' -module Pod - class Prebuild - class_attr_accessor :framework_changes - end -end - - # patch prebuild ability module Pod class Installer + + private + def local_manifest if not @local_manifest_inited @local_manifest_inited = true raise "This method should be call before generate project" unless self.analysis_result == nil @local_manifest = self.sandbox.manifest end @local_manifest end + # @return [Analyzer::SpecsState] + def prebuild_pods_changes + return nil if local_manifest.nil? + if @prebuild_pods_changes.nil? + changes = local_manifest.detect_changes_with_podfile(podfile) + @prebuild_pods_changes = Analyzer::SpecsState.new(changes) + # save the chagnes info for later stage + Pod::Prebuild::Passer.prebuild_pods_changes = @prebuild_pods_changes + end + @prebuild_pods_changes + end + + public + # check if need to prebuild def have_exact_prebuild_cache? # check if need build frameworks return false if local_manifest == nil - changes = local_manifest.detect_changes_with_podfile(podfile) - Pod::Prebuild.framework_changes = changes # save the chagnes info for later stage - added = changes[:added] || [] - changed = changes[:changed] || [] - unchanged = changes[:unchanged] || [] - deleted = changes[:removed] || [] + changes = prebuild_pods_changes + added = changes.added + changed = changes.changed + unchanged = changes.unchanged + deleted = changes.deleted - unchange_framework_names = added + unchanged + unchange_framework_names = (added + unchanged) + exsited_framework_names = sandbox.exsited_framework_names missing = unchanged.select do |pod_name| not exsited_framework_names.include?(pod_name) end @@ -52,55 +63,97 @@ end end # Build the needed framework files - def prebuild_frameworks + def prebuild_frameworks! - local_manifest = self.local_manifest + # build options sandbox_path = sandbox.root existed_framework_folder = sandbox.generate_framework_path - bitcode_enabled = Pod::Podfile::DSL.is_bitcode_enabled - + bitcode_enabled = Pod::Podfile::DSL.bitcode_enabled + targets = [] + if local_manifest != nil - changes = local_manifest.detect_changes_with_podfile(podfile) - added = changes[:added] || [] - changed = changes[:changed] || [] - unchanged = changes[:unchanged] || [] - deleted = changes[:removed] || [] + changes = prebuild_pods_changes + added = changes.added + changed = changes.changed + unchanged = changes.unchanged + deleted = changes.deleted existed_framework_folder.mkdir unless existed_framework_folder.exist? exsited_framework_names = sandbox.exsited_framework_names # deletions # remove all frameworks except ones to remain - unchange_framework_names = added + unchanged + unchange_framework_names = (added + unchanged) to_delete = exsited_framework_names.select do |framework_name| not unchange_framework_names.include?(framework_name) end to_delete.each do |framework_name| - path = sandbox.framework_path_for_pod_name framework_name + path = sandbox.framework_folder_path_for_pod_name(framework_name) path.rmtree if path.exist? end # additions missing = unchanged.select do |pod_name| not exsited_framework_names.include?(pod_name) end - targets = (added + changed + missing).map do |pod_name| - self.pod_targets.find do |pod_target| - pod_target.root_spec.name == pod_name - end + + root_names_to_update = (added + changed + missing) + + # transform names to targets + name_to_target_hash = self.pod_targets.reduce({}) do |sum, target| + sum[target.name] = target + sum end - Pod::Prebuild.build(sandbox_path, existed_framework_folder, targets, bitcode_enabled) - + targets = root_names_to_update.map do |root_name| + name_to_target_hash[root_name] + end || [] + + # add the dendencies + dependency_targets = targets.map {|t| t.recursive_dependent_targets }.flatten.uniq || [] + targets = (targets + dependency_targets).uniq else - Pod::Prebuild.build(sandbox_path, existed_framework_folder, self.pod_targets, bitcode_enabled) + targets = self.pod_targets end + targets = targets.reject {|pod_target| sandbox.local?(pod_target.pod_name) } + + + + # build! + Pod::UI.puts "Prebuild frameworks (total #{targets.count})" + Pod::Prebuild.remove_build_dir(sandbox_path) + targets.each do |target| + next unless target.should_build? + output_path = sandbox.framework_folder_path_for_pod_name(target.name) + output_path.mkpath unless output_path.exist? + Pod::Prebuild.build(sandbox_path, target, output_path, bitcode_enabled) + end + Pod::Prebuild.remove_build_dir(sandbox_path) + + + # copy vendored libraries and frameworks + targets.each do |target| + root_path = self.sandbox.pod_dir(target.name) + target.spec_consumers.each do |consumer| + file_accessor = Sandbox::FileAccessor.new(root_path, consumer) + lib_paths = file_accessor.vendored_frameworks || [] + lib_paths += file_accessor.vendored_libraries + # @TODO dSYM files + lib_paths.each do |lib_path| + relative = lib_path.relative_path_from(root_path) + destination = sandbox.framework_folder_path_for_pod_name(target.name) + relative + destination.dirname.mkpath unless destination.dirname.exist? + FileUtils.cp_r(lib_path, destination, :remove_destination => true) + end + end + end + # Remove useless files # only keep manifest.lock and framework folder to_remain_files = ["Manifest.lock", File.basename(existed_framework_folder)] to_delete_files = sandbox_path.children.select do |file| filename = File.basename(file) @@ -109,17 +162,17 @@ to_delete_files.each do |path| path.rmtree if path.exist? end end - - + + # patch the post install hook old_method2 = instance_method(:run_plugins_post_install_hooks) define_method(:run_plugins_post_install_hooks) do old_method2.bind(self).() if Pod::is_prebuild_stage - self.prebuild_frameworks + self.prebuild_frameworks! end end end \ No newline at end of file