]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Ecc/Check.py
BaseTools: Enhance BaseTools supports FixedAtBuild usage in VFR file
[mirror_edk2.git] / BaseTools / Source / Python / Ecc / Check.py
index 5bee6dba7cdcd99cac7eb561d636310d4d9da0d4..a22da3d85a1d0d24a93258bbd96ef2fd3a5062b0 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to define checkpoints used by ECC tool\r
 #\r
-# Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
 # which accompanies this distribution.  The full text of the license may be found at\r
@@ -19,6 +19,7 @@ from MetaDataParser import ParseHeaderCommentSection
 import EccGlobalData\r
 import c\r
 from Common.LongFilePathSupport import OpenLongFilePath as open\r
+from Common.MultipleWorkspace import MultipleWorkspace as mws\r
 \r
 ## Check\r
 #\r
@@ -100,6 +101,9 @@ class Check(object):
                         Dirnames.append(Dirname)\r
             if IgnoredPattern.match(Dirpath.upper()):\r
                 continue\r
+            for f in Filenames[:]:\r
+                if f.lower() in EccGlobalData.gConfig.SkipFileList:\r
+                    Filenames.remove(f)\r
             yield (Dirpath, Dirnames, Filenames)\r
 \r
     # Check whether return type exists and in the first line\r
@@ -377,9 +381,7 @@ class Check(object):
             for Key in RecordDict:\r
                 if len(RecordDict[Key]) > 1:\r
                     for Item in RecordDict[Key]:\r
-                        Path = Item[1].replace(EccGlobalData.gWorkspace, '')\r
-                        if Path.startswith('\\') or Path.startswith('/'):\r
-                            Path = Path[1:]\r
+                        Path = mws.relpath(Item[1], EccGlobalData.gWorkspace)\r
                         if not EccGlobalData.gException.IsException(ERROR_INCLUDE_FILE_CHECK_NAME, Path):\r
                             EccGlobalData.gDb.TblReport.Insert(ERROR_INCLUDE_FILE_CHECK_NAME, OtherMsg="The file name for [%s] is duplicate" % Path, BelongsToTable='File', BelongsToItem=Item[0])\r
 \r
@@ -561,6 +563,7 @@ class Check(object):
         self.MetaDataFileCheckLibraryInstanceDependent()\r
         self.MetaDataFileCheckLibraryInstanceOrder()\r
         self.MetaDataFileCheckLibraryNoUse()\r
+        self.MetaDataFileCheckLibraryDefinedInDec()\r
         self.MetaDataFileCheckBinaryInfInFdf()\r
         self.MetaDataFileCheckPcdDuplicate()\r
         self.MetaDataFileCheckPcdFlash()\r
@@ -649,7 +652,11 @@ class Check(object):
                 if LibraryClass[1].upper() == 'NULL' or LibraryClass[1].startswith('!ifdef') or LibraryClass[1].startswith('!ifndef') or LibraryClass[1].endswith('!endif'):\r
                     continue\r
                 else:\r
-                    LibraryIns = os.path.normpath(os.path.join(EccGlobalData.gWorkspace, LibraryClass[2]))\r
+                    LibraryIns = os.path.normpath(mws.join(EccGlobalData.gWorkspace, LibraryClass[2]))\r
+                    SkipDirString = '|'.join(EccGlobalData.gConfig.SkipDirList)\r
+                    p = re.compile(r'.*[\\/](?:%s^\S)[\\/]?.*' % SkipDirString)\r
+                    if p.match(os.path.split(LibraryIns)[0].upper()):\r
+                        continue\r
                     SqlCommand = """select Value3 from Inf where BelongsToFile =\r
                                     (select ID from File where lower(FullPath) = lower('%s'))\r
                                     and Value2 = '%s'""" % (LibraryIns, 'LIBRARY_CLASS')\r
@@ -692,7 +699,24 @@ class Check(object):
                     for FilePath in FilePathList:\r
                         if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NAME_DUPLICATE, Record[1]):\r
                             EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NAME_DUPLICATE, OtherMsg="The Library Class [%s] is duplicated in '%s' line %s and line %s." % (Record[1], FilePath, Record[3], Record[4]), BelongsToTable='Dsc', BelongsToItem=Record[0])\r
