Index: Mk/Scripts/print-submodule-gh_tuple.sh =================================================================== --- /dev/null +++ Mk/Scripts/print-submodule-gh_tuple.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +# print GH_TUPLE with all git submodules +# +# Feature: print-gh-tuple +# Usage: make print-gh-tuple +# Valid ARGS: git-repository-path (path of git directory cloned with submodules hierarchically) +# +# MAINTAINER: yuri@FreeBSD.org + +# CAVEATS: +# * Does not handle GitHub project redirects +# * Does not handle GitHub project case mismatches +# * Does not handle non-GitHub git modules + + +if [ -z "$1" ] || ! [ -d $1/.git ]; +then + echo >&2 "Usage: $0 {cloned-git-repository}" + exit 1 +fi + +cd $1 + +for gitmodules_file in $(find . -name .gitmodules); +do + echo "dir $(dirname $gitmodules_file)" + git config --file $gitmodules_file -l | sed -E 's/^submodule\.([A-Za-z0-9\._\/\-]*)\.(.*)=(.*)/submodule \1 \2 \3/' + (cd $(dirname $gitmodules_file) && git submodule status) | sed -e 's/^/hash /' +done | ${AWK} ' + BEGIN { + num_keys = 0 + } + /dir/ { + dir = $2 + if (dir == ".") + dir = "" + else { + sub("^./", "", dir) + dir = dir "/" + } + } + /submodule/ { + key = dir "/" $2 + if ($3 == "path") { + map_module_path[key] = $4 + all_keys[num_keys++] = key + } else if ($3 == "url") { + map_module_url[key] = $4 + } + map_module_dir[key] = dir + } + /hash/ { + map_module_hash[dir "/" $3]=$2 + } + END { + print "GH_TUPLE= \\" + idx = 0 + key = "" + for (i = 0; i < num_keys; i++) { + key_prev = key + key = all_keys[i] + url = map_module_url[key] + if (match(url, /^(https|git):\/\/github\.com\//)) { + gh_account_user = url + sub("^(https|git)://github\.com/", "", gh_account_user) + sub("(.git|/)$", "", gh_account_user) + sub("/", ":", gh_account_user) + id = gh_account_user + gsub("[:-]", "_", id) + if (idx > 0 && map_module_dir[key] != map_module_dir[key_prev]) + print " \\" + print " " gh_account_user ":" map_module_hash[map_module_dir[key] "/" map_module_path[key]] ":" id "/" map_module_dir[key] map_module_path[key] " \\" + id_uniq[id]++ + idx++ + } + } + + for (i = 0; i < num_keys; i++) { + key = all_keys[i] + if (!match(map_module_url[key], /^(https|git):\/\/github\.com\//)) + print "# not a GitHub URL: " map_module_url[key] " " map_module_hash[key] " " map_module_dir[key] " " map_module_path[key] + } + } +' Index: Mk/bsd.sites.mk =================================================================== --- Mk/bsd.sites.mk +++ Mk/bsd.sites.mk @@ -504,6 +504,10 @@ . endif convert-to-gh-tuple: @${ECHO_MSG} ${GH_ACCOUNT}:${GH_PROJECT}:${GH_TAGNAME} ${_GH_TUPLE_OUT:S/\/$//} +print-gh-tuple: ${_GITHUB_CLONE_DIR} + @git clone --recurse-submodules https://github.com/${GH_ACCOUNT}/${GH_PROJECT}.git ${_GITHUB_CLONE_DIR}/${GH_ACCOUNT}:${GH_PROJECT} + @${SH} ${SCRIPTSDIR}/print-submodule-gh_tuple.sh ${_GITHUB_CLONE_DIR}/${GH_ACCOUNT}:${GH_PROJECT} + @${RM} -rf ${_GITHUB_CLONE_DIR}/${GH_ACCOUNT}:${GH_PROJECT} .endif # defined(USE_GITHUB) .endif # !defined(IGNORE_MASTER_SITE_GITHUB)