]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Implement BUILDRULEORDER for tools_def
authorYingke Liu <yingke.d.liu@intel.com>
Tue, 26 May 2015 10:32:07 +0000 (10:32 +0000)
committerlgao4 <lgao4@Edk2>
Tue, 26 May 2015 10:32:07 +0000 (10:32 +0000)
This feature allows the toolchain to choose a preference for source file
extensions in tools_def.txt. The first extension is given the highest priority.

Here is an example usage for tools_def.txt:
*_*_*_*_BUILDRULEORDER         = nasm Nasm NASM asm Asm ASM S s
*_XCODE5_*_*_BUILDRULEORDER    = S s nasm Nasm NASM

Now, if a .inf lists these sources: 1.nasm, 1.asm and 1.S
All toolchains, except XCODE5 will use the 1.nasm file. The XCODE5
toolchain will use the 1.S file.

Note that the build_rule.txt file also impacts the decision, because,
for instance there is no build rule for .asm files on GCC toolchains.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Yingke Liu <yingke.d.liu@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17509 6f19259b-4bc3-4df7-8a09-765794883524

BaseTools/Source/Python/AutoGen/AutoGen.py
BaseTools/Source/Python/AutoGen/BuildEngine.py
BaseTools/Source/Python/Common/DataType.py

index a1e1818e3b5f5878f89a075630b55c22b20157cc..b2d9f6a8efb2e5177e309f31fe16bf68d58b26b9 100644 (file)
@@ -2082,6 +2082,13 @@ class PlatformAutoGen(AutoGen):
         else:\r
             PlatformModuleOptions = {}\r
 \r
         else:\r
             PlatformModuleOptions = {}\r
 \r
+        BuildRuleOrder = None\r
+        for Options in [self.ToolDefinition, ModuleOptions, PlatformOptions, PlatformModuleOptions]:\r
+            for Tool in Options:\r
+                for Attr in Options[Tool]:\r
+                    if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
+                        BuildRuleOrder = Options[Tool][Attr]\r
+\r
         AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() + PlatformModuleOptions.keys() + self.ToolDefinition.keys())\r
         BuildOptions = {}\r
         for Tool in AllTools:\r
         AllTools = set(ModuleOptions.keys() + PlatformOptions.keys() + PlatformModuleOptions.keys() + self.ToolDefinition.keys())\r
         BuildOptions = {}\r
         for Tool in AllTools:\r
@@ -2093,6 +2100,11 @@ class PlatformAutoGen(AutoGen):
                     continue\r
                 for Attr in Options[Tool]:\r
                     Value = Options[Tool][Attr]\r
                     continue\r
                 for Attr in Options[Tool]:\r
                     Value = Options[Tool][Attr]\r
+                    #\r
+                    # Do not generate it in Makefile\r
+                    #\r
+                    if Attr == TAB_TOD_DEFINES_BUILDRULEORDER:\r
+                        continue\r
                     if Attr not in BuildOptions[Tool]:\r
                         BuildOptions[Tool][Attr] = ""\r
                     # check if override is indicated\r
                     if Attr not in BuildOptions[Tool]:\r
                         BuildOptions[Tool][Attr] = ""\r
                     # check if override is indicated\r
@@ -2107,7 +2119,7 @@ class PlatformAutoGen(AutoGen):
             if 'BUILD' not in BuildOptions:\r
                 BuildOptions['BUILD'] = {}\r
             BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
             if 'BUILD' not in BuildOptions:\r
                 BuildOptions['BUILD'] = {}\r
             BuildOptions['BUILD']['FLAGS'] = self.Workspace.UniFlag\r
-        return BuildOptions\r
+        return BuildOptions, BuildRuleOrder\r
 \r
     Platform            = property(_GetPlatform)\r
     Name                = property(_GetName)\r
 \r
     Platform            = property(_GetPlatform)\r
     Name                = property(_GetName)\r
@@ -2195,6 +2207,7 @@ class ModuleAutoGen(AutoGen):
         self.DepexGenerated = False\r
 \r
         self.BuildDatabase = self.Workspace.BuildDatabase\r
         self.DepexGenerated = False\r
 \r
         self.BuildDatabase = self.Workspace.BuildDatabase\r
+        self.BuildRuleOrder = None\r
 \r
         self._Module          = None\r
         self._Name            = None\r
 \r
         self._Module          = None\r
         self._Name            = None\r
