Sha256: 6352fcebee22b77e70d52c96f06da4a5cb84dc4b080f5e1522661fa66bfb322f

Contents?: true

Size: 1.43 KB

Versions: 16

Compression:

Stored size: 1.43 KB

Contents

module XCPretty
  class JSONCompilationDatabase

    include XCPretty::FormatMethods
    FILE_PATH = 'build/reports/compilation_db.json'

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

    def initialize(options)
      load_dependencies
      @file_path = options[:path] || FILE_PATH
      @parser = Parser.new(self)
      @compilation_units = []
      @pch_path = nil
      @current_file = nil
      @current_path = nil
    end

    def handle(line)
      @parser.parse(line)
    end

    def format_process_pch_command(file_path)
      @pch_path = file_path
    end

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

    def format_compile_command(compiler_command, file_path)
      directory = file_path.gsub("#{@current_path}", '').gsub(/\/$/, '')
      directory = '/' if directory.empty?
      cmd = compiler_command.gsub(/(\-include)\s.*\.pch/, "\\1 #{@pch_path}")
      @compilation_units << {command: cmd,
                             file: @current_path,
                             directory: directory}
    end

    def finish
      FileUtils.mkdir_p(File.dirname(@file_path))
      write_report
    end

    private

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

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
xcpretty-bb-0.1.12.bb14 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb13 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb12 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb11 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb10 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb9 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb8 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb7 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-0.2.1 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb6 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-0.2.0 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb5 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb4 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb3 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb2 lib/xcpretty/reporters/json_compilation_database.rb
xcpretty-bb-0.1.12.bb1 lib/xcpretty/reporters/json_compilation_database.rb