summaryrefslogtreecommitdiffstats
path: root/BaseTools/Scripts/ConvertMasmToNasm.py
diff options
context:
space:
mode:
authorJordan Justen <jordan.l.justen@intel.com>2016-03-19 01:06:13 -0700
committerJordan Justen <jordan.l.justen@intel.com>2016-06-28 13:16:46 -0700
commit5de927b54b9f4b314ec65bd2ae1d1908ceabd423 (patch)
tree9d8573d6c02a75a0441a7bd163b53f9f73ee24e3 /BaseTools/Scripts/ConvertMasmToNasm.py
parent90694f121865073c93123c41046349ca84eb1a25 (diff)
downloadedk2-5de927b54b9f4b314ec65bd2ae1d1908ceabd423.tar.gz
edk2-5de927b54b9f4b314ec65bd2ae1d1908ceabd423.tar.bz2
edk2-5de927b54b9f4b314ec65bd2ae1d1908ceabd423.zip
BaseTools ConvertMasmToNasm: Support preserving assembly files
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>
Diffstat (limited to 'BaseTools/Scripts/ConvertMasmToNasm.py')
-rwxr-xr-xBaseTools/Scripts/ConvertMasmToNasm.py61
1 files changed, 44 insertions, 17 deletions
diff --git a/BaseTools/Scripts/ConvertMasmToNasm.py b/BaseTools/Scripts/ConvertMasmToNasm.py
index 6343fbd94c..3c8f994fcf 100755
--- a/BaseTools/Scripts/ConvertMasmToNasm.py
+++ b/BaseTools/Scripts/ConvertMasmToNasm.py
@@ -53,6 +53,7 @@ class CommonUtils:
self.unsupportedSyntaxSeen = False
self.src = self.args.source
+ self.keep = self.args.keep
assert(os.path.exists(self.src))
self.dirmode = os.path.isdir(self.src)
srcExt = os.path.splitext(self.src)[1]
@@ -78,6 +79,9 @@ class CommonUtils:
help="Disable all messages except FATAL ERRORS.")
parser.add_argument("--git", action="store_true",
help="Use git to create commits for each file converted")
+ parser.add_argument("--keep", action="append", choices=('asm', 's'),
+ default=[],
+ help="Don't remove files with this extension")
parser.add_argument("--diff", action="store_true",
help="Show diff of conversion")
parser.add_argument("-f", "--force", action="store_true",
@@ -175,9 +179,18 @@ class CommonUtils:
if not self.git or not self.gitdir:
return
+ if self.ShouldKeepFile(path):
+ return
+
cmd = ('git', 'rm', path)
self.RunAndCaptureOutput(cmd)
+ def ShouldKeepFile(self, path):
+ ext = os.path.splitext(path)[1].lower()
+ if ext.startswith('.'):
+ ext = ext[1:]
+ return ext in self.keep
+
def FileConversionFinished(self, pkg, module, src, dst):
if not self.git or not self.gitdir:
return
@@ -843,36 +856,50 @@ class ConvertInfFile(CommonUtils):
conv = ConvertAsmFile(fullSrc, fullDst, self)
self.unsupportedSyntaxSeen = conv.unsupportedSyntaxSeen
- lastLine = ''
fileChanged = False
+ recentSources = list()
i = 0
- for line in self.lines:
- line = line.rstrip()
+ while i < len(self.lines):
+ line = self.lines[i].rstrip()
updatedLine = line
+ lineChanged = False
+ preserveOldSource = False
for src in self.dstToSrc[dst]:
assert self.srcToDst[src] == dst
updatedLine = self.ReplacePreserveSpacing(
updatedLine, src, dst)
+ lineChanged = updatedLine != line
+ if lineChanged:
+ preserveOldSource = self.ShouldKeepFile(src)
+ break
- lineChanged = updatedLine != line
if lineChanged:
- if lastLine.strip() == updatedLine.strip():
- self.lines[i] = None
- else:
- self.lines[i] = updatedLine + '\n'
-
- if self.diff:
- if lineChanged:
- print('-%s' % line)
- if self.lines[i] is not None:
- print('+%s' % updatedLine)
+ if preserveOldSource:
+ if updatedLine.strip() not in recentSources:
+ self.lines.insert(i, updatedLine + '\n')
+ recentSources.append(updatedLine.strip())
+ i += 1
+ if self.diff:
+ print('+%s' % updatedLine)
+ if self.diff:
+ print('', line)
else:
+ if self.diff:
+ print('-%s' % line)
+ if updatedLine.strip() in recentSources:
+ self.lines[i] = None
+ else:
+ self.lines[i] = updatedLine + '\n'
+ recentSources.append(updatedLine.strip())
+ if self.diff:
+ print('+%s' % updatedLine)
+ else:
+ if len(recentSources) > 0:
+ recentSources = list()
+ if self.diff:
print('', line)
fileChanged |= lineChanged
- if self.lines[i] is not None:
- lastLine = self.lines[i]
-
i += 1
if fileChanged: