Class: XcodeBuildTimer
- Inherits:
-
Object
- Object
- XcodeBuildTimer
- Defined in:
- lib/xcode-build-times.rb
Instance Method Summary collapse
- #add_timings(xcodeproj_path) ⇒ Object
- #generate_events_js ⇒ Object
-
#initialize(options) ⇒ XcodeBuildTimer
constructor
A new instance of XcodeBuildTimer.
- #inject_timings_to_all_projects ⇒ Object
- #remove_timings(xcodeproj_path) ⇒ Object
- #remove_timings_from_all_projects ⇒ Object
Constructor Details
#initialize(options) ⇒ XcodeBuildTimer
Returns a new instance of XcodeBuildTimer.
8 9 10 11 |
# File 'lib/xcode-build-times.rb', line 8 def initialize() @inject_path = [:inject_path] || '' @events_file_path = [:events_file_path] end |
Instance Method Details
#add_timings(xcodeproj_path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/xcode-build-times.rb', line 13 def add_timings(xcodeproj_path) begin project = Xcodeproj::Project.open(xcodeproj_path) rescue Exception => e puts '[???]'.yellow + " There were some problems in opening #{xcodeproj_path} : #{e.to_s}" return end project.native_targets.each do |target| unless target.shell_script_build_phases.find {|phase| phase.name == 'Timing START' } timing_start = target.new_shell_script_build_phase('Timing START') timing_start.shell_script = <<-eos DATE=`date "+%Y-%m-%dT%H:%M:%S.%s"` echo "{\\"date\\":\\"$DATE\\", \\"taskName\\":\\"$TARGETNAME\\", \\"event\\":\\"start\\"}," >> #{@events_file_path} eos index = target.build_phases.index {|phase| (defined? phase.name) && phase.name == 'Timing START' } target.build_phases.move_from(index, 0) end unless target.shell_script_build_phases.find {|phase| phase.name == 'Timing END' } timing_end = target.new_shell_script_build_phase('Timing END') timing_end.shell_script = <<-eos DATE=`date "+%Y-%m-%dT%H:%M:%S.%s"` echo "{\\"date\\":\\"$DATE\\", \\"taskName\\":\\"$TARGETNAME\\", \\"event\\":\\"end\\"}," >> #{@events_file_path} eos end end project.save end |
#generate_events_js ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/xcode-build-times.rb', line 95 def generate_events_js begin raw_events = File.read(File.(@events_file_path)) rescue puts '[???]'.yellow + " There were some problems in opening #{@events_file_path} (It doesn't seem that build was created)" return end js_chart_directory = 'xcode-build-times-chart' unless File.exist?(js_chart_directory) puts "[CHART] Will copy chart to #{Dir.pwd}" source_dir = File.("../#{js_chart_directory}", __FILE__) FileUtils.copy_entry(source_dir, File.(js_chart_directory)) end js_valid_file = "var raw_events = [\n" + raw_events + "\n]" open("#{js_chart_directory}/events.js", 'w') do |f| f << js_valid_file puts '[EVENTS]'.green + " Updated events.js at #{f.path}\n" + '[EVENTS]'.green + " It's time to open #{js_chart_directory}/gantt.html" end end |
#inject_timings_to_all_projects ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/xcode-build-times.rb', line 72 def inject_timings_to_all_projects Dir.chdir(@inject_path) { all_xcode_projects = Dir.glob('**/*.xcodeproj').reject {|path| !File.directory?(path)} all_xcode_projects.each {|xcodeproj| puts "Adding timings phases to #{xcodeproj.green}" add_timings(xcodeproj) } } end |
#remove_timings(xcodeproj_path) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/xcode-build-times.rb', line 52 def remove_timings(xcodeproj_path) begin project = Xcodeproj::Project.open(xcodeproj_path) rescue Exception => e puts '[???]'.yellow + " There were some problems in opening #{xcodeproj_path} : #{e.to_s}" return end project.native_targets.each do |target| start_target = target.shell_script_build_phases.find {|phase| phase.name == 'Timing START' } start_target.remove_from_project if start_target end_target = target.shell_script_build_phases.find {|phase| phase.name == 'Timing END' } end_target.remove_from_project if end_target end project.save end |
#remove_timings_from_all_projects ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/xcode-build-times.rb', line 83 def remove_timings_from_all_projects Dir.chdir(@inject_path) { all_xcode_projects = Dir.glob('**/*.xcodeproj').reject {|path| !File.directory?(path)} all_xcode_projects.each {|xcodeproj| puts "Removing timings phases from #{xcodeproj.green}" remove_timings(xcodeproj) } } end |