Home | History | Annotate | Download | only in Parser
      1 ## @file

      2 # This file contained the parser for [Libraries] sections in INF file 

      3 #

      4 # Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>

      5 #

      6 # This program and the accompanying materials are licensed and made available 

      7 # under the terms and conditions of the BSD License which accompanies this 

      8 # distribution. The full text of the license may be found at 

      9 # http://opensource.org/licenses/bsd-license.php

     10 #

     11 # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,

     12 # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

     13 #

     14 '''
     15 InfLibrarySectionParser
     16 '''
     17 ##

     18 # Import Modules

     19 #

     20 
     21 import Logger.Log as Logger
     22 from Logger import StringTable as ST
     23 from Logger.ToolError import FORMAT_INVALID
     24 from Parser.InfParserMisc import InfExpandMacro
     25 from Library import DataType as DT
     26 from Library.Parsing import MacroParser
     27 from Library.Misc import GetSplitValueList
     28 from Object.Parser.InfCommonObject import InfLineCommentObject
     29 from Library import GlobalData
     30 from Parser.InfParserMisc import IsLibInstanceInfo
     31 from Parser.InfAsBuiltProcess import GetLibInstanceInfo
     32 from Parser.InfParserMisc import InfParserSectionRoot
     33 
     34 class InfLibrarySectionParser(InfParserSectionRoot):
     35     ## InfLibraryParser

     36     #

     37     #                 

     38     def InfLibraryParser(self, SectionString, InfSectionObject, FileName):
     39         #

     40         # For Common INF file

     41         #

     42         if not GlobalData.gIS_BINARY_INF:
     43             #

     44             # Macro defined in this section 

     45             #

     46             SectionMacros = {}
     47             ValueList = []
     48             LibraryList = []
     49             LibStillCommentFalg = False
     50             LibHeaderComments = []
     51             LibLineComment = None
     52             #

     53             # Parse section content

     54             #

     55             for Line in SectionString:
     56                 LibLineContent = Line[0]
     57                 LibLineNo = Line[1]
     58 
     59                 if LibLineContent.strip() == '':
     60                     continue
     61 
     62                 #

     63                 # Found Header Comments 

     64                 #

     65                 if LibLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):
     66                     #

     67                     # Last line is comments, and this line go on.

     68                     #

     69                     if LibStillCommentFalg:
     70                         LibHeaderComments.append(Line)
     71                         continue
     72                     #

     73                     # First time encounter comment 

     74                     #

     75                     else:
     76                         #

     77                         # Clear original data

     78                         #

     79                         LibHeaderComments = []
     80                         LibHeaderComments.append(Line)
     81                         LibStillCommentFalg = True
     82                         continue
     83                 else:
     84                     LibStillCommentFalg = False
     85 
     86                 if len(LibHeaderComments) >= 1:
     87                     LibLineComment = InfLineCommentObject()
     88                     LineCommentContent = ''
     89                     for Item in LibHeaderComments:
     90                         LineCommentContent += Item[0] + DT.END_OF_LINE
     91                     LibLineComment.SetHeaderComments(LineCommentContent)
     92 
     93                 #

     94                 # Find Tail comment.

     95                 #

     96                 if LibLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:
     97                     LibTailComments = LibLineContent[LibLineContent.find(DT.TAB_COMMENT_SPLIT):]
     98                     LibLineContent = LibLineContent[:LibLineContent.find(DT.TAB_COMMENT_SPLIT)]
     99                     if LibLineComment == None:
    100                         LibLineComment = InfLineCommentObject()
    101                     LibLineComment.SetTailComments(LibTailComments)
    102 
    103                 #

    104                 # Find Macro

    105                 #

    106                 Name, Value = MacroParser((LibLineContent, LibLineNo),
    107                                           FileName,
    108                                           DT.MODEL_EFI_LIBRARY_CLASS,
    109                                           self.FileLocalMacros)
    110                 if Name != None:
    111                     SectionMacros[Name] = Value
    112                     LibLineComment = None
    113                     LibHeaderComments = []
    114                     continue
    115 
    116                 TokenList = GetSplitValueList(LibLineContent, DT.TAB_VALUE_SPLIT, 1)
    117                 ValueList[0:len(TokenList)] = TokenList
    118 
    119                 #

    120                 # Replace with Local section Macro and [Defines] section Macro.

    121                 #            

    122                 ValueList = [InfExpandMacro(Value, (FileName, LibLineContent, LibLineNo),
    123                                             self.FileLocalMacros, SectionMacros, True)
    124                                             for Value in ValueList]
    125 
    126                 LibraryList.append((ValueList, LibLineComment,
    127                                     (LibLineContent, LibLineNo, FileName)))
    128                 ValueList = []
    129                 LibLineComment = None
    130                 LibTailComments = ''
    131                 LibHeaderComments = []
    132 
    133                 continue
    134 
    135             #

    136             # Current section archs

    137             #    

    138             KeyList = []
    139             for Item in self.LastSectionHeaderContent:
    140                 if (Item[1], Item[2]) not in KeyList:
    141                     KeyList.append((Item[1], Item[2]))
    142 
    143             if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList=KeyList):
    144                 Logger.Error('InfParser',
    145                              FORMAT_INVALID,
    146                              ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),
    147                              File=FileName,
    148                              Line=Item[3])
    149         #

    150         # For Binary INF

    151         #

    152         else:
    153             self.InfAsBuiltLibraryParser(SectionString, InfSectionObject, FileName)
    154 
    155     def InfAsBuiltLibraryParser(self, SectionString, InfSectionObject, FileName):
    156         LibraryList = []
    157         LibInsFlag = False
    158         for Line in SectionString:
    159             LineContent = Line[0]
    160             LineNo = Line[1]
    161 
    162             if LineContent.strip() == '':
    163                 LibInsFlag = False
    164                 continue
    165 
    166             if not LineContent.strip().startswith("#"):
    167                 Logger.Error('InfParser',
    168                             FORMAT_INVALID,
    169                             ST.ERR_LIB_CONTATIN_ASBUILD_AND_COMMON,
    170                             File=FileName,
    171                             Line=LineNo,
    172                             ExtraData=LineContent)
    173 
    174             if IsLibInstanceInfo(LineContent):
    175                 LibInsFlag = True
    176                 continue
    177 
    178             if LibInsFlag:
    179                 LibGuid, LibVer = GetLibInstanceInfo(LineContent, GlobalData.gWORKSPACE, LineNo, FileName)
    180                 #

    181                 # If the VERSION_STRING is missing from the INF file, tool should default to "0".

    182                 #

    183                 if LibVer == '':
    184                     LibVer = '0'
    185                 if LibGuid != '':
    186                     if (LibGuid, LibVer) not in LibraryList:
    187                         LibraryList.append((LibGuid, LibVer))
    188 
    189         #

    190         # Current section archs

    191         #    

    192         KeyList = []
    193         Item = ['', '', '']
    194         for Item in self.LastSectionHeaderContent:
    195             if (Item[1], Item[2]) not in KeyList:
    196                 KeyList.append((Item[1], Item[2]))
    197 
    198         if not InfSectionObject.SetLibraryClasses(LibraryList, KeyList=KeyList):
    199             Logger.Error('InfParser',
    200                          FORMAT_INVALID,
    201                          ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR % ("[Library]"),
    202                          File=FileName,
    203                          Line=Item[3])
    204