Commit fe7e633e authored by Gerd Stolpmann's avatar Gerd Stolpmann

Merge branch 'printppx' into 'master'

Printppx

This PR adds ocamlfind printppx including documentation. The last commit is independent of that and adds documentation for ppx preprocessors that I would have found very useful when I started to look at the ppx support of ocamlfind.


See merge request !2
parents dfab67d6 74ceb79d
......@@ -2365,6 +2365,28 @@ omit "./" to search it, and you can prefix it with "@name/" if the command
is taken from another package "name").
</para>
<para>For more complex scenarios, additional options or
arguments for the ppx preprocessor can be specified in descendant
packages with the "ppxopt" property. Package "A" might provide a
generic ppx preprocessor with a META file containing
<programlisting>
ppx = "./generic_ppx"
</programlisting>
Package B might instantiate that preprocessor with
<programlisting>
requires = "A"
ppxopt = "A,ppx_b.cmo"
</programlisting>
In this case "ocamlfind ocamlc -package B" would
add <literal>-ppx "path_to_A/genric_ppx ppx_b.cmo"</literal> to
the ocamlc invocation. The format of the "ppxopt" property is
specified in the findlib reference manual.
</para>
<para>This feature is still a bit experimental.</para>
......
......@@ -28,6 +28,7 @@
or: <link linkend="ocamlfind.remove">ocamlfind remove [-help | other options] <replaceable>package_name</replaceable></link>
or: <link linkend="ocamlfind.list">ocamlfind lint <replaceable>META</replaceable></link>
or: <link linkend="ocamlfind.list">ocamlfind list [-describe]</link>
or: <link linkend="ocamlfind.printppx">ocamlfind printppx [-help | other options] <replaceable>package_name</replaceable> ...</link>
or: <link linkend="ocamlfind.printconf">ocamlfind printconf [ variable ]</link>
or: <link linkend="ocamlfind.pkgcmd">ocamlfind <replaceable>package</replaceable>/<replaceable>command</replaceable> <replaceable>arg</replaceable> ...</link>
......@@ -495,6 +496,13 @@ The options relevant for the preprocessor are the following:
<listitem><para>This argument is passed to the camlp4 call.
</para></listitem>
</varlistentry>
<varlistentry>
<term>-ppxopt <replaceable>package</replaceable>,<replaceable>arg</replaceable></term>
<listitem><para>Add <replaceable>arg</replaceable> to the ppx
preprocessor invocation specified via the "ppx" property in
the META file of <replaceable>package</replaceable>.
</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
......@@ -1212,6 +1220,48 @@ outputs the package descriptions, too.
<!-- ********************************************************************** -->
<refsect1>
<title><anchor id="ocamlfind.printppx">
THE "printppx" SUBCOMMAND
</title>
<refsect2>
<title>Synopsis</title>
<programlisting>
ocamlfind printppx
[ -predicates <replaceable>pred-name-list</replaceable> ]
[ -ppxopt <replaceable>package</replaceable>,<replaceable>arg</replaceable> ]
<replaceable>package</replaceable> ...
</programlisting>
</refsect2>
<refsect2>
<title>Description</title>
<para>
This command prints the ppx preprocessor options as they would
occur in an OCaml compiler invocation for the packages listed in
the command. The output includes one "-ppx" option for each
preprocessor. The possible options have the same meaning as for
"ocamlfind ocamlc". The option "-predicates" adds assumed
predicates and
"-ppxopt <replaceable>package</replaceable>,<replaceable>arg</replaceable>"
adds "<replaceable>arg</replaceable>" to the ppx invocation of
package <replaceable>package</replaceable>.
</para>
<para>
The output of "ocamlfind printppx" will contain quotes
"<literal>"</literal>" for ppx commands that contain
space-separated arguments. In this case <literal>$(ocamlfind
printppx ...)</literal> won't work as naively expected, because
many shells (including bash and dash) perform field splitting on
the result of command substitutions without honoring quotes.
</para>
</refsect2>
</refsect1>
<!-- ********************************************************************** -->
<refsect1>
<title><anchor id="ocamlfind.lint">
THE "lint" SUBCOMMAND
......
......@@ -11,7 +11,7 @@ exception Silent_error;;
type mode =
M_use | M_query | M_install | M_remove | M_compiler of string | M_dep
| M_printconf | M_list | M_browser | M_call of (string*string)
| M_doc | M_lint
| M_doc | M_lint | M_printppx
;;
......@@ -202,6 +202,11 @@ let arg n =
;;
let escape_if_needed s =
if String.contains s ' ' then "\"" ^ String.escaped s ^ "\"" else s
;;
let use_package prefix pkgnames =
(* may raise No_such_package *)
let pdirs =
......@@ -345,8 +350,6 @@ type verbosity =
let run_command ?filter verbose cmd args =
let escape_if_needed s =
if String.contains s ' ' then "\"" ^ String.escaped s ^ "\"" else s in
let printable_cmd =
cmd ^ " " ^ String.concat " " (List.map escape_if_needed args) in
( match verbose with
......@@ -2454,6 +2457,34 @@ let lint () =
;;
(** print ppx options *)
let print_ppx () =
let packages = ref [] in
let predicates = ref [] in
let ppx_opts = ref [] in
let add_pred =
Arg.String (fun s -> predicates := !predicates @ (Fl_split.in_words s)) in
let add_ppx_opt =
Arg.String (fun s -> ppx_opts := !ppx_opts @ [s]) in
parse_args
[ "-predicates", add_pred,
" specifies comma-separated list of assumed predicates";
"-ppxopt", add_ppx_opt,
"<pkg>,<opts> Append options <opts> to ppx invocation for package <pkg>";
]
(fun p -> packages := !packages @ [p])
"usage: ocamlfind printppx [options] package ...";
let ppx_commands =
process_ppx_spec !predicates !packages !ppx_opts
in
print_endline (String.concat " " (List.map escape_if_needed ppx_commands))
;;
let rec select_mode () =
let k = !Arg.current in
let m_string = try arg (k+1) with Not_found -> raise Usage in
......@@ -2475,6 +2506,7 @@ let rec select_mode () =
| ("printconf"|"-printconf") -> incr Arg.current; M_printconf
| ("list"|"-list") -> incr Arg.current; M_list
| ("lint"|"-lint") -> incr Arg.current; M_lint
| ("printppx"|"-printppx") -> incr Arg.current; M_printppx
| "-toolchain" ->
let t = try arg (k+2) with Not_found -> raise Usage in
Findlib.init ~toolchain:t ();
......@@ -2519,6 +2551,7 @@ let main() =
| M_call(pkg,cmd) -> ocamlcall pkg cmd
| M_compiler which -> ocamlc which ()
| M_lint -> lint()
| M_printppx -> print_ppx()
with
Usage ->
prerr_endline "Usage: ocamlfind query [-help | other options] <package_name> ...";
......@@ -2535,6 +2568,7 @@ let main() =
prerr_endline " or: ocamlfind ocamldoc [-help | other options] <file> ...";
prerr_endline " or: ocamlfind install [-help | other options] <package_name> <file> ...";
prerr_endline " or: ocamlfind remove [-help | other options] <package_name>";
prerr_endline " or: ocamlfind printppx [-help | other options] <package_name> ...";
prerr_endline " or: ocamlfind printconf [-help] [variable]";
prerr_endline " or: ocamlfind lint [-help] <file>";
prerr_endline " or: ocamlfind list";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment