Fixed incorrect error number and added necessary error checks
authorjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 13 Mar 2008 03:20:22 +0000 (03:20 +0000)
committerjwang36 <jwang36@7335b38e-4728-0410-8992-fb3ffe349368>
Thu, 13 Mar 2008 03:20:22 +0000 (03:20 +0000)
git-svn-id: https://buildtools.tianocore.org/svn/buildtools/trunk/BaseTools@1061 7335b38e-4728-0410-8992-fb3ffe349368

Source/Python/AutoGen/AutoGen.py
Source/Python/AutoGen/BuildEngine.py
Source/Python/AutoGen/GenMake.py
Source/Python/Common/EdkLogger.py
Source/Python/Common/Misc.py
Source/Python/Common/ToolDefClassObject.py

index 352e3bb..5d7d613 100755 (executable)
@@ -930,6 +930,9 @@ class ModuleAutoGen(object):
     #\r
     def GetSourceFileList(self, Info):\r
         # use toolchain family of CC as the primary toolchain family\r
+        if "CC" not in Info.PlatformInfo.ToolChainFamily:\r
+            EdkLogger.error("AutoGen", AUTOGEN_ERROR, "Tool [CC] is not supported for %s [%s, %s]" \\r
+                             % (Info.ToolChain, Info.BuildTarget, Info.Arch))\r
         ToolChainFamily = Info.PlatformInfo.ToolChainFamily["CC"]\r
         BuildRule = Info.PlatformInfo.BuildRule\r
         BuildFileList = []\r
index ed7f036..c81f104 100644 (file)
@@ -218,7 +218,7 @@ class BuildRule:
         elif Content != None:\r
             self.RuleContent = Content\r
         else:\r
-            EdkLogger.error("BuildRuleParser", PARSER_ERROR, "No rule file or string given")\r
+            EdkLogger.error("BuildRuleParser", PARAMETER_MISSING, ExtraData="No rule file or string given")\r
 \r
         self.SupportedToolChainFamilyList = SupportedFamily\r
         self.RuleDatabase = {}  # {version : {family : {file type : FileBuildRule object}}}\r
@@ -273,14 +273,14 @@ class BuildRule:
         TokenList = self.RuleContent[LineIndex].split("=", 1)\r
         # currently only BUILD_VERSION is supported\r
         if len(TokenList) != 2 or TokenList[0] != "BUILD_VERSION":\r
-            EdkLogger.error("BuildRuleParser", PARSER_ERROR, "Invalid definition",\r
-                            File=RuleFile, Line=LineIndex+1, ExtraData=self.RuleContent[LineIndex])\r
+            EdkLogger.error("BuildRuleParser", FORMAT_INVALID, File=RuleFile, Line=LineIndex+1, \r
+                            ExtraData="Invalid definition: " + self.RuleContent[LineIndex])\r
 \r
         try:\r
             self._BuildVersion = int(TokenList[1].strip(), 0)\r
         except:\r
-            EdkLogger.error("BuildRuleParser", PARSER_ERROR, "Version is not a valid number",\r
-                            File=self.RuleFile, Line=LineIndex+1, ExtraData=self.RuleContent[LineIndex])\r
+            EdkLogger.error("BuildRuleParser", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1, \r
+                            ExtraData="Version is not a valid number: " + self.RuleContent[LineIndex])\r
 \r
     ## Parse definitions under a subsection\r
     #\r
@@ -339,12 +339,12 @@ class BuildRule:
             if self._InputFile in Rule:\r
                 Input = Rule[self._InputFile]\r
             else:\r
-                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "No input files found for a rule")\r
+                EdkLogger.error("BuildRuleParser", FORMAT_INVALID, ExtraData="No input files found for a rule")\r
 \r
             if self._OutputFile in Rule:\r
                 Output = Rule[self._OutputFile]\r
             else:\r
-                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "No output files found a rule")\r
+                EdkLogger.error("BuildRuleParser", FORMAT_INVALID, ExtraData="No output files found a rule")\r
 \r
             if self._Command in Rule:\r
                 Command = Rule[self._Command]\r
@@ -378,8 +378,8 @@ class BuildRule:
         for RuleName in RuleNameList:\r
             TokenList = RuleName.split('.')\r
             if len(TokenList) == 1:\r
-                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "Invalid rule section",\r
-                                File=self.RuleFile, Line=LineIndex+1, ExtraData=self.RuleContent[LineIndex])\r
+                EdkLogger.error("BuildRuleParser", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1, \r
+                                ExtraData="Invalid rule section: " + self.RuleContent[LineIndex])\r
 \r
             Rule = TokenList[0].strip()\r
             if Rule.upper() != "BUILD":\r
@@ -388,8 +388,8 @@ class BuildRule:
 \r
             FileType = TokenList[1].strip()\r
             if FileType == '':\r
