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

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

      3 #

      4 # Copyright (c) 2011, 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 InfPackageSectionParser
     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 Parser.InfParserMisc import InfParserSectionRoot
     30 
     31 class InfPackageSectionParser(InfParserSectionRoot):
     32     ## InfPackageParser

     33     #

     34     #                       

     35     def InfPackageParser(self, SectionString, InfSectionObject, FileName):
     36         #

     37         # Macro defined in this section 

     38         #

     39         SectionMacros = {}
     40         ValueList     = []
     41         PackageList   = []
     42         StillCommentFalg  = False
     43         HeaderComments    = []
     44         LineComment       = None                  
     45         #

     46         # Parse section content

     47         #

     48         for Line in SectionString:
     49             PkgLineContent = Line[0]
     50             PkgLineNo      = Line[1]  
     51             
     52             if PkgLineContent.strip() == '':
     53                 continue
     54             
     55             #

     56             # Find Header Comments 

     57             #

     58             if PkgLineContent.strip().startswith(DT.TAB_COMMENT_SPLIT):
     59                 #

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

     61                 #

     62                 if StillCommentFalg:
     63                     HeaderComments.append(Line)
     64                     continue
     65                 #

     66                 # First time encounter comment 

     67                 #

     68                 else:
     69                     #

     70                     # Clear original data

     71                     #

     72                     HeaderComments = []
     73                     HeaderComments.append(Line)
     74                     StillCommentFalg = True
     75                     continue
     76             else:
     77                 StillCommentFalg = False
     78                           
     79             if len(HeaderComments) >= 1:
     80                 LineComment = InfLineCommentObject()
     81                 LineCommentContent = ''
     82                 for Item in HeaderComments:
     83                     LineCommentContent += Item[0] + DT.END_OF_LINE
     84                 LineComment.SetHeaderComments(LineCommentContent)
     85             
     86             #

     87             # Find Tail comment.

     88             #

     89             if PkgLineContent.find(DT.TAB_COMMENT_SPLIT) > -1:
     90                 TailComments = PkgLineContent[PkgLineContent.find(DT.TAB_COMMENT_SPLIT):]
     91                 PkgLineContent = PkgLineContent[:PkgLineContent.find(DT.TAB_COMMENT_SPLIT)]
     92                 if LineComment == None:
     93                     LineComment = InfLineCommentObject()
     94                 LineComment.SetTailComments(TailComments)                   
     95             #

     96             # Find Macro

     97             #

     98             Name, Value = MacroParser((PkgLineContent, PkgLineNo),
     99                                       FileName,
    100                                       DT.MODEL_META_DATA_PACKAGE,
    101                                       self.FileLocalMacros)
    102             if Name != None:
    103                 SectionMacros[Name] = Value
    104                 LineComment = None
    105                 HeaderComments = []                
    106                 continue
    107 
    108             TokenList = GetSplitValueList(PkgLineContent, DT.TAB_VALUE_SPLIT, 1)
    109             ValueList[0:len(TokenList)] = TokenList
    110             
    111             #

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

    113             #            

    114             ValueList = [InfExpandMacro(Value, (FileName, PkgLineContent, PkgLineNo), 
    115                                         self.FileLocalMacros, SectionMacros, True)
    116                                         for Value in ValueList]
    117             
    118             PackageList.append((ValueList, LineComment, 
    119                                 (PkgLineContent, PkgLineNo, FileName)))
    120             ValueList = []
    121             LineComment = None
    122             TailComments = ''
    123             HeaderComments = []            
    124             continue
    125 
    126         #

    127         # Current section archs

    128         #    

    129         ArchList = []
    130         for Item in self.LastSectionHeaderContent:
    131             if Item[1] not in ArchList:
    132                 ArchList.append(Item[1])  
    133         
    134         if not InfSectionObject.SetPackages(PackageList, Arch = ArchList):
    135             Logger.Error('InfParser', 
    136                          FORMAT_INVALID, 
    137                          ST.ERR_INF_PARSER_MODULE_SECTION_TYPE_ERROR\
    138                          %("[Packages]"),
    139                          File=FileName,
    140                          Line=Item[3])