mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-07-13 07:31:28 +00:00
llvm-build: Add sketchy support for preserving comments when using
--write-llvmbuild. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146434 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
dcfc2eaf62
commit
a3217165c6
@ -46,7 +46,10 @@ component combinations.
|
|||||||
=item B<--write-llvmbuild>
|
=item B<--write-llvmbuild>
|
||||||
|
|
||||||
Write out new I<LLVMBuild.txt> files based on the loaded components. This is
|
Write out new I<LLVMBuild.txt> files based on the loaded components. This is
|
||||||
useful for auto-upgrading the schema of the files.
|
useful for auto-upgrading the schema of the files. B<llvm-build> will try to a
|
||||||
|
limited extent to preserve the comments which were written in the original
|
||||||
|
source file, although at this time it only preserves block comments that preceed
|
||||||
|
the section names in the I<LLVMBuild> files.
|
||||||
|
|
||||||
=item B<--write-cmake-fragment>
|
=item B<--write-cmake-fragment>
|
||||||
|
|
||||||
|
@ -42,6 +42,9 @@ class ComponentInfo(object):
|
|||||||
self.parent_instance = None
|
self.parent_instance = None
|
||||||
self.children = []
|
self.children = []
|
||||||
|
|
||||||
|
# The original source path.
|
||||||
|
self._source_path = None
|
||||||
|
|
||||||
def set_parent_instance(self, parent):
|
def set_parent_instance(self, parent):
|
||||||
assert parent.name == self.parent, "Unexpected parent!"
|
assert parent.name == self.parent, "Unexpected parent!"
|
||||||
self.parent_instance = parent
|
self.parent_instance = parent
|
||||||
@ -407,4 +410,5 @@ def load_from_path(path, subpath):
|
|||||||
fatal("unable to load component %r in %r: %s" % (
|
fatal("unable to load component %r in %r: %s" % (
|
||||||
section, path, e.message))
|
section, path, e.message))
|
||||||
|
|
||||||
|
info._source_path = path
|
||||||
yield info
|
yield info
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import StringIO
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
@ -231,7 +232,22 @@ class LLVMProjectInfo(object):
|
|||||||
if not os.path.exists(directory_path):
|
if not os.path.exists(directory_path):
|
||||||
os.makedirs(directory_path)
|
os.makedirs(directory_path)
|
||||||
|
|
||||||
# Create the LLVMBuild file.
|
# In an effort to preserve comments (which aren't parsed), read in
|
||||||
|
# the original file and extract the comments. We only know how to
|
||||||
|
# associate comments that prefix a section name.
|
||||||
|
f = open(infos[0]._source_path)
|
||||||
|
comments_map = {}
|
||||||
|
comment_block = ""
|
||||||
|
for ln in f:
|
||||||
|
if ln.startswith(';'):
|
||||||
|
comment_block += ln
|
||||||
|
elif ln.startswith('[') and ln.endswith(']\n'):
|
||||||
|
comments_map[ln[:-1]] = comment_block
|
||||||
|
else:
|
||||||
|
comment_block = ""
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
# Create the LLVMBuild fil[e.
|
||||||
file_path = os.path.join(directory_path, 'LLVMBuild.txt')
|
file_path = os.path.join(directory_path, 'LLVMBuild.txt')
|
||||||
f = open(file_path, "w")
|
f = open(file_path, "w")
|
||||||
|
|
||||||
@ -260,7 +276,11 @@ class LLVMProjectInfo(object):
|
|||||||
""" % header_string
|
""" % header_string
|
||||||
|
|
||||||
for i,fragment in enumerate(fragments):
|
for i,fragment in enumerate(fragments):
|
||||||
print >>f, '[component_%d]' % i
|
name = '[component_%d]' % i
|
||||||
|
comment = comments_map.get(name)
|
||||||
|
if comment is not None:
|
||||||
|
f.write(comment)
|
||||||
|
print >>f, name
|
||||||
f.write(fragment)
|
f.write(fragment)
|
||||||
if fragment is not fragments[-1]:
|
if fragment is not fragments[-1]:
|
||||||
print >>f
|
print >>f
|
||||||
|
Loading…
Reference in New Issue
Block a user