Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from CocoaPods/refactor
Refactor
- Loading branch information
Showing
113 changed files
with
11,687 additions
and
1,966 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ ext/xcodeproj/conftest.dSYM | |
doc | ||
tmp | ||
.DS_Store | ||
xcuserdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
--markup-provider=redcarpet | ||
--markup=markdown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,6 @@ end | |
|
||
group :documentation do | ||
gem "redcarpet" | ||
gem "github-markup" | ||
gem "yard" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,13 @@ | ||
#!/usr/bin/env ruby | ||
|
||
if $0 == __FILE__ | ||
ENV['BUNDLE_GEMFILE'] = File.expand_path('../../Gemfile', __FILE__) | ||
require "rubygems" | ||
require "bundler/setup" | ||
$:.unshift File.expand_path('../../ext', __FILE__) | ||
$:.unshift File.expand_path('../../lib', __FILE__) | ||
end | ||
|
||
require 'xcodeproj' | ||
|
||
require 'optparse' | ||
$options = {} | ||
$option_parser = OptionParser.new do |opts| | ||
opts.banner = "Usage: xcodeproj [command] [options]" | ||
opts.separator "" | ||
opts.separator "Commands:" | ||
opts.separator "" | ||
opts.separator " targets-diff [target 1] [target 2]\tShows the difference between two targets. (Only build source files atm.)" | ||
opts.separator "" | ||
|
||
opts.separator "Options:" | ||
opts.separator "" | ||
|
||
opts.on('--project PATH', "The Xcode project document to use.") do |xcodeproj| | ||
$options[:xcodeproj] = xcodeproj | ||
end | ||
|
||
opts.on("--version", "Show xcodeproj version.") do |v| | ||
puts Xcodeproj::VERSION | ||
exit | ||
end | ||
end | ||
$option_parser.parse! | ||
|
||
|
||
def invalid_command(msg = nil) | ||
if msg | ||
puts msg | ||
puts | ||
end | ||
puts $option_parser | ||
exit 1 | ||
end | ||
|
||
|
||
def xcodeproj | ||
unless xcodeproj = $options[:xcodeproj] | ||
projects = Dir.glob('*.xcodeproj') | ||
if projects.size == 1 | ||
xcodeproj = projects.first | ||
elsif projects.size > 1 | ||
invalid_command('There are more than one Xcode project documents in the current working directory. Please specify which to use.') | ||
else | ||
invalid_command('No Xcode project document found in the current working directory. Please specify which to use.') | ||
end | ||
end | ||
File.expand_path(xcodeproj) | ||
end | ||
|
||
|
||
class Xcodeproj::Project::Object::PBXGroup | ||
attributes :path | ||
end | ||
class Xcodeproj::Project::Object::PBXFileReference | ||
alias_method :_path, :path | ||
def path | ||
# TODO somethings not working right, I'm seeing the dir being prepended twice with ZipKit | ||
if (sourceTree == '<group>') && dir = group.path | ||
File.join(dir, _path) | ||
else | ||
_path | ||
end | ||
end | ||
end | ||
def target_source_files(project, target_name) | ||
project.targets.object_named(target_name).source_build_phases.map do |source_build_phase| | ||
source_build_phase.files.map { |buildFile| buildFile.file.path } | ||
end.flatten.sort | ||
end | ||
|
||
|
||
case cmd = ARGV.shift | ||
when 'targets-diff' | ||
target1, target2 = ARGV.first(2) | ||
if target1 && target2 | ||
project = Xcodeproj::Project.new(xcodeproj) | ||
target1_files = target_source_files(project, target1) | ||
target2_files = target_source_files(project, target2) | ||
|
||
diff = target1_files - target2_files | ||
puts "Files in `#{target1}' which are not present in `#{target2}':\n* #{diff.join("\n* ")}\n\n" unless diff.empty? | ||
|
||
diff = target2_files - target1_files | ||
puts "Files in `#{target2}' which are not present in `#{target1}':\n* #{diff.join("\n* ")}\n\n" unless diff.empty? | ||
else | ||
invalid_command("Needs the names of the two targets to diff.") | ||
end | ||
|
||
else | ||
invalid_command(cmd.nil? ? nil : "Unknown command: #{cmd}") | ||
end | ||
Xcodeproj::Command.run(*ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,19 @@ | ||
module Xcodeproj | ||
VERSION = '0.3.5' | ||
|
||
class PlainInformative < StandardError | ||
end | ||
|
||
class Informative < PlainInformative | ||
def message | ||
super !~ /\[!\]/ ? "[!] #{super}\n".red : super | ||
end | ||
end | ||
|
||
autoload :Config, 'xcodeproj/config' | ||
autoload :Command, 'xcodeproj/command' | ||
autoload :Constants, 'xcodeproj/constants' | ||
autoload :Helper, 'xcodeproj/helper' | ||
autoload :Project, 'xcodeproj/project' | ||
autoload :Workspace, 'xcodeproj/workspace' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
module Xcodeproj | ||
class Command | ||
class ProjectDiff < Command | ||
def self.banner | ||
%{Installing dependencies of a project: | ||
$ project-diff PROJECT_1 PROJECT_2 | ||
Shows the difference between two projects in an UUID agnostic fashion. | ||
To reduce the noise (and to simplify implementation) differences in the | ||
other of arrays are ignored. | ||
} | ||
end | ||
|
||
def self.options | ||
[ ["--ignore KEY", "A key to ignore in the comparison. Can be specified multiple times."] ].concat(super) | ||
end | ||
|
||
def initialize(argv) | ||
@path_project1 = argv.shift_argument | ||
@path_project2 = argv.shift_argument | ||
@keys_to_ignore = [] | ||
while (idx = argv.index('--ignore')) | ||
@keys_to_ignore << argv.delete_at(idx + 1) | ||
argv.delete_at(idx) | ||
end | ||
super unless argv.empty? | ||
end | ||
|
||
|
||
def run | ||
hash_1 = Project.new(@path_project1).to_tree_hash | ||
hash_2 = Project.new(@path_project2).to_tree_hash | ||
(@keys_to_ignore).each do |key| | ||
hash_1.recursive_delete(key) | ||
hash_2.recursive_delete(key) | ||
end | ||
|
||
diff = hash_1.recursive_diff(hash_2, @path_project1, @path_project2) | ||
diff.recursive_delete('displayName') | ||
|
||
require 'yaml' | ||
yaml = diff.to_yaml | ||
yaml = yaml.gsub(@path_project1, @path_project1.cyan) | ||
yaml = yaml.gsub(@path_project2, @path_project2.magenta) | ||
puts yaml | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module Xcodeproj | ||
class Command | ||
class Show < Command | ||
def self.banner | ||
%{Installing dependencies of a project: | ||
$ project-diff PROJECT_1 PROJECT_2 | ||
Shows a YAML reppresentation of a project. | ||
} | ||
end | ||
|
||
def self.options | ||
[ | ||
["--project PATH", "The Xcode project document to use."], | ||
].concat(super) | ||
end | ||
|
||
def initialize(argv) | ||
if argv.option('--project') | ||
@xcodeproj_path = File.expand_path(argv.shift_argument) | ||
end | ||
super unless argv.empty? | ||
end | ||
|
||
def run | ||
require 'yaml' | ||
yaml = xcodeproj.to_tree_hash.to_yaml | ||
puts yaml | ||
end | ||
end | ||
end | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
module Xcodeproj | ||
class Command | ||
class TargetDiff < Command | ||
def self.banner | ||
%{Installing dependencies of a project: | ||
$ targets-diff [target 1] [target 2] | ||
Shows the difference between two targets. (Only build source files atm.) | ||
} | ||
end | ||
|
||
def self.options | ||
[ | ||
["--project PATH", "The Xcode project document to use."], | ||
].concat(super) | ||
end | ||
|
||
def initialize(argv) | ||
@target1 = argv.shift_argument | ||
@target2 = argv.shift_argument | ||
if argv.option('--project') | ||
@xcodeproj_path = File.expand_path(argv.shift_argument) | ||
end | ||
super unless argv.empty? | ||
end | ||
|
||
def run | ||
require 'yaml' | ||
differ = Helper::TargetDiff.new(xcodeproj, @target1, @target2) | ||
files = differ.new_source_build_files.map do |build_file| | ||
{ | ||
'Name' => build_file.file_ref.name, | ||
'Path' => build_file.file_ref.path, | ||
'Build settings' => build_file.settings, | ||
} | ||
end | ||
puts files.to_yaml | ||
end | ||
end | ||
end | ||
end | ||
|
Oops, something went wrong.