@@ -2587,7 +2600,9 @@ class ModuleAutoGen(AutoGen):
     #\r
     def _GetModuleBuildOption(self):\r
         if self._BuildOption == None:\r
     #\r
     def _GetModuleBuildOption(self):\r
         if self._BuildOption == None:\r
-            self._BuildOption = self.PlatformInfo.ApplyBuildOption(self.Module)\r
+            self._BuildOption, self.BuildRuleOrder = self.PlatformInfo.ApplyBuildOption(self.Module)\r
+            if self.BuildRuleOrder:\r
+                self.BuildRuleOrder = ['.%s' % Ext for Ext in self.BuildRuleOrder.split()]\r
         return self._BuildOption\r
 \r
     ## Get include path list from tool option for the module build\r
         return self._BuildOption\r
 \r
     ## Get include path list from tool option for the module build\r
@@ -2746,6 +2761,11 @@ class ModuleAutoGen(AutoGen):
         RuleChain = []\r
         SourceList = [File]\r
         Index = 0\r
         RuleChain = []\r
         SourceList = [File]\r
         Index = 0\r
+        #\r
+        # Make sure to get build rule order value\r
+        #\r
+        self._GetModuleBuildOption()\r
+\r
         while Index < len(SourceList):\r
             Source = SourceList[Index]\r
             Index = Index + 1\r
         while Index < len(SourceList):\r
             Source = SourceList[Index]\r
             Index = Index + 1\r
@@ -2779,7 +2799,7 @@ class ModuleAutoGen(AutoGen):
                     self._FinalBuildTargetList.add(LastTarget)\r
                 break\r
 \r
                     self._FinalBuildTargetList.add(LastTarget)\r
                 break\r
 \r
-            Target = RuleObject.Apply(Source)\r
+            Target = RuleObject.Apply(Source, self.BuildRuleOrder)\r
             if not Target:\r
                 if LastTarget:\r
                     self._FinalBuildTargetList.add(LastTarget)\r
             if not Target:\r
                 if LastTarget:\r
                     self._FinalBuildTargetList.add(LastTarget)\r
index d15ccc06d55808a9e12a5306951f551d3ad6e62d..ee1d3c89f292d3cbbcdc96bbd57845c130b3bb0f 100644 (file)
@@ -220,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
     #\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
         if not self.CommandList or not self.DestFileList:\r
             return None\r
 \r
@@ -281,13 +281,20 @@ class FileBuildRule:
 \r
         if DstFile[0] in self.BuildTargets:\r
             TargetDesc = self.BuildTargets[DstFile[0]]\r
 \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
         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
             TargetDesc = TargetDescBlock([SourceFile], DstFile, CommandList, self.ExtraSourceFileList)\r
             TargetDesc.ListFileMacro = self.ListFileMacro\r
             TargetDesc.FileListMacro = self.FileListMacro\r
@@ -298,6 +305,14 @@ class FileBuildRule:
             self.BuildTargets[DstFile[0]] = TargetDesc\r
         return TargetDesc\r
 \r
             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
 ## Class for build rules\r
 #\r
 # BuildRule class parses rules defined in a file or passed by caller, and converts\r
index b4abc88e3ec09d154c89f67b4e065c636e4d74df..4fd46edab96d69fe044a7ba837571d8341e242c5 100644 (file)
@@ -432,6 +432,7 @@ TAB_TOD_DEFINES_TARGET_ARCH = 'TARGET_ARCH'
 TAB_TOD_DEFINES_COMMAND_TYPE = 'COMMAND_TYPE'\r
 TAB_TOD_DEFINES_FAMILY = 'FAMILY'\r
 TAB_TOD_DEFINES_BUILDRULEFAMILY = 'BUILDRULEFAMILY'\r
 TAB_TOD_DEFINES_COMMAND_TYPE = 'COMMAND_TYPE'\r
 TAB_TOD_DEFINES_FAMILY = 'FAMILY'\r
 TAB_TOD_DEFINES_BUILDRULEFAMILY = 'BUILDRULEFAMILY'\r
+TAB_TOD_DEFINES_BUILDRULEORDER = 'BUILDRULEORDER'\r
 \r
 #\r
 # Conditional Statements\r
 \r
 #\r
 # Conditional Statements\r