From ea07f34afd17c3547e93d109adcf28c245a95cc9 Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 12 Dec 2011 22:45:35 +0000 Subject: llvm-build: Add sketchy support for preserving comments when using --write-llvmbuild. llvm-svn: 146434 --- llvm/utils/llvm-build/llvmbuild/componentinfo.py | 4 ++++ llvm/utils/llvm-build/llvmbuild/main.py | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) (limited to 'llvm/utils') diff --git a/llvm/utils/llvm-build/llvmbuild/componentinfo.py b/llvm/utils/llvm-build/llvmbuild/componentinfo.py index 079102f676a..e9ef973d08a 100644 --- a/llvm/utils/llvm-build/llvmbuild/componentinfo.py +++ b/llvm/utils/llvm-build/llvmbuild/componentinfo.py @@ -42,6 +42,9 @@ class ComponentInfo(object): self.parent_instance = None self.children = [] + # The original source path. + self._source_path = None + def set_parent_instance(self, parent): assert parent.name == self.parent, "Unexpected parent!" self.parent_instance = parent @@ -407,4 +410,5 @@ def load_from_path(path, subpath): fatal("unable to load component %r in %r: %s" % ( section, path, e.message)) + info._source_path = path yield info diff --git a/llvm/utils/llvm-build/llvmbuild/main.py b/llvm/utils/llvm-build/llvmbuild/main.py index 4c14f46c80a..71e11d79cff 100644 --- a/llvm/utils/llvm-build/llvmbuild/main.py +++ b/llvm/utils/llvm-build/llvmbuild/main.py @@ -1,3 +1,4 @@ +import StringIO import os import sys @@ -231,7 +232,22 @@ class LLVMProjectInfo(object): if not os.path.exists(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') f = open(file_path, "w") @@ -260,7 +276,11 @@ class LLVMProjectInfo(object): """ % header_string 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) if fragment is not fragments[-1]: print >>f -- cgit v1.2.3