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

Launch process without stdin by default #3677

Merged
merged 2 commits into from
Aug 7, 2020

Conversation

rgrinberg
Copy link
Member

Introduce a null input/output for processes. This can be used for
redirecting to /dev/null or running a process without stdin.

Change the default for Process.run to not read anything from stdin.
Previously, processes would inherit stdin from dune. That seems like a
bad default.

@rgrinberg rgrinberg force-pushed the process-run-redirect branch from 7019e13 to faf0887 Compare August 5, 2020 05:17
@rgrinberg rgrinberg requested review from nojb and a user and removed request for nojb August 5, 2020 05:18
@rgrinberg rgrinberg force-pushed the process-run-redirect branch from faf0887 to c996aef Compare August 5, 2020 20:15
@rgrinberg rgrinberg requested a review from aalekseyev August 5, 2020 20:25
@rgrinberg
Copy link
Member Author

Added @aalekseyev as a reviewer since he expressed interest in the PR.

@aalekseyev
Copy link
Collaborator

I think action_exec.ml also needs a fix: it uses Process.Io.stdin where it should use the null device. In fact I would imagine that's the only place that's important to fix because that's used to run user-specified actions.

I'm now confused: is your original fix intended to affect something that's not an action, or was it just not tested?

@aalekseyev
Copy link
Collaborator

By the way, that's the only remaining use of Process.Io.stdin, so we should be able to delete that.

@rgrinberg rgrinberg force-pushed the process-run-redirect branch from c996aef to 34d5466 Compare August 6, 2020 12:12
@rgrinberg
Copy link
Member Author

rgrinberg commented Aug 6, 2020

I think action_exec.ml also needs a fix: it uses Process.Io.stdin where it should use the null device. In fact I would imagine that's the only place that's important to fix because that's used to run user-specified actions.

Good call. Pushed a commit to fix this.

I'm now confused: is your original fix intended to affect something that's not an action, or was it just not tested?

My fix was meant to address #3672. So this change was sufficient to fix the cram action in this PR #3601

By the way, that's the only remaining use of Process.Io.stdin, so we should be able to delete that.

I think this is still going to be useful for #3660 so I'll leave it for now

@aalekseyev
Copy link
Collaborator

Looks good.
A small nit: it would probably make sense to have the special case | File fn1, File fn2 when Path.equal fn1 fn2 in command_line_enclosers function in process.ml to also apply in the Null, Null case.

Maybe one way to do it is to add:

let io_to_redirection_path (io : _ Io.t) = match io.kind with
  | Terminal -> None
  | Null -> Some (Lazy.force Io.null_path)
  | File fn -> Some (Path.to_string fn)

But feel free to do whatever you find expedient here.

I also wonder if we should add a changelog entry for this, since it's a behavior change that can be noticed by users in rare cases. (clearly when the command is blocked on stdin, but more subtly that can happen if the command uses stdin to determine the terminal dimensions or to decide whether or not colors should be used, etc.)

@rgrinberg rgrinberg force-pushed the process-run-redirect branch from 34d5466 to 05fdc42 Compare August 6, 2020 15:27
Introduce a `null` input/output for processes. This can be used for
redirecting to /dev/null or running a process without stdin.

Change the default for Process.run to not read anything from stdin.
Previously, processes would inherit stdin from dune. That seems like a
bad default.

Signed-off-by: Rudi Grinberg <[email protected]>
@rgrinberg rgrinberg force-pushed the process-run-redirect branch from c61a208 to 52449ef Compare August 6, 2020 22:02
@rgrinberg rgrinberg force-pushed the process-run-redirect branch from 52449ef to 44b774a Compare August 7, 2020 00:36
@rgrinberg rgrinberg merged commit fe26bce into ocaml:master Aug 7, 2020
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Aug 14, 2020
…lugin, dune-private-libs and dune-glob (2.7.0)

CHANGES:

