provide error messages for git bisect
Signed-off-by: Lin Jiaxin ljx.joe@qq.com --- lib/error_messages.rb | 73 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 lib/error_messages.rb
diff --git a/lib/error_messages.rb b/lib/error_messages.rb new file mode 100644 index 0000000..7bf3aa8 --- /dev/null +++ b/lib/error_messages.rb @@ -0,0 +1,73 @@ +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'set' + +# usage: +# foo = ErrorMessages.new(build-pkg) +# build-pkg is a file that includes errors generated by make +# error_messages_hash = foo.obtain_error_messages +# error_messages_hash.each { |k,v| puts k; puts; v.each {|m| puts m } } +# output: +# src/arg.c:117:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] +# +# src/arg.c:117:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] +# for (nbarg = 0; nbarg < ARGM_NBARGS && ((mask >> (nbarg * ARGT_BITS)) & ARGT_MASK); nbarg++); +# ^ +class ErrorMessages + def initialize(file) + @file = file + @seqno = '' + @in_stderr = false + @error_line = '' + @error_details = '' + @error_message = {} + @error_messages = Hash.new { |h, k| h[k] = Set.new } + end + + def obtain_error_messages + File.open(@file).each_line do |line| + next if extract_error_message(line) + next unless @in_stderr + next unless @error_message['error_line'] =~ /error|warning/i + + @error_messages[@error_message['error_line']] << @error_message['error_line'] + @error_message['error_details'] + end + return @error_messages + end + + private + + def extract_error_message(line) + if line =~ /^ / + @error_details += line + else + update_error_message(line) + case line + when /^## ______________([0-9.]+):stderr$/ + @in_stderr = true + @seqno = $1 + return true + + when /^## ______________#{@seqno}:enderr$/ + @in_stderr = false + @seqno = '' + add_error_message + end + end + end + + def update_error_message(line) + @error_message['error_line'] = @error_line + @error_message['error_details'] = @error_details + @error_line = line + @error_details = '' + end + + def add_error_message + return unless @error_message['error_line'] =~ /error|warning/i + + @error_messages[@error_message['error_line']] << @error_message['error_line'] + @error_message['error_details'] + end +end