#NEWLINE# def parse_build_file( self , build_file ) : #NEWLINE# #INDENT# 'Capture Addressable instances from parsing `build_file`.\n    Prepare a context for parsing, read a BUILD file from the filesystem, and return the\n    Addressable instances generated by executing the code.\n    ' #NEWLINE# def _format_context_msg( lineno , offset , error_type , message ) : #NEWLINE# #INDENT# 'Show the line of the BUILD file that has the error along with a few line of context' #NEWLINE# build_contents = build_file . source ( ) . decode ( 'utf-8' ) #NEWLINE# context = 'While parsing {build_file}:\n' . format ( build_file = build_file ) #NEWLINE# curr_lineno = 0 #NEWLINE# for line in build_contents . split ( '\n' ) : #NEWLINE# #INDENT# line = line . encode ( 'ascii' , 'backslashreplace' ) #NEWLINE# curr_lineno += 1 #NEWLINE# if ( curr_lineno == lineno ) : #NEWLINE# #INDENT# highlight = '*' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# highlight = ' ' #NEWLINE# #UNINDENT# if ( curr_lineno >= ( lineno - 3 ) ) : #NEWLINE# #INDENT# context += '{highlight}{curr_lineno:4d}: {line}\n' . format ( highlight = highlight , line = line , curr_lineno = curr_lineno ) #NEWLINE# if ( lineno == curr_lineno ) : #NEWLINE# #INDENT# if offset : #NEWLINE# #INDENT# context += '       {caret:>{width}} {error_type}: {message}\n\n' . format ( caret = '^' , width = int ( offset ) , error_type = error_type , message = message ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# context += '        {error_type}: {message}\n\n' . format ( error_type = error_type , message = message ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( curr_lineno > ( lineno + 3 ) ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# #UNINDENT# return context #NEWLINE# #UNINDENT# logger . debug ( 'Parsing BUILD file {build_file}.' . format ( build_file = build_file ) ) #NEWLINE# try : #NEWLINE# #INDENT# build_file_code = build_file . code ( ) #NEWLINE# #UNINDENT# except SyntaxError as e : #NEWLINE# #INDENT# raise self . ParseError ( _format_context_msg ( e . lineno , e . offset , e . __class__ . __name__ , e ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# raise self . ParseError ( '{error_type}: {message}\n while parsing BUILD file {build_file}' . format ( error_type = e . __class__ . __name__ , message = e , build_file = build_file ) ) #NEWLINE# #UNINDENT# parse_state = self . _build_configuration . initialize_parse_state ( build_file ) #NEWLINE# try : #NEWLINE# #INDENT# with warnings . catch_warnings ( record = True ) as warns : #NEWLINE# #INDENT# six . exec_ ( build_file_code , parse_state . parse_globals ) #NEWLINE# for warn in warns : #NEWLINE# #INDENT# logger . warning ( _format_context_msg ( lineno = warn . lineno , offset = None , error_type = warn . category . __name__ , message = build_file_code . message ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# raise self . ExecuteError ( '{message}\n while executing BUILD file {build_file}' . format ( message = e , build_file = build_file ) ) #NEWLINE# #UNINDENT# address_map = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( address , addressable ) in parse_state . registered_addressable_instances : #NEWLINE# #INDENT# logger . debug ( 'Adding {addressable} to the BuildFileParser address map with {address}' . format ( addressable = addressable , address = address ) ) #NEWLINE# if ( address in address_map ) : #NEWLINE# #INDENT# raise self . AddressableConflictException ( "File {conflicting_file} defines address '{target_name}' more than once." . format ( conflicting_file = address . build_file , target_name = address . target_name ) ) #NEWLINE# #UNINDENT# address_map [ address ] = addressable #NEWLINE# #UNINDENT# logger . debug ( '{build_file} produced the following Addressables:' . format ( build_file = build_file ) ) #NEWLINE# for ( address , addressable ) in address_map . items ( ) : #NEWLINE# #INDENT# logger . debug ( '  * {address}: {addressable}' . format ( address = address , addressable = addressable ) ) #NEWLINE# #UNINDENT# return address_map