Skip to content

Commit 4859c7d

Browse files
author
Julien Blond
committed
Fixes #230: compute the opam root using opam itself.
1 parent 865cffe commit 4859c7d

File tree

9 files changed

+211
-61
lines changed

9 files changed

+211
-61
lines changed

.drom

+89-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ version:0.9.0
55

66
# hash of toml configuration files
77
# used for generation of all files
8-
cfd502831bbf686b41df41219629c1c4:.
8+
812a88073a143fbfd65d11dd1ac586fd:.
99
# end context for .
1010

1111
# begin context for .github/workflows/workflow.yml
@@ -15,7 +15,7 @@ eee26f5d13b222b48706c4fcbd98a19a:.github/workflows/workflow.yml
1515

1616
# begin context for .gitignore
1717
# file .gitignore
18-
f7a24abcad0ba9301c03bb64464b1718:.gitignore
18+
33c88a25e8b40f3683f6c03ec26be5db:.gitignore
1919
# end context for .gitignore
2020

2121
# begin context for .ocamlformat
@@ -55,7 +55,7 @@ f7a24abcad0ba9301c03bb64464b1718:.gitignore
5555

5656
# begin context for README.md
5757
# file README.md
58-
616ddd2660258447be65bdb664b9241d:README.md
58+
5d523350230459e853bc57803b729e29:README.md
5959
# end context for README.md
6060

6161
# begin context for docs/README.txt
@@ -88,11 +88,31 @@ e739f3026aa997af4026bc428f4c9ef6:docs/favicon.png
8888
c8281f46ba9a11d0b61bc8ef67eaa357:docs/style.css
8989
# end context for docs/style.css
9090

91+
# begin context for docs\README.txt
92+
# file docs\README.txt
93+
bfbacf00053bb9ab2a6e2ce94ed4a642:docs\README.txt
94+
# end context for docs\README.txt
95+
96+
# begin context for docs\favicon.png
97+
# file docs\favicon.png
98+
e739f3026aa997af4026bc428f4c9ef6:docs\favicon.png
99+
# end context for docs\favicon.png
100+
101+
# begin context for docs\style.css
102+
# file docs\style.css
103+
c8281f46ba9a11d0b61bc8ef67eaa357:docs\style.css
104+
# end context for docs\style.css
105+
91106
# begin context for dot_gitattributes
92107
# file dot_gitattributes
93108
20bbe7a5dbb3c3278a1511d960616fe5:dot_gitattributes
94109
# end context for dot_gitattributes
95110

111+
# begin context for dot_github\workflows\workflow.yml
112+
# file dot_github\workflows\workflow.yml
113+
004b92dd628d26b4f8a5a5139bf4aa79:dot_github\workflows\workflow.yml
114+
# end context for dot_github\workflows\workflow.yml
115+
96116
# begin context for drom.toml
97117
# file drom.toml
98118
9949d65b87e55480a30122e9e77ae7d3:drom.toml
@@ -105,7 +125,7 @@ e850a13c004f963e9f5a568eac93c217:dune
105125

106126
# begin context for dune-project
107127
# file dune-project
108-
c063288437da29a5a21e8c76c1906adc:dune-project
128+
7f0439af8599faf105447755ebd72e7e:dune-project
109129
# end context for dune-project
110130

111131
# begin context for opam/drom.opam
@@ -143,6 +163,16 @@ e55d659410b556d7bc60183d8ff1f788:opam/drom_toml.opam
143163
cda3f8bad69d9c6e8cbeab1c720d739a:scripts/static-build.sh
144164
# end context for scripts/static-build.sh
145165

166+
# begin context for scripts\after.sh
167+
# file scripts\after.sh
168+
cb2282903fb6ae1ac71fb2fbbcccffbd:scripts\after.sh
169+
# end context for scripts\after.sh
170+
171+
# begin context for scripts\before.sh
172+
# file scripts\before.sh
173+
97c9b1f22a04f7c0b42477aee6f4393e:scripts\before.sh
174+
# end context for scripts\before.sh
175+
146176
# begin context for sphinx/_static/css/fixes.css
147177
# file sphinx/_static/css/fixes.css
148178
68b329da9893e34099c7d8ad5cb9c940:sphinx/_static/css/fixes.css
@@ -173,6 +203,21 @@ a44c87f3a364dd95f55427fe40b2c5d1:sphinx/about.rst
173203
8f504f01aea592543c0a662b81169d91:sphinx/license.rst
174204
# end context for sphinx/license.rst
175205

