llvm.org GIT mirror llvm / b5cd41e
llvm-build: Add support for non-installed libraries (e.g., gtest). - These libraries are only reported by llvm-config when run from a development tree. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156838 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 7 years ago
5 changed file(s) with 47 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
271271 components. For example, the X86 target might define a library
272272 group for all of the X86 components. That library group might
273273 then be included in the all-targets library group.

274
275
  • installed [optional] [boolean]
  • 276

    Whether this library is installed. Libraries that are not installed

    277 are only reported by llvm-config when it is run as part of a
    278 development directory.

    274279
    275280
    276281
    5353 static void VisitComponent(StringRef Name,
    5454 const StringMap &ComponentMap,
    5555 std::set &VisitedComponents,
    56 std::vector &RequiredLibs) {
    56 std::vector &RequiredLibs,
    57 bool IncludeNonInstalled) {
    5758 // Lookup the component.
    5859 AvailableComponent *AC = ComponentMap.lookup(Name);
    5960 assert(AC && "Invalid component name!");
    6465 return;
    6566 }
    6667
    68 // Only include non-installed components if requested.
    69 if (!AC->IsInstalled && !IncludeNonInstalled)
    70 return;
    71
    6772 // Otherwise, visit all the dependencies.
    6873 for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {
    6974 VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,
    70 RequiredLibs);
    75 RequiredLibs, IncludeNonInstalled);
    7176 }
    7277
    7378 // Add to the required library list.
    8287 /// \param Components - The names of the components to find libraries for.
    8388 /// \param RequiredLibs [out] - On return, the ordered list of libraries that
    8489 /// are required to link the given components.
    90 /// \param IncludeNonInstalled - Whether non-installed components should be
    91 /// reported.
    8592 void ComputeLibsForComponents(const std::vector &Components,
    86 std::vector &RequiredLibs) {
    93 std::vector &RequiredLibs,
    94 bool IncludeNonInstalled) {
    8795 std::set VisitedComponents;
    8896
    8997 // Build a map of component names to information.
    106114 }
    107115
    108116 VisitComponent(ComponentLower, ComponentMap, VisitedComponents,
    109 RequiredLibs);
    117 RequiredLibs, IncludeNonInstalled);
    110118 }
    111119
    112120 // The list is now ordered with leafs first, we want the libraries to printed
    277285 PrintLibFiles = true;
    278286 } else if (Arg == "--components") {
    279287 for (unsigned j = 0; j != array_lengthof(AvailableComponents); ++j) {
    288 // Only include non-installed components when in a development tree.
    289 if (!AvailableComponents[j].IsInstalled && !IsInDevelopmentTree)
    290 continue;
    291
    280292 OS << ' ';
    281293 OS << AvailableComponents[j].Name;
    282294 }
    309321
    310322 // Construct the list of all the required libraries.
    311323 std::vector RequiredLibs;
    312 ComputeLibsForComponents(Components, RequiredLibs);
    324 ComputeLibsForComponents(Components, RequiredLibs,
    325 /*IncludeNonInstalled=*/IsInDevelopmentTree);
    313326
    314327 for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
    315328 StringRef Lib = RequiredLibs[i];
    115115 kwargs['required_libraries'] = items.get_list('required_libraries')
    116116 kwargs['add_to_library_groups'] = items.get_list(
    117117 'add_to_library_groups')
    118 kwargs['installed'] = items.get_optional_bool('installed', True)
    118119 return kwargs
    119120
    120121 @staticmethod
    123124 return LibraryComponentInfo(subpath, **kwargs)
    124125
    125126 def __init__(self, subpath, name, dependencies, parent, library_name,
    126 required_libraries, add_to_library_groups):
    127 required_libraries, add_to_library_groups, installed):
    127128 ComponentInfo.__init__(self, subpath, name, dependencies, parent)
    128129
    129130 # If given, the name to use for the library instead of deriving it from
    137138 # The names of the library group components this component should be
    138139 # considered part of.
    139140 self.add_to_library_groups = list(add_to_library_groups)
    141
    142 # Whether or not this library is installed.
    143 self.installed = installed
    140144
    141145 def get_component_references(self):
    142146 for r in ComponentInfo.get_component_references(self):
    159163 if self.add_to_library_groups:
    160164 print >>result, 'add_to_library_groups = %s' % ' '.join(
    161165 self.add_to_library_groups)
    166 if not self.installed:
    167 print >>result, 'installed = 0'
    162168 return result.getvalue()
    163169
    164170 def get_library_name(self):
    193199 return OptionalLibraryComponentInfo(subpath, **kwargs)
    194200
    195201 def __init__(self, subpath, name, dependencies, parent, library_name,
    196 required_libraries, add_to_library_groups):
    202 required_libraries, add_to_library_groups, installed):
    197203 LibraryComponentInfo.__init__(self, subpath, name, dependencies, parent,
    198204 library_name, required_libraries,
    199 add_to_library_groups)
    205 add_to_library_groups, installed)
    200206
    201207 class LibraryGroupComponentInfo(ComponentInfo):
    202208 type_name = 'LibraryGroup'
    340340 # Get the library name, or None for LibraryGroups.
    341341 if c.type_name == 'Library' or c.type_name == 'OptionalLibrary':
    342342 library_name = c.get_prefixed_library_name()
    343 is_installed = c.installed
    343344 else:
    344345 library_name = None
    346 is_installed = True
    345347
    346348 # Get the component names of all the required libraries.
    347349 required_llvmconfig_component_names = [
    354356
    355357 # Add the entry.
    356358 entries[c.name] = (llvmconfig_component_name, library_name,
    357 required_llvmconfig_component_names)
    359 required_llvmconfig_component_names,
    360 is_installed)
    358361
    359362 # Convert to a list of entries and sort by name.
    360363 entries = entries.values()
    362365 # Create an 'all' pseudo component. We keep the dependency list small by
    363366 # only listing entries that have no other dependents.
    364367 root_entries = set(e[0] for e in entries)
    365 for _,_,deps in entries:
    368 for _,_,deps,_ in entries:
    366369 root_entries -= set(deps)
    367 entries.append(('all', None, root_entries))
    370 entries.append(('all', None, root_entries, True))
    368371
    369372 entries.sort()
    370373
    371374 # Compute the maximum number of required libraries, plus one so there is
    372375 # always a sentinel.
    373376 max_required_libraries = max(len(deps)
    374 for _,_,deps in entries) + 1
    377 for _,_,deps,_ in entries) + 1
    375378
    376379 # Write out the library table.
    377380 make_install_dir(os.path.dirname(output_path))
    392395 print >>f, ' /// The name of the library for this component (or NULL).'
    393396 print >>f, ' const char *Library;'
    394397 print >>f, ''
    398 print >>f, ' /// Whether the component is installed.'
    399 print >>f, ' bool IsInstalled;'
    400 print >>f, ''
    395401 print >>f, '\
    396402 /// The list of libraries required when linking this component.'
    397403 print >>f, ' const char *RequiredLibraries[%d];' % (
    398404 max_required_libraries)
    399405 print >>f, '} AvailableComponents[%d] = {' % len(entries)
    400 for name,library_name,required_names in entries:
    406 for name,library_name,required_names,is_installed in entries:
    401407 if library_name is None:
    402408 library_name_as_cstr = '0'
    403409 else:
    404410 library_name_as_cstr = '"lib%s.a"' % library_name
    405 print >>f, ' { "%s", %s, { %s } },' % (
    406 name, library_name_as_cstr,
    411 print >>f, ' { "%s", %s, %d, { %s } },' % (
    412 name, library_name_as_cstr, is_installed,
    407413 ', '.join('"%s"' % dep
    408414 for dep in required_names))
    409415 print >>f, '};'
    1919 name = gtest
    2020 parent = Libraries
    2121 required_libraries = Support
    22 installed = 0
    2223
    2324 [component_1]
    2425 type = Library
    2526 name = gtest_main
    2627 parent = Libraries
    2728 required_libraries = gtest
    29 installed = 0