@@ -19,66 +19,68 @@ DependencyScanningTool::DependencyScanningTool(
19
19
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> FS)
20
20
: Worker(Service, std::move(FS)) {}
21
21
22
- llvm::Expected<std::string> DependencyScanningTool::getDependencyFile (
23
- const std::vector<std::string> &CommandLine, StringRef CWD) {
24
- // / Prints out all of the gathered dependencies into a string.
25
- class MakeDependencyPrinterConsumer : public DependencyConsumer {
26
- public:
27
- void handleBuildCommand (Command) override {}
28
-
29
- void
30
- handleDependencyOutputOpts (const DependencyOutputOptions &Opts) override {
31
- this ->Opts = std::make_unique<DependencyOutputOptions>(Opts);
32
- }
22
+ namespace {
23
+ // / Prints out all of the gathered dependencies into a string.
24
+ class MakeDependencyPrinterConsumer : public DependencyConsumer {
25
+ public:
26
+ void handleBuildCommand (Command) override {}
27
+
28
+ void
29
+ handleDependencyOutputOpts (const DependencyOutputOptions &Opts) override {
30
+ this ->Opts = std::make_unique<DependencyOutputOptions>(Opts);
31
+ }
33
32
34
- void handleFileDependency (StringRef File) override {
35
- Dependencies.push_back (std::string (File));
36
- }
33
+ void handleFileDependency (StringRef File) override {
34
+ Dependencies.push_back (std::string (File));
35
+ }
37
36
38
- void handlePrebuiltModuleDependency (PrebuiltModuleDep PMD) override {
39
- // Same as `handleModuleDependency`.
40
- }
37
+ void handlePrebuiltModuleDependency (PrebuiltModuleDep PMD) override {
38
+ // Same as `handleModuleDependency`.
39
+ }
41
40
42
- void handleModuleDependency (ModuleDeps MD) override {
43
- // These are ignored for the make format as it can't support the full
44
- // set of deps, and handleFileDependency handles enough for implicitly
45
- // built modules to work.
46
- }
41
+ void handleModuleDependency (ModuleDeps MD) override {
42
+ // These are ignored for the make format as it can't support the full
43
+ // set of deps, and handleFileDependency handles enough for implicitly
44
+ // built modules to work.
45
+ }
47
46
48
- void handleContextHash (std::string Hash) override {}
47
+ void handleContextHash (std::string Hash) override {}
49
48
50
- std::string lookupModuleOutput (const ModuleID &ID,
51
- ModuleOutputKind Kind) override {
52
- llvm::report_fatal_error (" unexpected call to lookupModuleOutput" );
53
- }
49
+ std::string lookupModuleOutput (const ModuleID &ID,
50
+ ModuleOutputKind Kind) override {
51
+ llvm::report_fatal_error (" unexpected call to lookupModuleOutput" );
52
+ }
54
53
55
- void printDependencies (std::string &S) {
56
- assert (Opts && " Handled dependency output options." );
57
-
58
- class DependencyPrinter : public DependencyFileGenerator {
59
- public:
60
- DependencyPrinter (DependencyOutputOptions &Opts,
61
- ArrayRef<std::string> Dependencies)
62
- : DependencyFileGenerator(Opts) {
63
- for (const auto &Dep : Dependencies)
64
- addDependency (Dep);
65
- }
66
-
67
- void printDependencies (std::string &S) {
68
- llvm::raw_string_ostream OS (S);
69
- outputDependencyFile (OS);
70
- }
71
- };
72
-
73
- DependencyPrinter Generator (*Opts, Dependencies);
74
- Generator.printDependencies (S);
75
- }
54
+ void printDependencies (std::string &S) {
55
+ assert (Opts && " Handled dependency output options." );
56
+
57
+ class DependencyPrinter : public DependencyFileGenerator {
58
+ public:
59
+ DependencyPrinter (DependencyOutputOptions &Opts,
60
+ ArrayRef<std::string> Dependencies)
61
+ : DependencyFileGenerator(Opts) {
62
+ for (const auto &Dep : Dependencies)
63
+ addDependency (Dep);
64
+ }
65
+
66
+ void printDependencies (std::string &S) {
67
+ llvm::raw_string_ostream OS (S);
68
+ outputDependencyFile (OS);
69
+ }
70
+ };
71
+
72
+ DependencyPrinter Generator (*Opts, Dependencies);
73
+ Generator.printDependencies (S);
74
+ }
76
75
77
- private:
78
- std::unique_ptr<DependencyOutputOptions> Opts;
79
- std::vector<std::string> Dependencies;
80
- };
76
+ protected:
77
+ std::unique_ptr<DependencyOutputOptions> Opts;
78
+ std::vector<std::string> Dependencies;
79
+ };
80
+ } // anonymous namespace
81
81
82
+ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile (
83
+ const std::vector<std::string> &CommandLine, StringRef CWD) {
82
84
MakeDependencyPrinterConsumer Consumer;
83
85
auto Result = Worker.computeDependencies (CWD, CommandLine, Consumer);
84
86
if (Result)
@@ -89,26 +91,18 @@ llvm::Expected<std::string> DependencyScanningTool::getDependencyFile(
89
91
}
90
92
91
93
llvm::Expected<P1689Rule> DependencyScanningTool::getP1689ModuleDependencyFile (
92
- const CompileCommand &Command, StringRef CWD) {
93
- class P1689ModuleDependencyPrinterConsumer : public DependencyConsumer {
94
+ const CompileCommand &Command, StringRef CWD,
95
+ std::string &MakeformatOutput, std::string &MakeformatOutputPath,
96
+ std::optional<StringRef> ModuleName) {
97
+ class P1689ModuleDependencyPrinterConsumer
98
+ : public MakeDependencyPrinterConsumer {
94
99
public:
95
100
P1689ModuleDependencyPrinterConsumer (P1689Rule &Rule,
96
101
const CompileCommand &Command)
97
102
: Filename(Command.Filename), Rule(Rule) {
98
103
Rule.PrimaryOutput = Command.Output ;
99
104
}
100
105
101
- void
102
- handleDependencyOutputOpts (const DependencyOutputOptions &Opts) override {}
103
- void handleFileDependency (StringRef File) override {}
104
- void handlePrebuiltModuleDependency (PrebuiltModuleDep PMD) override {}
105
- void handleModuleDependency (ModuleDeps MD) override {}
106
- void handleContextHash (std::string Hash) override {}
107
- std::string lookupModuleOutput (const ModuleID &ID,
108
- ModuleOutputKind Kind) override {
109
- llvm::report_fatal_error (" unexpected call to lookupModuleOutput" );
110
- }
111
-
112
106
void handleProvidedAndRequiredStdCXXModules (
113
107
std::optional<P1689ModuleInfo> Provided,
114
108
std::vector<P1689ModuleInfo> Requires) override {
@@ -118,6 +112,12 @@ llvm::Expected<P1689Rule> DependencyScanningTool::getP1689ModuleDependencyFile(
118
112
Rule.Requires = Requires;
119
113
}
120
114
115
+ StringRef getMakeFormatDependencyOutputPath () {
116
+ if (Opts->OutputFormat != DependencyOutputFormat::Make)
117
+ return {};
118
+ return Opts->OutputFile ;
119
+ }
120
+
121
121
private:
122
122
StringRef Filename;
123
123
P1689Rule &Rule;
@@ -128,6 +128,10 @@ llvm::Expected<P1689Rule> DependencyScanningTool::getP1689ModuleDependencyFile(
128
128
auto Result = Worker.computeDependencies (CWD, Command.CommandLine , Consumer);
129
129
if (Result)
130
130
return std::move (Result);
131
+
132
+ MakeformatOutputPath = Consumer.getMakeFormatDependencyOutputPath ();
133
+ if (!MakeformatOutputPath.empty ())
134
+ Consumer.printDependencies (MakeformatOutput);
131
135
return Rule;
132
136
}
133
137
0 commit comments