llvm.org GIT mirror llvm / b49fb7b
[llvm-build] Make Py3 compatible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@188424 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 7 years ago
4 changed file(s) with 118 addition(s) and 103 deletion(s). Raw diff Collapse all Expand all
None from main import main
0 from llvmbuild.main import main
11 Descriptor objects for entities that are part of the LLVM project.
22 """
33
4 import ConfigParser
5 import StringIO
4 from __future__ import absolute_import
5 try:
6 import configparser
7 except:
8 import ConfigParser as configparser
69 import sys
710
8 from util import *
11 from llvmbuild.util import *
912
1013 class ParseError(Exception):
1114 pass
2831
2932 def __init__(self, subpath, name, dependencies, parent):
3033 if not subpath.startswith('/'):
31 raise ValueError,"invalid subpath: %r" % subpath
34 raise ValueError("invalid subpath: %r" % subpath)
3235 self.subpath = subpath
3336 self.name = name
3437 self.dependencies = list(dependencies)
99102 ComponentInfo.__init__(self, subpath, name, [], parent)
100103
101104 def get_llvmbuild_fragment(self):
102 result = StringIO.StringIO()
103 print >>result, 'type = %s' % self.type_name
104 print >>result, 'name = %s' % self.name
105 print >>result, 'parent = %s' % self.parent
106 return result.getvalue()
105 return """\
106 type = %s
107 name = %s
108 parent = %s
109 """ % (self.type_name, self.name, self.parent)
107110
108111 class LibraryComponentInfo(ComponentInfo):
109112 type_name = 'Library'
151154 yield ('library group', r)
152155
153156 def get_llvmbuild_fragment(self):
154 result = StringIO.StringIO()
155 print >>result, 'type = %s' % self.type_name
156 print >>result, 'name = %s' % self.name
157 print >>result, 'parent = %s' % self.parent
157 result = """\
158 type = %s
159 name = %s
160 parent = %s
161 """ % (self.type_name, self.name, self.parent)
158162 if self.library_name is not None:
159 print >>result, 'library_name = %s' % self.library_name
163 result += 'library_name = %s\n' % self.library_name
160164 if self.required_libraries:
161 print >>result, 'required_libraries = %s' % ' '.join(
165 result += 'required_libraries = %s\n' % ' '.join(
162166 self.required_libraries)
163167 if self.add_to_library_groups:
164 print >>result, 'add_to_library_groups = %s' % ' '.join(
168 result += 'add_to_library_groups = %s\n' % ' '.join(
165169 self.add_to_library_groups)
166170 if not self.installed:
167 print >>result, 'installed = 0'
168 return result.getvalue()
171 result += 'installed = 0\n'
172 return result
169173
170174 def get_library_name(self):
171175 return self.library_name or self.name
236240 yield ('library group', r)
237241
238242 def get_llvmbuild_fragment(self):
239 result = StringIO.StringIO()
240 print >>result, 'type = %s' % self.type_name
241 print >>result, 'name = %s' % self.name
242 print >>result, 'parent = %s' % self.parent
243 result = """\
244 type = %s
245 name = %s
246 parent = %s
247 """ % (self.type_name, self.name, self.parent)
243248 if self.required_libraries and not self._is_special_group:
244 print >>result, 'required_libraries = %s' % ' '.join(
249 result += 'required_libraries = %s\n' % ' '.join(
245250 self.required_libraries)
246251 if self.add_to_library_groups:
247 print >>result, 'add_to_library_groups = %s' % ' '.join(
252 result += 'add_to_library_groups = %s\n' % ' '.join(
248253 self.add_to_library_groups)
249 return result.getvalue()
254 return result
250255
251256 def get_llvmconfig_component_name(self):
252257 return self.name.lower()
308313 yield ('library group', r)
309314
310315 def get_llvmbuild_fragment(self):
311 result = StringIO.StringIO()
312 print >>result, 'type = %s' % self.type_name
313 print >>result, 'name = %s' % self.name
314 print >>result, 'parent = %s' % self.parent
316 result = """\
317 type = %s
318 name = %s
319 parent = %s
320 """ % (self.type_name, self.name, self.parent)
315321 if self.required_libraries:
316 print >>result, 'required_libraries = %s' % ' '.join(
322 result += 'required_libraries = %s\n' % ' '.join(
317323 self.required_libraries)
318324 if self.add_to_library_groups:
319 print >>result, 'add_to_library_groups = %s' % ' '.join(
325 result += 'add_to_library_groups = %s\n' % ' '.join(
320326 self.add_to_library_groups)
321327 for bool_key in ('has_asmparser', 'has_asmprinter', 'has_disassembler',
322328 'has_jit'):
323329 if getattr(self, bool_key):
324 print >>result, '%s = 1' % (bool_key,)
325 return result.getvalue()
330 result += '%s = 1\n' % (bool_key,)
331 return result
326332
327333 def get_llvmconfig_component_name(self):
328334 return self.name.lower()
351357 yield ('required library', r)
352358
353359 def get_llvmbuild_fragment(self):
354 result = StringIO.StringIO()
355 print >>result, 'type = %s' % self.type_name
356 print >>result, 'name = %s' % self.name
357 print >>result, 'parent = %s' % self.parent
358 print >>result, 'required_libraries = %s' % ' '.join(
359 self.required_libraries)
360 return result.getvalue()
360 return """\
361 type = %s
362 name = %s
363 parent = %s
364 required_libraries = %s
365 """ % (self.type_name, self.name, self.parent,
366 ' '.join(self.required_libraries))
361367
362368 class BuildToolComponentInfo(ToolComponentInfo):
363369 type_name = 'BuildTool'
417423 TargetGroupComponentInfo, OptionalLibraryComponentInfo))
418424 def load_from_path(path, subpath):
419425 # Load the LLVMBuild.txt file as an .ini format file.
420 parser = ConfigParser.RawConfigParser()
426 parser = configparser.RawConfigParser()
421427 parser.read(path)
422428
423429 # Extract the common section.
458464 section, path, "unable to instantiate: %r" % type_name)
459465 import traceback
460466 traceback.print_exc()
461 raise SystemExit, 1
462 except ParseError,e:
467 raise SystemExit(1)
468 except ParseError:
469 e = sys.exc_info()[1]
463470 fatal("unable to load component %r in %r: %s" % (
464471 section, path, e.message))
465472
None import StringIO
0 from __future__ import absolute_import
11 import os
22 import sys
33
4 import componentinfo
5 import configutil
6
7 from util import *
4 import llvmbuild.componentinfo as componentinfo
5 import llvmbuild.configutil as configutil
6
7 from llvmbuild.util import *
88
99 ###
1010
185185 set(self.component_infos),
186186 key = lambda c: c.name)
187187 while components_to_visit:
188 visit_component_info(iter(components_to_visit).next(), [], set())
188 visit_component_info(components_to_visit[0], [], set())
189189
190190 # Canonicalize children lists.
191191 for c in self.ordered_component_infos:
193193
194194 def print_tree(self):
195195 def visit(node, depth = 0):
196 print '%s%-40s (%s)' % (' '*depth, node.name, node.type_name)
196 print('%s%-40s (%s)' % (' '*depth, node.name, node.type_name))
197197 for c in node.children:
198198 visit(c, depth + 1)
199199 visit(self.component_info_map['$ROOT'])
282282 header_name = '.' + os.path.join(subpath, 'LLVMBuild.txt')
283283 header_pad = '-' * (80 - len(header_fmt % (header_name, '')))
284284 header_string = header_fmt % (header_name, header_pad)
285 print >>f, """\
285 f.write("""\
286286 %s
287287 ;
288288 ; The LLVM Compiler Infrastructure
299299 ; http://llvm.org/docs/LLVMBuild.html
300300 ;
301301 ;===------------------------------------------------------------------------===;
302 """ % header_string
302
303 """ % header_string)
303304
304305 # Write out each fragment.each component fragment.
305306 for name,fragment in fragments:
306307 comment = comments_map.get(name)
307308 if comment is not None:
308309 f.write(comment)
309 print >>f, "[%s]" % name
310 f.write("[%s]\n" % name)
310311 f.write(fragment)
311312 if fragment is not fragments[-1][1]:
312 print >>f
313 f.write('\n')
313314
314315 f.close()
315316
362363 is_installed)
363364
364365 # Convert to a list of entries and sort by name.
365 entries = entries.values()
366 entries = list(entries.values())
366367
367368 # Create an 'all' pseudo component. We keep the dependency list small by
368369 # only listing entries that have no other dependents.
381382 # Write out the library table.
382383 make_install_dir(os.path.dirname(output_path))
383384 f = open(output_path, 'w')
384 print >>f, """\
385 f.write("""\
385386 //===- llvm-build generated file --------------------------------*- C++ -*-===//
386387 //
387388 // Component Library Depenedency Table
389390 // Automatically generated file, do not edit!
390391 //
391392 //===----------------------------------------------------------------------===//
392 """
393 print >>f, 'struct AvailableComponent {'
394 print >>f, ' /// The name of the component.'
395 print >>f, ' const char *Name;'
396 print >>f, ''
397 print >>f, ' /// The name of the library for this component (or NULL).'
398 print >>f, ' const char *Library;'
399 print >>f, ''
400 print >>f, ' /// Whether the component is installed.'
401 print >>f, ' bool IsInstalled;'
402 print >>f, ''
403 print >>f, '\
404 /// The list of libraries required when linking this component.'
405 print >>f, ' const char *RequiredLibraries[%d];' % (
406 max_required_libraries)
407 print >>f, '} AvailableComponents[%d] = {' % len(entries)
393
394 """)
395 f.write('struct AvailableComponent {\n')
396 f.write(' /// The name of the component.\n')
397 f.write(' const char *Name;\n')
398 f.write('\n')
399 f.write(' /// The name of the library for this component (or NULL).\n')
400 f.write(' const char *Library;\n')
401 f.write('\n')
402 f.write(' /// Whether the component is installed.\n')
403 f.write(' bool IsInstalled;\n')
404 f.write('\n')
405 f.write('\
406 /// The list of libraries required when linking this component.\n')
407 f.write(' const char *RequiredLibraries[%d];\n' % (
408 max_required_libraries))
409 f.write('} AvailableComponents[%d] = {\n' % len(entries))
408410 for name,library_name,required_names,is_installed in entries:
409411 if library_name is None:
410412 library_name_as_cstr = '0'
411413 else:
412414 library_name_as_cstr = '"lib%s.a"' % library_name
413 print >>f, ' { "%s", %s, %d, { %s } },' % (
415 f.write(' { "%s", %s, %d, { %s } },\n' % (
414416 name, library_name_as_cstr, is_installed,
415417 ', '.join('"%s"' % dep
416 for dep in required_names))
417 print >>f, '};'
418 for dep in required_names)))
419 f.write('};\n')
418420 f.close()
419421
420422 def get_required_libraries_for_component(self, ci, traverse_groups = False):
511513 header_name = os.path.basename(output_path)
512514 header_pad = '-' * (80 - len(header_fmt % (header_name, '')))
513515 header_string = header_fmt % (header_name, header_pad)
514 print >>f, """\
516 f.write("""\
515517 %s
516518 #
517519 # The LLVM Compiler Infrastructure
527529 # This file is autogenerated by llvm-build, do not edit!
528530 #
529531 #===------------------------------------------------------------------------===#
530 """ % header_string
532
533 """ % header_string)
531534
532535 # Write the dependency information in the best way we can.
533 print >>f, """
536 f.write("""
534537 # LLVMBuild CMake fragment dependencies.
535538 #
536539 # CMake has no builtin way to declare that the configuration depends on
540543 # CMake.
541544 #
542545 # FIXME: File a CMake RFE to get a properly supported version of this
543 # feature."""
546 # feature.
547 """)
544548 for dep in dependencies:
545 print >>f, """\
549 f.write("""\
546550 configure_file(\"%s\"
547 ${CMAKE_CURRENT_BINARY_DIR}/DummyConfigureOutput)""" % (
548 cmake_quote_path(dep),)
551 ${CMAKE_CURRENT_BINARY_DIR}/DummyConfigureOutput)\n""" % (
552 cmake_quote_path(dep),))
549553
550554 # Write the properties we use to encode the required library dependency
551555 # information in a form CMake can easily use directly.
552 print >>f, """
556 f.write("""
553557 # Explicit library dependency information.
554558 #
555559 # The following property assignments effectively create a map from component
556 # names to required libraries, in a way that is easily accessed from CMake."""
560 # names to required libraries, in a way that is easily accessed from CMake.
561 """)
557562 for ci in self.ordered_component_infos:
558563 # We only write the information for libraries currently.
559564 if ci.type_name != 'Library':
560565 continue
561566
562 print >>f, """\
563 set_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_%s %s)""" % (
567 f.write("""\
568 set_property(GLOBAL PROPERTY LLVMBUILD_LIB_DEPS_%s %s)\n""" % (
564569 ci.get_prefixed_library_name(), " ".join(sorted(
565570 dep.get_prefixed_library_name()
566 for dep in self.get_required_libraries_for_component(ci))))
571 for dep in self.get_required_libraries_for_component(ci)))))
567572
568573 f.close()
569574
589594 header_name = os.path.basename(output_path)
590595 header_pad = '-' * (80 - len(header_fmt % (header_name, '')))
591596 header_string = header_fmt % (header_name, header_pad)
592 print >>f, """\
597 f.write("""\
593598 %s
594599 #
595600 # The LLVM Compiler Infrastructure
605610 # This file is autogenerated by llvm-build, do not edit!
606611 #
607612 #===------------------------------------------------------------------------===#
608 """ % header_string
613
614 """ % header_string)
609615
610616 # Write the dependencies for the fragment.
611617 #
612618 # FIXME: Technically, we need to properly quote for Make here.
613 print >>f, """\
619 f.write("""\
614620 # Clients must explicitly enable LLVMBUILD_INCLUDE_DEPENDENCIES to get
615621 # these dependencies. This is a compromise to help improve the
616 # performance of recursive Make systems."""
617 print >>f, 'ifeq ($(LLVMBUILD_INCLUDE_DEPENDENCIES),1)'
618 print >>f, "# The dependencies for this Makefile fragment itself."
619 print >>f, "%s: \\" % (mk_quote_string_for_target(output_path),)
622 # performance of recursive Make systems.
623 """)
624 f.write('ifeq ($(LLVMBUILD_INCLUDE_DEPENDENCIES),1)\n')
625 f.write("# The dependencies for this Makefile fragment itself.\n")
626 f.write("%s: \\\n" % (mk_quote_string_for_target(output_path),))
620627 for dep in dependencies:
621 print >>f, "\t%s \\" % (dep,)
622 print >>f
628 f.write("\t%s \\\n" % (dep,))
629 f.write('\n')
623630
624631 # Generate dummy rules for each of the dependencies, so that things
625632 # continue to work correctly if any of those files are moved or removed.
626 print >>f, """\
633 f.write("""\
627634 # The dummy targets to allow proper regeneration even when files are moved or
628 # removed."""
635 # removed.
636 """)
629637 for dep in dependencies:
630 print >>f, "%s:" % (mk_quote_string_for_target(dep),)
631 print >>f, 'endif'
638 f.write("%s:\n" % (mk_quote_string_for_target(dep),))
639 f.write('endif\n')
632640
633641 f.close()
634642
800808 dest="optional_components", metavar="NAMES",
801809 help=("Enable the given space or semi-colon separated "
802810 "list of optional components"),
803 action="store", default=None)
811 action="store", default="")
804812 parser.add_option_group(group)
805813
806814 (opts, args) = parser.parse_args()
22
33 def _write_message(kind, message):
44 program = os.path.basename(sys.argv[0])
5 print >>sys.stderr, '%s: %s: %s' % (program, kind, message)
5 sys.stderr.write('%s: %s: %s\n' % (program, kind, message))
66
77 note = lambda message: _write_message('note', message)
88 warning = lambda message: _write_message('warning', message)