+ const char *Library;
+ const char *RequiredLibraries[1];
+} AvailableComponents[1] = {
+ { "all", 0, { } }
+};
+
+/// \brief Traverse a single component adding to the topological ordering in
+/// \arg RequiredLibs.
+///
+/// \param Name - The component to traverse.
+/// \param ComponentMap - A prebuilt map of component names to descriptors.
+/// \param VisitedComponents [in] [out] - The set of already visited components.
+/// \param RequiredLibs [out] - The ordered list of required libraries.
+static void VisitComponent(StringRef Name,
+ const StringMap<AvailableComponent*> &ComponentMap,
+ std::set<StringRef> &VisitedComponents,
+ std::vector<StringRef> &RequiredLibs) {
+ // Add to the visited table.
+ if (!VisitedComponents.insert(Name).second) {
+ // We are done if the component has already been visited.
+ return;
+ }
+
+ // Otherwise, visit all the dependencies.
+ AvailableComponent *AC = ComponentMap.lookup(Name);
+ assert(AC && "Invalid component name!");
+
+ for (unsigned i = 0; AC->RequiredLibraries[i]; ++i) {
+ VisitComponent(AC->RequiredLibraries[i], ComponentMap, VisitedComponents,
+ RequiredLibs);
+ }
+
+ // Add to the required library list.
+ if (AC->Library)
+ RequiredLibs.push_back(AC->Library);
+}