]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools ConvertMasmToNasm: Support preserving assembly files
authorJordan Justen <jordan.l.justen@intel.com>
Sat, 19 Mar 2016 08:06:13 +0000 (01:06 -0700)
committerJordan Justen <jordan.l.justen@intel.com>
Tue, 28 Jun 2016 20:16:46 +0000 (13:16 -0700)
In the first stage of conversion, we need to preserve the AT&T style
.s assembly files for use with OS X toolchains.

This change allows '--keep=s' to be used with the script to preserve
these files.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Scripts/ConvertMasmToNasm.py

index 6343fbd94c6df4c9ff4725ef6a47a47707408e44..3c8f994fcf7c2ec3d8066e12b043b92448da186f 100755 (executable)
@@ -53,6 +53,7 @@ class CommonUtils:
 \r
         self.unsupportedSyntaxSeen = False\r
         self.src = self.args.source\r
+        self.keep = self.args.keep\r
         assert(os.path.exists(self.src))\r
         self.dirmode = os.path.isdir(self.src)\r
         srcExt = os.path.splitext(self.src)[1]\r
@@ -78,6 +79,9 @@ class CommonUtils:
                             help="Disable all messages except FATAL ERRORS.")\r
         parser.add_argument("--git", action="store_true",\r
                             help="Use git to create commits for each file converted")\r
+        parser.add_argument("--keep", action="append", choices=('asm', 's'),\r
+                            default=[],\r
+                            help="Don't remove files with this extension")\r
         parser.add_argument("--diff", action="store_true",\r
                             help="Show diff of conversion")\r
         parser.add_argument("-f", "--force", action="store_true",\r
@@ -175,9 +179,18 @@ class CommonUtils:
         if not self.git or not self.gitdir:\r
             return\r
 \r
+        if self.ShouldKeepFile(path):\r
+            return\r
+\r
         cmd = ('git', 'rm', path)\r
         self.RunAndCaptureOutput(cmd)\r
 \r
+    def ShouldKeepFile(self, path):\r
+        ext = os.path.splitext(path)[1].lower()\r
+        if ext.startswith('.'):\r
+            ext = ext[1:]\r
+        return ext in self.keep\r
+\r
     def FileConversionFinished(self, pkg, module, src, dst):\r
         if not self.git or not self.gitdir:\r
             return\r
@@ -843,36 +856,50 @@ class ConvertInfFile(CommonUtils):
             conv = ConvertAsmFile(fullSrc, fullDst, self)\r
             self.unsupportedSyntaxSeen = conv.unsupportedSyntaxSeen\r
 \r
-        lastLine = ''\r
         fileChanged = False\r
+        recentSources = list()\r
         i = 0\r
-        for line in self.lines:\r
-            line = line.rstrip()\r
+        while i < len(self.lines):\r
+            line = self.lines[i].rstrip()\r
             updatedLine = line\r
+            lineChanged = False\r
+            preserveOldSource = False\r
             for src in self.dstToSrc[dst]:\r
                 assert self.srcToDst[src] == dst\r
                 updatedLine = self.ReplacePreserveSpacing(\r
                     updatedLine, src, dst)\r
+                lineChanged = updatedLine != line\r
+                if lineChanged:\r
+                    preserveOldSource = self.ShouldKeepFile(src)\r
+                    break\r
 \r
-            lineChanged = updatedLine != line\r
             if lineChanged:\r
-                if lastLine.strip() == updatedLine.strip():\r
-                    self.lines[i] = None\r
-                else:\r
-                    self.lines[i] = updatedLine + '\n'\r
-\r
-            if self.diff:\r
-                if lineChanged:\r
-                    print('-%s' % line)\r
-                    if self.lines[i] is not None:\r
-                        print('+%s' % updatedLine)\r
+                if preserveOldSource:\r
+                    if updatedLine.strip() not in recentSources:\r
+                        self.lines.insert(i, updatedLine + '\n')\r
+                        recentSources.append(updatedLine.strip())\r
+                        i += 1\r
+                        if self.diff:\r
+                            print('+%s' % updatedLine)\r
+                    if self.diff:\r
+                        print('', line)\r
                 else:\r
+                    if self.diff:\r
+                        print('-%s' % line)\r
+                    if updatedLine.strip() in recentSources:\r
+                        self.lines[i] = None\r
+                    else:\r
+                        self.lines[i] = updatedLine + '\n'\r
+                        recentSources.append(updatedLine.strip())\r
+                        if self.diff:\r
+                            print('+%s' % updatedLine)\r
+            else:\r
+                if len(recentSources) > 0:\r
+                    recentSources = list()\r
+                if self.diff:\r
                     print('', line)\r
 \r
             fileChanged |= lineChanged\r
-            if self.lines[i] is not None:\r
-                lastLine = self.lines[i]\r
-\r
             i += 1\r
 \r
         if fileChanged:\r