206+
# begin context for sphinx\conf.py
207+
# file sphinx\conf.py
208+
67496ee935ab27fdabb4544f4f81eeb6:sphinx\conf.py
209+
# end context for sphinx\conf.py
210+
211+
# begin context for sphinx\license.rst
212+
# file sphinx\license.rst
213+
8f504f01aea592543c0a662b81169d91:sphinx\license.rst
214+
# end context for sphinx\license.rst
215+
216+
# begin context for sphinx\under_static\css\fixes.css
217+
# file sphinx\under_static\css\fixes.css
218+
20bbe7a5dbb3c3278a1511d960616fe5:sphinx\under_static\css\fixes.css
219+
# end context for sphinx\under_static\css\fixes.css
220+
176221
# begin context for src/drom/dune
177222
# file src/drom/dune
178223
68aec4169671c0163b98bb38205d2e4d:src/drom/dune
@@ -198,6 +243,11 @@ a44c87f3a364dd95f55427fe40b2c5d1:sphinx/about.rst
198243
bb6803d414fd5a5479ed6381914604de:src/drom/package.toml
199244
# end context for src/drom/package.toml
200245

246+
# begin context for src/drom\index.mld
247+
# file src/drom\index.mld
248+
2818d15f527a37c2cfafe85ef89f675b:src/drom\index.mld
249+
# end context for src/drom\index.mld
250+
201251
# begin context for src/drom_lib/dune
202252
# file src/drom_lib/dune
203253
103b365e9f24dbbae02b6be22b3efd0a:src/drom_lib/dune
@@ -218,6 +268,21 @@ c4d6597dc5b0966758c213bfffb9d594:src/drom_lib/package.toml
218268
a3e5d8a00664ceaa6addf376bedf6de1:src/drom_lib/version.mlt
219269
# end context for src/drom_lib/version.mlt
220270

271+
# begin context for src/drom_lib\dune
272+
# file src/drom_lib\dune
273+
8c189e7a8bac651b008889b1dd38a8fe:src/drom_lib\dune
274+
# end context for src/drom_lib\dune
275+
276+
# begin context for src/drom_lib\index.mld
277+
# file src/drom_lib\index.mld
278+
3e03ec5e98f99c1d5b09dd366177ad13:src/drom_lib\index.mld
279+
# end context for src/drom_lib\index.mld
280+
281+
# begin context for src/drom_lib\version.mlt
282+
# file src/drom_lib\version.mlt
283+
a3e5d8a00664ceaa6addf376bedf6de1:src/drom_lib\version.mlt
284+
# end context for src/drom_lib\version.mlt
285+
221286
# begin context for src/toml.7.1.0/dune
222287
# file src/toml.7.1.0/dune
223288
0841a2e47118b9fcd9b900f84ff66c34:src/toml.7.1.0/dune
@@ -243,6 +308,16 @@ d1b05207fce876a1b44a8b268bcaf226:src/toml.7.1.0/index.mld
243308
a3e5d8a00664ceaa6addf376bedf6de1:src/toml.7.1.0/version.mlt
244309
# end context for src/toml.7.1.0/version.mlt
245310

311+
# begin context for src/toml.7.1.0\index.mld
312+
# file src/toml.7.1.0\index.mld
313+
d1b05207fce876a1b44a8b268bcaf226:src/toml.7.1.0\index.mld
314+
# end context for src/toml.7.1.0\index.mld
315+
316+
# begin context for src/toml.7.1.0\version.mlt
317+
# file src/toml.7.1.0\version.mlt
318+
a3e5d8a00664ceaa6addf376bedf6de1:src/toml.7.1.0\version.mlt
319+
# end context for src/toml.7.1.0\version.mlt
320+
246321
# begin context for test/expect-tests/dune
247322
# file test/expect-tests/dune
248323
d7e2675a767e30edf28d061c94f0ec62:test/expect-tests/dune
@@ -312,3 +387,13 @@ ee63957b3b77455a12e6c269a5032c3f:test/output-tests/test2.expected
312387
# file test/output-tests/test2.ml
313388
e8eaab7626ef0aace5e570fffe81f869:test/output-tests/test2.ml
314389
# end context for test/output-tests/test2.ml
390+
391+
# begin context for test\inline-tests\test.ml
392+
# file test\inline-tests\test.ml
393+
37b8bc6035cda6302a80178c61f9626e:test\inline-tests\test.ml
394+
# end context for test\inline-tests\test.ml
395+
396+
# begin context for test\output-tests\test1.expected
397+
# file test\output-tests\test1.expected
398+
dc8d6157230e9ef8e965865f990fbc49:test\output-tests\test1.expected
399+
# end context for test\output-tests\test1.expected

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*~
33
_build
44
.merlin
5+
.vscode
56
/_drom
67
/_opam
78
/_build

