/**
 *
 * @param string $location The location of the super project in the mirror.
 * @param BoostVersion $version The version of the release.
 * @throws RuntimeException
 */
function read_metadata_from_filesystem($location, $version)
{
    // Scan release for metadata files.
    $parent_directories = array("{$location}/libs");
    foreach (glob("{$location}/libs/*/sublibs") as $path) {
        $parent_directories[] = dirname($path);
    }
    $library_paths = array();
    $path_pattern = "@^{$location}/(.*)/meta/libraries.json\$@";
    foreach ($parent_directories as $parent) {
        foreach (glob("{$parent}/*/meta/libraries.json") as $path) {
            if (preg_match($path_pattern, $path, $match)) {
                $library_paths[] = $match[1];
            } else {
                echo "Unexpected path: {$path}.\n";
            }
        }
    }
    $updated_libs = array();
    foreach ($library_paths as $path) {
        $json_path = "{$location}/{$path}/meta/libraries.json";
        try {
            $updated_libs = array_merge($updated_libs, load_from_file($json_path, $path));
        } catch (library_decode_exception $e) {
            echo "Error decoding metadata for library at {$json_path}:\n{$e->content()}\n";
        }
    }
    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";
            }
        }
    }
}