CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
104 lines
3.9 KiB
C++
104 lines
3.9 KiB
C++
//===- DependencyScanningWorker.cpp - Thread-Safe Scanning Worker ---------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "clang/DependencyScanning/DependencyScanningWorker.h"
|
|
#include "clang/Basic/Diagnostic.h"
|
|
#include "clang/Basic/DiagnosticFrontend.h"
|
|
#include "clang/DependencyScanning/DependencyConsumer.h"
|
|
#include "clang/DependencyScanning/DependencyScannerImpl.h"
|
|
#include "clang/Serialization/ObjectFilePCHContainerReader.h"
|
|
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
|
#include "llvm/Support/VirtualFileSystem.h"
|
|
|
|
using namespace clang;
|
|
using namespace dependencies;
|
|
|
|
DependencyScanningWorker::DependencyScanningWorker(
|
|
DependencyScanningService &Service)
|
|
: Service(Service) {
|
|
PCHContainerOps = std::make_shared<PCHContainerOperations>();
|
|
// We need to read object files from PCH built outside the scanner.
|
|
PCHContainerOps->registerReader(
|
|
std::make_unique<ObjectFilePCHContainerReader>());
|
|
// The scanner itself writes only raw ast files.
|
|
PCHContainerOps->registerWriter(std::make_unique<RawPCHContainerWriter>());
|
|
|
|
auto BaseFS = Service.getOpts().MakeVFS();
|
|
|
|
if (Service.getOpts().TraceVFS) {
|
|
TracingFS = llvm::makeIntrusiveRefCnt<llvm::vfs::TracingFileSystem>(
|
|
std::move(BaseFS));
|
|
BaseFS = TracingFS;
|
|
}
|
|
|
|
DepFS = llvm::makeIntrusiveRefCnt<DependencyScanningWorkerFilesystem>(
|
|
Service, std::move(BaseFS));
|
|
}
|
|
|
|
DependencyScanningWorker::~DependencyScanningWorker() = default;
|
|
|
|
static bool createAndRunToolInvocation(
|
|
ArrayRef<std::string> CommandLine, DependencyScanningAction &Action,
|
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS,
|
|
std::shared_ptr<clang::PCHContainerOperations> &PCHContainerOps,
|
|
DiagnosticsEngine &Diags) {
|
|
auto Invocation = createCompilerInvocation(CommandLine, Diags);
|
|
if (!Invocation)
|
|
return false;
|
|
|
|
return Action.runInvocation(CommandLine[0], std::move(Invocation),
|
|
std::move(FS), PCHContainerOps,
|
|
Diags.getClient());
|
|
}
|
|
|
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem>
|
|
DependencyScanningWorker::makeEffectiveVFS(
|
|
StringRef WorkingDirectory,
|
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> OverlayFS) const {
|
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS = DepFS;
|
|
if (OverlayFS) {
|
|
auto NewFS =
|
|
llvm::makeIntrusiveRefCnt<llvm::vfs::OverlayFileSystem>(std::move(FS));
|
|
NewFS->pushOverlay(std::move(OverlayFS));
|
|
FS = std::move(NewFS);
|
|
}
|
|
FS->setCurrentWorkingDirectory(WorkingDirectory);
|
|
return FS;
|
|
}
|
|
|
|
bool DependencyScanningWorker::computeDependencies(
|
|
StringRef WorkingDirectory, ArrayRef<ArrayRef<std::string>> CommandLines,
|
|
DependencyConsumer &DepConsumer, DependencyActionController &Controller,
|
|
DiagnosticConsumer &DiagConsumer,
|
|
IntrusiveRefCntPtr<llvm::vfs::FileSystem> OverlayFS) {
|
|
auto FS = makeEffectiveVFS(WorkingDirectory, std::move(OverlayFS));
|
|
|
|
DependencyScanningAction Action(Service, WorkingDirectory, DepConsumer,
|
|
Controller, DepFS);
|
|
|
|
const bool Success = llvm::all_of(CommandLines, [&](const auto &Cmd) {
|
|
if (StringRef(Cmd[1]) != "-cc1") {
|
|
// Non-clang command. Just pass through to the dependency consumer.
|
|
DepConsumer.handleBuildCommand(
|
|
{Cmd.front(), {Cmd.begin() + 1, Cmd.end()}});
|
|
return true;
|
|
}
|
|
|
|
auto DiagEngineWithDiagOpts =
|
|
DiagnosticsEngineWithDiagOpts(Cmd, FS, DiagConsumer);
|
|
auto &Diags = *DiagEngineWithDiagOpts.DiagEngine;
|
|
|
|
// Create an invocation that uses the underlying file system to ensure that
|
|
// any file system requests that are made by the driver do not go through
|
|
// the dependency scanning filesystem.
|
|
return createAndRunToolInvocation(Cmd, Action, FS, PCHContainerOps, Diags);
|
|
});
|
|
|
|
return Success && Action.hasScanned();
|
|
}
|