Accepting request 745385 from devel:languages:ocaml

- Moved ocaml-findlib.rpm.prov_req.attr.sh from ocaml to provide
  ocamlfind() in ocaml itself
- Handle license separately because sed w truncates output
- Document individual file extensions
- Move cmxs and so files to devel packages because they are not
  used at runtime. Also, cmxs dependencies in main pkg are
  not covered by ocaml-find-requires.sh (bsc#1154874)
- Set VERSION unconditionally for each patch, sometimes dune picks it up
- Pass --for-release-of-packages to dune via dune_release_pkgs=
- Print potential BuildRequires during build
- Package sml for camlp5
- SLE_12 has still no license macro, package as doc instead
- Use _smp_mflags instead of nproc for parallel build

OBS-URL: https://build.opensuse.org/request/show/745385
OBS-URL: https://build.opensuse.org/package/show/openSUSE:Factory/ocaml-rpm-macros?expand=0&rev=3
This commit is contained in:
Dominique Leuenberger 2019-11-07 22:14:11 +00:00 committed by Git OBS Bridge
commit fe4ad8af80
3 changed files with 336 additions and 48 deletions

View File

@ -0,0 +1,160 @@
#!/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 {
dbg=1;
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" ;
reqs[pkg_name]=""
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" ;
if (candidate ~ /^\^/) {
next
}
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) {
reqs[candidate] = reqs[pkg_name];
delete reqs[pkg_name];
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
}
/^[[:blank:]]*requires.*[[:blank:]]*=/ {
if(dbg) printf "GOT: %s\n", $0 > "/dev/stderr" ;
x = split($0, 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" ;
reqs[pkg_name] = a[2];
}
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];
reqs[pkg_name]=""
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" ;
for (req in reqs) {
if(dbg)printf "eNd \\"%s\\"\n", req > "/dev/stderr";
# format: provides:requires
printf "%s:%s\n", req, reqs[req];
}
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

View File

