| 1 | //===----------------------------------------------------------------------===// |
|---|---|
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "clang/DependencyScanning/DependencyGraph.h" |
| 10 | |
| 11 | #include "clang/Serialization/ASTReader.h" |
| 12 | #include "llvm/ADT/SmallString.h" |
| 13 | |
| 14 | using namespace clang; |
| 15 | using namespace clang::dependencies; |
| 16 | |
| 17 | void ModuleDeps::forEachFileDep(llvm::function_ref<void(StringRef)> Cb) const { |
| 18 | SmallString<0> PathBuf; |
| 19 | PathBuf.reserve(N: 256); |
| 20 | for (StringRef FileDep : FileDeps) { |
| 21 | auto ResolvedFileDep = |
| 22 | ASTReader::ResolveImportedPath(Buf&: PathBuf, Path: FileDep, Prefix: FileDepsBaseDir); |
| 23 | Cb(*ResolvedFileDep); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | const std::vector<std::string> &ModuleDeps::getBuildArguments() const { |
| 28 | // FIXME: this operation is not thread safe and is expected to be called |
| 29 | // on a single thread. Otherwise, it should be protected with a lock. |
| 30 | assert(!std::holds_alternative<std::monostate>(BuildInfo) && |
| 31 | "Using uninitialized ModuleDeps"); |
| 32 | if (const auto *CI = std::get_if<CowCompilerInvocation>(ptr: &BuildInfo)) |
| 33 | BuildInfo = CI->getCC1CommandLine(); |
| 34 | return std::get<std::vector<std::string>>(v&: BuildInfo); |
| 35 | } |
| 36 |