Skip to content

Conversation

@hhugo
Copy link
Collaborator

@hhugo hhugo commented Jun 24, 2024

Add a test that we can handle commands bigger that 8k characters.
Fix the windows implementation that previously had a 8K limit.

@hhugo
Copy link
Collaborator Author

hhugo commented Jun 24, 2024

On windows, the limit seems to be ~8185 which seems very close to the 8192 character limit imposed by CMD.EXE. Yet, we're not longer supposed to go through cmd.exe.
@dra27, any idea where the current limit could be coming from ?

@hhugo hhugo force-pushed the longcmd branch 2 times, most recently from 9c2fbc6 to e67e55c Compare June 24, 2024 13:03
@hhugo
Copy link
Collaborator Author

hhugo commented Jun 24, 2024

With this PR, I believe we now have all important piece of code of fdopen's patches. The maintenance of ocamlbuild can return to its previous state :)

@hhugo hhugo mentioned this pull request Jun 24, 2024
@hhugo hhugo requested a review from gasche June 24, 2024 13:29
@hhugo
Copy link
Collaborator Author

hhugo commented Jun 24, 2024

With this PR, I believe we now have all important piece of code of fdopen's patches. The maintenance of ocamlbuild can return to its previous state :)

To be more explicit, there are still things present in fdopen patches and absent from upstream but I don't think they are necessary.

  • normalize path with forward slash
  • set stdout to binary mode to avoid CRLF

Copy link
Member

@gasche gasche left a comment

Choose a reason for hiding this comment

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

prepare_command_for_windows is a bit of a spaghetti soup now, but I don't see an obvious way to avoid this. (We can use Fun.protect but annoyingly none of the cleanup logic fits its restricted expressivity.) Oh well.

src/my_std.ml Outdated
|| string_exists (function ' ' | '\"'| '\t' -> true | _ -> false) f
then Filename.quote f
else f
in
Copy link
Member

Choose a reason for hiding this comment

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

Could we just compute the size of Filename.quote f? This over-approximates but probably not by a lot, and it makes the code simpler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

| Unix.WEXITED _ | Unix.WSIGNALED _ | Unix.WSTOPPED _ ->
failwith (Printf.sprintf "Error while running: %s" s) in
Option.iter (fun f -> f ()) cleanup;
failwith (Printf.sprintf "Error while running: %s" s) in
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we would benefit from splitting the two paths more.

Untested:

let close ic = ... in
if not Sys.win32 then begin
  let ic = Unix.open_process_in s in
  Fun.protect ~finally:(fun () -> close ic) @@ fun () ->
  kont ic
else
  let args, cleanup = My_std.prepare_command_for_windows s in
  let ic = Unix.open_process_args_in args.(0) args in
  Fun.protect ~finally:cleanup @@ fun () ->
  Fun.protect ~finally:(fun () -> close ic) @@ fun () ->
  kont ic

Copy link
Member

Choose a reason for hiding this comment

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

(Or whatever style other than @@ fun () -> that you prefer or find more consistent with the codebase.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This patch makes the CI complain because it changes the exception raise:

  • previously: Failure ...
  • with this patch: Finally_raised ..

I'll revert that part

Hugo Heuzard added 2 commits June 24, 2024 16:58
@hhugo hhugo merged commit 6bbb1c0 into master Jun 24, 2024
@hhugo hhugo deleted the longcmd branch June 24, 2024 15:24
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.

3 participants