Skip to content

Commit

Permalink
Merge pull request #233 from Ninjapouet/fix#230
Browse files Browse the repository at this point in the history
Fixes #230: compute the `opam` root using `opam` itself.
  • Loading branch information
lefessan authored Sep 9, 2024
2 parents 865cffe + 4859c7d commit 2fe1a83
Show file tree
Hide file tree
Showing 9 changed files with 211 additions and 61 deletions.
93 changes: 89 additions & 4 deletions .drom
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version:0.9.0

# hash of toml configuration files
# used for generation of all files
cfd502831bbf686b41df41219629c1c4:.
812a88073a143fbfd65d11dd1ac586fd:.
# end context for .

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

# begin context for .gitignore
# file .gitignore
f7a24abcad0ba9301c03bb64464b1718:.gitignore
33c88a25e8b40f3683f6c03ec26be5db:.gitignore
# end context for .gitignore

# begin context for .ocamlformat
Expand Down Expand Up @@ -55,7 +55,7 @@ f7a24abcad0ba9301c03bb64464b1718:.gitignore

# begin context for README.md
# file README.md
616ddd2660258447be65bdb664b9241d:README.md
5d523350230459e853bc57803b729e29:README.md
# end context for README.md

# begin context for docs/README.txt
Expand Down Expand Up @@ -88,11 +88,31 @@ e739f3026aa997af4026bc428f4c9ef6:docs/favicon.png
c8281f46ba9a11d0b61bc8ef67eaa357:docs/style.css
# end context for docs/style.css

# begin context for docs\README.txt
# file docs\README.txt
bfbacf00053bb9ab2a6e2ce94ed4a642:docs\README.txt
# end context for docs\README.txt

# begin context for docs\favicon.png
# file docs\favicon.png
e739f3026aa997af4026bc428f4c9ef6:docs\favicon.png
# end context for docs\favicon.png

# begin context for docs\style.css
# file docs\style.css
c8281f46ba9a11d0b61bc8ef67eaa357:docs\style.css
# end context for docs\style.css

# begin context for dot_gitattributes
# file dot_gitattributes
20bbe7a5dbb3c3278a1511d960616fe5:dot_gitattributes
# end context for dot_gitattributes

# begin context for dot_github\workflows\workflow.yml
# file dot_github\workflows\workflow.yml
004b92dd628d26b4f8a5a5139bf4aa79:dot_github\workflows\workflow.yml
# end context for dot_github\workflows\workflow.yml

# begin context for drom.toml
# file drom.toml
9949d65b87e55480a30122e9e77ae7d3:drom.toml
Expand All @@ -105,7 +125,7 @@ e850a13c004f963e9f5a568eac93c217:dune

# begin context for dune-project
# file dune-project
c063288437da29a5a21e8c76c1906adc:dune-project
7f0439af8599faf105447755ebd72e7e:dune-project
# end context for dune-project

# begin context for opam/drom.opam
Expand Down Expand Up @@ -143,6 +163,16 @@ e55d659410b556d7bc60183d8ff1f788:opam/drom_toml.opam
cda3f8bad69d9c6e8cbeab1c720d739a:scripts/static-build.sh
# end context for scripts/static-build.sh

# begin context for scripts\after.sh
# file scripts\after.sh
cb2282903fb6ae1ac71fb2fbbcccffbd:scripts\after.sh
# end context for scripts\after.sh

# begin context for scripts\before.sh
# file scripts\before.sh
97c9b1f22a04f7c0b42477aee6f4393e:scripts\before.sh
# end context for scripts\before.sh

# begin context for sphinx/_static/css/fixes.css
# file sphinx/_static/css/fixes.css
68b329da9893e34099c7d8ad5cb9c940:sphinx/_static/css/fixes.css
Expand Down Expand Up @@ -173,6 +203,21 @@ a44c87f3a364dd95f55427fe40b2c5d1:sphinx/about.rst
8f504f01aea592543c0a662b81169d91:sphinx/license.rst
# end context for sphinx/license.rst

# begin context for sphinx\conf.py
# file sphinx\conf.py
67496ee935ab27fdabb4544f4f81eeb6:sphinx\conf.py
# end context for sphinx\conf.py

# begin context for sphinx\license.rst
# file sphinx\license.rst
8f504f01aea592543c0a662b81169d91:sphinx\license.rst
# end context for sphinx\license.rst

