From 588fc2ba282014fde5446c2e9b344260bb8c4439 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Fri, 24 May 2019 22:33:24 +0700 Subject: [PATCH] Run ocamlformat from build context root This will output errors relative to the correct directory. Signed-off-by: Rudi Grinberg --- CHANGES.md | 3 +++ src/format_rules.ml | 3 ++- test/blackbox-tests/test-cases/formatting/run.t | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 90fcc2ad271..f460ab964c1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -77,6 +77,9 @@ unreleased - Support the `.cc` extension fro C++ sources (#2195, fixes #83, @rgrinberg) +- Run `ocamlformat` relative to the context root. This improves the locations of + errors. (#2196, fixes #1370, @rgrinberg) + 1.9.3 (06/05/2019) ------------------ diff --git a/src/format_rules.ml b/src/format_rules.ml index 74499b5d7fe..b097e93b9b8 100644 --- a/src/format_rules.ml +++ b/src/format_rules.ml @@ -61,7 +61,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 exe args) + Some (Lazy.force ocamlformat_deps + >>> Build.run ~dir:(Super_context.build_dir sctx) exe args) else None in diff --git a/test/blackbox-tests/test-cases/formatting/run.t b/test/blackbox-tests/test-cases/formatting/run.t index 4a9f7f33ad5..8c2e4be6f9a 100644 --- a/test/blackbox-tests/test-cases/formatting/run.t +++ b/test/blackbox-tests/test-cases/formatting/run.t @@ -77,7 +77,7 @@ And fixable files can be promoted: Promoting _build/default/enabled/.formatted/ocaml_file.ml to enabled/ocaml_file.ml. Promoting _build/default/enabled/.formatted/reason_file.re to enabled/reason_file.re. $ cat enabled/ocaml_file.ml - Sys.argv: ../../install/default/bin/ocamlformat --impl ocaml_file.ml --name ../../../enabled/ocaml_file.ml -o .formatted/ocaml_file.ml + Sys.argv: ../install/default/bin/ocamlformat --impl enabled/ocaml_file.ml --name ../../enabled/ocaml_file.ml -o enabled/.formatted/ocaml_file.ml ocamlformat output $ cat enabled/reason_file.re Sys.argv: ../../install/default/bin/refmt reason_file.re