lib/pod/command/check.rb in cocoapods-check-0.1.1.beta.1 vs lib/pod/command/check.rb in cocoapods-check-0.2.1.beta.1

- old
+ new

@@ -9,14 +9,12 @@ SUMMARY self.description = <<-DESC Compares the Pod lockfile with the manifest lockfile and shows any differences. In non-verbose mode, '~' indicates an existing Pod - will be updated to the version specified in Podfile.lock, '+' - indicates a missing Pod will be installed, and 'Δ' indicates a Pod - is a development Pod. Development Pods are always considered - to need installation. + will be updated to the version specified in Podfile.lock and '+' + indicates a missing Pod will be installed. DESC self.arguments = [] def self.options @@ -41,11 +39,11 @@ end def find_development_pods(podfile) development_pods = {} podfile.dependencies.each do |dependency| - development_pods[dependency.name] = dependency.external_source if dependency.external? + development_pods[dependency.name] = dependency.external_source if dependency.local? end development_pods end def find_differences(config, development_pods) @@ -62,14 +60,17 @@ manifest_version = nil end # If this Pod is installed if manifest_version + # If this is a development pod do a modified time check if development_pods[spec_name] != nil - if is_development_pod_modified?(config, development_pods[spec_name]) - changed_result(spec_name, manifest_version, locked_version) + newer_files = get_files_newer_than_lockfile_for_podspec(config, development_pods[spec_name]) + if newer_files.any? + changed_development_result(spec_name, newer_files) end + # Otherwise just compare versions elsif locked_version != manifest_version changed_result(spec_name, manifest_version, locked_version) end # If this Pod is not installed @@ -77,15 +78,28 @@ added_result(spec_name) end end.compact end - def is_development_pod_modified?(config, development_pod) - development_podspec_file = development_pod[:path] - development_pod_dir = File.dirname(development_podspec_file) - spec = Specification.from_file(development_podspec_file) + def get_files_newer_than_lockfile_for_podspec(config, development_pod) + files_for_podspec = get_files_for_podspec(development_pod[:path]) + lockfile_mtime = File.mtime(config.lockfile.defined_in_file) + podspec_file = get_podspec_for_file_or_path(development_pod[:path]) + podspec_dir = Pathname.new(File.dirname(podspec_file)) + files_for_podspec + .select {|f| File.mtime(f) >= lockfile_mtime} + .map {|f| Pathname.new(f).relative_path_from(podspec_dir).to_s} + end + + # Returns an array of all files pointed to by the podspec + def get_files_for_podspec(podspec_file) + podspec_file = get_podspec_for_file_or_path(podspec_file) + + development_pod_dir = File.dirname(podspec_file) + spec = Specification.from_file(podspec_file) + # Gather all the dependencies used by the spec, across all platforms, and including subspecs. all_files = [spec, spec.subspecs].flatten.map { |a_spec| a_spec.available_platforms.map { |platform| accessor = Sandbox::FileAccessor.new(Sandbox::PathList.new(Pathname.new(development_pod_dir)), a_spec.consumer(platform)) [ @@ -100,26 +114,38 @@ accessor.source_files ].compact } }.flatten - # Also check the podspec date - all_files.push(development_podspec_file) + # Include the podspec files as well + all_files.push(podspec_file) + end - latest_modified_file = all_files.max_by {|f| File.mtime(f)} - - if latest_modified_file - pod_mtime = File.mtime(latest_modified_file) - manifest_mtime = File.mtime(config.lockfile.defined_in_file) - pod_mtime >= manifest_mtime + def get_podspec_for_file_or_path(podspec_file_or_path) + if File.basename(podspec_file_or_path).include?('.podspec') + podspec_file_or_path else - false + glob_pattern = podspec_file_or_path + '/*.podspec{,.json}' + Pathname.glob(glob_pattern).first end end def changed_result(spec_name, manifest_version, locked_version) if @check_command_verbose "#{spec_name} #{manifest_version} -> #{locked_version}" + else + "~#{spec_name}" + end + end + + def changed_development_result(spec_name, newer_files) + if @check_command_verbose + number_files_not_shown = newer_files.length - 2 + newer_files = newer_files[0..1] + if number_files_not_shown > 0 + newer_files.push("and #{number_files_not_shown} other#{'s' if number_files_not_shown > 1}") + end + "#{spec_name} (#{newer_files.join(', ')})" else "~#{spec_name}" end end