# begin context for sphinx\under_static\css\fixes.css
# file sphinx\under_static\css\fixes.css
20bbe7a5dbb3c3278a1511d960616fe5:sphinx\under_static\css\fixes.css
# end context for sphinx\under_static\css\fixes.css

# begin context for src/drom/dune
# file src/drom/dune
68aec4169671c0163b98bb38205d2e4d:src/drom/dune
Expand All @@ -198,6 +243,11 @@ a44c87f3a364dd95f55427fe40b2c5d1:sphinx/about.rst
bb6803d414fd5a5479ed6381914604de:src/drom/package.toml
# end context for src/drom/package.toml

# begin context for src/drom\index.mld
# file src/drom\index.mld
2818d15f527a37c2cfafe85ef89f675b:src/drom\index.mld
# end context for src/drom\index.mld

# begin context for src/drom_lib/dune
# file src/drom_lib/dune
103b365e9f24dbbae02b6be22b3efd0a:src/drom_lib/dune
Expand All @@ -218,6 +268,21 @@ c4d6597dc5b0966758c213bfffb9d594:src/drom_lib/package.toml
a3e5d8a00664ceaa6addf376bedf6de1:src/drom_lib/version.mlt
# end context for src/drom_lib/version.mlt

# begin context for src/drom_lib\dune
# file src/drom_lib\dune
8c189e7a8bac651b008889b1dd38a8fe:src/drom_lib\dune
# end context for src/drom_lib\dune

# begin context for src/drom_lib\index.mld
# file src/drom_lib\index.mld
3e03ec5e98f99c1d5b09dd366177ad13:src/drom_lib\index.mld
# end context for src/drom_lib\index.mld

# begin context for src/drom_lib\version.mlt
# file src/drom_lib\version.mlt
a3e5d8a00664ceaa6addf376bedf6de1:src/drom_lib\version.mlt
# end context for src/drom_lib\version.mlt

# begin context for src/toml.7.1.0/dune
# file src/toml.7.1.0/dune
0841a2e47118b9fcd9b900f84ff66c34:src/toml.7.1.0/dune
Expand All @@ -243,6 +308,16 @@ d1b05207fce876a1b44a8b268bcaf226:src/toml.7.1.0/index.mld
a3e5d8a00664ceaa6addf376bedf6de1:src/toml.7.1.0/version.mlt
# end context for src/toml.7.1.0/version.mlt

# begin context for src/toml.7.1.0\index.mld
# file src/toml.7.1.0\index.mld
d1b05207fce876a1b44a8b268bcaf226:src/toml.7.1.0\index.mld
# end context for src/toml.7.1.0\index.mld

# begin context for src/toml.7.1.0\version.mlt
# file src/toml.7.1.0\version.mlt
a3e5d8a00664ceaa6addf376bedf6de1:src/toml.7.1.0\version.mlt
# end context for src/toml.7.1.0\version.mlt

# begin context for test/expect-tests/dune
# file test/expect-tests/dune
d7e2675a767e30edf28d061c94f0ec62:test/expect-tests/dune
Expand Down Expand Up @@ -312,3 +387,13 @@ ee63957b3b77455a12e6c269a5032c3f:test/output-tests/test2.expected
# file test/output-tests/test2.ml
e8eaab7626ef0aace5e570fffe81f869:test/output-tests/test2.ml
# end context for test/output-tests/test2.ml

# begin context for test\inline-tests\test.ml
# file test\inline-tests\test.ml
37b8bc6035cda6302a80178c61f9626e:test\inline-tests\test.ml
# end context for test\inline-tests\test.ml

# begin context for test\output-tests\test1.expected
# file test\output-tests\test1.expected
dc8d6157230e9ef8e965865f990fbc49:test\output-tests\test1.expected
# end context for test\output-tests\test1.expected
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*~
_build
.merlin
.vscode
/_drom
/_opam
/_build
Expand Down
45 changes: 0 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,48 +14,3 @@ will generate files for Github Actions CI and Github pages.
* General Documentation: https://ocamlpro.github.io/drom/sphinx
* API Documentation: https://ocamlpro.github.io/drom/doc
* Sources: https://github.com/ocamlpro/drom


## Simple Example

You can create a new OCaml project with:

