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

ocamlc -pp needs an absolute path on Windows. #7235

Closed
davesnx opened this issue Mar 7, 2023 · 13 comments
Closed

ocamlc -pp needs an absolute path on Windows. #7235

davesnx opened this issue Mar 7, 2023 · 13 comments

Comments

@davesnx
Copy link
Contributor

davesnx commented Mar 7, 2023

Hi,

While migrating Reason to cram tests, I found something a little rare when running ocamlc on Windows. The CI running Windows with the error is here: https://dev.azure.com/reasonml/reason/_build/results?buildId=954&view=logs&j=bb2dc71e-f3f0-5721-3a31-6b3d9958e8c3&t=3667bf50-9f4f-54f0-1e4d-fdf1bef18185&l=27

I want to compile with -pp refmt_impl.exe --print binary and previously it had a script that ensures this path was absolute via cygwin. Such as https://github.com/reasonml/reason/blob/master/formatTest/test.sh#L21-L31

As @rgrinberg suggests, here's the bug report.

@nojb
Copy link
Collaborator

nojb commented Mar 7, 2023

I think the problem is not the relative path, but the forward slashes (they are not understood by cmd.exe). Can you try with backslashes?

@davesnx
Copy link
Contributor Author

davesnx commented Mar 7, 2023

Oh, totally. Backlashes might work, but I had previously ocamlc -c -pp D:/a/1/s/_esy/default/store/i/reason_cli-7cca9581/bin/refmt.exe -intf-suffix .rei -impl D:/a/1/s/formatTest/typeCheckedTests/actual_output/arityConversion.re working fine.

@nojb
Copy link
Collaborator

nojb commented Mar 7, 2023

I am not sure what Dune can do about this issue, though.

@rgrinberg
Copy link
Member

@davesnx in your actual example, I think you did the following:

  1. Add refmt_impl.exe as a dependency in the tests
  2. Added the refmt_impl.exe to PATH using env

And running refmt_impl.exe didn't work in a cram test, right?

@davesnx
Copy link
Contributor Author

davesnx commented Mar 7, 2023

 (_
  (env-vars
   (refmt "../../src/refmt/refmt_impl.exe"))))

Exactly, If I set it via env-vars. I shouldn't use $refmt in cram running Windows and I'm not aware of a way to set the env-var based on the OS.

@davesnx
Copy link
Contributor Author

davesnx commented Mar 7, 2023

If there's a way to point to different scripts or env vars based on the OS, it can be unblocked.

@nojb
Copy link
Collaborator

nojb commented Mar 7, 2023

If there's a way to point to different scripts or env vars based on the OS, it can be unblocked.

There are various ways to create a file that depends on the OS. The easiest one is:

(rule (with-stdout-to my_script my_script.%{os_type}))

This will copy my_script.Unix to my_script when you are executing on a Unix system; my_script.Win32 to my_script if running under Windows.

@davesnx
Copy link
Contributor Author

davesnx commented Mar 8, 2023

I managed to have the executable as binary with (env (binaries and then I'm able to run refmt_impl in the cram tests 🥳

(env
 (_
  (binaries
   (%{project_root}/src/refmt/refmt_impl.exe as refmt_impl))))

(cram
 (deps %{bin:ocamlc} %{bin:refmt_impl}))

but when running it with Windows I got the same problem with ocamlc:

ocamlc -c -pp "refmt_impl --print binary" -intf-suffix .rei -impl input.re
+  'refmt_impl' is not recognized as an internal or external command,

I'm not sure neither if this is an issue for dune, OCaml or a missing piece of config under Windows Azure.

@trite
Copy link

trite commented Mar 8, 2023

I think the problem is not the relative path, but the forward slashes (they are not understood by cmd.exe). Can you try with backslashes?

Just a side note on this - I don't know exactly which version of windows started to support it, but Windows Vista and above will generally treat forward slashes in paths as valid. Example from the cmd prompt on my Win11 machine (though this is a behavior I've observed since Server 2008, the server equivalent of Vista):

E:\>cd stuff/git/reason

E:\Stuff\Git\reason>

@davesnx
Copy link
Contributor Author

davesnx commented Mar 8, 2023

I made a repo in GH actions with the same error: https://github.com/davesnx/windows-bash/actions/runs/4364816084/jobs/7632603001#step:5:42

@nojb
Copy link
Collaborator

nojb commented Mar 8, 2023

Windows Vista and above will generally treat forward slashes in paths as valid.

I think we are talking about different things. Forward slashes are not understood by cmd.exe when passed in the command line, ie if you do cmd.exe /C ../foo it won't work, but if you do cmd.exe /C ..\foo then it will work. I don't think this has changed in any meaningful way recently.

@trite
Copy link

trite commented Mar 8, 2023

I think we are talking about different things. Forward slashes are not understood by cmd.exe when passed in the command line, ie if you do cmd.exe /C ../foo it won't work, but if you do cmd.exe /C ..\foo then it will work. I don't think this has changed in any meaningful way recently.

Ah, yeah it looks like in that particular case of feeding a relative path to cmd.exe things won't work out. If using the full path it should work:

E:\Stuff\Git>cmd.exe /C ../test.bat
'..' is not recognized as an internal or external command,
operable program or batch file.

E:\Stuff\Git>cmd.exe /C "../test.bat"
'..' is not recognized as an internal or external command,
operable program or batch file.

E:\Stuff\Git>cmd.exe /C ..\test.bat

E:\Stuff\Git>echo "Testing"
"Testing"

E:\Stuff\Git>cmd.exe /C e:/stuff/test.bat

E:\Stuff\Git>echo "Testing"
"Testing"

@davesnx
Copy link
Contributor Author

davesnx commented Mar 8, 2023

This solves the original issue #6326

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

No branches or pull requests

4 participants