]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/AutoGen/BuildEngine.py
BaseTools: Remove equality operator with None
[mirror_edk2.git] / BaseTools / Source / Python / AutoGen / BuildEngine.py
index b3083d0395f3f692e27f2156302029112b605108..0daed7da610db1340c273205b671cb55a1166b95 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # The engine for building files\r
 #\r
-# Copyright (c) 2007, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2014, 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
 ##\r
 # Import Modules\r
 #\r
-import os\r
+import Common.LongFilePathOs as os\r
 import re\r
 import copy\r
 import string\r
+from Common.LongFilePathSupport import OpenLongFilePath as open\r
 \r
 from Common.GlobalData import *\r
 from Common.BuildToolError import *\r
@@ -219,7 +220,7 @@ class FileBuildRule:
     #\r
     #   @retval     tuple       (Source file in full path, List of individual sourcefiles, Destionation file, List of build commands)\r
     #\r
-    def Apply(self, SourceFile):\r
+    def Apply(self, SourceFile, BuildRuleOrder=None):\r
         if not self.CommandList or not self.DestFileList:\r
             return None\r
 \r
@@ -280,13 +281,20 @@ class FileBuildRule:
 \r
         if DstFile[0] in self.BuildTargets:\r
             TargetDesc = self.BuildTargets[DstFile[0]]\r
-            TargetDesc.AddInput(SourceFile)\r
+            if BuildRuleOrder and SourceFile.Ext in BuildRuleOrder:\r
+                Index = BuildRuleOrder.index(SourceFile.Ext)\r
+                for Input in TargetDesc.Inputs:\r
+                    if Input.Ext not in BuildRuleOrder or BuildRuleOrder.index(Input.Ext) > Index:\r
+                        #\r
+                        # Command line should be regenerated since some macros are different\r
+                        #\r
+                        CommandList = self._BuildCommand(BuildRulePlaceholderDict)\r
+                        TargetDesc._Init([SourceFile], DstFile, CommandList, self.ExtraSourceFileList)\r
+                        break\r
+            else:\r
+                TargetDesc.AddInput(SourceFile)\r
         else:\r
-            CommandList = []\r
-            for CommandString in self.CommandList:\r
-                CommandString = string.Template(CommandString).safe_substitute(BuildRulePlaceholderDict)\r
-                CommandString = string.Template(CommandString).safe_substitute(BuildRulePlaceholderDict)\r
-                CommandList.append(CommandString)\r
+            CommandList = self._BuildCommand(BuildRulePlaceholderDict)\r
             TargetDesc = TargetDescBlock([SourceFile], DstFile, CommandList, self.ExtraSourceFileList)\r
             TargetDesc.ListFileMacro = self.ListFileMacro\r
             TargetDesc.FileListMacro = self.FileListMacro\r
@@ -297,6 +305,14 @@ class FileBuildRule:
             self.BuildTargets[DstFile[0]] = TargetDesc\r
         return TargetDesc\r
 \r
+    def _BuildCommand(self, Macros):\r
+        CommandList = []\r
+        for CommandString in self.CommandList:\r
+            CommandString = string.Template(CommandString).safe_substitute(Macros)\r
+            CommandString = string.Template(CommandString).safe_substitute(Macros)\r
+            CommandList.append(CommandString)\r
+        return CommandList\r
+\r
 ## Class for build rules\r
 #\r
 # BuildRule class parses rules defined in a file or passed by caller, and converts\r
@@ -330,12 +346,12 @@ class BuildRule:
     def __init__(self, File=None, Content=None, LineIndex=0, SupportedFamily=["MSFT", "INTEL", "GCC", "RVCT"]):\r
         self.RuleFile = File\r
         # Read build rules from file if it's not none\r
-        if File != None:\r
+        if File is not None:\r
             try:\r
                 self.RuleContent = open(File, 'r').readlines()\r
             except:\r
                 EdkLogger.error("build", FILE_OPEN_FAILURE, ExtraData=File)\r
-        elif Content != None:\r
+        elif Content is not None:\r
             self.RuleContent = Content\r
         else:\r
             EdkLogger.error("build", PARAMETER_MISSING, ExtraData="No rule file or string given")\r
@@ -372,7 +388,7 @@ class BuildRule:
             \r
             # find the build_rule_version\r
             if Line and Line[0] == "#" and Line.find(TAB_BUILD_RULE_VERSION) <> -1:\r
-                if Line.find("=") <> -1 and Line.find("=") < (len(Line)-1) and (Line[(Line.find("=") + 1):]).split():\r
+                if Line.find("=") <> -1 and Line.find("=") < (len(Line) - 1) and (Line[(Line.find("=") + 1):]).split():\r
                     self._FileVersion = (Line[(Line.find("=") + 1):]).split()[0]\r
             # skip empty or comment line\r
             if Line == "" or Line[0] == "#":\r
