This is an archive of the discontinued LLVM Phabricator instance.

[clang][deps] NFC: Stop going through ClangTool
ClosedPublic

Authored by jansvoboda11 on Aug 31 2021, 2:42 AM.

Details

Summary

The dependency scanner currently uses ClangTool to invoke the dependency scanning action.

However, ClangTool seems to be the wrong level of abstraction. It's intended to be run over a collection of compile commands, which we actively avoid via SingleCommandCompilationDatabase. It automatically injects -fsyntax-only and other flags, which we avoid by calling clearArgumentsAdjusters(). It deduces the resource directory based on the current executable path, which we'd like to change to deducing from argv[0].

Internally, ClangTool uses ToolInvocation which seems to be more in line with what the dependency scanner tries to achieve. This patch switches to directly using ToolInvocation instead. NFC.

Diff Detail

Event Timeline

jansvoboda11 requested review of this revision.Aug 31 2021, 2:42 AM
jansvoboda11 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2021, 2:42 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
dexonsmith accepted this revision.Aug 31 2021, 7:46 AM

LGTM. I've independently been wondering for a while whether ClangTool was doing more harm than good for the scanning usecase.

I'm approving as-is, since this is a step forward, but I'm curious if you can clarify what ToolInvocation is providing, and whether that's worth it or if it'd make sense (eventually) to go a step further.

This revision is now accepted and ready to land.Aug 31 2021, 7:46 AM

I'm approving as-is, since this is a step forward, but I'm curious if you can clarify what ToolInvocation is providing, and whether that's worth it or if it'd make sense (eventually) to go a step further.

(To be concrete, I feel any libclang API is likely to accept command-lines as something directly representable as ArrayRef<const char *>. Having to repackage that as std::vector<std::string> seems a bit unfortunate since the CompilerInvocation will want it repackaged again as ArrayRef<const char *>. But maybe ToolInvocation is doing something valuable, and certainly we could change that later.)

I think ToolInvocation is somewhat well-suited for the dependency scanner. It takes care of the DiagnosticOptions setup, running the driver, extracting source-reading cc1 command-line, creating CompilerInvocation and invoking the action itself. This is what we'd need to do anyways.

I agree that the std::vector<std::string> interface is unfortunate, especially since ToolInvocation::run converts that into std::vector<const char *> anyways. I think we can move that conversion into the current constructor that accepts std::vector<std::string>, add another constructor that takes ArrayRef<const char *> and use that from the dependency scanner.

Thanks for explaining why ToolInvocation fits well here. SGTM.

I think we can move that conversion into the current constructor that accepts std::vector<std::string>, add another constructor that takes ArrayRef<const char *> and use that from the dependency scanner.

Yeah, that makes sense. (No reason to block this though... can be done later.)

Resolve test failing on Windows by re-setting the VFS on FileManager.

This revision was landed with ongoing or failed builds.Sep 10 2021, 2:02 AM
This revision was automatically updated to reflect the committed changes.