-                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "No file type given",\r
-                                File=self.RuleFile, Line=LineIndex+1, ExtraData=Line)\r
+                EdkLogger.error("BuildRuleParser", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1, \r
+                                ExtraData="No file type given: " + Line)\r
             FileTypeList.append(FileType)\r
 \r
         self._FileTypeList = FileTypeList\r
@@ -411,8 +411,8 @@ class BuildRule:
             if SectionType == "":\r
                 SectionType = Type\r
             elif SectionType != Type:\r
-                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "Two different section types are not allowed",\r
-                                File=self.RuleFile, Line=LineIndex+1, ExtraData=Line)\r
+                EdkLogger.error("BuildRuleParser", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1, \r
+                                ExtraData="Two different section types are not allowed: " + Line)\r
 \r
             if len(TokenList) > 1:\r
                 Family = TokenList[1].strip().upper()\r
@@ -436,14 +436,13 @@ class BuildRule:
         if len(TokenList) > 1:\r
             FileType = TokenList[0].strip()\r
             if FileType not in self._FileTypeList:\r
-                EdkLogger.error("BuildRuleParser", PARSER_ERROR,\r
-                                "File type must be one of %s: %s" % (self._FileTypeList, FileType),\r
-                                File=self.RuleFile, ExtraData=Line, Line=LineIndex+1)\r
+                EdkLogger.error("BuildRuleParser", FORMAT_INVALID, File=self.RuleFile,  Line=LineIndex+1,\r
+                                ExtraData="File type must be one of %s: %s" % (self._FileTypeList, FileType))\r
             FileString = TokenList[1]\r
         else:\r
             if len(self._FileTypeList) > 1:\r
-                EdkLogger.error("BuildRuleParser", PARSER_ERROR, "File type must be given",\r
-                                File=self.RuleFile, Line=LineIndex, ExtraData=Line)\r
+                EdkLogger.error("BuildRuleParser", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex, \r
+                                ExtraData="File type must be given: " + Line)\r
             else:\r
                 FileType = self._FileTypeList[0]\r
             FileString = TokenList[0]\r
index 4a21df8..f305aa8 100755 (executable)
@@ -614,9 +614,12 @@ class Makefile(object):
     ## Create necessary directory for makefile generation\r
     def PrepareDirectory(self):\r
         if self.ModuleBuild:\r
-            CreateDirectory(self.PlatformInfo.BuildDir)\r
-            CreateDirectory(self.ModuleInfo.BuildDir)\r
-            CreateDirectory(self.ModuleInfo.DebugDir)\r
+            if not CreateDirectory(self.PlatformInfo.BuildDir):\r
+                EdkLogger.error("AutoGen", FILE_CREATE_FAILURE, ExtraData=self.PlatformInfo.BuildDir)\r
+            if not CreateDirectory(self.ModuleInfo.BuildDir):\r
+                EdkLogger.error("AutoGen", FILE_CREATE_FAILURE, ExtraData=self.ModuleInfo.BuildDir)\r
+            if not CreateDirectory(self.ModuleInfo.DebugDir):\r
+                EdkLogger.error("AutoGen", FILE_CREATE_FAILURE, ExtraData=self.ModuleInfo.DebugDir)\r
 \r
     ## Create the makefile\r
     #\r
@@ -643,6 +646,8 @@ class Makefile(object):
     #                           since last time\r
     #\r
     def GeneratePlatformMakefile(self, File=None, MakeType=gMakeType):\r
+        if MakeType not in gDirectorySeparator:\r
+            EdkLogger.error("GenMake", PARAMETER_INVALID, "Invalid Makefile type", ExtraData=MakeType)\r
         Separator = gDirectorySeparator[MakeType]\r
 \r
         ArchList = self.PlatformInfo.keys()\r
@@ -659,6 +664,7 @@ class Makefile(object):
         MacroList = []\r
         if PlatformInfo.FdfFile != None and PlatformInfo.FdfFile != "":\r
             FdfFileList = [PlatformInfo.FdfFile]\r
+            # macros passed to GenFds\r
             for MacroName in GlobalData.gGlobalDefines:\r
                 MacroList.append('"%s=%s"' % (MacroName, GlobalData.gGlobalDefines[MacroName]))    \r
         else:\r
@@ -738,6 +744,8 @@ class Makefile(object):
         if MakeType in self.ModuleInfo.CustomMakefile and self.ModuleInfo.CustomMakefile[MakeType] != "":\r
             return self.GenerateCustomBuildMakefile(File, MakeType)\r
 \r
+        if MakeType not in gDirectorySeparator:\r
+            EdkLogger.error("GenMake", PARAMETER_INVALID, "Invalid Makefile type", ExtraData=MakeType)\r
         Separator = gDirectorySeparator[MakeType]\r
         PlatformInfo = self.PlatformInfo\r
 \r
@@ -769,6 +777,7 @@ class Makefile(object):
             EntryPoint = "_ModuleEntryPoint"\r
 \r
         DefaultToolFlag = PlatformInfo.ToolOption.values()\r
