summaryrefslogtreecommitdiff
path: root/BaseTools
diff options
context:
space:
mode:
authorJordan Justen <jordan.l.justen@intel.com>2016-03-19 01:06:13 -0700
committerHao Wu <hao.a.wu@intel.com>2016-07-13 09:34:02 +0800
commit14bff3d7536b522160981fc1c5e76f496addad9c (patch)
treea16d8fa88c720f7a8ceb29677130aa4653fbb3f6 /BaseTools
parent4f9fb18fa7ffdb81361da59e9bbf9f68d80e39f5 (diff)
downloadedk2-platforms-14bff3d7536b522160981fc1c5e76f496addad9c.tar.xz
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> (cherry picked from commit 5de927b54b9f4b314ec65bd2ae1d1908ceabd423)
Diffstat (limited to 'BaseTools')
-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: