The OCaml Package Manager opam is a source-based package manager for OCaml.
This tool automatically generates flatpak-builder
sources files from a .json file generated by:
$ opam tree --json=deps.json [PACKAGE]
Note: opam tree
subcommand was implemented on versions >= 2.2.0.
Usage: flatpak-opam-generator.py [-h] [--generate PACKAGE] [--install] opam_deps
Let's generate the sources file for the lablgtk
library:
$ opam --version
2.2.0~alpha2
$ opam tree --json=lablgtk_deps.json lablgtk
$ ./flatpak-opam-generator.py lablgtk_deps.json > lablgtk_sources.json
Check the resulting file:
$ cat lablgtk_sources.json
[
{
"type": "file",
"url": "https://github.com/garrigue/lablgtk/archive/2.18.13.tar.gz",
"name": "lablgtk.2.18.13",
"md5": "d0a326b99475216cc22232e72c89415f",
"dest": "cache/md5/d0",
"dest-filename": "d0a326b99475216cc22232e72c89415f"
},
{
"type": "file",
"url": "https://github.com/ocaml/camlp-streams/archive/v5.0.1.tar.gz",
"name": "camlp-streams.5.0.1",
"md5": "afc874b25f7a1f13e8f5cfc1182b51a7",
"dest": "cache/md5/af",
"dest-filename": "afc874b25f7a1f13e8f5cfc1182b51a7"
},
{
"type": "file",
"url": "https://github.com/ocaml/dune/releases/download/3.11.1/dune-3.11.1.tbz",
"name": "dune.3.11.1",
"sha256": "866f2307adadaf7604f3bf9d98bb4098792baa046953a6726c96c40fc5ed3f71",
"dest": "cache/sha256/86",
"dest-filename": "866f2307adadaf7604f3bf9d98bb4098792baa046953a6726c96c40fc5ed3f71"
},
{
"type": "file",
"url": "http:https://download.camlcity.org/download/findlib-1.9.6.tar.gz",
"name": "ocamlfind.1.9.6",
"md5": "96c6ee50a32cca9ca277321262dbec57",
"dest": "cache/md5/96",
"dest-filename": "96c6ee50a32cca9ca277321262dbec57"
}
]
This sources file is intended to be used as opam cache (see an example of the corresponding flaktpak manifest code below). The download from the cache uses the base url, appends the archive-mirror, followed by the hash algorithm, the first two characters of the has of the tarball, and the hex encoded hash of the archive.
Let's generate the corresponding Flatpak manifest code:
$ ./flatpak-opam-generator.py --generate lablgtk lablgtk_deps.json
# Manifest code generated by flatpak-opam-generator
- name: lablgtk
buildsystem: simple
#build-options:
# append-path:
# env:
# OPAMROOT:
# OPAMSWITCH:
sources:
- sources/lablgtk.json
- type: git
branch: master
url: https://github.com/ocaml/opam-repository
build-commands:
- ls -A --color=never | grep -Ev "cache|packages|repo" | xargs rm -rf
- opam admin filter -y lablgtk.2.18.13 camlp-streams.5.0.1 dune.3.11.1 ocamlfind.1.9.6
- opam admin cache
- opam repo add lablgtk .
- opam install -y lablgtk.2.18.13 camlp-streams.5.0.1 dune.3.11.1 ocamlfind.1.9.6
- opam repo remove --all lablgtk
post-install:
- opam info --field name,all-installed-versions lablgtk