Skip to content

Commit

Permalink
Run ocamlformat from build context root
Browse files Browse the repository at this point in the history
This will output errors relative to the correct directory.

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed May 27, 2019
1 parent 0ac200f commit a28666f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
2 changes: 0 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ unreleased
- Run `ocamlformat` relative to the context root. This improves the locations of
errors. (#..., fixes #1370, @rgrinberg)

- Support the `.cc` extension fro C++ sources (#2195, fixes #83, @rgrinberg)

1.9.3 (06/05/2019)
------------------

Expand Down
11 changes: 4 additions & 7 deletions src/format_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,15 @@ let gen_rules_output sctx (config : Dune_file.Auto_format.t) ~output_dir =
let resolve_program =
Super_context.resolve_program ~dir sctx ~loc:(Some loc) in
let ocamlformat_deps = lazy (
depend_on_files ~named:[".ocamlformat"; ".ocamlformat-ignore"] (Path.source source_dir)
depend_on_files ~named:[".ocamlformat"; ".ocamlformat-ignore"]
(Path.source source_dir)
) in
let setup_formatting file =
let open Build.O in
let input_basename = Path.Source.basename file in
let input = Path.relative dir input_basename in
let output = Path.relative output_dir input_basename in

let run_build_root =
let dir = Super_context.build_dir sctx in
Build.run ~dir
in

let ocaml kind =
if Dune_file.Auto_format.includes config Ocaml then
let exe = resolve_program "ocamlformat" in
Expand All @@ -64,7 +60,8 @@ let gen_rules_output sctx (config : Dune_file.Auto_format.t) ~output_dir =
; Target output
]
in
Some (Lazy.force ocamlformat_deps >>> Build.run ~dir:(Super_context.build_dir sctx) exe args)
Some (Lazy.force ocamlformat_deps
>>> Build.run ~dir:(Super_context.build_dir sctx) exe args)
else
None
in
Expand Down

0 comments on commit a28666f

Please sign in to comment.