This is an archive of the discontinued LLVM Phabricator instance.

[GN] Locate prebuilt binaries correctly.
AbandonedPublic

Authored by hctim on Mar 5 2019, 3:31 PM.

Details

Summary

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.

Event Timeline

hctim created this revision.Mar 5 2019, 3:31 PM
pcc added a subscriber: pcc.Mar 5 2019, 4:01 PM
pcc added inline comments.
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.

thakis added a comment.Mar 5 2019, 5:30 PM

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']...

pcc added inline comments.Mar 5 2019, 5:48 PM
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:
https://docs.python.org/2/library/subprocess.html

thakis added inline comments.Mar 7 2019, 1:00 PM
llvm/utils/gn/gn.py
41

hctim, does using subprocess.call('gn --version', ..., shell=True) work for you?

hctim added inline comments.Mar 7 2019, 1:16 PM
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?

thakis added inline comments.Mar 7 2019, 2:13 PM
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.

hctim marked an inline comment as done.Mar 7 2019, 2:20 PM
hctim added inline comments.
llvm/utils/gn/gn.py
41

No problems. I've sumitted the small change as rL355645. Will abandon this change :)

hctim abandoned this revision.Mar 7 2019, 2:20 PM