-                                                \r
+    \r
+    # Check the header file in Include\Library directory whether be defined in the package DEC file.\r
+    def MetaDataFileCheckLibraryDefinedInDec(self):\r
+        if EccGlobalData.gConfig.MetaDataFileCheckLibraryDefinedInDec == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
+            EdkLogger.quiet("Checking for library instance whether be defined in the package dec file ...")\r
+            SqlCommand = """\r
+                    select A.Value1, A.StartLine, A.ID, B.Value1 from Inf as A left join Dec as B\r
+                    on A.Model = B.Model and A.Value1 = B.Value1 where A.Model=%s\r
+                    """ % MODEL_EFI_LIBRARY_CLASS\r
+            RecordSet = EccGlobalData.gDb.TblDsc.Exec(SqlCommand)\r
+            for Record in RecordSet:\r
+                LibraryInInf, Line, ID, LibraryDec = Record\r
+                if not LibraryDec:\r
+                    if not EccGlobalData.gException.IsException(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, LibraryInInf):\r
+                        EccGlobalData.gDb.TblReport.Insert(ERROR_META_DATA_FILE_CHECK_LIBRARY_NOT_DEFINED, \\r
+                                            OtherMsg="The Library Class [%s] in %s line is not defined in the associated package file." % (LibraryInInf, Line), \r
+                                            BelongsToTable='Inf', BelongsToItem=ID)\r
+    \r
     # Check whether an Inf file is specified in the FDF file, but not in the Dsc file, then the Inf file must be for a Binary module only\r
     def MetaDataFileCheckBinaryInfInFdf(self):\r
         if EccGlobalData.gConfig.MetaDataFileCheckBinaryInfInFdf == '1' or EccGlobalData.gConfig.MetaDataFileCheckAll == '1' or EccGlobalData.gConfig.CheckAll == '1':\r
@@ -708,7 +732,7 @@ class Check(object):
             for Record in RecordSet:\r
                 FdfID = Record[0]\r
                 FilePath = Record[1]\r
-                FilePath = os.path.normpath(os.path.join(EccGlobalData.gWorkspace, FilePath))\r
+                FilePath = os.path.normpath(mws.join(EccGlobalData.gWorkspace, FilePath))\r
                 SqlCommand = """select ID from Inf where Model = %s and BelongsToFile = (select ID from File where FullPath like '%s')\r
                                 """ % (MODEL_EFI_SOURCE_FILE, FilePath)\r
                 NewRecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
@@ -892,9 +916,7 @@ class Check(object):
         RecordSet = Table.Exec(SqlCommand)\r
         Path = ""\r
         for Record in RecordSet:\r
-            Path = Record[0].replace(EccGlobalData.gWorkspace, '')\r
-            if Path.startswith('\\') or Path.startswith('/'):\r
-                Path = Path[1:]\r
+            Path = mws.relpath(Record[0], EccGlobalData.gWorkspace)\r
         return Path\r
 \r
     # Check whether two module INFs under one workspace has the same FILE_GUID value\r
@@ -1065,7 +1087,7 @@ class Check(object):
         SqlCommand = """\r
                      select A.ID, A.Value1 from %s as A, %s as B\r
                      where A.Model = %s and B.Model = %s\r
-                     and A.Value1 = B.Value1 and A.ID <> B.ID\r
+                     and A.Value1 like B.Value1 and A.ID <> B.ID\r
                      and A.Scope1 = B.Scope1\r
                      and A.Enabled > -1\r
                      and B.Enabled > -1\r
@@ -1089,13 +1111,13 @@ class Check(object):
         SqlCommand = """\r
                      select A.ID, A.Value1, A.Value2 from %s as A, %s as B\r
                      where A.Model = %s and B.Model = %s\r
-                     and A.Value2 = B.Value2 and A.ID <> B.ID\r
+                     and A.Value2 like B.Value2 and A.ID <> B.ID\r
                      and A.Scope1 = B.Scope1 and A.Value1 <> B.Value1\r
                      group by A.ID\r
                      """ % (Table.Table, Table.Table, Model, Model)\r
         RecordSet = Table.Exec(SqlCommand)\r
         for Record in RecordSet:     \r
-            if not EccGlobalData.gException.IsException(ErrorID, Record[1] + ':' + Record[2]):\r
+            if not EccGlobalData.gException.IsException(ErrorID, Record[2]):\r
                 EccGlobalData.gDb.TblReport.Insert(ErrorID, OtherMsg="The %s value [%s] is used more than one time" % (Name.upper(), Record[2]), BelongsToTable=Table.Table, BelongsToItem=Record[0])\r
 \r
     # Naming Convention Check\r
@@ -1202,7 +1224,10 @@ class Check(object):
             SqlCommand = """select ID, Name from %s where Model = %s""" % (FileTable, MODEL_IDENTIFIER_VARIABLE)\r
             RecordSet = EccGlobalData.gDb.TblFile.Exec(SqlCommand)\r
             for Record in RecordSet:\r
-                if not Pattern.match(Record[1]):\r
+                Var = Record[1]\r
+                if Var.startswith('CONST'):\r
+                    Var = Var[5:].lstrip()\r
+                if not Pattern.match(Var):\r
                     if not EccGlobalData.gException.IsException(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, Record[1]):\r
                         EccGlobalData.gDb.TblReport.Insert(ERROR_NAMING_CONVENTION_CHECK_VARIABLE_NAME, OtherMsg="The variable name [%s] does not follow the rules" % (Record[1]), BelongsToTable=FileTable, BelongsToItem=Record[0])\r
 \r