]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Source/Python/Trim/Trim.py
BaseTools: update the mail address for stack trace info
[mirror_edk2.git] / BaseTools / Source / Python / Trim / Trim.py
index 13485c72da51c22e6c12deb51777addcec2da3ae..9ccc0273c254c63bb4c2da9b96bd8ea7978a861f 100644 (file)
@@ -1,7 +1,7 @@
 ## @file\r
 # Trim files preprocessed by compiler\r
 #\r
-# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.<BR>\r
+# Copyright (c) 2007 - 2016, 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
@@ -29,7 +29,7 @@ from Common.LongFilePathSupport import OpenLongFilePath as open
 # Version and Copyright\r
 __version_number__ = ("0.10" + " " + gBUILD_VERSION)\r
 __version__ = "%prog Version " + __version_number__\r
-__copyright__ = "Copyright (c) 2007-2010, Intel Corporation. All rights reserved."\r
+__copyright__ = "Copyright (c) 2007-2016, Intel Corporation. All rights reserved."\r
 \r
 ## Regular expression for matching Line Control directive like "#line xxx"\r
 gLineControlDirective = re.compile('^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*)"')\r
@@ -37,6 +37,10 @@ gLineControlDirective = re.compile('^\s*#(?:line)?\s+([0-9]+)\s+"*([^"]*)"')
 gTypedefPattern = re.compile("^\s*typedef\s+struct(\s+\w+)?\s*[{]*$", re.MULTILINE)\r
 ## Regular expression for matching "#pragma pack"\r
 gPragmaPattern = re.compile("^\s*#pragma\s+pack", re.MULTILINE)\r
+## Regular expression for matching "typedef"\r
+gTypedef_SinglePattern = re.compile("^\s*typedef", re.MULTILINE)\r
+## Regular expression for matching "typedef struct, typedef union, struct, union"\r
+gTypedef_MulPattern = re.compile("^\s*(typedef)?\s+(struct|union)(\s+\w+)?\s*[{]*$", re.MULTILINE)\r
 \r
 #\r
 # The following number pattern match will only match if following criteria is met:\r
@@ -177,13 +181,13 @@ def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
             EdkLogger.verbose("Found original file content starting from line %d"\r
                               % (LineIndexOfOriginalFile + 1))\r
 \r
+        if TrimLong:\r
+            Line = gLongNumberPattern.sub(r"\1", Line)\r
         # convert HEX number format if indicated\r
         if ConvertHex:\r
             Line = gHexNumberPattern.sub(r"0\2h", Line)\r
         else:\r
             Line = gHexNumberPattern.sub(r"\1\2", Line)\r
-        if TrimLong:\r
-            Line = gLongNumberPattern.sub(r"\1", Line)\r
 \r
         # convert Decimal number format\r
         Line = gDecNumberPattern.sub(r"\1", Line)\r
@@ -206,7 +210,34 @@ def TrimPreprocessedFile(Source, Target, ConvertHex, TrimLong):
 \r
     # in case there's no line directive or linemarker found\r
     if (not LineControlDirectiveFound) and NewLines == []:\r
-        NewLines = Lines\r
+        MulPatternFlag = False\r
+        SinglePatternFlag = False\r
+        Brace = 0\r
+        for Index in range(len(Lines)):\r
+            Line = Lines[Index]\r
+            if MulPatternFlag == False and gTypedef_MulPattern.search(Line) == None:\r
+                if SinglePatternFlag == False and gTypedef_SinglePattern.search(Line) == None:\r
+                    # remove "#pragram pack" directive\r
+                    if gPragmaPattern.search(Line) == None:\r
+                        NewLines.append(Line)\r
+                    continue\r
+                elif SinglePatternFlag == False:\r
+                    SinglePatternFlag = True\r
+                if Line.find(";") >= 0:\r
+                    SinglePatternFlag = False\r
+            elif MulPatternFlag == False:\r
+                # found "typedef struct, typedef union, union, struct", keep its position and set a flag\r
+                MulPatternFlag = True\r
+\r
+            # match { and } to find the end of typedef definition\r
+            if Line.find("{") >= 0:\r
+                Brace += 1\r
+            elif Line.find("}") >= 0:\r
+                Brace -= 1\r
+\r
+            # "typedef struct, typedef union, union, struct" must end with a ";"\r
+            if Brace == 0 and Line.find(";") >= 0:\r
+                MulPatternFlag = False\r
 \r
     # save to file\r
     try:\r
@@ -594,7 +625,7 @@ def Main():
                     "\nTrim",\r
                     CODE_ERROR,\r
                     "Unknown fatal error when trimming [%s]" % InputFile,\r
-                    ExtraData="\n(Please send email to edk2-buildtools-devel@lists.sourceforge.net for help, attaching following call stack trace!)\n",\r
+                    ExtraData="\n(Please send email to edk2-devel@lists.01.org for help, attaching following call stack trace!)\n",\r
                     RaiseError=False\r
                     )\r
         EdkLogger.quiet("(Python %s on %s) " % (platform.python_version(), sys.platform) + traceback.format_exc())\r