Class: XCPretty::JSONCompilationDatabase

Inherits:
Reporter show all
Defined in:
lib/xcpretty/reporters/json_compilation_database.rb

Constant Summary collapse

FILEPATH =
'build/reports/compilation_db.json'

Constants inherited from Formatter

Formatter::ASCII_ERROR, Formatter::ASCII_WARNING, Formatter::ERROR, Formatter::WARNING

Constants included from FormatMethods

FormatMethods::EMPTY

Constants included from ANSI

ANSI::COLORS, ANSI::EFFECT, ANSI::FORMATTED_MATCHER

Instance Attribute Summary

Attributes inherited from Reporter

#tests

Attributes inherited from Formatter

#parser

Attributes included from ANSI

#colorize

Instance Method Summary collapse

Methods inherited from Reporter

#finish, #format_failing_test, #format_passing_test, #format_pending_test, #handle

Methods inherited from Formatter

#finish, #format_compile_error, #format_compile_warning, #format_duplicate_symbols, #format_error, #format_file_missing_error, #format_ld_warning, #format_test_summary, #format_undefined_symbols, #format_will_not_be_code_signed, #optional_newline, #pretty_format, #use_unicode?

Methods included from FormatMethods

#format_aggregate_target, #format_analyze, #format_analyze_target, #format_build_target, #format_check_dependencies, #format_clean, #format_clean_remove, #format_clean_target, #format_codesign, #format_compile_error, #format_compile_storyboard, #format_compile_warning, #format_compile_xib, #format_copy_header_file, #format_copy_plist_file, #format_copy_strings_file, #format_cpresource, #format_duplicate_symbols, #format_error, #format_failing_test, #format_file_missing_error, #format_generate_dsym, #format_ld_warning, #format_libtool, #format_linking, #format_measuring_test, #format_passing_test, #format_pbxcp, #format_pending_test, #format_phase_script_execution, #format_phase_success, #format_preprocess, #format_process_info_plist, #format_process_pch, #format_shell_command, #format_test_run_finished, #format_test_run_started, #format_test_suite_started, #format_test_summary, #format_tiffutil, #format_touch, #format_undefined_symbols, #format_warning, #format_write_auxiliary_files, #format_write_file

Methods included from ANSI

#ansi_parse, #applied_effects, #colorize?, #cyan, #green, #red, #strip, #white, #yellow

Constructor Details

#initialize(options) ⇒ JSONCompilationDatabase

Returns a new instance of JSONCompilationDatabase.



15
16
17
18
19
20
21
# File 'lib/xcpretty/reporters/json_compilation_database.rb', line 15

def initialize(options)
  super(options)
  @compilation_units = []
  @pch_path = nil
  @current_file = nil
  @current_path = nil
end

Instance Method Details

#format_compile(file_name, file_path) ⇒ Object



27
28
29
30
# File 'lib/xcpretty/reporters/json_compilation_database.rb', line 27

def format_compile(file_name, file_path)
  @current_file = file_name
  @current_path = file_path
end

#format_compile_command(compiler_command, file_path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xcpretty/reporters/json_compilation_database.rb', line 32

def format_compile_command(compiler_command, file_path)
  directory = file_path.gsub("#{@current_path}", '').gsub(/\/$/, '')
  directory = '/' if directory.empty?

  cmd = compiler_command
  cmd = cmd.gsub(/(\-include)\s.*\.pch/, "\\1 #{@pch_path}") if @pch_path

  @compilation_units << {command: cmd,
                         file: @current_path,
                         directory: directory}
end

#format_process_pch_command(file_path) ⇒ Object



23
24
25
# File 'lib/xcpretty/reporters/json_compilation_database.rb', line 23

def format_process_pch_command(file_path)
  @pch_path = file_path
end

#load_dependenciesObject



6
7
8
9
10
11
12
13
# File 'lib/xcpretty/reporters/json_compilation_database.rb', line 6

def load_dependencies
  unless @@loaded ||= false
    require 'fileutils'
    require 'pathname'
    require 'json'
    @@loaded = true
  end
end

#write_reportObject



44
45
46
47
48
# File 'lib/xcpretty/reporters/json_compilation_database.rb', line 44

def write_report
  File.open(@filepath, 'w') do |f|
    f.write(@compilation_units.to_json)
  end
end