Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix UNDEFINED_SYMBOL formatter and print #222

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions lib/xcpretty/formatters/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def format_compile_error(file_name, file_path, reason,
def format_error(message); EMPTY; end
def format_file_missing_error(error, file_path); EMPTY; end
def format_ld_warning(message); EMPTY; end
def format_undefined_symbols(message, symbol, reference); EMPTY; end
def format_undefined_symbols(message, infos); EMPTY; end
def format_duplicate_symbols(message, file_paths); EMPTY; end
def format_warning(message); message; end

Expand Down Expand Up @@ -137,10 +137,16 @@ def format_ld_warning(reason)
"#{yellow(warning_symbol + ' ' + reason)}"
end

def format_undefined_symbols(message, symbol, reference)
"\n#{red(error_symbol + " " + message)}\n" \
"> Symbol: #{symbol}\n" \
"> Referenced from: #{reference}\n\n"
def format_undefined_symbols(message, infos)
msg = "\n#{red(error_symbol + " " + message)}\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

infos.each do |info|
msg = "#{msg}> Symbol: #{info[:symbol]}\n"
info[:references].each do |reference|
msg = "#{msg}> Referenced from: #{reference}\n"
end
msg = "#{msg}\n"
end
msg
end

def format_duplicate_symbols(message, file_paths)
Expand Down
20 changes: 10 additions & 10 deletions lib/xcpretty/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ module Errors

# @regex Captured groups
# $1 symbol location
LINKER_UNDEFINED_SYMBOL_LOCATION_MATCHER = /^(.* in .*\.o)$/
LINKER_UNDEFINED_SYMBOL_LOCATION_MATCHER = /^(.* in .*\.o[\)]?)$/

# @regex Captured groups
# $1 reason
Expand Down Expand Up @@ -279,7 +279,6 @@ def parse(text)

return format_compile_error if should_format_error?
return format_compile_warning if should_format_warning?
return format_undefined_symbols if should_format_undefined_symbols?
return format_duplicate_symbols if should_format_duplicate_symbols?

case text
Expand Down Expand Up @@ -334,7 +333,7 @@ def parse(text)
when LD_WARNING_MATCHER
formatter.format_ld_warning($1 + $2)
when LD_ERROR_MATCHER
formatter.format_error($1)
format_undefined_symbols($1) if should_format_undefined_symbols?
when LIBTOOL_MATCHER
formatter.format_libtool($1)
when LINKING_MATCHER
Expand Down Expand Up @@ -430,9 +429,10 @@ def update_linker_failure_state(text)

case text
when SYMBOL_REFERENCED_FROM_MATCHER
current_linker_failure[:symbol] = $1
info = { symbol: $1 , references: []}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Space found before comma.
Space inside { detected.

current_linker_failure[:infos] << info
when LINKER_UNDEFINED_SYMBOL_LOCATION_MATCHER
current_linker_failure[:reference] = text.strip
current_linker_failure[:infos][-1][:references] << text.strip
when LINKER_DUPLICATE_SYMBOLS_LOCATION_MATCHER
current_linker_failure[:files] << $1
end
Expand All @@ -452,7 +452,7 @@ def error_or_warning_is_present
end

def should_format_undefined_symbols?
current_linker_failure[:message] && current_linker_failure[:symbol] && current_linker_failure[:reference]
current_linker_failure[:message] && current_linker_failure[:infos].count > 1
end

def should_format_duplicate_symbols?
Expand All @@ -464,7 +464,7 @@ def current_issue
end

def current_linker_failure
@linker_failure ||= {files: []}
@linker_failure ||= {files: [], infos: []}
end

def format_compile_error
Expand All @@ -489,12 +489,12 @@ def format_compile_warning
warning[:cursor])
end

def format_undefined_symbols
def format_undefined_symbols(ld_error)
result = formatter.format_undefined_symbols(
current_linker_failure[:message],
current_linker_failure[:symbol],
current_linker_failure[:reference]
current_linker_failure[:infos]
)
result = result + formatter.format_error(ld_error)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use self-assignment shorthand +=.

reset_linker_format_state
result
end
Expand Down