From 7f1c20a50b8cb483b77f998257bcffc220587d18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Dimino?= Date: Mon, 7 Jan 2019 12:20:48 +0000 Subject: [PATCH] Get rid of the ocamlbuild plugin (#63) Signed-off-by: Jeremie Dimino --- CHANGES.md | 3 + MANUAL.md | 76 ------------------- README.md | 52 ------------- ocaml-migrate-parsetree-ocamlbuild.opam | 25 ------ ocamlbuild_plugin/dune | 5 -- .../migrate_parsetree_ocamlbuild.ml | 60 --------------- .../migrate_parsetree_ocamlbuild.mli | 1 - 7 files changed, 3 insertions(+), 219 deletions(-) delete mode 100644 ocaml-migrate-parsetree-ocamlbuild.opam delete mode 100644 ocamlbuild_plugin/dune delete mode 100644 ocamlbuild_plugin/migrate_parsetree_ocamlbuild.ml delete mode 100644 ocamlbuild_plugin/migrate_parsetree_ocamlbuild.mli diff --git a/CHANGES.md b/CHANGES.md index e07b10d1..d333f171 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,9 @@ next - Fix Windows compatibility by setting the output to binary mode when writing a binary ast (#57, @bryphe) +- Get rid of the ocamlbuild plugin. Nobody is using it in opam and it + is more work to maintain + v1.1.0 2018-09-05 London ------------------------ diff --git a/MANUAL.md b/MANUAL.md index 544c0849..95f909df 100644 --- a/MANUAL.md +++ b/MANUAL.md @@ -14,7 +14,6 @@ Date: March 9, 2017 - [New registration interface](#new-registration-interface) - [A minimal driver](#a-minimal-driver) - [Custom and standalone drivers](#custom-and-standalone-drivers) - - [Custom drivers with OCamlbuild](#custom-drivers-with-ocamlbuild) - [ppx_tools_versioned](#ppx_tools_versioned) - [ppx_metaquots](#ppx_metaquots) - [Findlib specification](#findlib-specification) @@ -180,81 +179,6 @@ ocamlfind ocamlopt -linkpkg -package rewriter1,rewriter2,... \ -package ocaml-migrate-parsetree.driver-main -o myrewriter ``` -## Custom drivers with OCamlbuild - -To build a custom driver using ocamlfind, simply link all the ppx -rewriter libraries together with the -`ocaml-migrate-parsetree.driver-main` package at the end: - - ocamlfind ocamlopt -predicates ppx_driver -o ppx -linkpkg \ - -package ppx_sexp_conv -package ppx_bin_prot \ - -package ocaml-migrate-parsetree.driver-main - -Normally, ocaml-migrate-parsetree based rewriters should be build with -the approriate `-linkall` option on individual libraries. If one is -missing this option, the rewriter might not get linked in. If this is -the case, a workaround is to pass `-linkall` when linking the custom -driver. - -The resulting `ppx` program can be used as follow: - -- `./ppx file.ml` to print the transformed code -- `ocamlc -pp './ppx --as-pp ...` to use it as a pre-processor -- `ocamlc -ppx './ppx --as-ppx' ...` to use it as a `-ppx` rewriter - -### Using the ocaml-migrate-parsetree driver with ocamlbuild - -The ocaml-migrate-parsetree-ocamlbuild package provides an ocamlbuild -plugin to help building and using custom drivers on demand. - -#### Setup - -To use it you need to first tell ocamlbuild to use the plugin in -`myocamlbuild.ml`. If you are using oasis, add this to your `_oasis` -file: - -``` -AlphaFeatures: ocamlbuild_more_args -XOCamlbuildPluginTags: package(ocaml-migrate-parsetree-ocamlbuild) -``` - -If you are calling ocamlbuild directly, you need to call it this way: - -``` -$ ocamlbuild -plugin-tag "package(ocaml-migrate-parsetree-ocamlbuild)" ... -``` - -Once you have done that, you need to enable it in your myocamlbuild.ml: - -```ocaml -let () = - Ocamlbuild_plugin.dispatch (fun hook -> - Migrate_parsetree_ocamlbuild.dispatch hook; - - ) -``` - -#### Usage - -The plugin provides a new parametric tag: `omp-driver`. The tag takes -as argument a `+` separated list of rewriters (as findlib package -names) followed by any command line arguments. - -For instance to use `ppx_sexp_conv` and `ppx_bin_prot` put this in -your tags file: - -``` -<**/*>: predicate(custom_ppx) -: omp-driver(ppx_sexp_conv+ppx_bin_prot) -``` - -The first line is to instruct ocamlfind not to automatically add -implicit `-ppx` argument. Without this, you might still get individual -`-ppx` for both `ppx_sexp_conv` and `ppx_bin_prot` in addition to the -main driver that already contains them both, meaning your code would -be transformed more than it should... - - # ppx_tools_versioned Some rewriters make use of the *ppx_tools* package that offers conveniences for manipulating parsetrees. As *ppx_tools* itself uses compiler-libs, using it directly defeats the purpose of *ocaml-migrate-parsetree*. diff --git a/README.md b/README.md index 911f9753..de88d0e9 100644 --- a/README.md +++ b/README.md @@ -108,58 +108,6 @@ The resulting `ppx` program can be used as follow: - `ocamlc -pp './ppx --as-pp' ...` to use it as a pre-processor - `ocamlc -ppx './ppx --as-ppx' ...` to use it as a `-ppx` rewriter -### Using the ocaml-migrate-parsetree driver with ocamlbuild - -The ocaml-migrate-parsetree-ocamlbuild package provides an ocamlbuild -plugin to help building and using custom drivers on demand. - -#### Setup - -To use it you need to first tell ocamlbuild to use the plugin in -`myocamlbuild.ml`. If you are using oasis, add this to your `_oasis` -file: - -``` -AlphaFeatures: ocamlbuild_more_args -XOCamlbuildPluginTags: package(ocaml-migrate-parsetree-ocamlbuild) -``` - -If you are calling ocamlbuild directly, you need to call it this way: - -``` -$ ocamlbuild -plugin-tag "package(ocaml-migrate-parsetree-ocamlbuild)" ... -``` - -Once you have done that, you need to enable it in your myocamlbuild.ml: - -```ocaml -let () = - Ocamlbuild_plugin.dispatch (fun hook -> - Migrate_parsetree_ocamlbuild.dispatch hook; - - ) -``` - -#### Usage - -The plugin provides a new parametric tag: `omp-driver`. The tag takes -as argument a `+` separated list of rewriters (as findlib package -names) followed by any command line arguments. - -For instance to use `ppx_sexp_conv` and `ppx_bin_prot` put this in -your tags file: - -``` -<**/*>: predicate(custom_ppx) -: omp-driver(ppx_sexp_conv+ppx_bin_prot) -``` - -The first line is to instruct ocamlfind not to automatically add -implicit `-ppx` argument. Without this, you might still get individual -`-ppx` for both `ppx_sexp_conv` and `ppx_bin_prot` in addition to the -main driver that already contains them both, meaning your code would -be transformed more than it should... - # Development It started from the work of Alain Frisch in diff --git a/ocaml-migrate-parsetree-ocamlbuild.opam b/ocaml-migrate-parsetree-ocamlbuild.opam deleted file mode 100644 index 5ec369ef..00000000 --- a/ocaml-migrate-parsetree-ocamlbuild.opam +++ /dev/null @@ -1,25 +0,0 @@ -opam-version: "2.0" -maintainer: "frederic.bour@lakaban.net" -authors: [ - "Jérémie Dimino " -] -license: "LGPL-2.1" -homepage: "https://github.com/let-def/ocaml-migrate-parsetree" -bug-reports: "https://github.com/let-def/ocaml-migrate-parsetree/issues" -dev-repo: "git+https://github.com/let-def/ocaml-migrate-parsetree.git" -tags: [ "syntax" "org:ocamllabs" ] -build: [ - ["dune" "build" "-p" name "-j" jobs] -] -depends: [ - "dune" {build & >= "1.6.0"} - "ocaml-migrate-parsetree" - "ocamlbuild" - "ocaml" {>= "4.02.3"} -] -synopsis: "Ocamlbuild plugin for ocaml-migrate-parsetree" -description: """ -This package provides an ocamlbuild plugin that can be used to produce -optimized on-demand statically linked ppx drivers, as Dune does -by default. -""" diff --git a/ocamlbuild_plugin/dune b/ocamlbuild_plugin/dune deleted file mode 100644 index c854dd18..00000000 --- a/ocamlbuild_plugin/dune +++ /dev/null @@ -1,5 +0,0 @@ -(library - (name migrate_parsetree_ocamlbuild) - (public_name ocaml-migrate-parsetree-ocamlbuild) - (synopsis "ocamlbuild plugin for automatically generating ppx dirvers") - (libraries ocamlbuild)) diff --git a/ocamlbuild_plugin/migrate_parsetree_ocamlbuild.ml b/ocamlbuild_plugin/migrate_parsetree_ocamlbuild.ml deleted file mode 100644 index c690a4e9..00000000 --- a/ocamlbuild_plugin/migrate_parsetree_ocamlbuild.ml +++ /dev/null @@ -1,60 +0,0 @@ -open Ocamlbuild_plugin - -let split s ~on = - let rec loop i = - match String.index_from s i on with - | exception Not_found -> [String.sub s i (String.length s - i)] - | j -> String.sub s i (j - i) :: loop (j + 1) - in - loop 0 - -let exe_ext ~native = if native then "native" else "byte" - -let parse_tag_arg s = - let set, args = - match String.index s ' ' with - | exception Not_found -> (s, "") - | i -> (String.before s i, String.after s i) - in - let libs = split set ~on:'+' in - (List.sort String.compare libs, args) - -let prog_of_libs ~native libs = - "omp-driver-" ^ String.concat "+" libs -.- exe_ext ~native - -let pp_command_of_string ~native s = - let libs, args = parse_tag_arg s in - S [ A "-pp" - ; A (Printf.sprintf "./%s --dump-ast%s" (prog_of_libs ~native libs) args) - ] - -let deps_of_string ~native s = - let libs, _ = parse_tag_arg s in - [ prog_of_libs ~native libs ] - -let dispatch = function - | After_rules -> begin - (* If we are using a native plugin, we might as well use a native preprocessor. *) - let native = !Options.native_plugin in - - pflag [ "ocaml"; "compile" ] "omp-driver" (pp_command_of_string ~native); - pflag [ "ocaml"; "ocamldep" ] "omp-driver" (pp_command_of_string ~native); - pflag [ "ocaml"; "doc" ] "omp-driver" (pp_command_of_string ~native); - - pdep [ "ocaml"; "compile" ] "omp-driver" (deps_of_string ~native); - pdep [ "ocaml"; "ocamldep" ] "omp-driver" (deps_of_string ~native); - pdep [ "ocaml"; "doc" ] "omp-driver" (deps_of_string ~native); - - let target = "omp-driver-%" -.- exe_ext ~native in - rule "autogenerated ocaml-migrate-parsetree driver" - ~prod:target - (fun env _ -> - let pkgs = split (env "%") ~on:'+' @ ["ocaml-migrate-parsetree.driver-main"] in - Cmd (S [ if native then !Options.ocamlopt else !Options.ocamlc - ; A "-predicates"; A "ppx_driver" - ; A "-linkpkg" - ; A "-o"; A (env target) - ; A "-package"; A (String.concat "," pkgs) - ])) - end - | _ -> () diff --git a/ocamlbuild_plugin/migrate_parsetree_ocamlbuild.mli b/ocamlbuild_plugin/migrate_parsetree_ocamlbuild.mli deleted file mode 100644 index 8005c13c..00000000 --- a/ocamlbuild_plugin/migrate_parsetree_ocamlbuild.mli +++ /dev/null @@ -1 +0,0 @@ -val dispatch : Ocamlbuild_plugin.hook -> unit