+        # USER_DEFINED modules should take care of tools definitions by its own\r
         if self.ModuleInfo.ModuleType == "USER_DEFINED":\r
             DefaultToolFlag = ["" for p in DefaultToolFlag]\r
 \r
@@ -905,8 +914,14 @@ class Makefile(object):
     #                           since last time\r
     #\r
     def GenerateCustomBuildMakefile(self, File=None, MakeType=gMakeType):\r
+        if MakeType not in gDirectorySeparator:\r
+            EdkLogger.error("GenMake", PARAMETER_INVALID, "Invalid Makefile type", ExtraData=MakeType)\r
         Separator = gDirectorySeparator[MakeType]\r
-        CustomMakefile = open(os.path.join(self.ModuleInfo.WorkspaceDir, self .ModuleInfo.CustomMakefile[MakeType]), 'r').read()\r
+\r
+        try:\r
+            CustomMakefile = open(os.path.join(self.ModuleInfo.WorkspaceDir, self .ModuleInfo.CustomMakefile[MakeType]), 'r').read()\r
+        except:\r
+            EdkLogger.error(None, FILE_OPEN_FAILURE, ExtraData=self .ModuleInfo.CustomMakefile[MakeType])\r
 \r
         MakefileName = gMakefileName[MakeType]\r
         MakefileTemplateDict = {\r
index 6f37165..d59e7db 100644 (file)
@@ -204,8 +204,8 @@ quiet   = _ErrorLogger.error
 ## Initialize log system
 def Initialize():
     #
-    # Since we use different format to log different levels of message into differen
-    # place (stdout or stderr), we have to use different "Logger" object to do this.
+    # Since we use different format to log different levels of message into different
+    # place (stdout or stderr), we have to use different "Logger" objects to do this.
     # 
     # For DEBUG level (All DEBUG_0~9 are applicable)
     _DebugLogger.setLevel(INFO)
index 8049ad4..1c527f3 100755 (executable)
@@ -135,9 +135,13 @@ def GuidStructureStringToGuidValueName(GuidValue):
 #\r
 def CreateDirectory(Directory):\r
     if Directory == None or Directory.strip() == "":\r
-        return\r
-    if not os.access(Directory, os.F_OK):\r
-        os.makedirs(Directory)\r
+        return True\r
+    try:\r
+        if not os.access(Directory, os.F_OK):\r
+            os.makedirs(Directory)\r
+    except:\r
+        return False\r
+    return True\r
 \r
 ## Check if given file is changed or not\r
 #\r
@@ -184,7 +188,10 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True):
         BinaryFlag = ''\r
     Fd = None\r
     if os.path.exists(File):\r
-        Fd = open(File, "r"+BinaryFlag)\r
+        try:\r
+            Fd = open(File, "r"+BinaryFlag)\r
+        except:\r
+            EdkLogger.error(None, FILE_OPEN_FAILURE, ExtraData=File)\r
         FileSize = os.fstat(Fd.fileno()).st_size\r
         if len(Content) == FileSize and Content == Fd.read():\r
             Fd.close()\r
@@ -192,7 +199,10 @@ def SaveFileOnChange(File, Content, IsBinaryFile=True):
         Fd.close()\r
         # os.remove(File) # seems creating new file is faster than overwriting old one\r
     CreateDirectory(os.path.dirname(File))\r
-    Fd = open(File, "w"+BinaryFlag)\r
+    try:\r
+        Fd = open(File, "w"+BinaryFlag)\r
+    except:\r
+        EdkLogger.error(None, FILE_CREATE_FAILURE, ExtraData=File)\r
     Fd.write(Content)\r
     Fd.close()\r
     return True\r
index 49a291a..627264f 100755 (executable)
@@ -155,16 +155,16 @@ class ToolDefClassObject(object):
         EnvReference = gEnvRefPattern.findall(Value)\r
         for Ref in EnvReference:\r
             if Ref not in self.MacroDictionary:\r
-                EdkLogger.error("tools_def.txt parser", PARSER_ERROR,\r
-                                "Environment [%s] has not been defined" % Ref,\r
+                EdkLogger.error("tools_def.txt parser", RESOURCE_NOT_AVAILABLE,\r
+                                ExtraData="Environment [%s] has not been defined" % Ref,\r
                                 File=FileName, Line=Index+1)\r
             Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
 \r
         MacroReference = gMacroRefPattern.findall(Value)\r
         for Ref in MacroReference:\r
             if Ref not in self.MacroDictionary:\r
-                EdkLogger.error("tools_def.txt parser", PARSER_ERROR,\r
-                                "Macro [%s] has not been defined" % Ref,\r
+                EdkLogger.error("tools_def.txt parser", RESOURCE_NOT_AVAILABLE,\r
+                                ExtraData="Macro [%s] has not been defined" % Ref,\r
                                 File=FileName, Line=Index+1)\r
             Value = Value.replace(Ref, self.MacroDictionary[Ref])\r
 \r