Skip to content

Commit

Permalink
Revert "[clang][deps] Split translation units into individual -cc1 or…
Browse files Browse the repository at this point in the history
… other commands"

Failing on some bots, reverting until I can fix it.

This reverts commit f80a0ea.
  • Loading branch information
benlangmuir committed Aug 30, 2022
1 parent 2fdf963 commit 1877d76
Show file tree
Hide file tree
Showing 27 changed files with 207 additions and 650 deletions.
Expand Up @@ -49,16 +49,8 @@ struct FullDependencies {
/// determined that the differences are benign for this compilation.
std::vector<ModuleID> ClangModuleDeps;

/// The sequence of commands required to build the translation unit. Commands
/// should be executed in order.
///
/// FIXME: If we add support for multi-arch builds in clang-scan-deps, we
/// should make the dependencies between commands explicit to enable parallel
/// builds of each architecture.
std::vector<Command> Commands;

/// Deprecated driver command-line. This will be removed in a future version.
std::vector<std::string> DriverCommandLine;
/// The command line of the TU (excluding the compiler executable).
std::vector<std::string> CommandLine;
};

struct FullDependenciesResult {
Expand Down Expand Up @@ -107,12 +99,6 @@ class DependencyScanningTool {
LookupModuleOutputCallback LookupModuleOutput,
llvm::Optional<StringRef> ModuleName = None);

llvm::Expected<FullDependenciesResult> getFullDependenciesLegacyDriverCommand(
const std::vector<std::string> &CommandLine, StringRef CWD,
const llvm::StringSet<> &AlreadySeen,
LookupModuleOutputCallback LookupModuleOutput,
llvm::Optional<StringRef> ModuleName = None);

private:
DependencyScanningWorker Worker;
};
Expand All @@ -125,10 +111,6 @@ class FullDependencyConsumer : public DependencyConsumer {
: AlreadySeen(AlreadySeen), LookupModuleOutput(LookupModuleOutput),
EagerLoadModules(EagerLoadModules) {}

void handleBuildCommand(Command Cmd) override {
Commands.push_back(std::move(Cmd));
}

void handleDependencyOutputOpts(const DependencyOutputOptions &) override {}

void handleFileDependency(StringRef File) override {
Expand All @@ -152,17 +134,14 @@ class FullDependencyConsumer : public DependencyConsumer {
return LookupModuleOutput(ID, Kind);
}

FullDependenciesResult getFullDependenciesLegacyDriverCommand(
FullDependenciesResult getFullDependencies(
const std::vector<std::string> &OriginalCommandLine) const;

FullDependenciesResult takeFullDependencies();

private:
std::vector<std::string> Dependencies;
std::vector<PrebuiltModuleDep> PrebuiltModuleDeps;
llvm::MapVector<std::string, ModuleDeps, llvm::StringMap<unsigned>>
ClangModuleDeps;
std::vector<Command> Commands;
std::string ContextHash;
std::vector<std::string> OutputPaths;
const llvm::StringSet<> &AlreadySeen;
Expand Down
Expand Up @@ -28,20 +28,10 @@ namespace dependencies {

class DependencyScanningWorkerFilesystem;

/// A command-line tool invocation that is part of building a TU.
///
/// \see FullDependencies::Commands.
struct Command {
std::string Executable;
std::vector<std::string> Arguments;
};

class DependencyConsumer {
public:
virtual ~DependencyConsumer() {}

virtual void handleBuildCommand(Command Cmd) = 0;

virtual void
handleDependencyOutputOpts(const DependencyOutputOptions &Opts) = 0;

Expand Down
Expand Up @@ -181,16 +181,12 @@ class ModuleDepCollector final : public DependencyCollector {
public:
ModuleDepCollector(std::unique_ptr<DependencyOutputOptions> Opts,
CompilerInstance &ScanInstance, DependencyConsumer &C,
CompilerInvocation OriginalCI, bool OptimizeArgs,
CompilerInvocation &&OriginalCI, bool OptimizeArgs,
bool EagerLoadModules);

void attachToPreprocessor(Preprocessor &PP) override;
void attachToASTReader(ASTReader &R) override;

/// Apply any changes implied by the discovered dependencies to the given
/// invocation, (e.g. disable implicit modules, add explicit module paths).
void applyDiscoveredDependencies(CompilerInvocation &CI);

private:
friend ModuleDepCollectorPP;

Expand Down
58 changes: 8 additions & 50 deletions clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp
Expand Up @@ -45,8 +45,6 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
/// Prints out all of the gathered dependencies into a string.
class MakeDependencyPrinterConsumer : public DependencyConsumer {
public:
void handleBuildCommand(Command) override {}

void
handleDependencyOutputOpts(const DependencyOutputOptions &Opts) override {
this->Opts = std::make_unique<DependencyOutputOptions>(Opts);
Expand Down Expand Up @@ -122,74 +120,34 @@ DependencyScanningTool::getFullDependencies(
Worker.computeDependencies(CWD, CommandLine, Consumer, ModuleName);
if (Result)
return std::move(Result);
return Consumer.takeFullDependencies();
}

llvm::Expected<FullDependenciesResult>
DependencyScanningTool::getFullDependenciesLegacyDriverCommand(
const std::vector<std::string> &CommandLine, StringRef CWD,
const llvm::StringSet<> &AlreadySeen,
LookupModuleOutputCallback LookupModuleOutput,
llvm::Optional<StringRef> ModuleName) {
FullDependencyConsumer Consumer(AlreadySeen, LookupModuleOutput,
Worker.shouldEagerLoadModules());
llvm::Error Result =
Worker.computeDependencies(CWD, CommandLine, Consumer, ModuleName);
if (Result)
return std::move(Result);
return Consumer.getFullDependenciesLegacyDriverCommand(CommandLine);
}

FullDependenciesResult FullDependencyConsumer::takeFullDependencies() {
FullDependenciesResult FDR;
FullDependencies &FD = FDR.FullDeps;

FD.ID.ContextHash = std::move(ContextHash);
FD.FileDeps = std::move(Dependencies);
FD.PrebuiltModuleDeps = std::move(PrebuiltModuleDeps);
FD.Commands = std::move(Commands);

for (auto &&M : ClangModuleDeps) {
auto &MD = M.second;
if (MD.ImportedByMainFile)
FD.ClangModuleDeps.push_back(MD.ID);
// TODO: Avoid handleModuleDependency even being called for modules
// we've already seen.
if (AlreadySeen.count(M.first))
continue;
FDR.DiscoveredModules.push_back(std::move(MD));
}

return FDR;
return Consumer.getFullDependencies(CommandLine);
}

FullDependenciesResult
FullDependencyConsumer::getFullDependenciesLegacyDriverCommand(
FullDependenciesResult FullDependencyConsumer::getFullDependencies(
const std::vector<std::string> &OriginalCommandLine) const {
FullDependencies FD;

FD.DriverCommandLine = makeTUCommandLineWithoutPaths(
FD.CommandLine = makeTUCommandLineWithoutPaths(
ArrayRef<std::string>(OriginalCommandLine).slice(1));

FD.ID.ContextHash = std::move(ContextHash);

FD.FileDeps.assign(Dependencies.begin(), Dependencies.end());

for (const PrebuiltModuleDep &PMD : PrebuiltModuleDeps)
FD.DriverCommandLine.push_back("-fmodule-file=" + PMD.PCMFile);
FD.CommandLine.push_back("-fmodule-file=" + PMD.PCMFile);

for (auto &&M : ClangModuleDeps) {
auto &MD = M.second;
if (MD.ImportedByMainFile) {
FD.ClangModuleDeps.push_back(MD.ID);
auto PCMPath = LookupModuleOutput(MD.ID, ModuleOutputKind::ModuleFile);
if (EagerLoadModules) {
FD.DriverCommandLine.push_back("-fmodule-file=" + PCMPath);
FD.CommandLine.push_back("-fmodule-file=" + PCMPath);
} else {
FD.DriverCommandLine.push_back("-fmodule-map-file=" +
MD.ClangModuleMapFile);
FD.DriverCommandLine.push_back("-fmodule-file=" + MD.ID.ModuleName +
"=" + PCMPath);
FD.CommandLine.push_back("-fmodule-map-file=" + MD.ClangModuleMapFile);
FD.CommandLine.push_back("-fmodule-file=" + MD.ID.ModuleName + "=" +
PCMPath);
}
}
}
Expand Down

0 comments on commit 1877d76

Please sign in to comment.