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

      2 # This file is used to define class objects of INF file [Depex] section. 

      3 # It will consumed by InfParser. 

      4 #

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

      6 #

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

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

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

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

     11 #

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

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

     14 
     15 '''
     16 InfDepexObject
     17 '''
     18 
     19 from Library import DataType as DT
     20 from Library import GlobalData
     21 import Logger.Log as Logger
     22 from Logger import ToolError
     23 from Logger import StringTable as ST
     24 
     25 from Object.Parser.InfCommonObject import InfSectionCommonDef
     26 from Library.ParserValidate import IsValidArch
     27 
     28 class InfDepexContentItem():
     29     def __init__(self):
     30         self.SectionType = ''
     31         self.SectionString = ''
     32 
     33     def SetSectionType(self, SectionType):
     34         self.SectionType = SectionType
     35     def GetSectionType(self):
     36         return self.SectionType
     37 
     38     def SetSectionString(self, SectionString):
     39         self.SectionString = SectionString
     40     def GetSectionString(self):
     41         return self.SectionString
     42 
     43 
     44 class InfDepexItem():
     45     def __init__(self):
     46         self.DepexContent = ''
     47         self.ModuleType = ''
     48         self.SupArch = ''
     49         self.HelpString = ''
     50         self.FeatureFlagExp = ''
     51         self.InfDepexContentItemList = []
     52 
     53     def SetFeatureFlagExp(self, FeatureFlagExp):
     54         self.FeatureFlagExp = FeatureFlagExp
     55     def GetFeatureFlagExp(self):
     56         return self.FeatureFlagExp
     57 
     58     def SetSupArch(self, Arch):
     59         self.SupArch = Arch
     60     def GetSupArch(self):
     61         return self.SupArch
     62 
     63     def SetHelpString(self, HelpString):
     64         self.HelpString = HelpString
     65     def GetHelpString(self):
     66         return self.HelpString
     67 
     68     def SetModuleType(self, Type):
     69         self.ModuleType = Type
     70     def GetModuleType(self):
     71         return self.ModuleType
     72 
     73     def SetDepexConent(self, Content):
     74         self.DepexContent = Content
     75     def GetDepexContent(self):
     76         return self.DepexContent
     77 
     78     def SetInfDepexContentItemList(self, InfDepexContentItemList):
     79         self.InfDepexContentItemList = InfDepexContentItemList
     80     def GetInfDepexContentItemList(self):
     81         return self.InfDepexContentItemList
     82 
     83 ## InfDepexObject

     84 #

     85 #

     86 #

     87 class InfDepexObject(InfSectionCommonDef):
     88     def __init__(self):
     89         self.Depex = []
     90         self.AllContent = ''
     91         self.SectionContent = ''
     92         InfSectionCommonDef.__init__(self)
     93 
     94     def SetDepex(self, DepexContent, KeyList=None, CommentList=None):
     95         for KeyItem in KeyList:
     96             Arch = KeyItem[0]
     97             ModuleType = KeyItem[1]
     98             InfDepexItemIns = InfDepexItem()
     99 
    100             #

    101             # Validate Arch

    102             #                 

    103             if IsValidArch(Arch.strip().upper()):
    104                 InfDepexItemIns.SetSupArch(Arch)
    105             else:
    106                 Logger.Error("InfParser",
    107                              ToolError.FORMAT_INVALID,
    108                              ST.ERR_INF_PARSER_DEFINE_NAME_INVALID % (Arch),
    109                              File=GlobalData.gINF_MODULE_NAME,
    110                              Line=KeyItem[2])
    111 
    112             #

    113             # Validate Module Type

    114             #

    115             if ModuleType and ModuleType != 'COMMON':
    116                 if ModuleType in DT.VALID_DEPEX_MODULE_TYPE_LIST:
    117                     InfDepexItemIns.SetModuleType(ModuleType)
    118                 else:
    119                     Logger.Error("InfParser",
    120                                  ToolError.FORMAT_INVALID,
    121                                  ST.ERR_INF_PARSER_DEPEX_SECTION_MODULE_TYPE_ERROR % (ModuleType),
    122                                  File=GlobalData.gINF_MODULE_NAME,
    123                                  Line=KeyItem[2])
    124 
    125             #

    126             # Parser content in [Depex] section.

    127             #

    128             DepexString = ''
    129             HelpString = ''
    130             #

    131             # Get Depex Expression

    132             #

    133             for Line in DepexContent:
    134                 LineContent = Line[0].strip()
    135                 if LineContent.find(DT.TAB_COMMENT_SPLIT) > -1:
    136                     LineContent = LineContent[:LineContent.find(DT.TAB_COMMENT_SPLIT)]
    137                 if LineContent:
    138                     DepexString = DepexString + LineContent + DT.END_OF_LINE
    139                 continue
    140 
    141             if DepexString.endswith(DT.END_OF_LINE):
    142                 DepexString = DepexString[:-1]
    143 
    144             if not DepexString.strip():
    145                 continue
    146 
    147             #

    148             # Get Help Text

    149             #

    150             for HelpLine in CommentList:
    151                 HelpString = HelpString + HelpLine + DT.END_OF_LINE
    152             if HelpString.endswith(DT.END_OF_LINE):
    153                 HelpString = HelpString[:-1]
    154 
    155             InfDepexItemIns.SetDepexConent(DepexString)
    156             InfDepexItemIns.SetHelpString(HelpString)
    157 
    158             self.Depex.append(InfDepexItemIns)
    159 
    160         return True
    161 
    162     def GetDepex(self):
    163         return self.Depex
    164 
    165     def GetAllContent(self):
    166         return self.AllContent
    167