Skip to content

Commit

Permalink
llvm-build: Add support for non-installed libraries (e.g., gtest).
Browse files Browse the repository at this point in the history
 - 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
  • Loading branch information
ddunbar committed May 15, 2012
1 parent 177a119 commit b5cd41e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 15 deletions.
5 changes: 5 additions & 0 deletions docs/LLVMBuild.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ <h2><a name="formatreference">LLVMBuild Format Reference</a></h2>
components. For example, the <i>X86</i> target might define a library
group for all of the <i>X86</i> components. That library group might
then be included in the <i>all-targets</i> library group.</p></li>

<li><i>installed</i> <b>[optional]</b> <b>[boolean]</b>
<p>Whether this library is installed. Libraries that are not installed
are only reported by <tt>llvm-config</tt> when it is run as part of a
development directory.</p></li>
</ul>
</li>

Expand Down
23 changes: 18 additions & 5 deletions tools/llvm-config/llvm-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ using namespace llvm;
static void VisitComponent(StringRef Name,
const StringMap<AvailableComponent*> &ComponentMap,
std::set<AvailableComponent*> &VisitedComponents,
std::vector<StringRef> &RequiredLibs) {
std::vector<StringRef> &RequiredLibs,
bool IncludeNonInstalled) {
// Lookup the component.
AvailableComponent *AC = ComponentMap.lookup(Name);
assert(AC && "Invalid component name!");
Expand All @@ -65,10 +66,14 @@ static void VisitComponent(StringRef Name,
return;
}

// Only include non-installed components if requested.
if (!AC->IsInstalled && !IncludeNonInstalled)
return;

// Otherwise, visit all the dependencies.
for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {
VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,
RequiredLibs);
RequiredLibs, IncludeNonInstalled);
}

// Add to the required library list.
Expand All @@ -83,8 +88,11 @@ static void VisitComponent(StringRef Name,
/// \param Components - The names of the components to find libraries for.
/// \param RequiredLibs [out] - On return, the ordered list of libraries that
/// are required to link the given components.
/// \param IncludeNonInstalled - Whether non-installed components should be
/// reported.
void ComputeLibsForComponents(const std::vector<StringRef> &Components,
std::vector<StringRef> &RequiredLibs) {
std::vector<StringRef> &RequiredLibs,
bool IncludeNonInstalled) {
std::set<AvailableComponent*> VisitedComponents;

// Build a map of component names to information.
Expand All @@ -107,7 +115,7 @@ void ComputeLibsForComponents(const std::vector<StringRef> &Components,
}

VisitComponent(ComponentLower, ComponentMap, VisitedComponents,
RequiredLibs);
RequiredLibs, IncludeNonInstalled);
}

