Created
January 19, 2015 09:07
-
-
Save kam800/9e42c8e8f115e3f0de09 to your computer and use it in GitHub Desktop.
Prints files that where not added to all xcode targets given in parameter
This file contains hidden or 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
# | |
# pbxproj_unused_files.rb | |
# v.1.0.0 | |
# | |
# Copyright (c) 2015 Kamil Borzym | |
# Released under the MIT License | |
# | |
require 'rubygems' | |
require 'json' | |
class PbxStructure | |
attr_accessor :target_names | |
def initialize(pbx_tree) | |
@pbx_tree = pbx_tree | |
end | |
def scanFiles | |
pbx_objects = @pbx_tree["objects"] | |
root_object = pbx_objects[@pbx_tree["rootObject"]] | |
root_object["targets"].select do |target_id| | |
@target_names.include?(pbx_objects[target_id]["name"]) | |
end.map do |target_id| | |
pbx_objects[target_id]["buildPhases"] | |
end.flatten.select do |phase_id| | |
pbx_objects[phase_id]["isa"] == "PBXSourcesBuildPhase" | |
end.map do |phase_id| | |
pbx_objects[phase_id]["files"] | |
end.flatten.map do |file_id| | |
pbx_objects[file_id]["fileRef"] | |
end.group_by do |file_id| | |
file_id | |
end.inject(Hash.new) do |hash, (k,v)| | |
hash[k] = v.length | |
hash | |
end.select do |k,v| | |
v.to_i < @target_names.length | |
end.keys.map do |file_id| | |
pbx_objects[file_id]["path"] | |
end.each do |path| | |
print path, "\n" | |
end | |
end | |
end | |
if __FILE__ == $0 | |
def usage | |
abort "Prints files that where not added to all xcode targets given in parameter | |
usage: | |
ruby #{__FILE__} pbx_path [target_name:...]" | |
end | |
pbx_path = ARGV[0] | |
target_names = ARGV[1] | |
if pbx_path.nil? or target_names.nil? | |
usage | |
end | |
pbx_data = `plutil -convert json -o - #{ARGV[0]}` | |
if $? != 0 | |
abort "Could not read project file!" | |
end | |
pbx_tree = JSON.parse(pbx_data) | |
pbx_structure = PbxStructure.new(pbx_tree) | |
pbx_structure.target_names = target_names.split(":") | |
pbx_structure.scanFiles | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment