]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: add error check for Macro usage in the INF file
authorYonghong Zhu <yonghong.zhu@intel.com>
Mon, 20 Feb 2017 10:49:32 +0000 (18:49 +0800)
committerYonghong Zhu <yonghong.zhu@intel.com>
Wed, 22 Feb 2017 02:45:27 +0000 (10:45 +0800)
Use of MACRO statements in the EDK II INF files is limited to local
usage only; global or external macros are not permitted. This patch
add the check for not defined macros.

Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yonghong Zhu <yonghong.zhu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Source/Python/Workspace/MetaFileParser.py
BaseTools/Source/Python/Workspace/WorkspaceDatabase.py

index 1a5fdf5e62b9a1726c0321d2c5caf89b01217ca8..37a7f5d1de7e86e0f999ed0ba90c7a2aca7b969c 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to parse meta files\r
 #\r
-# Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r
 # (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
@@ -351,6 +351,13 @@ class MetaFileParser(object):
 \r
         self._ValueList = [ReplaceMacro(Value, self._Macros) for Value in self._ValueList]\r
         Name, Value = self._ValueList[1], self._ValueList[2]\r
+        MacroUsed = GlobalData.gMacroRefPattern.findall(Value)\r
+        if len(MacroUsed) != 0:\r
+            for Macro in MacroUsed:\r
+                if Macro in GlobalData.gGlobalDefines:\r
+                    EdkLogger.error("Parser", FORMAT_INVALID, "Global macro %s is not permitted." % (Macro), ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r
+            else:\r
+                EdkLogger.error("Parser", FORMAT_INVALID, "%s not defined" % (Macro), ExtraData=self._CurrentLine, File=self.MetaFile, Line=self._LineIndex + 1)\r
         # Sometimes, we need to make differences between EDK and EDK2 modules \r
         if Name == 'INF_VERSION':\r
             if re.match(r'0[xX][\da-f-A-F]{5,8}', Value):\r
index e7bc87dc6bdcfcf106cffdd02374f3aa59e5054f..06867219b71191ef5d6d2fbeb80c2d448d9f386a 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # This file is used to create a database used by build tool\r
 #\r
-# Copyright (c) 2008 - 2016, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2008 - 2017, Intel Corporation. All rights reserved.<BR>\r
 # (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>\r
 # This program and the accompanying materials\r
 # are licensed and made available under the terms and conditions of the BSD License\r
@@ -1830,6 +1830,8 @@ class InfBuildData(ModuleBuildClassObject):
             if self.AutoGenVersion < 0x00010005:\r
                 self.__Macros.update(GlobalData.gEdkGlobal)\r
                 self.__Macros.update(GlobalData.gGlobalDefines)\r
+            else:\r
+                self.__Macros.update(self.Defines)\r
         return self.__Macros\r
 \r
     ## Get architecture\r