From 5de927b54b9f4b314ec65bd2ae1d1908ceabd423 Mon Sep 17 00:00:00 2001 From: Jordan Justen Date: Sat, 19 Mar 2016 01:06:13 -0700 Subject: [PATCH] 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 Reviewed-by: Liming Gao --- BaseTools/Scripts/ConvertMasmToNasm.py | 61 +++++++++++++++++++------- 1 file 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: -- 2.39.2