```
$ drom new my-client --skeleton mini_prg
Creating project "my-client" with skeleton "mini_prg", license "LGPL2"
and sources in src/my-client:
Creating directory my-client
Using skeleton "program" for package "my-client"
[master (root-commit) 8d83262] Initial commit
└── my-client/
├── .drom (drom state, do not edit)
├── .github/
│ └── workflows/
│ └── workflow.yml
├── .gitignore
├── CHANGES.md
├── LICENSE.md
├── Makefile
├── README.md
├── drom.toml <────────── project config EDIT !
├── dune
├── dune-project
├── opam/
│ └── my-client.opam
├── scripts/
│ ├── after.sh
│ ├── before.sh
│ └── copy-bin.sh
└── src/
└── my-client/
├── dune
├── main.ml
├── package.toml <────────── package config EDIT !
└── version.mlt
```

This project uses the minimalist `mini_prg` skeleton, but other skeletons
like `program` or `library` have more files.


105 changes: 105 additions & 0 deletions dot_github/workflows/workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: Main Workflow

on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
build:
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
ocaml-compiler:
- 4.14.1
skip_test:
- false

include:
- os: ubuntu-latest
ocaml-compiler: 4.08.0
skip_test: true


runs-on: ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Retrieve opam cache
uses: actions/cache@v2
id: cache-opam
with:
path: ~/.opam
key: v2-${{ runner.os }}-drom-${{ matrix.ocaml-compiler }}-${{ hashFiles('opam/*.opam') }}
# restore-keys: |
# v2-${{ runner.os }}-opam-${{ matrix.ocaml-compiler }}-

- name: Use OCaml ${{ matrix.ocaml-compiler }}
uses: avsm/setup-ocaml@v2
with:
ocaml-compiler: ${{ matrix.ocaml-compiler }}
opam-pin: false
opam-depext: false

- name: Set git user
run: |
git config --global user.name github-actions
git config --global user.email [email protected]
# define opam-repo = "git+https://" to add an extra opam repo

- run: opam pin add . -y --no-action

- run: opam depext -y drom drom_lib drom_toml
# if: steps.cache-opam.outputs.cache-hit != 'true'

- run: opam install -y opam/*.opam --deps-only --with-test
# if: steps.cache-opam.outputs.cache-hit != 'true'

# - run: opam upgrade --fixup
# if: steps.cache-opam.outputs.cache-hit == 'true'

- run: dos2unix scripts/*.sh
if: matrix.os == 'windows-latest'

- run: make build

- name: run test suite
run: |
./scripts/before.sh test
opam exec -- dune build @runtest
./scripts/after.sh test
if: matrix.skip_test != 'true'

- name: test source is well formatted
run: make fmt
continue-on-error: true
if: matrix.ocaml-compiler == '4.14.1' && matrix.os == 'ubuntu-latest'

- name: build-doc
if: github.ref == 'refs/heads/master' && matrix.ocaml-compiler == '4.14.1' && matrix.os == 'ubuntu-latest'
run: |
sudo apt install -yqq python3-sphinx python3-sphinx-rtd-theme
opam install -y dune odoc
make doc
touch _drom/docs/.nojekyll
touch _drom/docs/sphinx/.nojekyll
touch _drom/docs/doc/.nojekyll
- name: deploy-doc
uses: JamesIves/[email protected]
if: github.ref == 'refs/heads/master' && matrix.ocaml-compiler == '4.14.1' && matrix.os == 'ubuntu-latest'
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: _drom/docs/
CLEAN: true
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
(lang dune 2.8)
(using dune_site 0.1)
; This file was generated by drom, using drom.toml

(cram enable)
Expand Down Expand Up @@ -52,6 +51,7 @@
(ez_cmdliner (and (>= 0.2.0) (< 1.0.0)))
(drom_toml (= version))
(directories ( >= 0.2 ))
bos
ppx_inline_test
ppx_expect
odoc
Expand Down
Empty file.
7 changes: 1 addition & 6 deletions src/drom_lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
(name drom_lib)
(public_name drom_lib)
(wrapped true)
; use field 'dune-libraries' to add libraries without opam deps
(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)
; use field 'dune-flags' to set this value
(flags (:standard))
; use field 'dune-stanzas' to add more stanzas here
(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)

(preprocess (pps ppx_deriving.show ppx_protocol_conv))
)
Expand All @@ -22,5 +18,4 @@
(documentation
(package drom_lib))

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

18 changes: 13 additions & 5 deletions src/drom_lib/globals.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,20 @@ let find_ancestor_file file f =
in
iter dir ""

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

let opam_root () = Lazy.force opam_root

let verbose_subst =
try
Expand Down
Loading

0 comments on commit 2fe1a83

Please sign in to comment.