Added more check on settings
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 9 Apr 2008 12:51:10 +0000 (12:51 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Wed, 9 Apr 2008 12:51:10 +0000 (12:51 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1133 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/Common/TargetTxtClassObject.py

index d52a9df..ce29188 100644 (file)
@@ -74,35 +74,50 @@ class TargetTxtClassObject(object):
     # @retval 1 Open file failed\r
     #\r
     def ConvertTextFileToDict(self, FileName, CommentCharacter, KeySplitCharacter):\r
+        F = None\r
         try:\r
             F = open(FileName,'r')\r
-            for Line in F:\r
-                Line = Line.strip()\r
-                if Line.startswith(CommentCharacter) or Line == '':\r
-                    continue\r
+        except:\r
+            EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=FileName)\r
+            if F != None:\r
+                F.close()\r
 \r
-                LineList = Line.split(KeySplitCharacter, 1)\r
-                Key = LineList[0].strip()\r
-                if len(LineList) == 2:\r
-                    Value = LineList[1].strip()\r
-                else:\r
-                    Value = ""\r
+        for Line in F:\r
+            Line = Line.strip()\r
+            if Line.startswith(CommentCharacter) or Line == '':\r
+                continue\r
 \r
-                if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \\r
-                           DataType.TAB_TAT_DEFINES_MULTIPLE_THREAD, DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER, \\r
-                           DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:\r
-                    self.TargetTxtDictionary[Key] = Value.replace('\\', '/')\r
-                elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \\r
-                             DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:\r
-                    self.TargetTxtDictionary[Key] = Value.split()\r
-                #elif Key not in GlobalData.gGlobalDefines:\r
-                #    GlobalData.gGlobalDefines[Key] = Value\r
+            LineList = Line.split(KeySplitCharacter, 1)\r
+            Key = LineList[0].strip()\r
+            if len(LineList) == 2:\r
+                Value = LineList[1].strip()\r
+            else:\r
+                Value = ""\r
 \r
-            F.close()\r
-            return 0\r
-        except:\r
-            EdkLogger.quiet('Open file failed')\r
-            return 1\r
+            if Key in [DataType.TAB_TAT_DEFINES_ACTIVE_PLATFORM, DataType.TAB_TAT_DEFINES_TOOL_CHAIN_CONF, \\r
+                       DataType.TAB_TAT_DEFINES_ACTIVE_MODULE, DataType.TAB_TAT_DEFINES_BUILD_RULE_CONF]:\r
+                self.TargetTxtDictionary[Key] = Value.replace('\\', '/')\r
+            elif Key in [DataType.TAB_TAT_DEFINES_TARGET, DataType.TAB_TAT_DEFINES_TARGET_ARCH, \\r
+                         DataType.TAB_TAT_DEFINES_TOOL_CHAIN_TAG]:\r
+                self.TargetTxtDictionary[Key] = Value.split()\r
+            elif Key == DataType.TAB_TAT_DEFINES_MULTIPLE_THREAD:\r
+                if Value not in ["Enable", "Disable"]:\r
+                    EdkLogger.error("build", FORMAT_INVALID, "Invalid setting of [%s]: %s." % (Key, Value),\r
+                                    ExtraData="\tSetting must be one of [Enable, Disable]",\r
+                                    File=FileName)\r
+                self.TargetTxtDictionary[Key] = Value\r
+            elif Key == DataType.TAB_TAT_DEFINES_MAX_CONCURRENT_THREAD_NUMBER:\r
+                try:\r
+                    V = int(Value, 0)\r
+                except:\r
+                    EdkLogger.error("build", FORMAT_INVALID, "Invalid number of [%s]: %s." % (Key, Value),\r
+                                    File=FileName)\r
+                self.TargetTxtDictionary[Key] = Value\r
+            #elif Key not in GlobalData.gGlobalDefines:\r
+            #    GlobalData.gGlobalDefines[Key] = Value\r
+\r
+        F.close()\r
+        return 0\r
 \r
     ## Print the dictionary\r
     #\r