HaxeFoundation / HaxeFoundation/haxe
Using `lib` argument causes Haxe to access system shell
- Dominant language
- Haxe
- Stars
- 6.9k
- Forks
- 715
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 11
Description
I'd like to use the Haxe compiler in Windows environments where access to cmd.exe is restricted (which is not uncommon in, for example, schools).
Two arguments passed to the haxe compiler will cause the compiler to invoke cmd.exe to start a new process. These are `cmd` and `lib`.
See:
https://ocaml.org/api/Unix.html#VALopen_process_full
https://ocaml.org/api/Unix.html#VALsystem
> The command is interpreted by the shell `/bin/sh` (or `cmd.exe` on Windows), cf. `Unix.system`. The `Filename.quote_command` function can be used to quote the command and its arguments as appropriate for the shell being used. If the command does not need to be run through the shell, `Unix.open_process_args_in` can be used as a more robust and more efficient alternative to `Unix.open_process_in`.
`cmd`:
https://github.com/HaxeFoundation/haxe/blob/e70ba872494dfd5d93c11f721d1e11c1f2087be2/src/compiler/haxe.ml#L170
https://github.com/HaxeFoundation/haxe/blob/e70ba872494dfd5d93c11f721d1e11c1f2087be2/src/compiler/haxe.ml#L187
`lib`:
https://github.com/HaxeFoundation/haxe/blob/e70ba872494dfd5d93c11f721d1e11c1f2087be2/src/compiler/haxe.ml#L111
I think that `cmd` has the expectation of being passed to the system shell, so it makes sense to simply avoid using `cmd` as an argument if shell/interpreter access isn't available. I would expect `lib`, on the other hand, not to need to use the shell. Is it possible to replace `open_process_full` with `open_process_args_full` for the case of `lib`?
In my case, the Haxe compiler is started from inside an IDE. I can simply have the IDE automatically read the hxml file, find `lib` arguments, run `haxelib path {libs}`, and replace the `lib` arguments with the appropriate classpaths and defines. Then there will be no `cmd.exe` access and things will work as expected. However, the behavior is a little bit surprising as-is.
Contributor guide
Research direction
Start in src/compiler/haxe.ml at the linked lines for the lib argument, then compare the referenced OCaml process APIs and the cmd handling nearby. Done means lib resolution no longer invokes cmd.exe while preserving its expected compiler behavior; verify the result in a restricted Windows shell environment.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- compilers, operating-systems
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100