@ -1,3 +1,20 @@
-------------------------------------------------------------------
Fri Nov 1 12:34:56 UTC 2019 - ohering@suse.de
- Moved ocaml-findlib.rpm.prov_req.attr.sh from ocaml to provide
ocamlfind() in ocaml itself
- Handle license separately because sed w truncates output
- Document individual file extensions
- Move cmxs and so files to devel packages because they are not
used at runtime. Also, cmxs dependencies in main pkg are
not covered by ocaml-find-requires.sh (bsc#1154874)
- Set VERSION unconditionally for each patch, sometimes dune picks it up
- Pass --for-release-of-packages to dune via dune_release_pkgs=
- Print potential BuildRequires during build
- Package sml for camlp5
- SLE_12 has still no license macro, package as doc instead
- Use _smp_mflags instead of nproc for parallel build
------------------------------------------------------------------- -------------------------------------------------------------------
Wed Oct 9 05:48:16 UTC 2019 - ohering@suse.de Wed Oct 9 05:48:16 UTC 2019 - ohering@suse.de

View File

@ -12,18 +12,18 @@
# license that conforms to the Open Source Definition (Version 1.9) # license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative. # published by the Open Source Initiative.
# Please submit bugfixes or comments via http://bugs.opensuse.org/ # Please submit bugfixes or comments via https://bugs.opensuse.org/
# #
Name: ocaml-rpm-macros Name: ocaml-rpm-macros
Version: 20191009 Version: 20191101
Release: 0 Release: 0
Summary: RPM macros for building OCaml source packages Summary: RPM macros for building OCaml source packages
License: GPL-2.0-only License: GPL-2.0-only
Group: Development/Languages/OCaml Group: Development/Languages/OCaml
Url: https://build.opensuse.org/project/show/devel:languages:ocaml Url: https://build.opensuse.org/project/show/devel:languages:ocaml
# Source1: ocaml-findlib.rpm.prov_req.attr.sh
# keep the following macros in sync with ocaml.spec:
%define do_opt 0 %define do_opt 0
# macros to be set in prjconf: # macros to be set in prjconf:
#Macros: #Macros:
@ -60,6 +60,17 @@ in ocaml spec files.
%build %build
%install %install
# map findlib names to rpm Provides/Requires
tag="ocamlfind"
mkdir -vp %{buildroot}%{_rpmconfigdir}/fileattrs
tee %{buildroot}%{_rpmconfigdir}/fileattrs/${tag}.attr <<_EOF_
%__${tag}_provides %%{_rpmconfigdir}/${tag}.sh -prov
%__${tag}_requires %%{_rpmconfigdir}/${tag}.sh -req
%__${tag}_path ^%%{_libdir}/ocaml/.*/META$|^%%{_libdir}/ocaml/META$
_EOF_
#
tee %{buildroot}%{_rpmconfigdir}/${tag}.sh < %{SOURCE1}
# install OCaml macros # install OCaml macros
mkdir -vp %{buildroot}%{_rpmmacrodir} mkdir -vp %{buildroot}%{_rpmmacrodir}
tee %{buildroot}%{_rpmmacrodir}/macros.%{name} <<'_EOF_' tee %{buildroot}%{_rpmmacrodir}/macros.%{name} <<'_EOF_'
@ -91,8 +102,9 @@ tee %{buildroot}%{_rpmmacrodir}/macros.%{name} <<'_EOF_'
> %%{name}.files ;\ > %%{name}.files ;\
> %%{name}.files.devel ;\ > %%{name}.files.devel ;\
> %%{name}.files.ldsoconf ;\ > %%{name}.files.ldsoconf ;\
> %%{name}.files.license ;\
> %%{name}.files.unhandled ;\ > %%{name}.files.unhandled ;\
for i in \\\ for license in \\\
COPYING \\\ COPYING \\\
COPYING.txt \\\ COPYING.txt \\\
COPYRIGHT \\\ COPYRIGHT \\\
@ -103,50 +115,87 @@ tee %{buildroot}%{_rpmmacrodir}/macros.%{name} <<'_EOF_'
LICENSE.txt \\\ LICENSE.txt \\\
;\ ;\
do\ do\
test -f "$i" && echo "%%%%license $i" >> %%{name}.files ;\ %if 0%{?suse_version} > 1315
license_macro='license' ;\
%else
license_macro='doc' ;\
%endif
test -f "${license}" && echo "%%%%${license_macro} ${license}" >> '%%{name}.files.license' ;\
done ;\ done ;\
find %%{buildroot}$(ocamlc -where) | sed -ne '\ find %%{buildroot}$(ocamlc -where) | sed -ne '\
s@^%%{buildroot}@@\ s@^%%{buildroot}@@\
/\\/\\(META\\|dune-package\\|opam\\)$/{\ #\
w %%{name}.files.devel\ # for findlib, describing a package\
s@\\/[^/]\\+$@@\ /\\/META$/{ b files_devel }\
s@^@%%dir @\ # stub ELF library\
w %%{name}.files.devel\ /\\/[^/]\\+\\.so$/{ b files_ldsoconf }\
s@\\/[^/]\\+$@@\ # stub ELF library\
w %%{name}.files.devel\ /\\/[^/]\\+\\.so.owner$/{ b files_ldsoconf }\
d\ # ELF archive with object files\
}\ /\\/[^/]\\+\\.a$/{ b files_devel }\
/\\/[^/]\\+\\.\\(a\\|annot\\|cmx\\|cmxa\\|cma\\|cmi\\|cmo\\|cmt\\|cmti\\|exe\\|h\\|js\\|ml\\|mli\\|o\\)$/{\ # OCaml legacy source code annotations, produced via -annot\
w %%{name}.files.devel\ /\\/[^/]\\+\\.annot$/{ b files_devel }\
s@\\/[^/]\\+$@@\ # OCaml library file with bytecode\
s@^@%%dir @\ /\\/[^/]\\+\\.cma$/{ b files_devel }\
w %%{name}.files.devel\ # OCaml compiled header file\
s@\\/[^/]\\+$@@\ /\\/[^/]\\+\\.cmi$/{ b files_devel }\
w %%{name}.files.devel\ # OCaml object file with bytecode\
d\ /\\/[^/]\\+\\.cmo$/{ b files_devel }\
}\ # OCaml source code annotations, produced via -bin-annot from source files\
/\\/[^/]\\+\\.\\(so\\|so.owner\\)$/{\ /\\/[^/]\\+\\.cmt$/{ b files_devel }\
w %%{name}.files\ # OCaml source code annotations, produced via -bin-annot from header files\
s@\\/[^/]\\+$@@\ /\\/[^/]\\+\\.cmti$/{ b files_devel }\
w %%{name}.files.ldsoconf\ # OCaml object file with native code\
s@^@%%dir @\ /\\/[^/]\\+\\.cmx$/{ b files_devel }\
w %%{name}.files\ # OCaml library file with native code\
s@\\/[^/]\\+$@@\ /\\/[^/]\\+\\.cmxa$/{ b files_devel }\
w %%{name}.files\ # ELF shared library with native code\
d\ /\\/[^/]\\+\\.cmxs$/{ b files_devel }\
}\ # Some helper binary\
/\\/[^/]\\+\\.\\(cmxs\\)$/{\ /\\/[^/]\\+\\.exe$/{ b files_devel }\
w %%{name}.files\ # C header\
s@\\/[^/]\\+$@@\ /\\/[^/]\\+\\.h$/{ b files_devel }\
s@^@%%dir @\ #\
w %%{name}.files\ /\\/[^/]\\+\\.js$/{ b files_devel }\
s@\\/[^/]\\+$@@\ # OCaml source code, source file\
w %%{name}.files\ /\\/[^/]\\+\\.ml$/{ b files_devel }\
d\ # OCaml source code, header file\
}\ /\\/[^/]\\+\\.mli$/{ b files_devel }\
# ELF object file\
/\\/[^/]\\+\\.o$/{ b files_devel }\
#\
/\\/[^/]\\+\\.sml$/{ b files_devel }\
#\
/\\/dune-package$/{ b files_devel }\
#\
/\\/opam$/{ b files_devel }\
#\
# record unknown paths\
w %%{name}.files.unhandled\ w %%{name}.files.unhandled\
d\ d\
#\
: files_devel\
# full path for file\
w %%{name}.files.devel\
# tag + dirname\
s@\\/[^/]\\+$@@\
: tag_dirname\
s@^@%%dir @\
w %%{name}.files.devel\
# parent directory\
s@\\/[^/]\\+$@@\
w %%{name}.files.devel\
d\
#\
: files_ldsoconf\
# full path for file\
w %%{name}.files.devel\
# dirname for ld.so.conf\
s@\\/[^/]\\+$@@\
w %%{name}.files.ldsoconf\
b tag_dirname\
' ;\ ' ;\
cat '%%{name}.files.license' >> '%%{name}.files' ; \
for i in \\\ for i in \\\
%%{name}.files \\\ %%{name}.files \\\
%%{name}.files.devel \\\ %%{name}.files.devel \\\
@ -238,17 +287,55 @@ ocaml setup.ml -configure \\\
%ifarch ppc64 ppc64le %ifarch ppc64 ppc64le
ulimit -s $((1024 * 64)) ; \ ulimit -s $((1024 * 64)) ; \
%endif %endif
echo '%%{version}' | tee VERSION ; \
dune_for_release= ; \
: dune_release_pkgs \
if test -n "${dune_release_pkgs}" ; \
then \
echo "${dune_release_pkgs}" > dune_release_pkgs-%%{name}-%%{version}-%%{release} ; \
dune_for_release="--for-release-of-packages=${dune_release_pkgs}" ; \
fi ; \
dune installed-libraries $OCAML_DUNE_INSTALLED_LIBRARIES_ARGS ; \ dune installed-libraries $OCAML_DUNE_INSTALLED_LIBRARIES_ARGS ; \
dune external-lib-deps @install $OCAML_DUNE_EXTERNAL_LIB_DEPS_ARGS ; \ dune external-lib-deps \\\
dune external-lib-deps @runtest $OCAML_DUNE_EXTERNAL_LIB_DEPS_ARGS ; \ ${dune_for_release} \\\
'@install' \\\
$OCAML_DUNE_EXTERNAL_LIB_DEPS_ARGS ; \
dune external-lib-deps \\\
${dune_for_release} \\\
'@runtest' \\\
$OCAML_DUNE_EXTERNAL_LIB_DEPS_ARGS ; \
dune external-lib-deps \\\
${dune_for_release} \\\
'@install' '@runtest' \\\
$OCAML_DUNE_EXTERNAL_LIB_DEPS_ARGS \\\
| awk '/^-[[:blank:]]/{ printf "BuildRequires: ocamlfind(%%s)\\n", $2}' | sort -u ; \
%%{nil} %%{nil}
%%ocaml_dune_build \ %%ocaml_dune_build \
dune build --verbose @install $OCAML_DUNE_BUILD_INSTALL_ARGS dune build \\\
--verbose \\\
${dune_for_release} \\\
%%{?_smp_mflags} \\\
'@install' \\\
$OCAML_DUNE_BUILD_INSTALL_ARGS
%%ocaml_dune_install \ %%ocaml_dune_install \
%ifarch ppc64 ppc64le %ifarch ppc64 ppc64le
ulimit -s $((1024 * 64)) ; \ ulimit -s $((1024 * 64)) ; \
%endif %endif
dune install --verbose --destdir=%%{buildroot} $OCAML_DUNE_INSTALL_ARGS ; \ dune_for_release= ; \
if test -f dune_release_pkgs-%%{name}-%%{version}-%%{release} ; \
then \
read dune_release_pkgs < dune_release_pkgs-%%{name}-%%{version}-%%{release} ; \
dune_for_release="--for-release-of-packages=${dune_release_pkgs}" ; \
fi ; \
dune install \\\
--verbose \\\
${dune_for_release} \\\
%%{?_smp_mflags} \\\
--prefix=%%{_prefix} \\\
--libdir=$(ocamlc -where) \\\
--destdir=%%{buildroot} \\\
${dune_release_pkgs//,/ } \\\
$OCAML_DUNE_INSTALL_ARGS ; \
rm -rfv %%{buildroot}%%{_prefix}/doc ; \ rm -rfv %%{buildroot}%%{_prefix}/doc ; \
if test -d %%{buildroot}%%{_prefix}/man ; then \ if test -d %%{buildroot}%%{_prefix}/man ; then \
mkdir -vp %%{buildroot}%%{_datadir} ; \ mkdir -vp %%{buildroot}%%{_datadir} ; \
@ -258,12 +345,36 @@ ocaml setup.ml -configure \\\
%ifarch ppc64 ppc64le %ifarch ppc64 ppc64le
ulimit -s $((1024 * 64)) ; \ ulimit -s $((1024 * 64)) ; \
%endif %endif
dune runtest --verbose $OCAML_DUNE_RUNTEST_ARGS dune_for_release= ; \
if test -f dune_release_pkgs-%%{name}-%%{version}-%%{release} ; \
then \
read dune_release_pkgs < dune_release_pkgs-%%{name}-%%{version}-%%{release} ; \
dune_for_release="--for-release-of-packages=${dune_release_pkgs}" ; \
fi ; \
if dune runtest \\\
--verbose \\\
${dune_for_release} \\\
$OCAML_DUNE_RUNTEST_ARGS ; \
then \
echo "dune runtest succeeded" ; \
else \
echo "dune runtest failed" ; \
if test -n "${dune_test_tolerate_fail}" ; \
then \
echo "ignored" ; \
else \
echo "aborting" ; \
exit 1 ; \
fi ; \
fi
# #
# #
_EOF_ _EOF_
%files %files
%{_rpmmacrodir}/* %{_rpmmacrodir}/*
%{_rpmconfigdir}/fileattrs
%attr(755,root,root) %{_rpmconfigdir}/*.sh
%changelog %changelog