// The list is now ordered with leafs first, we want the libraries to printed
Expand Down Expand Up @@ -278,6 +286,10 @@ int main(int argc, char **argv) {
PrintLibFiles = true;
} else if (Arg == "--components") {
for (unsigned j = 0; j != array_lengthof(AvailableComponents); ++j) {
// Only include non-installed components when in a development tree.
if (!AvailableComponents[j].IsInstalled && !IsInDevelopmentTree)
continue;

OS << ' ';
OS << AvailableComponents[j].Name;
}
Expand Down Expand Up @@ -310,7 +322,8 @@ int main(int argc, char **argv) {

// Construct the list of all the required libraries.
std::vector<StringRef> RequiredLibs;
ComputeLibsForComponents(Components, RequiredLibs);
ComputeLibsForComponents(Components, RequiredLibs,
/*IncludeNonInstalled=*/IsInDevelopmentTree);

for (unsigned i = 0, e = RequiredLibs.size(); i != e; ++i) {
StringRef Lib = RequiredLibs[i];
Expand Down
12 changes: 9 additions & 3 deletions utils/llvm-build/llvmbuild/componentinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def parse_items(items):
kwargs['required_libraries'] = items.get_list('required_libraries')
kwargs['add_to_library_groups'] = items.get_list(
'add_to_library_groups')
kwargs['installed'] = items.get_optional_bool('installed', True)
return kwargs

@staticmethod
Expand All @@ -124,7 +125,7 @@ def parse(subpath, items):
return LibraryComponentInfo(subpath, **kwargs)

def __init__(self, subpath, name, dependencies, parent, library_name,
required_libraries, add_to_library_groups):
required_libraries, add_to_library_groups, installed):
ComponentInfo.__init__(self, subpath, name, dependencies, parent)

# If given, the name to use for the library instead of deriving it from
Expand All @@ -139,6 +140,9 @@ def __init__(self, subpath, name, dependencies, parent, library_name,
# considered part of.
self.add_to_library_groups = list(add_to_library_groups)

# Whether or not this library is installed.
self.installed = installed

def get_component_references(self):
for r in ComponentInfo.get_component_references(self):
yield r
Expand All @@ -160,6 +164,8 @@ def get_llvmbuild_fragment(self):
if self.add_to_library_groups:
print >>result, 'add_to_library_groups = %s' % ' '.join(
self.add_to_library_groups)
if not self.installed:
print >>result, 'installed = 0'
return result.getvalue()

def get_library_name(self):
Expand Down Expand Up @@ -194,10 +200,10 @@ def parse(subpath, items):
return OptionalLibraryComponentInfo(subpath, **kwargs)

def __init__(self, subpath, name, dependencies, parent, library_name,
required_libraries, add_to_library_groups):
required_libraries, add_to_library_groups, installed):
LibraryComponentInfo.__init__(self, subpath, name, dependencies, parent,
library_name, required_libraries,
add_to_library_groups)
add_to_library_groups, installed)

class LibraryGroupComponentInfo(ComponentInfo):
type_name = 'LibraryGroup'
Expand Down
20 changes: 13 additions & 7 deletions utils/llvm-build/llvmbuild/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ def write_library_table(self, output_path, enabled_optional_components):
# Get the library name, or None for LibraryGroups.
if c.type_name == 'Library' or c.type_name == 'OptionalLibrary':
library_name = c.get_prefixed_library_name()
is_installed = c.installed
else:
library_name = None
is_installed = True

# Get the component names of all the required libraries.
required_llvmconfig_component_names = [
Expand All @@ -355,24 +357,25 @@ def write_library_table(self, output_path, enabled_optional_components):

# Add the entry.
entries[c.name] = (llvmconfig_component_name, library_name,
required_llvmconfig_component_names)
required_llvmconfig_component_names,
is_installed)

# Convert to a list of entries and sort by name.
entries = entries.values()

# Create an 'all' pseudo component. We keep the dependency list small by
# only listing entries that have no other dependents.
root_entries = set(e[0] for e in entries)
for _,_,deps in entries:
for _,_,deps,_ in entries:
root_entries -= set(deps)
entries.append(('all', None, root_entries))
entries.append(('all', None, root_entries, True))

entries.sort()

# Compute the maximum number of required libraries, plus one so there is
# always a sentinel.
max_required_libraries = max(len(deps)
for _,_,deps in entries) + 1
for _,_,deps,_ in entries) + 1

# Write out the library table.
make_install_dir(os.path.dirname(output_path))
Expand All @@ -393,18 +396,21 @@ def write_library_table(self, output_path, enabled_optional_components):
print >>f, ' /// The name of the library for this component (or NULL).'
print >>f, ' const char *Library;'
print >>f, ''
print >>f, ' /// Whether the component is installed.'
print >>f, ' bool IsInstalled;'
print >>f, ''
print >>f, '\
/// The list of libraries required when linking this component.'
print >>f, ' const char *RequiredLibraries[%d];' % (
max_required_libraries)
print >>f, '} AvailableComponents[%d] = {' % len(entries)
for name,library_name,required_names in entries:
for name,library_name,required_names,is_installed in entries:
if library_name is None:
library_name_as_cstr = '0'
else:
library_name_as_cstr = '"lib%s.a"' % library_name
print >>f, ' { "%s", %s, { %s } },' % (
name, library_name_as_cstr,
print >>f, ' { "%s", %s, %d, { %s } },' % (
name, library_name_as_cstr, is_installed,
', '.join('"%s"' % dep
for dep in required_names))
print >>f, '};'
Expand Down
2 changes: 2 additions & 0 deletions utils/unittest/LLVMBuild.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ type = Library
name = gtest
parent = Libraries
required_libraries = Support
installed = 0

[component_1]
type = Library
name = gtest_main
parent = Libraries
required_libraries = gtest
installed = 0

0 comments on commit b5cd41e

Please sign in to comment.