Currently downloading a prebuilt binary and not having it on $PATH fails ungracefully, as subprocess.call doesn't like being called to a binary that doesn't exist. This should hopefully solve this problem for Linux, OSX and Windows, but I can only test the Linux component.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
- Build Status
Buildable 28818 Build 28817: arc lint + arc unit
Event Timeline
llvm/utils/gn/gn.py | ||
---|---|---|
41 | Maybe you could pass shell=True here instead? On my machine at least, that causes the shell to fail if the command is not found instead of an exception being thrown. |
Thanks for the patch1
llvm/utils/gn/gn.py | ||
---|---|---|
41 | I like this suggestion, but shell=True means that the args array is interpreted differently on Win and non-Win. On non-Win, the args are passed to the shell and you have to make the first item something like 'gn --version' as a single string, while on Windows iirc you have to have two list entries (or the other way round)? | |
47 | There's distutils.spawn.find_executable() which does this, but it has the problem that if you happen to have depot_tools on your path, that includes a dummy gn binary that tries to forward to some real gn binary that's present in depot_tools using projects but not in llvm. So this would claim that the system binary is available but it would then fail to run. So you'd have to check not system_binary_available(gn) or subprocess.call([gn, '--version']... |
llvm/utils/gn/gn.py | ||
---|---|---|
41 | A quick test on Linux and Windows reveals that passing a string instead of an array for args appears to do the same thing on both platforms. This is also how the documentation suggests using subprocess.call with shell=True: |
llvm/utils/gn/gn.py | ||
---|---|---|
41 | hctim, does using subprocess.call('gn --version', ..., shell=True) work for you? |
llvm/utils/gn/gn.py | ||
---|---|---|
41 | Yep, adding shell=True works fine for me. Would you prefer that oneliner to be committed or this change? |
llvm/utils/gn/gn.py | ||
---|---|---|
41 | I'd prefer the oneliner since this change as-is breaks the depot_tools-with-existing-but-broken-gn-binary-on-path use case. |
There's distutils.spawn.find_executable() which does this, but it has the problem that if you happen to have depot_tools on your path, that includes a dummy gn binary that tries to forward to some real gn binary that's present in depot_tools using projects but not in llvm. So this would claim that the system binary is available but it would then fail to run.
So you'd have to check not system_binary_available(gn) or subprocess.call([gn, '--version']...