@@ -454,16 +470,16 @@ class BuildRule:
             if TokenList[0] == "BUILD":\r
                 if len(TokenList) == 1:\r
                     EdkLogger.error("build", FORMAT_INVALID, "Invalid rule section",\r
-                                    File=self.RuleFile, Line=LineIndex+1,\r
+                                    File=self.RuleFile, Line=LineIndex + 1,\r
                                     ExtraData=self.RuleContent[LineIndex])\r
 \r
                 FileType = TokenList[1]\r
                 if FileType == '':\r
                     EdkLogger.error("build", FORMAT_INVALID, "No file type given",\r
-                                    File=self.RuleFile, Line=LineIndex+1,\r
+                                    File=self.RuleFile, Line=LineIndex + 1,\r
                                     ExtraData=self.RuleContent[LineIndex])\r
-                if self._FileTypePattern.match(FileType) == None:\r
-                    EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1,\r
+                if self._FileTypePattern.match(FileType) is None:\r
+                    EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex + 1,\r
                                     ExtraData="Only character, number (non-first character), '_' and '-' are allowed in file type")\r
             # new format: File-Type.Build-Type.Arch\r
             else:\r
@@ -472,7 +488,7 @@ class BuildRule:
                 elif FileType != TokenList[0]:\r
                     EdkLogger.error("build", FORMAT_INVALID,\r
                                     "Different file types are not allowed in the same rule section",\r
-                                    File=self.RuleFile, Line=LineIndex+1,\r
+                                    File=self.RuleFile, Line=LineIndex + 1,\r
                                     ExtraData=self.RuleContent[LineIndex])\r
                 if len(TokenList) > 1:\r
                     BuildType = TokenList[1]\r
@@ -486,12 +502,12 @@ class BuildRule:
         if 'COMMON' in self._BuildTypeList and len(self._BuildTypeList) > 1:\r
             EdkLogger.error("build", FORMAT_INVALID,\r
                             "Specific build types must not be mixed with common one",\r
-                            File=self.RuleFile, Line=LineIndex+1,\r
+                            File=self.RuleFile, Line=LineIndex + 1,\r
                             ExtraData=self.RuleContent[LineIndex])\r
         if 'COMMON' in self._ArchList and len(self._ArchList) > 1:\r
             EdkLogger.error("build", FORMAT_INVALID,\r
                             "Specific ARCH must not be mixed with common one",\r
-                            File=self.RuleFile, Line=LineIndex+1,\r
+                            File=self.RuleFile, Line=LineIndex + 1,\r
                             ExtraData=self.RuleContent[LineIndex])\r
 \r
         self._FileType = FileType\r
@@ -515,7 +531,7 @@ class BuildRule:
             elif SectionType != Type:\r
                 EdkLogger.error("build", FORMAT_INVALID,\r
                                 "Two different section types are not allowed in the same sub-section",\r
-                                File=self.RuleFile, Line=LineIndex+1,\r
+                                File=self.RuleFile, Line=LineIndex + 1,\r
                                 ExtraData=self.RuleContent[LineIndex])\r
 \r
             if len(TokenList) > 1:\r
@@ -532,10 +548,10 @@ class BuildRule:
         if 'COMMON' in FamilyList and len(FamilyList) > 1:\r
             EdkLogger.error("build", FORMAT_INVALID,\r
                             "Specific tool chain family should not be mixed with general one",\r
-                            File=self.RuleFile, Line=LineIndex+1,\r
+                            File=self.RuleFile, Line=LineIndex + 1,\r
                             ExtraData=self.RuleContent[LineIndex])\r
         if self._State not in self._StateHandler:\r
-            EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex+1,\r
+            EdkLogger.error("build", FORMAT_INVALID, File=self.RuleFile, Line=LineIndex + 1,\r
                             ExtraData="Unknown subsection: %s" % self.RuleContent[LineIndex])\r
     ## Parse <InputFile> sub-section\r
     #\r
@@ -545,7 +561,7 @@ class BuildRule:
         FileList = [File.strip() for File in self.RuleContent[LineIndex].split(",")]\r
         for ToolChainFamily in self._FamilyList:\r
             InputFiles = self._RuleInfo[ToolChainFamily, self._State]\r
-            if InputFiles == None:\r
+            if InputFiles is None:\r
                 InputFiles = []\r
                 self._RuleInfo[ToolChainFamily, self._State] = InputFiles\r
             InputFiles.extend(FileList)\r
@@ -557,7 +573,7 @@ class BuildRule:
     def ParseCommon(self, LineIndex):\r
         for ToolChainFamily in self._FamilyList:\r
             Items = self._RuleInfo[ToolChainFamily, self._State]\r
-            if Items == None:\r
+            if Items is None:\r
                 Items = []\r
                 self._RuleInfo[ToolChainFamily, self._State] = Items\r
             Items.append(self.RuleContent[LineIndex])\r