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

Improve Windows support #248

Merged
merged 6 commits into from
Apr 1, 2022
Merged

Improve Windows support #248

merged 6 commits into from
Apr 1, 2022

Conversation

elopez
Copy link
Member

@elopez elopez commented Mar 21, 2022

This PR aims to improve Windows support on crytic-compile:

  • Fix edge cases that break on Windows
  • Fix external tool execution on windows (npx, etc.)
  • Normalize use of relative paths to be POSIX-style
  • Clean up extra leftover prints from when GH Super Linter v4 was introduced (not Windows specific)

Windows will throw ValueError and not OSError if the path is too long

    pathobj = WindowsPath('{"compilation_units": {"/home/monty/tob/tools/slither/tests/ast-parsing/function-0.6.0.sol": {"compiler":...unction abstractFunc2() public virtual override(C6) {}/n    function abstractFunc3() public virtual override {}/n}"}}')
    args = ()

        @functools.wraps(strfunc)
        def wrapped(pathobj, *args):
    >       return strfunc(str(pathobj), *args)
    E       ValueError: stat: path too long for Windows

    c:\hostedtoolcache\windows\python\3.6.8\x64\lib\pathlib.py:387: ValueError
Windows may throw an exception if the path is too long, which is
the case when the string is not really a path. Catch it and try
decoding the JSON in that case.
Some of the command executions could fail on Windows with errors
such as the following:

    FileNotFoundError: [WinError 2] The system cannot find the file specified

This is because the program name used in the command (e.g. "npm")
is unqualified, and PATH lookup is not performed on Windows when
`shell=False` is used.

We can avoid this problem by converting the executable name to a
fully-qualified path by using `shutil.which` and passing it as
`executable` on the `Popen` call.
@elopez elopez marked this pull request as draft March 21, 2022 17:34
When looking up full paths, Windows-style paths may show up, but
standardize on using POSIX-style paths for everything else.
These were introduced in bb594de ("upgrade pylint and black for super-linter v4")
and currently break Slither's tests, which expect a certain output.
@elopez elopez changed the title utils: npm: fix path detection on Windows Improve Windows support Mar 21, 2022
It is currently broken, and tries to pull a repository via git://
which GH Actions now blocks.
@0xalpharush
Copy link
Member

Is this still a draft? It might be nice to merge this so we can depend on master here crytic/slither#1137

@elopez elopez marked this pull request as ready for review March 22, 2022 17:50
@elopez
Copy link
Member Author

elopez commented Mar 22, 2022

@0xalpharush undrafted and ready for review 👍

@montyly montyly merged commit 66fe16d into dev Apr 1, 2022
@montyly montyly deleted the dev-windows-long-paths branch October 4, 2022 09:21
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.

None yet

3 participants