]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Trim/Trim.py
BaseTools/Trim: Normalize filepaths to fix comparisons on Windows
[mirror_edk2.git] / BaseTools / Source / Python / Trim / Trim.py
index b512d15243f83225457b2dc099ac0c026142a5ed..b46d507b4e55e503712ecf0a205cb3d940f206b4 100644 (file)
@@ -17,7 +17,7 @@
 import Common.LongFilePathOs as os\r
 import sys\r
 import re\r
-import StringIO\r
+from io import BytesIO\r
 \r
 from optparse import OptionParser\r
 from optparse import make_option\r
@@ -166,6 +166,8 @@ def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
             if len(MatchList) == 2:\r
                 LineNumber = int(MatchList[0], 0)\r
                 InjectedFile = MatchList[1]\r
+                InjectedFile = os.path.normpath(InjectedFile)\r
+                InjectedFile = os.path.normcase(InjectedFile)\r
                 # The first injetcted file must be the preprocessed file itself\r
                 if PreprocessedFile == "":\r
                     PreprocessedFile = InjectedFile\r
@@ -261,7 +263,7 @@ def TrimPreprocessedVfr(Source, Target):
     CreateDirectory(os.path.dirname(Target))\r
     \r
     try:\r
-        f = open (Source,'r')\r
+        f = open (Source, 'r')\r
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)\r
     # read whole file\r
@@ -310,7 +312,7 @@ def TrimPreprocessedVfr(Source, Target):
 \r
     # save all lines trimmed\r
     try:\r
-        f = open (Target,'w')\r
+        f = open (Target, 'w')\r
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)\r
     f.writelines(Lines)\r
@@ -407,7 +409,7 @@ def TrimAslFile(Source, Target, IncludePathFile):
     if IncludePathFile:\r
         try:\r
             LineNum = 0\r
-            for Line in open(IncludePathFile,'r'):\r
+            for Line in open(IncludePathFile, 'r'):\r
                 LineNum += 1\r
                 if Line.startswith("/I") or Line.startswith ("-I"):\r
                     IncludePathList.append(Line[2:].strip())\r
@@ -425,7 +427,7 @@ def TrimAslFile(Source, Target, IncludePathFile):
 \r
     # save all lines trimmed\r
     try:\r
-        f = open (Target,'w')\r
+        f = open (Target, 'w')\r
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)\r
 \r
@@ -455,8 +457,8 @@ def GenerateVfrBinSec(ModuleName, DebugDir, OutputFile):
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, "File open failed for %s" %OutputFile, None)\r
 \r
-    # Use a instance of StringIO to cache data\r
-    fStringIO = StringIO.StringIO('')\r
+    # Use a instance of BytesIO to cache data\r
+    fStringIO = BytesIO('')\r
 \r
     for Item in VfrUniOffsetList:\r
         if (Item[0].find("Strings") != -1):\r
@@ -560,7 +562,7 @@ def TrimEdkSourceCode(Source, Target):
     CreateDirectory(os.path.dirname(Target))\r
 \r
     try:\r
-        f = open (Source,'rb')\r
+        f = open (Source, 'rb')\r
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Source)\r
     # read whole file\r
@@ -568,7 +570,7 @@ def TrimEdkSourceCode(Source, Target):
     f.close()\r
 \r
     NewLines = None\r
-    for Re,Repl in gImportCodePatterns:\r
+    for Re, Repl in gImportCodePatterns:\r
         if NewLines is None:\r
             NewLines = Re.sub(Repl, Lines)\r
         else:\r
@@ -579,7 +581,7 @@ def TrimEdkSourceCode(Source, Target):
         return\r
 \r
     try:\r
-        f = open (Target,'wb')\r
+        f = open (Target, 'wb')\r
     except:\r
         EdkLogger.error("Trim", FILE_OPEN_FAILURE, ExtraData=Target)\r
     f.write(NewLines)\r