class LogParser

Parser class for the xcodebuild log.

Constants

KEYWORD_WARNING

The keyword for detecing warnings.

Warning

Struct represents warnings.

Attributes

show_build_timing_summary[RW]

Whether show build timing summary or not. @return [void]

show_build_warnings[RW]

Whether show build warnings or not. @return [void]

show_linker_warnings[RW]

Whether show linker warnings or not. @return [void]

Public Instance Methods

parse_build_timing_summary(text) click to toggle source

Parses the log text into a build timing summary message.

@param [String] text The text to parse. @return [String] Message of build timing summary.

# File lib/xcode_warnings/log_parser.rb, line 38
def parse_build_timing_summary(text)
  return nil unless @show_build_timing_summary

  lines = text.lines.map!(&:chomp)
  index = lines.reverse.index("Build Timing Summary")
  return nil if index.nil?

  build_times = lines[-index..-1]
    .select { |s| s =~ /.+/ }
    .reject { |s| s.include?("*") }
  total_time = build_times
    .map { |s| s.split(" | ")[1].split[0].to_f }
    .inject(:+)

  "#{build_times.join("\n")}\nTotal Build Time: **#{total_time}s**"
end
parse_warnings(text) click to toggle source

Parses the log text into an array of Warnings.

@param [String] text The text to parse. @return [Array] Array of `Warning`.

# File lib/xcode_warnings/log_parser.rb, line 28
def parse_warnings(text)
  warning_texts = text.each_line.select { |s| s.include?(KEYWORD_WARNING) }.uniq
  warning_texts.map! { |s| parse_warning_text(s) }.compact
end

Private Instance Methods

parse_warning_text(text) click to toggle source
# File lib/xcode_warnings/log_parser.rb, line 57
def parse_warning_text(text)
  puts text
  position, message = text.split(KEYWORD_WARNING)
  if position.start_with?("ld")
    # Linker warning
    return nil unless @show_linker_warnings

    return Warning.new(nil, nil, message.chomp)
  end

  # Build warnings
  return nil unless @show_build_warnings

  path, line, _column = position.split(":")
  return nil if path.nil?

  Warning.new(path.gsub("#{Dir.pwd}/", ""), line, message.chomp)
end