Skip to content

Commit 57d77d2

Browse files
committed
add tool to generate GH_TUPLES from git submodules to wrote port's Makefile
1 parent 865e2e3 commit 57d77d2

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

FreeBSD/generate_GH_TUPLES.sh

+103
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/sh
2+
# From a git cloned repos, generate FreeBSD port Makefile GH_TUPLE=
3+
# git clone [email protected]:pytorch/pytorch.git
4+
# git submodule update --init --recursive
5+
# git submodule status
6+
#
7+
# Almost related, plist update
8+
# grep 'Error: Orphaned: ' build.log | sed 's/Error: Orphaned: //' > to-be-added.txt
9+
# grep 'Error: Missing: ' build.log | sed 's/Error: Missing: //'> to-be-removed.txt
10+
# grep -F -x -v -f /root/To-remove.txt pkg-plist > pkg-plist.new
11+
# cat to-be-added.txt >> pkg-plist.new
12+
13+
set -eu
14+
15+
die () {
16+
echo $1
17+
exit 1
18+
}
19+
20+
if [ ! -r .gitmodules ]; then
21+
die "no .gitmodules"
22+
fi
23+
24+
path=""
25+
fullhash=""
26+
hash=""
27+
url=""
28+
account=""
29+
tag=""
30+
project=""
31+
gl=""
32+
33+
while read -r line; do
34+
if echo "${line}" | grep -q '\[submodule'; then
35+
continue
36+
elif echo "${line}" | grep -q 'ignore = '; then
37+
continue
38+
elif echo "${line}" | grep -q 'path = '; then
39+
if [ -n "${path}" ]; then
40+
die "BUG: path could not be already filled with ${path}"
41+
fi
42+
path=$(echo "$line" | cut -d ' ' -f 3)
43+
if [ -z "${path}" ]; then
44+
die "BUG: path could not be empty, line is ${line}"
45+
fi
46+
if [ -n "${hash}" ]; then
47+
die "BUG: hash could not be already filled with ${hash}"
48+
fi
49+
fullhash=$(git submodule status "${path}" | cut -d ' ' -f 2)
50+
hash=$(echo "${fullhash}" head -c 8)
51+
if [ -z "${hash}" ]; then
52+
die "BUG: hash could not be empty, line is ${line}"
53+
fi
54+
elif echo "${line}" | grep -q 'url = '; then
55+
if [ -n "${url}" ]; then
56+
die "BUG: url could not be already filled with ${url}"
57+
fi
58+
url=$(echo "$line" | cut -d ' ' -f 3)
59+
if [ -z "${url}" ]; then
60+
die "BUG: url could not be empty, line is $line"
61+
fi
62+
# Warning of gitlab
63+
if echo "${url}" | grep -q 'gitlab.com'; then
64+
gl="GL_TUPLE="
65+
# gitlab doesn't support shorthash
66+
hash="${fullhash}"
67+
fi
68+
if [ -n "${account}" ]; then
69+
die "BUG: account could not be already filled with ${account}"
70+
fi
71+
account=$(echo "${url}" | cut -d '/' -f 4)
72+
if [ -z "${account}" ]; then
73+
die "BUG: account could not be empty, line is $line"
74+
fi
75+
if [ -n "${project}" ]; then
76+
die "BUG: account could not be already filled with ${project}"
77+
fi
78+
project=$(echo "${url}" | cut -d '/' -f 5 | cut -d '.' -f 1)
79+
if [ -z "${project}" ]; then
80+
die "BUG: project could not be empty, line is $line"
81+
fi
82+
fi
83+
if [ -n "${account}" ] && [ -n "${project}" ] && [ -n "${hash}" ]; then
84+
# Tag is project with '-' replaced by '_'
85+
if [ -n "${tag}" ]; then
86+
die "BUG: tag could not be already filled with ${tag}"
87+
fi
88+
tag=$(echo "${project}" | tr '-' '_')
89+
if [ -z "${tag}" ]; then
90+
die "BUG: tag could not be empty, project is $project"
91+
fi
92+
echo "${gl}${account}:${project}:${hash}:${tag}/${path} \\"
93+
gl=""
94+
path=""
95+
fullhash=""
96+
hash=""
97+
url=""
98+
account=""
99+
tag=""
100+
project=""
101+
102+
fi
103+
done < .gitmodules

0 commit comments

Comments
 (0)