mirror of https://github.com/acidanthera/audk.git
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>
This commit is contained in:
parent
90694f1218
commit
5de927b54b
|
@ -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:
|
||||
if lastLine.strip() == updatedLine.strip():
|
||||
self.lines[i] = None
|
||||
else:
|
||||
self.lines[i] = updatedLine + '\n'
|
||||
|
||||
if self.diff:
|
||||
lineChanged = updatedLine != line
|
||||
if lineChanged:
|
||||
print('-%s' % line)
|
||||
if self.lines[i] is not None:
|
||||
print('+%s' % updatedLine)
|
||||
preserveOldSource = self.ShouldKeepFile(src)
|
||||
break
|
||||
|
||||
if lineChanged:
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue