-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[clang][DependencyScanning] Remove dependency on clangDriver from clangDependencyScanning #169964
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
Closed
naveen-seth
wants to merge
7
commits into
llvm:main
from
naveen-seth:remove-clangDriver-dep-from-clangDependencyScanning
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
99dd142
[clang][DependencyScanning] Remove dependency on clangDriver from cla…
naveen-seth b0a4102
Fix small doxygen comment issue caused during rebase
naveen-seth 450f189
Another comment formatting fix
naveen-seth 68832dc
Merge branch 'main' into remove-clangDriver-dep-from-clangDependencyS…
naveen-seth ea5222a
Remove duplicate clangDependencyScanning entry in CMakeLists.txt
naveen-seth d2a6306
Remove tests for by-module-name scan with command line input
naveen-seth a3e4b95
fixup! Remove tests for by-module-name scan with command line input
naveen-seth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,9 +9,11 @@ | |||||||||||||||||||||||||||||||||
| #ifndef LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H | ||||||||||||||||||||||||||||||||||
| #define LLVM_CLANG_DEPENDENCYSCANNING_DEPENDENCYSCANNINGWORKER_H | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| #include "clang/Basic/Diagnostic.h" | ||||||||||||||||||||||||||||||||||
| #include "clang/Basic/DiagnosticOptions.h" | ||||||||||||||||||||||||||||||||||
| #include "clang/Basic/FileManager.h" | ||||||||||||||||||||||||||||||||||
| #include "clang/Basic/LLVM.h" | ||||||||||||||||||||||||||||||||||
| #include "clang/DependencyScanning/DependencyScannerImpl.h" | ||||||||||||||||||||||||||||||||||
| #include "clang/DependencyScanning/DependencyScanningService.h" | ||||||||||||||||||||||||||||||||||
| #include "clang/DependencyScanning/ModuleDepCollector.h" | ||||||||||||||||||||||||||||||||||
| #include "clang/Frontend/PCHContainerOperations.h" | ||||||||||||||||||||||||||||||||||
|
|
@@ -91,70 +93,72 @@ class DependencyScanningWorker { | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| ~DependencyScanningWorker(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// Run the dependency scanning tool for a given clang driver command-line, | ||||||||||||||||||||||||||||||||||
| /// and report the discovered dependencies to the provided consumer. If | ||||||||||||||||||||||||||||||||||
| /// TUBuffer is not nullopt, it is used as TU input for the dependency | ||||||||||||||||||||||||||||||||||
| /// scanning. Otherwise, the input should be included as part of the | ||||||||||||||||||||||||||||||||||
| /// command-line. | ||||||||||||||||||||||||||||||||||
| /// Run the dependency scanning tool for a given clang -cc1 command-line, | ||||||||||||||||||||||||||||||||||
| /// and report the discovered dependencies to the provided consumer. | ||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||
| /// \returns false if clang errors occurred (with diagnostics reported to | ||||||||||||||||||||||||||||||||||
| /// \return false if clang errors occurred (with diagnostics reported to | ||||||||||||||||||||||||||||||||||
| /// \c DiagConsumer), true otherwise. | ||||||||||||||||||||||||||||||||||
| bool computeDependencies( | ||||||||||||||||||||||||||||||||||
| StringRef WorkingDirectory, const std::vector<std::string> &CommandLine, | ||||||||||||||||||||||||||||||||||
| DependencyConsumer &DepConsumer, DependencyActionController &Controller, | ||||||||||||||||||||||||||||||||||
| DiagnosticConsumer &DiagConsumer, | ||||||||||||||||||||||||||||||||||
| std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt); | ||||||||||||||||||||||||||||||||||
| llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> ScanFS = nullptr); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// Run the dependency scanning tool for a given clang driver command-line | ||||||||||||||||||||||||||||||||||
| /// for a specific translation unit via file system or memory buffer. | ||||||||||||||||||||||||||||||||||
| /// Run the dependency scanning tool for all given clang -cc1 command-lines, | ||||||||||||||||||||||||||||||||||
| /// and report the discovered dependencies to the provided consumer. | ||||||||||||||||||||||||||||||||||
| /// | ||||||||||||||||||||||||||||||||||
| /// \returns A \c StringError with the diagnostic output if clang errors | ||||||||||||||||||||||||||||||||||
| /// occurred, success otherwise. | ||||||||||||||||||||||||||||||||||
| llvm::Error computeDependencies( | ||||||||||||||||||||||||||||||||||
| StringRef WorkingDirectory, const std::vector<std::string> &CommandLine, | ||||||||||||||||||||||||||||||||||
| /// \returns false if clang errors occurred (with diagnostics reported to | ||||||||||||||||||||||||||||||||||
| /// \c Diags), true otherwise. | ||||||||||||||||||||||||||||||||||
| bool computeDependencies( | ||||||||||||||||||||||||||||||||||
| StringRef WorkingDirectory, | ||||||||||||||||||||||||||||||||||
| ArrayRef<std::vector<std::string>> CommandLines, | ||||||||||||||||||||||||||||||||||
| DependencyConsumer &Consumer, DependencyActionController &Controller, | ||||||||||||||||||||||||||||||||||
| std::optional<llvm::MemoryBufferRef> TUBuffer = std::nullopt); | ||||||||||||||||||||||||||||||||||
| DiagnosticsEngine &Diags, | ||||||||||||||||||||||||||||||||||
| llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> ScanFS = nullptr); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// The three method below implements a new interface for by name | ||||||||||||||||||||||||||||||||||
| /// dependency scanning. They together enable the dependency scanning worker | ||||||||||||||||||||||||||||||||||
| /// to more effectively perform scanning for a sequence of modules | ||||||||||||||||||||||||||||||||||
| /// by name when the CWD and CommandLine do not change across the queries. | ||||||||||||||||||||||||||||||||||
| /// The initialization function asks the client for a DiagnosticsConsumer | ||||||||||||||||||||||||||||||||||
| /// that it direct the diagnostics to. | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// @brief Initializing the context and the compiler instance. | ||||||||||||||||||||||||||||||||||
| /// @param CWD The current working directory used during the scan. | ||||||||||||||||||||||||||||||||||
| /// @param CommandLine The commandline used for the scan. | ||||||||||||||||||||||||||||||||||
| /// @return Error if the initializaiton fails. | ||||||||||||||||||||||||||||||||||
| llvm::Error initializeCompilerInstanceWithContextOrError( | ||||||||||||||||||||||||||||||||||
| StringRef CWD, const std::vector<std::string> &CommandLine); | ||||||||||||||||||||||||||||||||||
| /// @return False if the initializaiton fails. | ||||||||||||||||||||||||||||||||||
| bool initializeCompilerInstanceWithContext(StringRef CWD, | ||||||||||||||||||||||||||||||||||
| ArrayRef<std::string> CommandLine, | ||||||||||||||||||||||||||||||||||
| DiagnosticConsumer &DC); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// @brief Initializing the context and the compiler instance. | ||||||||||||||||||||||||||||||||||
| /// @param CWD The current working directory used during the scan. | ||||||||||||||||||||||||||||||||||
| /// @param CommandLine The commandline used for the scan. | ||||||||||||||||||||||||||||||||||
| /// @param DiagEngineWithCmdAndOpts Preconfigured diagnostics engine and | ||||||||||||||||||||||||||||||||||
| /// options associated with the cc1 command line. | ||||||||||||||||||||||||||||||||||
| /// @param FS The file system (typically an overlay) to use for this compiler | ||||||||||||||||||||||||||||||||||
| /// instance. | ||||||||||||||||||||||||||||||||||
| /// @return False if the initializaiton fails. | ||||||||||||||||||||||||||||||||||
| bool initializeCompilerInstanceWithContext( | ||||||||||||||||||||||||||||||||||
| StringRef CWD, ArrayRef<std::string> CommandLine, | ||||||||||||||||||||||||||||||||||
| std::unique_ptr<DignosticsEngineWithDiagOpts> DiagEngineWithCmdAndOpts, | ||||||||||||||||||||||||||||||||||
| IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// @brief Performaces dependency scanning for the module whose name is | ||||||||||||||||||||||||||||||||||
| /// specified. | ||||||||||||||||||||||||||||||||||
| /// @param ModuleName The name of the module whose dependency will be | ||||||||||||||||||||||||||||||||||
| /// scanned. | ||||||||||||||||||||||||||||||||||
| /// @param Consumer The dependency consumer that stores the results. | ||||||||||||||||||||||||||||||||||
| /// @param Controller The controller for the dependency scanning action. | ||||||||||||||||||||||||||||||||||
| /// @return Error if the scanner incurs errors. | ||||||||||||||||||||||||||||||||||
| llvm::Error computeDependenciesByNameWithContextOrError( | ||||||||||||||||||||||||||||||||||
| StringRef ModuleName, DependencyConsumer &Consumer, | ||||||||||||||||||||||||||||||||||
| DependencyActionController &Controller); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// @brief Finalizes the diagnostics engine and deletes the compiler instance. | ||||||||||||||||||||||||||||||||||
| /// @return Error if errors occur during finalization. | ||||||||||||||||||||||||||||||||||
| llvm::Error finalizeCompilerInstanceWithContextOrError(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// The three methods below provides the same functionality as the | ||||||||||||||||||||||||||||||||||
| /// three methods above. Instead of returning `llvm::Error`s, these | ||||||||||||||||||||||||||||||||||
| /// three methods return a flag to indicate if the call is successful. | ||||||||||||||||||||||||||||||||||
| /// The initialization function asks the client for a DiagnosticsConsumer | ||||||||||||||||||||||||||||||||||
| /// that it direct the diagnostics to. | ||||||||||||||||||||||||||||||||||
| bool initializeCompilerInstanceWithContext( | ||||||||||||||||||||||||||||||||||
| StringRef CWD, const std::vector<std::string> &CommandLine, | ||||||||||||||||||||||||||||||||||
| DiagnosticConsumer *DC = nullptr); | ||||||||||||||||||||||||||||||||||
| /// @return False if the scanner incurs errors. | ||||||||||||||||||||||||||||||||||
| bool | ||||||||||||||||||||||||||||||||||
| computeDependenciesByNameWithContext(StringRef ModuleName, | ||||||||||||||||||||||||||||||||||
| DependencyConsumer &Consumer, | ||||||||||||||||||||||||||||||||||
| DependencyActionController &Controller); | ||||||||||||||||||||||||||||||||||
| bool finalizeCompilerInstance(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// @brief Finalizes the diagnostics engine and deletes the compiler instance. | ||||||||||||||||||||||||||||||||||
| /// @return False if errors occur during finalization. | ||||||||||||||||||||||||||||||||||
| bool finalizeCompilerInstanceWithContext(); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| llvm::vfs::FileSystem &getVFS() const { return *DepFS; } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
@@ -169,13 +173,21 @@ class DependencyScanningWorker { | |||||||||||||||||||||||||||||||||
| friend CompilerInstanceWithContext; | ||||||||||||||||||||||||||||||||||
| std::unique_ptr<CompilerInstanceWithContext> CIWithContext; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /// Actually carries out the scan. If \c OverlayFS is provided, it must be | ||||||||||||||||||||||||||||||||||
| /// based on top of DepFS. | ||||||||||||||||||||||||||||||||||
| bool scanDependencies( | ||||||||||||||||||||||||||||||||||
| StringRef WorkingDirectory, const std::vector<std::string> &CommandLine, | ||||||||||||||||||||||||||||||||||
| DependencyConsumer &Consumer, DependencyActionController &Controller, | ||||||||||||||||||||||||||||||||||
| DiagnosticConsumer &DC, | ||||||||||||||||||||||||||||||||||
| IntrusiveRefCntPtr<llvm::vfs::FileSystem> OverlayFS = nullptr); | ||||||||||||||||||||||||||||||||||
| /// Private helper functions to actually carry out the scan. If \c OverlayFS | ||||||||||||||||||||||||||||||||||
| /// is provided, it must be based on top of DepFS. | ||||||||||||||||||||||||||||||||||
| bool scanDependencies(StringRef WorkingDirectory, | ||||||||||||||||||||||||||||||||||
| const std::vector<std::string> &CommandLine, | ||||||||||||||||||||||||||||||||||
| DependencyConsumer &Consumer, | ||||||||||||||||||||||||||||||||||
| DependencyActionController &Controller, | ||||||||||||||||||||||||||||||||||
| DiagnosticConsumer &DC, | ||||||||||||||||||||||||||||||||||
| llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS); | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| bool scanDependencies(StringRef WorkingDirectory, | ||||||||||||||||||||||||||||||||||
| ArrayRef<std::vector<std::string>> CommandLine, | ||||||||||||||||||||||||||||||||||
| DependencyConsumer &Consumer, | ||||||||||||||||||||||||||||||||||
| DependencyActionController &Controller, | ||||||||||||||||||||||||||||||||||
| DiagnosticsEngine &Diags, | ||||||||||||||||||||||||||||||||||
| llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS); | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: these two function declarations look too similar to my eyes. Maybe we can do something along the following line:
Suggested change
Note the renamed functions, and the reordered parameter lists. |
||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| } // end namespace dependencies | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we please keep this as
OverlayFS? I personally have a hard time figuring out what all these VFSs flying around do, so being super clear what these are is helpful. Same for the internal functions below.