function main() { $args = $_SERVER['argv']; $boost_root = null; switch (count($args)) { case 2: $boost_root = $args[1]; break; default: echo "Usage: create-module-metadata.php boost_root\n"; exit(1); } $library_details = BoostLibraries::from_xml_file(__DIR__ . '/../doc/libraries.xml')->get_for_version(BoostVersion::develop()); $super_project = new BoostSuperProject($boost_root); $git_submodules = $super_project->get_modules(); // Split the libraries up into modules. $libraries_by_module = array(); foreach ($library_details as $library) { $module = $library['module']; if (!isset($git_submodules[$module])) { echo "Unknown module: {$module}\n"; continue; } if (isset($library['documentation'])) { $doc_url = $library['documentation']; $module_base = $git_submodules[$module]['path']; if ($doc_url == $module_base) { $doc_url = ''; } else { if (strpos($doc_url, "{$module_base}/") === 0) { $doc_url = substr($doc_url, strlen("{$module_base}/")); } else { $doc_url = "/{$doc_url}"; } } if (!$doc_url) { unset($library['documentation']); } else { $library['documentation'] = $doc_url; } } $libraries_by_module[$module][] = $library; } // Write the module metadata foreach ($libraries_by_module as $module => $libraries) { $module_libraries = BoostLibraries::from_array($libraries); $module_dir = "{$boost_root}/{$git_submodules[$module]['path']}"; $meta_dir = "{$module_dir}/meta"; $meta_file = "{$module_dir}/meta/libraries.json"; if (!is_dir($module_dir)) { echo "Module '{$module}' doesn't exist at '{$module_dir}'\n"; continue; } if (!is_dir($meta_dir)) { mkdir($meta_dir); } file_put_contents($meta_file, $module_libraries->to_json(array('boost-version', 'update-version', 'module')) . "\n"); } }
function read_metadata_from_modules($path, $location, $hash, $sublibs = array('libs' => true)) { // echo "Reading from {$path} - {$location} - {$hash}.\n"; $super_project = new BoostSuperProject($location, $hash); $modules = $super_project->get_modules(); // Used to quickly set submodule hash. $modules_by_path = array(); foreach ($modules as $name => $details) { $modules_by_path[$details['path']] = $name; } // Store possible metadata files in this array. $metadata_files = array(); // Get a list of everything that's relevant in the superproject+modules. foreach ($super_project->run_git("ls-tree {$hash} -r") as $line_number => $line) { if (!$line) { continue; } if (preg_match("@^(\\d{6}) (\\w+) ([a-zA-Z0-9]+)\t(.*)\$@", $line, $matches)) { switch ($matches[2]) { case 'blob': $blob_path = $path ? "{$path}/{$matches['4']}" : $matches[4]; if (fnmatch('*/sublibs', $blob_path)) { $sublibs[dirname($blob_path)] = true; } else { if (fnmatch('*/meta/libraries.json', $blob_path)) { $metadata_files[$blob_path] = $matches[3]; } } break; case 'commit': $modules[$modules_by_path[$matches[4]]]['hash'] = $matches[3]; break; } } else { throw new RuntimeException("Unmatched submodule line: {$line}"); } } // Process metadata files $updated_libs = array(); foreach ($metadata_files as $metadata_path => $metadata_hash) { if (empty($sublibs[dirname(dirname(dirname($metadata_path)))])) { echo "Ignoring non-library metadata file: {$metadata_path}.\n"; } else { $text = implode("\n", $super_project->run_git("show {$metadata_hash}")); $updated_libs = array_merge($updated_libs, load_from_text($text, $metadata_path, dirname(dirname($metadata_path)))); } } // Recurse over submodules foreach ($modules as $name => $module) { global $quiet; $submodule_path = $path ? "{$path}/{$module['path']}" : $module['path']; if (!preg_match('@^\\.\\./(\\w+)\\.git$@', $module['url'])) { // In quiet mode don't warn about documentation submodules, which // libraries have previously included from remote locations. if (!$quiet || strpos($submodule_path . '/', '/doc/') === false) { echo "Ignoring submodule '{$name}' in '{$location}'.\n"; } continue; } if (empty($module['hash'])) { echo "Missing module in .gitmodule: '{$name}' in '{$location}'.\n"; continue; } $updated_libs = array_merge($updated_libs, read_metadata_from_modules($submodule_path, "{$location}/{$module['url']}", $module['hash'], $sublibs)); } return $updated_libs; }
/** * * @param string $location The location of the super project in the mirror. * @param string $branch The branch to update from. * @throws RuntimeException */ function read_metadata_from_local_clone($location, $branch = 'latest') { echo "Updating from local checkout/{$branch}\n"; $super_project = new BoostSuperProject($location); $updated_libs = array(); foreach ($super_project->get_modules() as $name => $module_details) { foreach (glob("{$location}/{$module_details['path']}/meta/libraries.*") as $path) { try { $updated_libs = array_merge($updated_libs, load_from_file($path, $name, $module_details['path'])); } catch (library_decode_exception $e) { echo "Error decoding metadata for module {$name}:\n{$e->content()}\n"; } } } }