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

Lean.Core.Context fileName is mangled on Windows #1410

Closed
1 task done
lovettchris opened this issue Aug 2, 2022 · 5 comments · Fixed by #1452
Closed
1 task done

Lean.Core.Context fileName is mangled on Windows #1410

lovettchris opened this issue Aug 2, 2022 · 5 comments · Fixed by #1452
Labels
bug Something isn't working

Comments

@lovettchris
Copy link
Contributor

lovettchris commented Aug 2, 2022

Prerequisites

  • Put an X between the brackets on this line if you have done all of the following:
    • Checked that your issue isn't already filed.
    • Reduced the issue to a self-contained, reproducible test case.

Description

elab (name := includeStr) "include_str " str:str : term => do
  let str := str.getString
  let ctx ← readThe Lean.Core.Context
  let srcPath := System.FilePath.mk ctx.fileName
  let some srcDir := srcPath.parent | throwError "{srcPath} not in a valid directory"
  let path := srcDir / str
  Lean.mkStrLit <$> IO.FS.readFile path

Steps to Reproduce

  1. try and build feat: rubiks cube sample leanprover-community/lean4-samples#3 on Windows using lake build rubiksJs

Expected behavior:

Build should succeed.

Actual behavior:

error: no such file or directory (error code: 2)
error: build failed

The problem appears to be that the beginning of the ctx.fileName is mangled like this:

\d%3A\Temp\lean4-samples\RubiksCube\Rubiks.lean

It should be as follows instead:

d:\Temp\lean4-samples\RubiksCube\Rubiks.lean

This could be related to #1257

Reproduces how often: 100%

Versions

Lean (version 4.0.0-nightly-2022-08-01, commit c76fa0681651, Release)

Additional Information

Any additional information, configuration or data that might be necessary to reproduce the issue.

@Kha
Copy link
Member

Kha commented Aug 2, 2022

I think this is DocumentUri.toPath? not supporting absolute Windows paths

@lovettchris
Copy link
Contributor Author

Is that where ctx.fileName is coming from? I couldn't find the source code, can you include a pointer to the code so I can try and fix it on my machine?

@lovettchris
Copy link
Contributor Author

Note that #1257 fixes the npm build problem, but the Rubiks cube sample still doesn't work due to this path problem, so I see this in the editor:

image

@Kha
Copy link
Member

Kha commented Aug 3, 2022

Is that where ctx.fileName is coming from? I couldn't find the source code, can you include a pointer to the code so I can try and fix it on my machine?

It's here:

/-- Return local path from file:// URI, if any. -/
def toPath? (uri : DocumentUri) : Option System.FilePath := Id.run do
if !uri.startsWith "file:///" then
return none
let mut p := uri.drop "file://".length
if System.Platform.isWindows then
p := p.map fun c => if c == '/' then '\\' else c
some ⟨p⟩
. As you can see, it's a quite naive implementation right now, it doesn't do real URL decoding.

@leodemoura leodemoura added the bug Something isn't working label Aug 4, 2022
@lovettchris
Copy link
Contributor Author

This is fixed by #1452

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants