Skip to content

Commit

Permalink
Add remark about rule ordering
Browse files Browse the repository at this point in the history
(with Changes from Gabriel Scherer)
  • Loading branch information
rleonid authored and gasche committed Apr 20, 2016
1 parent 9913611 commit f24ff6b
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions manual.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1150,6 +1150,8 @@ OCamlbuild let you build your own rules, to teach it how to build new kind of ta
This is done by calling the `rule` function from a plugin, which is declared and documented in the `PLUGIN` module in `signatures.mli`.
We will not write an exhaustive documentation here (for this, have a look at `signatures.mli`), but rather expose the most common features through representative examples.

=== A simple rule

Our first example is simple, as it is a rule without dynamic dependencies:

[source,ocaml]
Expand Down Expand Up @@ -1302,6 +1304,22 @@ rule "ocaml C stubs: clib & (o|obj)* -> (a|lib) & (so|dll)"
~dep:"%(path)lib%(libname).clib"
----

==== Rule ordering and `~insert`

One cannot define a rule if there already exists a built-in rule of the same name.
Directly including the rule `"ocaml dependencies ml"` used above in your plugin would result in a failure when loading the plugin:

[source]
----
Rule.Exit_rule_error("Rule.add_rule: already exists: (ocaml dependencies ml)").
----

Even if you pick another name for the rule, you may find out that the rule you are defining is not used.
OCamlbuild orders rule definitions, and the new rule needs to come _before_ the rule that it is replacing.

Use the `~insert` argument to `rule` to either (suggested) place it before the built in rule (`~insert:(`before "ocaml dependencies ml)`) or at the top (`~insert:(`top)`).
The default behavior, in absence of `~insert` argument, is to place custom rules at the bottom; this is fine when defining rules for new targets, but not when overriding built-in rules.

=== Complete example: Menhir support in OCamlbuild

[source,ocaml]
Expand Down

0 comments on commit f24ff6b

Please sign in to comment.