- Write intermediate files in a `.mdx` folder for each `mdx` stanza
  to prevent the corresponding actions to be executed as part of the `@all`
  alias (ocaml/dune#3659, @NathanReb)

- Read Coq flags from `env` (ocaml/dune#3547 , fixes ocaml/dune#3486, @gares)

- Allow bisect_ppx to be enabled/disabled via dune-workspace. (ocaml/dune#3404,
  @stephanieyou)

- Formatting of dune files is now done in the executing dune process instead of
  in a separate process. (ocaml/dune#3536, @nojb)

- Add a `--debug-artifact-substution` flag to help debug problem with
  version not being captured by `dune-build-info` (ocaml/dune#3589,
  @jeremiedimino)

- Allow the use of the `context_name` variable in the `enabled_if` fields of
  executable(s) and install stanzas. (ocaml/dune#3568, fixes ocaml/dune#3566, @voodoos)

- Fix compatibility with OCaml 4.12.0 when compiling empty archives; no .a file
  is generated. (ocaml/dune#3576, @dra27)

- `$ dune utop` no longer tries to load optional libraries that are unavailable
  (ocaml/dune#3612, fixes ocaml/dune#3188, @anuragsoni)

- Fix dune-build-info on 4.10.0+flambda (ocaml/dune#3599, @emillon, @jeremiedimino).

- Allow multiple libraries with `inline_tests` to be defined in the same
  directory (ocaml/dune#3621, @rgrinberg)

- Run exit hooks in jsoo separate compilation mode (ocaml/dune#3626, fixes ocaml/dune#3622,
  @rgrinberg)

- Add (alias ...), (mode ...) fields to (copy_fields ...) stanza (ocaml/dune#3631, @nojb)

- (copy_files ...) now supports copying files from outside the workspace using
  absolute file names (ocaml/dune#3639, @nojb)

- Dune does not use `ocamlc` as an intermediary to call C compiler anymore.
  Configuration flags `ocamlc_cflags` and `ocamlc_cppflags` are always prepended
  to the compiler arguments. (ocaml/dune#3565, fixes ocaml/dune#3346, @voodoos)

- Revert the build optimization in ocaml/dune#2268. This optimization slows down building
  individual executables when they're part of an `executables` stanza group
  (ocaml/dune#3644, @rgrinberg)

- Use `{dev}` rather than `{pinned}` in the generated `.opam` file. (ocaml/dune#3647,
  @kit-ty-kate)

- Insert correct extension name when editing `dune-project` files. Previously,
  dune would just insert the stanza name. (ocaml/dune#3649, fixes ocaml/dune#3624, @rgrinberg)

- Fix crash when evaluating an `mdx` stanza that depends on unavailable
  packages. (ocaml/dune#3650, @craigfe)

- Fix typo in `cache-check-probablity` field in dune config files. This field
  now requires 2.7 as it wasn't usable before this version. (ocaml/dune#3652, @edwintorok)

- Add `"odoc" {with-doc}` to the dependencies in the generated `.opam` files.
  (ocaml/dune#3667, @kit-ty-kate)

- Do not allow user actions to capture dune's stdin (ocaml/dune#3677, fixes ocaml/dune#3672,
  @rgrinberg)

- `(subdir ...)` stanzas can now appear in dune files used via `(include ...)`.
  (ocaml/dune#3676, @nojb)
rgrinberg added a commit to rgrinberg/opam-repository that referenced this pull request Aug 14, 2020
…lugin, dune-private-libs and dune-glob (2.7.0)

CHANGES:

- Write intermediate files in a `.mdx` folder for each `mdx` stanza
  to prevent the corresponding actions to be executed as part of the `@all`
  alias (ocaml/dune#3659, @NathanReb)

- Read Coq flags from `env` (ocaml/dune#3547 , fixes ocaml/dune#3486, @gares)

- Add instrumentation framework to toggle instrumentation by `bisect_ppx`,
  `landmarks`, etc, via dune-workspace and/or the command-line. (ocaml/dune#3404, ocaml/dune#3526
  @stephanieyou, @nojb)

- Formatting of dune files is now done in the executing dune process instead of
  in a separate process. (ocaml/dune#3536, @nojb)

- Add a `--debug-artifact-substution` flag to help debug problem with
  version not being captured by `dune-build-info` (ocaml/dune#3589,
  @jeremiedimino)

- Allow the use of the `context_name` variable in the `enabled_if` fields of
  executable(s) and install stanzas. (ocaml/dune#3568, fixes ocaml/dune#3566, @voodoos)

- Fix compatibility with OCaml 4.12.0 when compiling empty archives; no .a file
  is generated. (ocaml/dune#3576, @dra27)

- `$ dune utop` no longer tries to load optional libraries that are unavailable
  (ocaml/dune#3612, fixes ocaml/dune#3188, @anuragsoni)

- Fix dune-build-info on 4.10.0+flambda (ocaml/dune#3599, @emillon, @jeremiedimino).

- Allow multiple libraries with `inline_tests` to be defined in the same
  directory (ocaml/dune#3621, @rgrinberg)

- Run exit hooks in jsoo separate compilation mode (ocaml/dune#3626, fixes ocaml/dune#3622,
  @rgrinberg)

- Add (alias ...), (mode ...) fields to (copy_fields ...) stanza (ocaml/dune#3631, @nojb)

- (copy_files ...) now supports copying files from outside the workspace using
  absolute file names (ocaml/dune#3639, @nojb)

- Dune does not use `ocamlc` as an intermediary to call C compiler anymore.
  Configuration flags `ocamlc_cflags` and `ocamlc_cppflags` are always prepended
  to the compiler arguments. (ocaml/dune#3565, fixes ocaml/dune#3346, @voodoos)

- Revert the build optimization in ocaml/dune#2268. This optimization slows down building
  individual executables when they're part of an `executables` stanza group
  (ocaml/dune#3644, @rgrinberg)

- Use `{dev}` rather than `{pinned}` in the generated `.opam` file. (ocaml/dune#3647,
  @kit-ty-kate)

- Insert correct extension name when editing `dune-project` files. Previously,
  dune would just insert the stanza name. (ocaml/dune#3649, fixes ocaml/dune#3624, @rgrinberg)

- Fix crash when evaluating an `mdx` stanza that depends on unavailable
  packages. (ocaml/dune#3650, @craigfe)

- Fix typo in `cache-check-probablity` field in dune config files. This field
  now requires 2.7 as it wasn't usable before this version. (ocaml/dune#3652, @edwintorok)

- Add `"odoc" {with-doc}` to the dependencies in the generated `.opam` files.
  (ocaml/dune#3667, @kit-ty-kate)

- Do not allow user actions to capture dune's stdin (ocaml/dune#3677, fixes ocaml/dune#3672,
  @rgrinberg)

- `(subdir ...)` stanzas can now appear in dune files used via `(include ...)`.
  (ocaml/dune#3676, @nojb)
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.

4 participants