README.md

-45
Original file line numberDiff line numberDiff line change
@@ -14,48 +14,3 @@ will generate files for Github Actions CI and Github pages.
1414
* General Documentation: https://ocamlpro.github.io/drom/sphinx
1515
* API Documentation: https://ocamlpro.github.io/drom/doc
1616
* Sources: https://github.com/ocamlpro/drom
17-
18-
19-
## Simple Example
20-
21-
You can create a new OCaml project with:
22-
23-
```
24-
$ drom new my-client --skeleton mini_prg
25-
Creating project "my-client" with skeleton "mini_prg", license "LGPL2"
26-
and sources in src/my-client:
27-
Creating directory my-client
28-
Using skeleton "program" for package "my-client"
29-
[master (root-commit) 8d83262] Initial commit
30-
31-
└── my-client/
32-
├── .drom (drom state, do not edit)
33-
├── .github/
34-
│ └── workflows/
35-
│ └── workflow.yml
36-
├── .gitignore
37-
├── CHANGES.md
38-
├── LICENSE.md
39-
├── Makefile
40-
├── README.md
41-
├── drom.toml <────────── project config EDIT !
42-
├── dune
43-
├── dune-project
44-
├── opam/
45-
│ └── my-client.opam
46-
├── scripts/
47-
│ ├── after.sh
48-
│ ├── before.sh
49-
│ └── copy-bin.sh
50-
└── src/
51-
└── my-client/
52-
├── dune
53-
├── main.ml
54-
├── package.toml <────────── package config EDIT !
55-
└── version.mlt
56-
```
57-
58-
This project uses the minimalist `mini_prg` skeleton, but other skeletons
59-
like `program` or `library` have more files.
60-
61-

