lib/pod_builder/command/build.rb in pod-builder-0.1.8.beta vs lib/pod_builder/command/build.rb in pod-builder-0.2.0

- old
+ new

@@ -12,33 +12,37 @@ unless argument_pods.count > 0 return false end + check_not_building_subspecs(argument_pods) + update_repo = options[:update_repos] || false installer, analyzer = Analyze.installer_at(PodBuilder::basepath, update_repo) all_buildable_items = Analyze.podfile_items(installer, analyzer) prebuilt_items = all_buildable_items.select { |x| x.is_prebuilt } buildable_items = all_buildable_items - prebuilt_items if argument_pods.first == "*" - argument_pods = buildable_items.map(&:name) + argument_pods = buildable_items.map(&:root_name) end - argument_pods.select! { |x| buildable_items.map(&:name).include?(x) } + argument_pods.select! { |x| buildable_items.map(&:root_name).include?(x) } + argument_pods.uniq! unless argument_pods.count > 0 puts "\n\nNo pods to build found, `#{ARGV.join(" ")}` is/are prebuilt\n".yellow puts "\n\n🎉 done!\n".green return true end + check_splitted_subspecs_are_static(all_buildable_items, options) check_pods_exists(argument_pods, buildable_items) - pods_to_build = buildable_items.select { |x| argument_pods.include?(x.name) } + pods_to_build = buildable_items.select { |x| argument_pods.include?(x.root_name) } pods_to_build += other_subspecs(pods_to_build, buildable_items) buildable_items -= pods_to_build check_no_common_dependencies(pods_to_build, buildable_items) @@ -47,15 +51,15 @@ # Remove dependencies from pods to build all_dependencies_name = pods_to_build.map(&:dependency_names).flatten.uniq pods_to_build.select! { |x| !all_dependencies_name.include?(x.name) } # We need to split pods to build in 3 groups - # 1. subspecs: because the resulting .framework path is treated differently + # 1. subspecs: because the resulting .framework path is treated differently when added to Configuration.subspecs_to_split # 2. pods to build in release # 3. pods to build in debug - pods_to_build_subspecs = pods_to_build.select { |x| x.is_subspec } + pods_to_build_subspecs = pods_to_build.select { |x| x.is_subspec && Configuration.subspecs_to_split.include?(x.name) } pods_to_build -= pods_to_build_subspecs pods_to_build_debug = pods_to_build.select { |x| x.build_configuration == "debug" } pods_to_build_release = pods_to_build - pods_to_build_debug check_dependencies_build_configurations(all_buildable_items) @@ -78,21 +82,24 @@ FileUtils.rm_f(PodBuilder::basepath("Podfile.lock")) end write_license_files(licenses, all_buildable_items) - Podspec::generate + GenerateLFS::call(nil) + Podspec::generate(analyzer) builded_pods = podfiles_items.flatten builded_pods_and_deps = add_dependencies(builded_pods, all_buildable_items).select { |x| !x.is_prebuilt } Podfile::write_restorable(builded_pods, all_buildable_items, analyzer) if !options.has_key?(:skip_prebuild_update) - Podfile::update_prebuilt(builded_pods_and_deps, all_buildable_items, analyzer) + Podfile::write_prebuilt(all_buildable_items, analyzer) end Podfile::deintegrate_install + sanity_checks(options) + puts "\n\n🎉 done!\n".green return true end private @@ -110,11 +117,12 @@ return [] end def self.write_license_files(licenses, all_buildable_items) - license_file_path = PodBuilder::xcodepath(Configuration.license_file_name) + ".plist" + puts "Writing licenses".yellow + license_file_path = PodBuilder::project_path(Configuration.license_filename) + ".plist" current_licenses = [] if File.exist?(license_file_path) plist = CFPropertyList::List.new(:file => license_file_path) dict = CFPropertyList.native_types(plist.value) @@ -184,12 +192,13 @@ buildable_items.each do |buildable_pod| unless !pod_to_build.dependency_names.include?(buildable_pod.name) next end - if buildable_pod.dependency_names.include?(dependency) && !buildable_pod.has_subspec(dependency) && !buildable_pod.has_common_spec(dependency) then - raise "\nCan't build #{pod_to_build.name} because it has common dependencies (#{dependency}) with #{buildable_pod.name}.\n\nUse `pod_builder build #{pods_to_build.map(&:name).join(" ")} #{buildable_pod.name}` instead\n\n".red + if buildable_pod.dependency_names.include?(dependency) && !buildable_pod.has_subspec(dependency) && !buildable_pod.has_common_spec(dependency) then + expected_pod_list = pods_to_build.map(&:root_name).uniq + raise "\n\nCan't build #{pod_to_build.name} because it has common dependencies (#{dependency}) with #{buildable_pod.name}.\n\nUse `pod_builder build #{expected_pod_list.join(" ")} #{buildable_pod.name}` instead\n\n".red end end end end end @@ -197,24 +206,50 @@ def self.check_not_building_dependency(pods_to_build, buildable_items) buildable_items_dependencies = buildable_items.map(&:dependency_names).flatten.uniq pods_to_build.each do |pod_to_build| if buildable_items_dependencies.include?(pod_to_build.name) parent = buildable_items.detect { |x| x.dependency_names.include?(pod_to_build.name) } - raise "\nCan't build #{pod_to_build.name} because it is a dependency of #{parent.name}.\n\nUse `pod_builder build #{parent.name}` instead\n\n".red + raise "\n\nCan't build #{pod_to_build.name} because it is a dependency of #{parent.name}.\n\nUse `pod_builder build #{parent.name}` instead\n\n".red end end end + def self.check_not_building_subspecs(pods_to_build) + pods_to_build.each do |pod_to_build| + if pod_to_build.include?("/") + raise "\n\nCan't build subspec #{pod_to_build} refer to podspec name.\n\nUse `pod_builder build #{pods_to_build.map { |x| x.split("/").first }.uniq.join(" ")}` instead\n\n".red + end + end + end + def self.check_pods_exists(pods, buildable_items) raise "Empty Podfile?" if buildable_items.nil? - buildable_items = buildable_items.map(&:name) + buildable_items = buildable_items.map(&:root_name) pods.each do |pod| - raise "\nPod `#{pod}` wasn't found in Podfile.\n\nFound:\n#{buildable_items.join("\n")}\n\n".red if !buildable_items.include?(pod) + raise "\n\nPod `#{pod}` wasn't found in Podfile.\n\nFound:\n#{buildable_items.join("\n")}\n\n".red if !buildable_items.include?(pod) end end + def self.check_splitted_subspecs_are_static(all_buildable_items, options) + non_static_subspecs = all_buildable_items.select { |x| x.is_subspec && x.is_static == false } + non_static_subspecs_names = non_static_subspecs.map(&:name) + + invalid_subspecs = Configuration.subspecs_to_split & non_static_subspecs_names # intersect + + unless invalid_subspecs.count > 0 + return + end + + warn_message = "The following pods `#{invalid_subspecs.join(" ")}` are non static frameworks which are being splitted over different targets. Beware that this is an unsafe setup as per https://github.com/CocoaPods/CocoaPods/issues/5708 and https://github.com/CocoaPods/CocoaPods/issues/5643\n" + if options[:allow_warnings] + puts "\n\n⚠️ #{warn_message}".yellow + else + raise "\n\n🚨️ #{warn_message}".yellow + end + end + def self.check_dependencies_build_configurations(pods) pods.each do |pod| pod_dependency_names = pod.dependency_names.select { |x| !pod.has_common_spec(x) } remaining_pods = pods - [pod] @@ -232,9 +267,25 @@ pods_to_build_subspecs = pods_to_build.select { |x| x.is_subspec }.map(&:root_name) buildable_subspecs.select! { |x| pods_to_build_subspecs.include?(x.root_name) } return buildable_subspecs - pods_to_build + end + + def self.sanity_checks(options) + lines = File.read(PodBuilder::project_path("Podfile")).split("\n") + stripped_lines = lines.map { |x| Podfile.strip_line(x) }.select { |x| !x.start_with?("#")} + + expected_stripped = Podfile::POST_INSTALL_ACTIONS.map { |x| Podfile.strip_line(x) } + + if !expected_stripped.all? { |x| stripped_lines.include?(x) } + warn_message = "PodBuilder's post install actions missing from application Podfile!\n" + if options[:allow_warnings] + puts "\n\n⚠️ #{warn_message}".yellow + else + raise "\n\n🚨️ #{warn_message}".red + end + end end end end end