Skip to content

Commit bf1652c

Browse files
committed
Name the switch, and use it from every worktree
The switch lived in the checkout as ./_opam, which a worktree outside the checkout cannot see, so the Makefile found it through git. It is now opam's own, hypha-postgres-eio, which the checkout and every worktree reach by name; make setup creates it empty, so opam takes the compiler from the declared bounds rather than a version written here.
1 parent 852dc6d commit bf1652c

5 files changed

Lines changed: 24 additions & 27 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
with:
2020
ocaml-compiler: ${{ matrix.ocaml }}
2121
- run: opam install . --deps-only --with-test --with-dev-setup -y
22-
# Use setup-ocaml's switch instead of the Makefile's local one.
22+
# Use setup-ocaml's switch instead of the Makefile's.
2323
- run: make lint OPAM="opam exec --"
2424
- run: make test OPAM="opam exec --"
2525

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
_build/
2-
_opam
32
.DS_Store

‎AGENTS.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ for anyone changing it, human or agent. Users start at [README.md](README.md).
66
## Commands
77

88
```sh
9-
make setup # once: local opam switch in ./_opam, all dependencies
9+
make setup # once: the switch hypha-postgres-eio, all dependencies
1010
make test # starts the test Postgres in Docker, runs every test
1111
make lint # formatting, odoc, and the release build
1212
make fmt # format in place

‎Makefile‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
# The opam switch is the checkout's (./_opam), so OCaml commands go through
2-
# opam exec. A worktree lives outside its checkout and uses its switch,
3-
# found through git.
4-
CHECKOUT := $(patsubst %/.git,%,$(shell git rev-parse --path-format=absolute --git-common-dir))
5-
OPAM = opam exec --switch=$(CHECKOUT) --
1+
SWITCH ?= hypha-postgres-eio
2+
OPAM = opam exec --switch=$(SWITCH) --
63

74
PG_TEST_PORT ?= 5435
85
PG_TEST_URL ?= postgres://postgres_eio:postgres_eio@localhost:$(PG_TEST_PORT)/postgres_eio
@@ -15,10 +12,10 @@ help: ## list targets
1512
@grep -hE '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
1613
| awk 'BEGIN {FS = ":.*?## "}; {printf " %-10s %s\n", $$1, $$2}'
1714

18-
setup: ## create the local switch and install dependencies
15+
setup: ## create the switch and install dependencies
1916
@docker compose version >/dev/null 2>&1 || echo "The tests need docker compose."
20-
@[ -d $(CHECKOUT)/_opam ] || opam switch create $(CHECKOUT) 5.5.1 --no-install -y
21-
opam install . --switch=$(CHECKOUT) --deps-only --with-test --with-dev-setup -y
17+
@opam switch list --short | grep -qx $(SWITCH) || opam switch create $(SWITCH) --empty -y
18+
opam install . --switch=$(SWITCH) --deps-only --with-test --with-dev-setup -y
2219

2320
build: ## build everything
2421
$(OPAM) dune build @all

‎OCAML.md‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,9 @@ the next where they expect it.
170170
writes the opam files from it. A Hypha library another depends on is
171171
pinned in the `*.opam.template`'s `pin-depends`, at a release's tag on
172172
GitHub, until the libraries are in opam-repository and the pins go.
173-
`make setup` makes the checkout's switch, `./_opam`, and installs into
173+
`make setup` makes the repository's switch, empty, and installs into
174174
it with `opam install . --deps-only`, which resolves everything, the
175-
pins included; a new release is taken by moving its tag and the bound
175+
compiler and the pins included; a new release is taken by moving its tag and the bound
176176
and running `make setup` again. An application commits its solution as
177177
an opam lock (`make lock` after an upgrade); a library commits none,
178178
its users solving their own. Why: it is how the libraries' users get
@@ -360,14 +360,15 @@ language server (the `LSP` tool) or, without one, Merlin's command line;
360360
every user of an export is found this way, since a shadowed, re-exported
361361
or aliased name defeats a text search.
362362

363-
Nothing is on PATH. Every OCaml tool runs through the checkout's local
364-
switch, `./_opam`, as `opam exec --switch=<checkout> --` or through the
365-
Makefile; no `eval`. A worktree has no switch of its own: it uses its
366-
checkout's, the directory `git rev-parse --git-common-dir` is in, as the
367-
Makefile and the language server find it. `make setup` installs Merlin
368-
and `ocaml-lsp-server` with the rest.
363+
Nothing is on PATH. Every OCaml tool runs through the repository's opam
364+
switch, named `hypha-<name>` after the `(name)` its `dune-project`
365+
declares, as `opam exec --switch=hypha-<name> --` or through the
366+
Makefile, whose `SWITCH` names it; no `eval`. The checkout and every
367+
worktree of it use that one switch, by its name, so a worktree needs no
368+
setup of its own. `make setup` installs Merlin and `ocaml-lsp-server` with
369+
the rest.
369370

370-
**`ocamllsp` runs as the agent's language server**, from the checkout's
371+
**`ocamllsp` runs as the agent's language server**, from the repository's
371372
switch. It answers every edit to OCaml source with its type errors,
372373
and gives a name's definition, its references, tests included, its type
373374
and a file's symbols; ask for the symbols before reading a long file
@@ -385,9 +386,10 @@ project`, `locate -position LINE:COL`, `type-enclosing -position LINE:COL`,
385386
a use**, never from its declaration in the `.mli`, which answers with that
386387
declaration alone; a value asked from its `.mli` finds every use.
387388

388-
**A dependency's API is read where it is installed**, from its `.mli`
389-
under `_opam/lib/<package>/` or the server's hover, never from memory: the
390-
version in the switch is the one the code builds against.
389+
**A dependency's API is read where it is installed**, from its `.mli` in
390+
the switch (`opam var --switch=hypha-<name> lib`, then `<package>/`) or the
391+
server's hover, never from memory: the version in the switch is the one
392+
the code builds against.
391393

392394
**The stdlib is 5.5's, and nothing newer.** A function whose odoc says
393395
`@since` a later version is not used until every `dune-project` asks for
@@ -396,7 +398,7 @@ that version.
396398
**A generated file is changed at its source.** An `*.opam` file is written
397399
by dune from `dune-project`, and from an `*.opam.template` beside it for
398400
what dune cannot say, so either of those is edited, never the `.opam`.
399-
Nothing under `_build/` or `_opam/` is edited; a test's new expected
401+
Nothing under `_build/` or in the switch is edited; a test's new expected
400402
output is taken with `dune promote`.
401403

402404
**A worktree is outside the checkout** (`GIT.md`), so dune takes it as
@@ -407,9 +409,8 @@ missed when the whole project is read.
407409

408410
**Search text with `rg`, always with a path**, never `grep -r` or `find`:
409411
with no path `rg` reads standard input, which an agent's shell never
410-
closes, and `_build/` and `_opam/` are gitignored, so `rg` skips them
411-
where `find . -name '*.ml'` returns every copy of the source under
412-
`_build/` and every package under `_opam/`.
412+
closes, and `_build/` is gitignored, so `rg` skips it where `find . -name
413+
'*.ml'` returns every copy of the source under `_build/`.
413414

414415
`opam list --installed` says what the switch holds; `opam list
415416
--required-by --recursive` resolves against what is available, not what is

0 commit comments

Comments
 (0)