2019-11-01 23:56:29 +01:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
prov_req_name="ocamlfind"
|
|
|
|
td=`mktemp --directory`
|
|
|
|
|
|
|
|
test -n "${td}"
|
|
|
|
_x() {
|
|
|
|
rm -rf "${td}"
|
|
|
|
}
|
|
|
|
trap _x EXIT
|
|
|
|
|
|
|
|
cmd=
|
|
|
|
test "$1" = "-prov" && cmd=prov
|
|
|
|
test "$1" = "-req" && cmd=req
|
|
|
|
do_work() {
|
|
|
|
local f=$1
|
|
|
|
local pkg_name
|
|
|
|
local pkg_prov_req
|
|
|
|
local pkg_prov
|
|
|
|
local pkg_req
|
|
|
|
local elem req
|
|
|
|
pkg_name="${f##*/}"
|
|
|
|
if test "${pkg_name}" = "META"
|
|
|
|
then
|
|
|
|
pkg_name="${f%/*}"
|
|
|
|
pkg_name="${pkg_name##*/}"
|
|
|
|
else
|
|
|
|
pkg_name="${pkg_name#META.}"
|
|
|
|
fi
|
|
|
|
pkg_prov_req="`
|
|
|
|
env \
|
|
|
|
pkg_name="${pkg_name}" \
|
|
|
|
cmd="${cmd}" \
|
|
|
|
awk '
|
|
|
|
BEGIN {
|
2020-02-21 11:50:25 +01:00
|
|
|
dbg=0;
|
2019-11-01 23:56:29 +01:00
|
|
|
count=1;
|
|
|
|
depth=0;
|
|
|
|
pkg_name=ENVIRON["pkg_name"];
|
|
|
|
cmd=ENVIRON["cmd"];
|
|
|
|
|
|
|
|
if(dbg) printf "bEGIN \\"%s\\" cmd: %s\n", pkg_name, cmd > "/dev/stderr" ;
|
2020-02-21 11:50:25 +01:00
|
|
|
requires[pkg_name]=""
|
|
|
|
ppx_runtime_deps[pkg_name]=""
|
2019-11-01 23:56:29 +01:00
|
|
|
pkg_names[depth]=pkg_name
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
if(dbg) printf "line: %s\n", $0 > "/dev/stderr"
|
|
|
|
}
|
|
|
|
|
|
|
|
/^[[:blank:]]*directory[[:blank:]]*=/ {
|
|
|
|
if(dbg) printf "GOT: %s\n", $0 > "/dev/stderr" ;
|
|
|
|
if (depth == 0) {
|
|
|
|
x = split($0, a, "\\"");
|
|
|
|
if ( a[2] ) {
|
|
|
|
candidate = a[2];
|
|
|
|
if(dbg) printf "dir: %s %s\n", x, candidate > "/dev/stderr" ;
|
2022-07-08 08:55:48 +02:00
|
|
|
if (candidate == "^") {
|
|
|
|
next
|
|
|
|
}
|
|
|
|
if (candidate == "+") {
|
2019-11-01 23:56:29 +01:00
|
|
|
next
|
|
|
|
}
|
2022-07-08 10:29:49 +02:00
|
|
|
if (candidate ~ /^\^/) {
|
|
|
|
next
|
|
|
|
}
|
2019-11-01 23:56:29 +01:00
|
|
|
if (candidate ~ /^\+/) {
|
|
|
|
candidate = substr(candidate, 2);
|
|
|
|
}
|
|
|
|
if (candidate ~ /^\//) {
|
|
|
|
x = split(candidate, a, "/");
|
|
|
|
if ( x )
|
|
|
|
candidate = a[x];
|
|
|
|
}
|
|
|
|
if (candidate ~ /^\.\.\//) {
|
|
|
|
x = split(candidate, a, "/");
|
|
|
|
if ( x )
|
|
|
|
candidate = a[x];
|
|
|
|
}
|
|
|
|
if(dbg) printf "dir: %s %s\n", x, candidate > "/dev/stderr" ;
|
|
|
|
if (candidate != pkg_name) {
|
2020-02-21 11:50:25 +01:00
|
|
|
requires[candidate] = requires[pkg_name];
|
|
|
|
delete requires[pkg_name];
|
2019-11-01 23:56:29 +01:00
|
|
|
pkg_name = candidate;
|
|
|
|
if(dbg) printf "new pkg_name %s %s\n", x, pkg_name > "/dev/stderr" ;
|
|
|
|
pkg_names[depth]=pkg_name
|
|
|
|
} else {
|
|
|
|
if(dbg) printf "pkg_name remains %s\n", pkg_name > "/dev/stderr" ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
2021-01-27 20:24:48 +01:00
|
|
|
/^[[:blank:]]*requires(|\([^-][^)]+\))[[:blank:]]*(+=|=)/ {
|
2019-11-01 23:56:29 +01:00
|
|
|
if(dbg) printf "GOT: %s\n", $0 > "/dev/stderr" ;
|
2020-02-21 11:50:25 +01:00
|
|
|
done=0
|
|
|
|
requires_line = ""
|
|
|
|
do {
|
|
|
|
need_next_line = 1
|
|
|
|
line = $0
|
|
|
|
requires_line = sprintf("%s%s", requires_line, line)
|
|
|
|
l = length(requires_line)
|
|
|
|
qm = index(requires_line, "\\"")
|
|
|
|
if (l > qm) {
|
|
|
|
line = substr(requires_line, qm + 1)
|
|
|
|
qm = index(line, "\\"")
|
|
|
|
need_next_line = qm == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_next_line) {
|
|
|
|
done = getline == 0
|
|
|
|
} else {
|
|
|
|
done = 1
|
|
|
|
}
|
|
|
|
} while (done == 0)
|
|
|
|
|
|
|
|
x = split(requires_line, a, "\\"");
|
2019-11-01 23:56:29 +01:00
|
|
|
if ( a[2] ) {
|
|
|
|
if(dbg) printf "req2 %s %s\n", x, a[2] > "/dev/stderr" ;
|
|
|
|
x = gsub("[[:blank:]]+", ",", a[2]);
|
|
|
|
if(dbg) printf "req2 %s %s\n", x, a[2] > "/dev/stderr" ;
|
2020-02-21 11:50:25 +01:00
|
|
|
if (requires[pkg_name] == "") {
|
|
|
|
requires[pkg_name] = a[2]
|
|
|
|
} else {
|
|
|
|
requires[pkg_name] = sprintf("%s,%s", requires[pkg_name],a[2])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
/^[[:blank:]]*ppx_runtime_deps[[:blank:]]*(+=|=)/ {
|
|
|
|
if(dbg) printf "GOT: %s\n", $0 > "/dev/stderr" ;
|
|
|
|
done=0
|
|
|
|
ppx_runtime_deps_line = ""
|
|
|
|
do {
|
|
|
|
need_next_line = 1
|
|
|
|
line = $0
|
|
|
|
ppx_runtime_deps_line = sprintf("%s%s", ppx_runtime_deps_line, line)
|
|
|
|
l = length(ppx_runtime_deps_line)
|
|
|
|
qm = index(ppx_runtime_deps_line, "\\"")
|
|
|
|
if (l > qm) {
|
|
|
|
line = substr(ppx_runtime_deps_line, qm + 1)
|
|
|
|
qm = index(line, "\\"")
|
|
|
|
need_next_line = qm == 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_next_line) {
|
|
|
|
done = getline == 0
|
|
|
|
} else {
|
|
|
|
done = 1
|
|
|
|
}
|
|
|
|
} while (done == 0)
|
|
|
|
|
|
|
|
x = split(ppx_runtime_deps_line, a, "\\"");
|
|
|
|
if ( a[2] ) {
|
|
|
|
if(dbg) printf "req2 %s %s\n", x, a[2] > "/dev/stderr" ;
|
|
|
|
x = gsub("[[:blank:]]+", ",", a[2]);
|
|
|
|
if(dbg) printf "req2 %s %s\n", x, a[2] > "/dev/stderr" ;
|
|
|
|
if (ppx_runtime_deps[pkg_name] == "") {
|
|
|
|
ppx_runtime_deps[pkg_name] = a[2]
|
|
|
|
} else {
|
|
|
|
requires[pkg_name] = sprintf("%s,%s", requires[pkg_name],a[2])
|
|
|
|
}
|
2019-11-01 23:56:29 +01:00
|
|
|
}
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
/^[[:blank:]]*package[[:blank:]]/ {
|
|
|
|
if(dbg) printf "GOT: %s\n", $0 > "/dev/stderr" ;
|
|
|
|
depth = depth + 1;
|
|
|
|
if(dbg) printf "depth %s\n", depth > "/dev/stderr" ;
|
|
|
|
x = split($0, a, "\\"");
|
|
|
|
if ( a[2] ) {
|
|
|
|
if(dbg) printf "req2 %s %s\n", x, a[2] > "/dev/stderr" ;
|
|
|
|
pkg_name = pkg_name"."a[2];
|
2020-02-21 11:50:25 +01:00
|
|
|
requires[pkg_name]=""
|
2019-11-01 23:56:29 +01:00
|
|
|
pkg_names[depth]=pkg_name
|
|
|
|
if(dbg) printf "new pkg_name %s %s\n", x, pkg_name > "/dev/stderr" ;
|
|
|
|
}
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
/^[[:blank:]]*)/ {
|
|
|
|
if(dbg) printf "GOT: %s\n", $0 > "/dev/stderr" ;
|
|
|
|
depth = depth -1;
|
|
|
|
if(dbg) printf "depth %s\n", depth > "/dev/stderr" ;
|
|
|
|
pkg_name=pkg_names[depth]
|
|
|
|
if(dbg) printf "old pkg_name %s %s\n", x, pkg_name > "/dev/stderr" ;
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
END {
|
|
|
|
if(dbg) printf "eND \\"%s\\"\n", pkg_name > "/dev/stderr" ;
|
2020-02-21 11:50:25 +01:00
|
|
|
for (req in requires) {
|
|
|
|
if(dbg)printf "eNd \\"%s\\"\n", req > "/dev/stderr";
|
|
|
|
# format: provides:requires
|
|
|
|
printf "%s:%s\n", req, requires[req];
|
|
|
|
}
|
|
|
|
for (req in ppx_runtime_deps) {
|
2019-11-01 23:56:29 +01:00
|
|
|
if(dbg)printf "eNd \\"%s\\"\n", req > "/dev/stderr";
|
|
|
|
# format: provides:requires
|
2020-02-21 11:50:25 +01:00
|
|
|
printf "%s:%s\n", req, ppx_runtime_deps[req];
|
2019-11-01 23:56:29 +01:00
|
|
|
}
|
|
|
|
if(dbg) printf "ENd \\"%s\\"\n", pkg_name > "/dev/stderr" ;
|
|
|
|
}
|
|
|
|
' \"${f}\"
|
|
|
|
`"
|
|
|
|
for elem in ${pkg_prov_req}
|
|
|
|
do
|
|
|
|
pkg_prov="${elem%%:*}"
|
|
|
|
pkg_req="${elem#*:}"
|
|
|
|
pkg_req="${pkg_req//,/ }"
|
|
|
|
if test -n "${pkg_prov}" && test "${cmd}" = "prov"
|
|
|
|
then
|
|
|
|
echo "${prov_req_name}($pkg_prov)"
|
|
|
|
fi
|
|
|
|
if test "${cmd}" = "req"
|
|
|
|
then
|
|
|
|
for i in ${pkg_req}
|
|
|
|
do
|
|
|
|
echo "${prov_req_name}(${i})"
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
while read filename
|
|
|
|
do
|
|
|
|
case "${filename}" in
|
|
|
|
*/META*) do_work "${filename}" ;;
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
done
|
2020-02-21 11:50:25 +01:00
|
|
|
# vim: tw=666 ts=2 shiftwidth=2 et
|