Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept correction files produced by ppx_driver #415

Merged
2 commits merged into from
Jan 16, 2018
Merged

Conversation

ghost
Copy link

@ghost ghost commented Jan 15, 2018

This PR makes [@@deriving_inline ...] works with jbuilder. It requires: janestreet-deprecated/ppx_driver#17

Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question and a couple of minor things.

Build.progn
[ build
; Build.return
(A.promote_if
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really worth introducing a module alias just for this one use?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just that super_context defines an Action module as well, so we get a name clash

| Some _ | None -> false

let promote_correction ~uses_ppx_driver fn build =
if not uses_ppx_driver then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small nit: I find else clauses in if (not ...) confusing and prefer if not x then foo else bar to turn to if x then bar else foo.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I find if/match expressions easier to read when the simple choice is first. That's why I wrote it this way

src/action.ml Outdated
@@ -744,7 +745,8 @@ let rec exec t ~ectx ~dir ~env_extra ~stdout_to ~stderr_to =
match mode with
| Always -> files
| If_corrected_file_exists ->
List.filter files ~f:(fun file -> Path.exists file.Promote.src)
List.filter files ~f:(fun { Promote. src; dst } ->
Path.exists src && Path.exists dst)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to make sure that the destination exists now?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically we must not promote the file if it's generated. But maybe we should do that check in super_context.ml instead

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this more, doing nothing when the source file doesn't exist seems wrong. For instance if the user generates a file containing some [@@deriving_inline ...] attribute, then we at least want to check that they are correct.

I guess promote-if could have the following behavior: print the diff but only promote if the source file exist as well.

@ghost
Copy link
Author

ghost commented Jan 16, 2018

I did the change for promote-if.

I also adapted the code so that -diff-cmd - is passed only if ppx_driver supports it. To do that ppx_driver installs a file config.sexp that contains has-diff-cmd-dash.

@ghost
Copy link
Author

ghost commented Jan 16, 2018

actually that's not necessary, the worse that can happen is that ppx_driver will try to run - file1 file2 and we'll get a weird weeor

@ghost ghost force-pushed the ppx-driver-corrected branch from 4ccfae3 to ae13072 Compare January 16, 2018 12:24
@ghost ghost merged commit 49edf8e into master Jan 16, 2018
@ghost
Copy link
Author

ghost commented Jan 16, 2018

We can merge this now then, I submitted a new minor release of ppx_driver: ocaml/opam-repository#11236

@ghost ghost deleted the ppx-driver-corrected branch February 7, 2018 14:48
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant