This is an archive of the discontinued LLVM Phabricator instance.

[Support][Program] Add findProgramByName(Name, OptionalPaths)
ClosedPublic

Authored by Bigcheese on Oct 31 2014, 3:38 PM.

Details

Reviewers
rafael
asl
Summary

This adds a replacement for FindProgramByName that accepts an optional list of paths to search. The main intent of this change is to move the code in Clang that searches for tools over to this API so that we correctly find .exe files on Windows.

Followup patches move all users of FindProgramByName over and remove it.

Diff Detail

Event Timeline

Bigcheese updated this revision to Diff 15656.Oct 31 2014, 3:38 PM
Bigcheese retitled this revision from to [Support][Program] Add findProgramByName(Name, OptionalPaths).
Bigcheese updated this object.
Bigcheese edited the test plan for this revision. (Show Details)
Bigcheese added reviewers: aaron.ballman, asl.
Bigcheese set the repository for this revision to rL LLVM.
Bigcheese added a subscriber: Unknown Object (MLST).

Seems a reasonable API. I just have a few small questions.

include/llvm/Support/Program.h
69

Why do we need the Optional? Can't we just use an empty Paths as a special value that means "read $PATH"?

lib/Support/Unix/Program.inc
107

Can't we just say that name should not be empty and assert? It looks like a misuse of the API, not an error.

114

Why do you need the extra storage for all cases? Can't this be

if (using $PATH) {

build the array
return  recurse passing the array

}

use the arrayref argument directly

Testcase ?

lib/Support/Unix/Program.inc
111

StringRef::npos ?

Bigcheese planned changes to this revision.Nov 3 2014, 12:50 PM
Bigcheese added inline comments.
include/llvm/Support/Program.h
69

K.

lib/Support/Unix/Program.inc
107

I was duplicating the behavior of FindProgramByName. I'm not sure if anything relies on the behavior.

111

K.

114

K.

rafael wrote:

Can't we just say that name should not be empty and assert? It looks like a misuse of the API, not an error.

I was duplicating the behavior of FindProgramByName. I'm not sure if anything relies on the behavior.

Lets assert and find out.

Bigcheese updated this revision to Diff 15732.Nov 3 2014, 2:23 PM

Address review comments.

rafael added inline comments.Nov 3 2014, 2:53 PM
lib/Support/Unix/Program.inc
107

assert

116

on windows it is ; instead of :, no.

120

Redundant if. Just let the for iterate 0 times.

130

.c_str() since we have a SmallString anyway.

Bigcheese planned changes to this revision.Nov 3 2014, 3:27 PM
Bigcheese added inline comments.
lib/Support/Unix/Program.inc
107

K.

116

This is UNIX only code.

120

K.

130

K.

Bigcheese updated this revision to Diff 15739.Nov 3 2014, 4:02 PM

Addressed review comments.

rafael accepted this revision.Nov 3 2014, 4:47 PM
rafael added a reviewer: rafael.

LGTM.

This revision is now accepted and ready to land.Nov 3 2014, 4:47 PM
aaron.ballman resigned from this revision.Oct 13 2015, 5:57 AM
aaron.ballman removed a reviewer: aaron.ballman.
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in r221220.