]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools: Limit command line length.
authorMingyue Liang <mingyuex.liang@intel.com>
Tue, 10 Nov 2020 05:39:50 +0000 (13:39 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Tue, 10 Nov 2020 05:49:38 +0000 (05:49 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2528

Currently, CL command contains multiple C files will be compiled,
and that caused command line too long, which may trigger build error.

In order to solve this issue, the following rules is used in this scene:

If the number of C files is greater than one, a txt file will be used
to record these C files, and replaces the corresponding content in
command line with the file name.

Else (only one C file listed in the command line), the length of the
whole CL command line will determine whether use a file to record. If
the length exceeds the limited max length, use the recording file; else
C file name directly listed in the command line

Signed-off-by: Mingyue Liang <mingyuex.liang@intel.com>
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
Reviewed-by: Bob Feng <bob.c.feng@intel.com>
BaseTools/Source/Python/AutoGen/GenMake.py
BaseTools/Source/Python/AutoGen/IncludesAutoGen.py

index b04d3f54368ea9e41d7e07ea473569528db2f264..1cfac1cd82caab901d1096b5810d2972d5c19e10 100755 (executable)
@@ -576,7 +576,7 @@ cleanlib:
             EdkLogger.error("build", AUTOGEN_ERROR, "Nothing to build",\r
                             ExtraData="[%s]" % str(MyAgo))\r
 \r
-        self.ProcessBuildTargetList()\r
+        self.ProcessBuildTargetList(MyAgo.OutputDir, ToolsDef)\r
         self.ParserGenerateFfsCmd()\r
 \r
         # Generate macros used to represent input files\r
@@ -903,7 +903,7 @@ cleanlib:
                                     BuildTargets[Target].Commands[i] = SingleCommand.replace('$(INC)', '').replace(FlagDict[Flag]['Macro'], RespMacro)\r
         return RespDict\r
 \r
-    def ProcessBuildTargetList(self):\r
+    def ProcessBuildTargetList(self, RespFile, ToolsDef):\r
         #\r
         # Search dependency file list for each source file\r
         #\r
@@ -1004,6 +1004,7 @@ cleanlib:
                     self.ObjTargetDict[T.Target.SubDir] = set()\r
                 self.ObjTargetDict[T.Target.SubDir].add(NewFile)\r
         for Type in self._AutoGenObject.Targets:\r
+            resp_file_number = 0\r
             for T in self._AutoGenObject.Targets[Type]:\r
                 # Generate related macros if needed\r
                 if T.GenFileListMacro and T.FileListMacro not in self.FileListMacros:\r
@@ -1045,7 +1046,10 @@ cleanlib:
                         Deps.append("$(%s)" % T.ListFileMacro)\r
 \r
                 if self._AutoGenObject.BuildRuleFamily == TAB_COMPILER_MSFT and Type == TAB_C_CODE_FILE:\r
-                    T, CmdTarget, CmdTargetDict, CmdCppDict = self.ParserCCodeFile(T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict)\r
+                    T, CmdTarget, CmdTargetDict, CmdCppDict = self.ParserCCodeFile(T, Type, CmdSumDict, CmdTargetDict,\r
+                                                                                   CmdCppDict, DependencyDict, RespFile,\r
+                                                                                   ToolsDef, resp_file_number)\r
+                    resp_file_number += 1\r
                     TargetDict = {"target": self.PlaceMacro(T.Target.Path, self.Macros), "cmd": "\n\t".join(T.Commands),"deps": CCodeDeps}\r
                     CmdLine = self._BUILD_TARGET_TEMPLATE.Replace(TargetDict).rstrip().replace('\t$(OBJLIST', '$(OBJLIST')\r
                     if T.Commands:\r
@@ -1062,7 +1066,9 @@ cleanlib:
                         AnnexeTargetDict = {"target": self.PlaceMacro(i.Path, self.Macros), "cmd": "", "deps": self.PlaceMacro(T.Target.Path, self.Macros)}\r
                         self.BuildTargetList.append(self._BUILD_TARGET_TEMPLATE.Replace(AnnexeTargetDict))\r
 \r
-    def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict):\r
+    def ParserCCodeFile(self, T, Type, CmdSumDict, CmdTargetDict, CmdCppDict, DependencyDict, RespFile, ToolsDef,\r
+                            resp_file_number):\r
+        SaveFilePath = os.path.join(RespFile, "cc_resp_%s.txt" % resp_file_number)\r
         if not CmdSumDict:\r
             for item in self._AutoGenObject.Targets[Type]:\r
                 CmdSumDict[item.Target.SubDir] = item.Target.BaseName\r
@@ -1089,17 +1095,36 @@ cleanlib:
                         if Temp.startswith('/Fo'):\r
                             CmdSign = '%s%s' % (Temp.rsplit(TAB_SLASH, 1)[0], TAB_SLASH)\r
                             break\r
-                    else: continue\r
+                    else:\r
+                        continue\r
                     if CmdSign not in list(CmdTargetDict.keys()):\r
-                        CmdTargetDict[CmdSign] = Item.replace(Temp, CmdSign)\r
+                        cmd = Item.replace(Temp, CmdSign)\r
+                        if SingleCommandList[-1] in cmd:\r
+                            CmdTargetDict[CmdSign] = [cmd.replace(SingleCommandList[-1], "").rstrip(), SingleCommandList[-1]]\r
                     else:\r
-                        CmdTargetDict[CmdSign] = "%s %s" % (CmdTargetDict[CmdSign], SingleCommandList[-1])\r
+                        # CmdTargetDict[CmdSign] = "%s %s" % (CmdTargetDict[CmdSign], SingleCommandList[-1])\r
+                        CmdTargetDict[CmdSign].append(SingleCommandList[-1])\r
                     Index = CommandList.index(Item)\r
                     CommandList.pop(Index)\r
                     if SingleCommandList[-1].endswith("%s%s.c" % (TAB_SLASH, CmdSumDict[CmdSign[3:].rsplit(TAB_SLASH, 1)[0]])):\r
                         Cpplist = CmdCppDict[T.Target.SubDir]\r
                         Cpplist.insert(0, '$(OBJLIST_%d): ' % list(self.ObjTargetDict.keys()).index(T.Target.SubDir))\r
-                        T.Commands[Index] = '%s\n\t%s' % (' \\\n\t'.join(Cpplist), CmdTargetDict[CmdSign])\r
+                        source_files = CmdTargetDict[CmdSign][1:]\r
+                        source_files.insert(0, " ")\r
+                        if len(source_files)>2:\r
+                            SaveFileOnChange(SaveFilePath, " ".join(source_files), False)\r
+                            T.Commands[Index] = '%s\n\t%s $(cc_resp_%s)' % (\r
+                            ' \\\n\t'.join(Cpplist), CmdTargetDict[CmdSign][0], resp_file_number)\r
+                            ToolsDef.append("cc_resp_%s = @%s" % (resp_file_number, SaveFilePath))\r
+\r
+                        elif len(source_files)<=2 and len(" ".join(CmdTargetDict[CmdSign][:2]))>GlobalData.gCommandMaxLength:\r
+                            SaveFileOnChange(SaveFilePath, " ".join(source_files), False)\r
+                            T.Commands[Index] = '%s\n\t%s $(cc_resp_%s)' % (\r
+                                ' \\\n\t'.join(Cpplist), CmdTargetDict[CmdSign][0], resp_file_number)\r
+                            ToolsDef.append("cc_resp_%s = @%s" % (resp_file_number, SaveFilePath))\r
+\r
+                        else:\r
+                            T.Commands[Index] = '%s\n\t%s' % (' \\\n\t'.join(Cpplist), " ".join(CmdTargetDict[CmdSign]))\r
                     else:\r
                         T.Commands.pop(Index)\r
         return T, CmdSumDict, CmdTargetDict, CmdCppDict\r
index c3e6333217c44adcd104b2bdba6ce60eb24df5cc..b06ef42573fd5c5419b490a9045fc23da5a07052 100644 (file)
@@ -201,7 +201,17 @@ ${END}
                             cc_options = line[len(cc_cmd)+2:].split()\r
                         else:\r
                             cc_options = line[len(cc_cmd):].split()\r
-                        SourceFileAbsPathMap = {os.path.basename(item):item for item in cc_options if not item.startswith("/") and os.path.exists(item)}\r
+                        for item in cc_options:\r
+                            if not item.startswith("/"):\r
+                                if item.endswith(".txt") and item.startswith("@"):\r
+                                    with open(item[1:], "r") as file:\r
+                                        source_files = file.readlines()[0].split()\r
+                                        SourceFileAbsPathMap = {os.path.basename(file): file for file in source_files if\r
+                                                                os.path.exists(file)}\r
+                                else:\r
+                                    if os.path.exists(item):\r
+                                        SourceFileAbsPathMap.update({os.path.basename(item): item.strip()})\r
+                        # SourceFileAbsPathMap = {os.path.basename(item):item for item in cc_options if not item.startswith("/") and os.path.exists(item)}\r
             if line in SourceFileAbsPathMap:\r
                 current_source = line\r
                 if current_source not in ModuleDepDict:\r