From 569d6c990cf7ac5227bb8540b96e4f6c619fdb46 Mon Sep 17 00:00:00 2001 From: Patrik Keller Date: Wed, 15 Dec 2021 21:35:15 +0100 Subject: [PATCH 1/3] Improve PPX template I try to improve the PPX template a bit: - The rewriter in `bin/main.exe` can now be used on source files directly. - The `CONTRIBUTING.md` documents this feature. --- template/ppx/template/CONTRIBUTING.md | 79 +++++++++++++++++++ template/ppx/template/bin/dune | 2 +- template/ppx/template/bin/main.ml | 2 +- .../test/{{ project_snake }}_test.mli | 3 + 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 template/ppx/template/CONTRIBUTING.md create mode 100644 template/ppx/template/test/{{ project_snake }}_test.mli diff --git a/template/ppx/template/CONTRIBUTING.md b/template/ppx/template/CONTRIBUTING.md new file mode 100644 index 0000000..9291d14 --- /dev/null +++ b/template/ppx/template/CONTRIBUTING.md @@ -0,0 +1,79 @@ +# Contributing + +## Setup your development environment + +You need Opam, you can install it by following [Opam's documentation](https://opam.ocaml.org/doc/Install.html). + +With Opam installed, you can install the dependencies in a new local switch with: + +```bash +make switch +``` + +Or globally, with: + +```bash +make deps +``` + +Then, build the project with: + +```bash +make build +``` + +### Running the PPX + +After building the project, you can run the main binary on an OCaml source file to see what the PPX is doing. + +```bash +opam exec -- dune exec bin/main.exe test/{{ project_snake }}_test.ml +``` + +### Running Tests + +You can run the test compiled executable: + +```bash +make test +``` + +### Building documentation + +Documentation for the libraries in the project can be generated with: + +```bash +make doc +make servedoc +``` + +### Repository Structure + +The following snippet describes {{ project_name }}'s repository structure. + +```text +. +├── bin/ +| Source for {{ project_slug }}'s binaries. This links to the rewriter defined in `lib/`. +│ +├── lib/ +| Source for {{ project_name }}'s library. Contains {{ project_name }}'s rewriting functionalities. +│ +├── test/ +| Unit tests and integration tests for {{ project_name }}. +│ +├── dune-project +| Dune file used to mark the root of the project and define project-wide parameters. +| For the documentation of the syntax, see https://dune.readthedocs.io/en/stable/dune-files.html#dune-project +│ +├── LICENSE +│ +├── Makefile +| Make file containing common development command. +│ +├── README.md +│ +└── {{ project_slug }}.opam + Opam package definition. + To know more about creating and publishing opam packages, see https://opam.ocaml.org/doc/Packaging.html. +``` diff --git a/template/ppx/template/bin/dune b/template/ppx/template/bin/dune index b6ad8c1..93fe1ea 100644 --- a/template/ppx/template/bin/dune +++ b/template/ppx/template/bin/dune @@ -1,4 +1,4 @@ (executable (name main) (public_name {{ project_slug }}) - (libraries {{ project_snake }} cmdliner fmt fmt.tty logs.fmt logs.cli)) + (libraries {{ project_snake }})) diff --git a/template/ppx/template/bin/main.ml b/template/ppx/template/bin/main.ml index 571a8d4..997bf20 100644 --- a/template/ppx/template/bin/main.ml +++ b/template/ppx/template/bin/main.ml @@ -1,3 +1,3 @@ open Ppxlib -let _ = Driver.run_as_ppx_rewriter () +let _ = Driver.standalone () diff --git a/template/ppx/template/test/{{ project_snake }}_test.mli b/template/ppx/template/test/{{ project_snake }}_test.mli new file mode 100644 index 0000000..997bf20 --- /dev/null +++ b/template/ppx/template/test/{{ project_snake }}_test.mli @@ -0,0 +1,3 @@ +open Ppxlib + +let _ = Driver.standalone () From 1d28e60c0996c237c139b6dc7d9f2dc249406b5e Mon Sep 17 00:00:00 2001 From: Patrik Keller Date: Thu, 16 Dec 2021 09:18:30 +0100 Subject: [PATCH 2/3] Delete spurious mli file --- template/ppx/template/test/{{ project_snake }}_test.mli | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 template/ppx/template/test/{{ project_snake }}_test.mli diff --git a/template/ppx/template/test/{{ project_snake }}_test.mli b/template/ppx/template/test/{{ project_snake }}_test.mli deleted file mode 100644 index 997bf20..0000000 --- a/template/ppx/template/test/{{ project_snake }}_test.mli +++ /dev/null @@ -1,3 +0,0 @@ -open Ppxlib - -let _ = Driver.standalone () From 1ddaef303e6a6cdc5462386199a6255b0ef3e4c1 Mon Sep 17 00:00:00 2001 From: Patrik Keller Date: Thu, 16 Dec 2021 09:27:36 +0100 Subject: [PATCH 3/3] Standalone rewriter does not need a public name --- template/ppx/template/bin/dune | 1 - 1 file changed, 1 deletion(-) diff --git a/template/ppx/template/bin/dune b/template/ppx/template/bin/dune index 93fe1ea..370410f 100644 --- a/template/ppx/template/bin/dune +++ b/template/ppx/template/bin/dune @@ -1,4 +1,3 @@ (executable (name main) - (public_name {{ project_slug }}) (libraries {{ project_snake }}))