dot_github/workflows/workflow.yml

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
name: Main Workflow
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
push:
8+
branches:
9+
- master
10+
11+
jobs:
12+
build:
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
os:
17+
- ubuntu-latest
18+
- macos-latest
19+
- windows-latest
20+
ocaml-compiler:
21+
- 4.14.1
22+
skip_test:
23+
- false
24+
25+
include:
26+
- os: ubuntu-latest
27+
ocaml-compiler: 4.08.0
28+
skip_test: true
29+
30+
31+
runs-on: ${{ matrix.os }}
32+
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v2
36+
37+
- name: Retrieve opam cache
38+
uses: actions/cache@v2
39+
id: cache-opam
40+
with:
41+
path: ~/.opam
42+
key: v2-${{ runner.os }}-drom-${{ matrix.ocaml-compiler }}-${{ hashFiles('opam/*.opam') }}
43+
# restore-keys: |
44+
# v2-${{ runner.os }}-opam-${{ matrix.ocaml-compiler }}-
45+
46+
- name: Use OCaml ${{ matrix.ocaml-compiler }}
47+
uses: avsm/setup-ocaml@v2
48+
with:
49+
ocaml-compiler: ${{ matrix.ocaml-compiler }}
50+
opam-pin: false
51+
opam-depext: false
52+
53+
- name: Set git user
54+
run: |
55+
git config --global user.name github-actions
56+
git config --global user.email [email protected]
57+
58+
# define opam-repo = "git+https://" to add an extra opam repo
59+
60+
- run: opam pin add . -y --no-action
61+
62+
- run: opam depext -y drom drom_lib drom_toml
63+
# if: steps.cache-opam.outputs.cache-hit != 'true'
64+
65+
- run: opam install -y opam/*.opam --deps-only --with-test
66+
# if: steps.cache-opam.outputs.cache-hit != 'true'
67+
68+
# - run: opam upgrade --fixup
69+
# if: steps.cache-opam.outputs.cache-hit == 'true'
70+
71+
- run: dos2unix scripts/*.sh
72+
if: matrix.os == 'windows-latest'
73+
74+
- run: make build
75+
76+
- name: run test suite
77+
run: |
78+
./scripts/before.sh test
79+
opam exec -- dune build @runtest
80+
./scripts/after.sh test
81+
if: matrix.skip_test != 'true'
82+
83+
- name: test source is well formatted
84+
run: make fmt
85+
continue-on-error: true
86+
if: matrix.ocaml-compiler == '4.14.1' && matrix.os == 'ubuntu-latest'
87+
88+
- name: build-doc
89+
if: github.ref == 'refs/heads/master' && matrix.ocaml-compiler == '4.14.1' && matrix.os == 'ubuntu-latest'
90+
run: |
91+
sudo apt install -yqq python3-sphinx python3-sphinx-rtd-theme
92+
opam install -y dune odoc
93+
make doc
94+
touch _drom/docs/.nojekyll
95+
touch _drom/docs/sphinx/.nojekyll
96+
touch _drom/docs/doc/.nojekyll
97+
98+
- name: deploy-doc
99+
uses: JamesIves/[email protected]
100+
if: github.ref == 'refs/heads/master' && matrix.ocaml-compiler == '4.14.1' && matrix.os == 'ubuntu-latest'
101+
with:
102+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
103+
BRANCH: gh-pages
104+
FOLDER: _drom/docs/
105+
CLEAN: true

dune-project

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
(lang dune 2.8)
2-
(using dune_site 0.1)
32
; This file was generated by drom, using drom.toml
43

54
(cram enable)
@@ -52,6 +51,7 @@
5251
(ez_cmdliner (and (>= 0.2.0) (< 1.0.0)))
5352
(drom_toml (= version))
5453
(directories ( >= 0.2 ))
54+
bos
5555
ppx_inline_test
5656
ppx_expect
5757
odoc

sphinx/under_static/css/fixes.css

Whitespace-only changes.

src/drom_lib/dune

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
(name drom_lib)
55
(public_name drom_lib)
66
(wrapped true)
7-
; use field 'dune-libraries' to add libraries without opam deps
8-
(libraries ppx_protocol_conv otoml omd jingoo fmt ez_subst ez_opam_file ez_file ez_cmdliner drom_toml directories bigarray ppx_protocol_conv.runtime ppx_protocol_conv.driver)
9-
; use field 'dune-flags' to set this value
10-
(flags (:standard))
11-
; use field 'dune-stanzas' to add more stanzas here
7+
(libraries ppx_protocol_conv otoml omd jingoo fmt ez_subst ez_opam_file ez_file ez_cmdliner drom_toml directories bos bigarray ppx_protocol_conv.runtime ppx_protocol_conv.driver)
128

139
(preprocess (pps ppx_deriving.show ppx_protocol_conv))
1410
)
@@ -22,5 +18,4 @@
2218
(documentation
2319
(package drom_lib))
2420

25-
; use field 'dune-trailer' to add more stuff here
2621

src/drom_lib/globals.ml

+13-5
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,20 @@ let find_ancestor_file file f =
8787
in
8888
iter dir ""
8989

90-
let opam_root =
91-
lazy
92-
( try Sys.getenv "OPAMROOT" with
93-
| Not_found -> home_dir // ".opam" )
90+
(** [opam_root ()] returns the opam root directory.
91+
92+
@raise Error.Error if any error happens. *)
93+
let opam_root : unit -> string =
94+
let compute = lazy begin
95+
(* Don't use OPAMROOT or hardcoded directories. `opam` gives its own
96+
way to give it. *)
97+
let cmd = Bos.Cmd.(v "opam" % "var" % "root") in
98+
match Bos.OS.Cmd.(run_out cmd |> to_string) with
99+
| Ok dir -> dir
100+
| Error _ -> Error.raise "%s: unknown error" __FUNCTION__
101+
end in
102+
fun () -> Lazy.force compute
94103

95-
let opam_root () = Lazy.force opam_root
96104

97105
let verbose_subst =
98106
try

0 commit comments

Comments
 (0)