Skip to content

Commit 0a518db

Browse files
authored
[InstallAPI] Set InstallAPI as a standalone tool instead of CC1 action (#82293)
Installapi has important distinctions when compared to the clang driver, so much that, it doesn't make much sense to try to integrate into it. This patch partially reverts the CC1 action & driver support to replace with its own driver as a clang tool. For distribution, we could use `LLVM_TOOL_LLVM_DRIVER_BUILD` mechanism for integrating the functionality into clang such that the toolchain size is less impacted.
1 parent cc13f3b commit 0a518db

30 files changed

+408
-271
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,4 @@ def warn_android_unversioned_fallback : Warning<
804804

805805
def err_drv_triple_version_invalid : Error<
806806
"version '%0' in target triple '%1' is invalid">;
807-
808-
def err_drv_installapi_unsupported : Error<
809-
"InstallAPI is not supported for '%0'">;
810807
}

clang/include/clang/Driver/Action.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class Action {
5959
PreprocessJobClass,
6060
PrecompileJobClass,
6161
ExtractAPIJobClass,
62-
InstallAPIJobClass,
6362
AnalyzeJobClass,
6463
MigrateJobClass,
6564
CompileJobClass,
@@ -449,17 +448,6 @@ class ExtractAPIJobAction : public JobAction {
449448
void addHeaderInput(Action *Input) { getInputs().push_back(Input); }
450449
};
451450

452-
class InstallAPIJobAction : public JobAction {
453-
void anchor() override;
454-
455-
public:
456-
InstallAPIJobAction(Action *Input, types::ID OutputType);
457-
458-
static bool classof(const Action *A) {
459-
return A->getKind() == InstallAPIJobClass;
460-
}
461-
};
462-
463451
class AnalyzeJobAction : public JobAction {
464452
void anchor() override;
465453

clang/include/clang/Driver/Options.td

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,6 @@ class AnalyzerOpts<string base>
336336
: KeyPathAndMacro<"AnalyzerOpts->", base, "ANALYZER_"> {}
337337
class MigratorOpts<string base>
338338
: KeyPathAndMacro<"MigratorOpts.", base, "MIGRATOR_"> {}
339-
class InstallAPIOpts<string base>
340-
: KeyPathAndMacro<"InstallAPIOpts.", base, "INSTALLAPI_"> {}
341339

342340
// A boolean option which is opt-in in CC1. The positive option exists in CC1 and
343341
// Args.hasArg(OPT_ffoo) can be used to check that the flag is enabled.
@@ -1143,8 +1141,7 @@ def config_user_dir_EQ : Joined<["--"], "config-user-dir=">,
11431141
def coverage : Flag<["-", "--"], "coverage">, Group<Link_Group>,
11441142
Visibility<[ClangOption, CLOption]>;
11451143
def cpp_precomp : Flag<["-"], "cpp-precomp">, Group<clang_ignored_f_Group>;
1146-
def current__version : JoinedOrSeparate<["-"], "current_version">,
1147-
Visibility<[ClangOption, CC1Option]>;
1144+
def current__version : JoinedOrSeparate<["-"], "current_version">;
11481145
def cxx_isystem : JoinedOrSeparate<["-"], "cxx-isystem">, Group<clang_i_Group>,
11491146
HelpText<"Add directory to the C++ SYSTEM include search path">,
11501147
Visibility<[ClangOption, CC1Option]>,
@@ -1559,9 +1556,6 @@ def static_libsan : Flag<["-"], "static-libsan">,
15591556
HelpText<"Statically link the sanitizer runtime (Not supported for ASan, TSan or UBSan on darwin)">;
15601557
def : Flag<["-"], "shared-libasan">, Alias<shared_libsan>;
15611558
def fasm : Flag<["-"], "fasm">, Group<f_Group>;
1562-
def installapi : Flag<["-"], "installapi">,
1563-
Visibility<[ClangOption, CC1Option]>, Group<Action_Group>,
1564-
HelpText<"Create a text-based stub file by scanning header files">;
15651559

15661560
defm assume_unique_vtables : BoolFOption<"assume-unique-vtables",
15671561
CodeGenOpts<"AssumeUniqueVTables">, DefaultTrue,
@@ -4320,9 +4314,7 @@ def verify_pch : Flag<["-"], "verify-pch">, Group<Action_Group>,
43204314
Visibility<[ClangOption, CC1Option]>,
43214315
HelpText<"Load and verify that a pre-compiled header file is not stale">;
43224316
def init : Separate<["-"], "init">;
4323-
def install__name : Separate<["-"], "install_name">,
4324-
Visibility<[ClangOption, CC1Option]>,
4325-
MarshallingInfoString<InstallAPIOpts<"InstallName">>;
4317+
def install__name : Separate<["-"], "install_name">;
43264318
def iprefix : JoinedOrSeparate<["-"], "iprefix">, Group<clang_i_Group>,
43274319
Visibility<[ClangOption, CC1Option]>,
43284320
HelpText<"Set the -iwithprefix/-iwithprefixbefore prefix">, MetaVarName<"<dir>">;

clang/include/clang/Driver/Types.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ TYPE("lto-bc", LTO_BC, INVALID, "o", phases
9494
TYPE("ast", AST, INVALID, "ast", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
9595
TYPE("ifs", IFS, INVALID, "ifs", phases::IfsMerge)
9696
TYPE("ifs-cpp", IFS_CPP, INVALID, "ifs", phases::Compile, phases::IfsMerge)
97-
TYPE("tbd", TextAPI, INVALID, "tbd", phases::Precompile)
9897
TYPE("pcm", ModuleFile, INVALID, "pcm", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
9998
TYPE("header-unit", HeaderUnit, INVALID, "pcm", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
10099
TYPE("plist", Plist, INVALID, "plist", phases::Compile, phases::Backend, phases::Assemble, phases::Link)

clang/include/clang/Frontend/CompilerInstance.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,6 @@ class CompilerInstance : public ModuleLoader {
294294
return Invocation->getFrontendOpts();
295295
}
296296

297-
InstallAPIOptions &getInstallAPIOpts() {
298-
return Invocation->getInstallAPIOpts();
299-
}
300-
const InstallAPIOptions &getInstallAPIOpts() const {
301-
return Invocation->getInstallAPIOpts();
302-
}
303-
304297
HeaderSearchOptions &getHeaderSearchOpts() {
305298
return Invocation->getHeaderSearchOpts();
306299
}

clang/include/clang/Frontend/CompilerInvocation.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
#include "clang/Basic/LangStandard.h"
1919
#include "clang/Frontend/DependencyOutputOptions.h"
2020
#include "clang/Frontend/FrontendOptions.h"
21-
#include "clang/Frontend/InstallAPIOptions.h"
2221
#include "clang/Frontend/MigratorOptions.h"
2322
#include "clang/Frontend/PreprocessorOutputOptions.h"
2423
#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
25-
#include "llvm/ADT/ArrayRef.h"
2624
#include "llvm/ADT/IntrusiveRefCntPtr.h"
25+
#include "llvm/ADT/ArrayRef.h"
2726
#include <memory>
2827
#include <string>
2928

@@ -112,9 +111,6 @@ class CompilerInvocationBase {
112111
/// Options controlling preprocessed output.
113112
std::shared_ptr<PreprocessorOutputOptions> PreprocessorOutputOpts;
114113

115-
/// Options controlling InstallAPI operations and output.
116-
std::shared_ptr<InstallAPIOptions> InstallAPIOpts;
117-
118114
/// Dummy tag type whose instance can be passed into the constructor to
119115
/// prevent creation of the reference-counted option objects.
120116
struct EmptyConstructor {};
@@ -149,7 +145,6 @@ class CompilerInvocationBase {
149145
const PreprocessorOutputOptions &getPreprocessorOutputOpts() const {
150146
return *PreprocessorOutputOpts;
151147
}
152-
const InstallAPIOptions &getInstallAPIOpts() const { return *InstallAPIOpts; }
153148
/// @}
154149

155150
/// Command line generation.
@@ -242,7 +237,6 @@ class CompilerInvocation : public CompilerInvocationBase {
242237
using CompilerInvocationBase::getFrontendOpts;
243238
using CompilerInvocationBase::getDependencyOutputOpts;
244239
using CompilerInvocationBase::getPreprocessorOutputOpts;
245-
using CompilerInvocationBase::getInstallAPIOpts;
246240
/// @}
247241

248242
/// Mutable getters.
@@ -264,7 +258,6 @@ class CompilerInvocation : public CompilerInvocationBase {
264258
PreprocessorOutputOptions &getPreprocessorOutputOpts() {
265259
return *PreprocessorOutputOpts;
266260
}
267-
InstallAPIOptions &getInstallAPIOpts() { return *InstallAPIOpts; }
268261
/// @}
269262

270263
/// Base class internals.

clang/include/clang/Frontend/FrontendActions.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,6 @@ class GenerateModuleAction : public ASTFrontendAction {
130130
bool shouldEraseOutputFiles() override;
131131
};
132132

133-
class InstallAPIAction : public ASTFrontendAction {
134-
protected:
135-
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,
136-
StringRef InFile) override;
137-
138-
public:
139-
static std::unique_ptr<llvm::raw_pwrite_stream>
140-
CreateOutputFile(CompilerInstance &CI, StringRef InFile);
141-
};
142-
143133
class GenerateInterfaceStubsAction : public ASTFrontendAction {
144134
protected:
145135
std::unique_ptr<ASTConsumer> CreateASTConsumer(CompilerInstance &CI,

clang/include/clang/Frontend/FrontendOptions.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,6 @@ enum ActionKind {
100100
/// Only execute frontend initialization.
101101
InitOnly,
102102

103-
// Create TextAPI stub.
104-
InstallAPI,
105-
106103
/// Dump information about a module file.
107104
ModuleFileInfo,
108105

clang/include/clang/Frontend/InstallAPIOptions.h

Lines changed: 0 additions & 28 deletions
This file was deleted.

clang/include/clang/InstallAPI/Context.h

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,10 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8-
//
9-
// Top level types for interacting with the generic clang driver and frontend
10-
// for InstallAPI operations.
11-
//
12-
//===----------------------------------------------------------------------===//
138

149
#ifndef LLVM_CLANG_INSTALLAPI_CONTEXT_H
1510
#define LLVM_CLANG_INSTALLAPI_CONTEXT_H
1611

17-
#include "clang/AST/ASTConsumer.h"
18-
#include "clang/Basic/Diagnostic.h"
19-
#include "llvm/ADT/IntrusiveRefCntPtr.h"
2012
#include "llvm/TextAPI/InterfaceFile.h"
2113
#include "llvm/TextAPI/RecordVisitor.h"
2214
#include "llvm/TextAPI/RecordsSlice.h"
@@ -35,30 +27,13 @@ struct InstallAPIContext {
3527
/// Active target triple to parse.
3628
llvm::Triple TargetTriple{};
3729

38-
/// Output stream to write TextAPI file to.
39-
std::unique_ptr<llvm::raw_pwrite_stream> OS = nullptr;
40-
41-
/// DiagnosticsEngine to report errors.
42-
llvm::IntrusiveRefCntPtr<DiagnosticsEngine> Diags = nullptr;
43-
4430
/// File Path of output location.
4531
StringRef OutputLoc{};
4632

4733
/// What encoding to write output as.
4834
llvm::MachO::FileType FT = llvm::MachO::FileType::TBD_V5;
4935
};
5036

51-
class InstallAPIConsumer : public ASTConsumer {
52-
public:
53-
InstallAPIConsumer(InstallAPIContext InstallAPICtx)
54-
: Ctx(std::move(InstallAPICtx)) {}
55-
56-
void HandleTranslationUnit(ASTContext &ASTContext) override;
57-
58-
private:
59-
InstallAPIContext Ctx;
60-
};
61-
6237
} // namespace installapi
6338
} // namespace clang
6439

clang/lib/Driver/Action.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ const char *Action::getClassName(ActionClass AC) {
3232
case CompileJobClass: return "compiler";
3333
case BackendJobClass: return "backend";
3434
case AssembleJobClass: return "assembler";
35-
case InstallAPIJobClass:
36-
return "installapi";
3735
case IfsMergeJobClass: return "interface-stub-merger";
3836
case LinkJobClass: return "linker";
3937
case LipoJobClass: return "lipo";
@@ -364,11 +362,6 @@ void ExtractAPIJobAction::anchor() {}
364362
ExtractAPIJobAction::ExtractAPIJobAction(Action *Inputs, types::ID OutputType)
365363
: JobAction(ExtractAPIJobClass, Inputs, OutputType) {}
366364

367-
void InstallAPIJobAction::anchor() {}
368-
369-
InstallAPIJobAction::InstallAPIJobAction(Action *Inputs, types::ID OutputType)
370-
: JobAction(InstallAPIJobClass, Inputs, OutputType) {}
371-
372365
void AnalyzeJobAction::anchor() {}
373366

374367
AnalyzeJobAction::AnalyzeJobAction(Action *Input, types::ID OutputType)

clang/lib/Driver/Driver.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4189,11 +4189,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
41894189
break;
41904190
}
41914191

4192-
if (isa<InstallAPIJobAction>(Current)) {
4193-
Current = nullptr;
4194-
break;
4195-
}
4196-
41974192
// FIXME: Should we include any prior module file outputs as inputs of
41984193
// later actions in the same command line?
41994194

@@ -4324,13 +4319,6 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args,
43244319
if (!MergerInputs.empty())
43254320
Actions.push_back(
43264321
C.MakeAction<IfsMergeJobAction>(MergerInputs, types::TY_Image));
4327-
} else if (Args.hasArg(options::OPT_installapi)) {
4328-
// TODO: Lift restriction once operation can handle multiple inputs.
4329-
assert(Inputs.size() == 1 && "InstallAPI action can only handle 1 input");
4330-
const auto [InputType, InputArg] = Inputs.front();
4331-
Action *Current = C.MakeAction<InputAction>(*InputArg, InputType);
4332-
Actions.push_back(
4333-
C.MakeAction<InstallAPIJobAction>(Current, types::TY_TextAPI));
43344322
}
43354323

43364324
for (auto Opt : {options::OPT_print_supported_cpus,
@@ -4774,8 +4762,6 @@ Action *Driver::ConstructPhaseAction(
47744762
return C.MakeAction<VerifyPCHJobAction>(Input, types::TY_Nothing);
47754763
if (Args.hasArg(options::OPT_extract_api))
47764764
return C.MakeAction<ExtractAPIJobAction>(Input, types::TY_API_INFO);
4777-
if (Args.hasArg(options::OPT_installapi))
4778-
return C.MakeAction<InstallAPIJobAction>(Input, types::TY_TextAPI);
47794765
return C.MakeAction<CompileJobAction>(Input, types::TY_LLVM_BC);
47804766
}
47814767
case phases::Backend: {
@@ -6455,7 +6441,7 @@ bool Driver::ShouldUseClangCompiler(const JobAction &JA) const {
64556441
// And say "no" if this is not a kind of action clang understands.
64566442
if (!isa<PreprocessJobAction>(JA) && !isa<PrecompileJobAction>(JA) &&
64576443
!isa<CompileJobAction>(JA) && !isa<BackendJobAction>(JA) &&
6458-
!isa<ExtractAPIJobAction>(JA) && !isa<InstallAPIJobAction>(JA))
6444+
!isa<ExtractAPIJobAction>(JA))
64596445
return false;
64606446

64616447
return true;

clang/lib/Driver/ToolChain.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,6 @@ Tool *ToolChain::getTool(Action::ActionClass AC) const {
532532
case Action::PrecompileJobClass:
533533
case Action::PreprocessJobClass:
534534
case Action::ExtractAPIJobClass:
535-
case Action::InstallAPIJobClass:
536535
case Action::AnalyzeJobClass:
537536
case Action::MigrateJobClass:
538537
case Action::VerifyPCHJobClass:

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4939,17 +4939,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
49394939
if (Arg *ExtractAPIIgnoresFileArg =
49404940
Args.getLastArg(options::OPT_extract_api_ignores_EQ))
49414941
ExtractAPIIgnoresFileArg->render(Args, CmdArgs);
4942-
} else if (isa<InstallAPIJobAction>(JA)) {
4943-
if (!Triple.isOSDarwin())
4944-
D.Diag(diag::err_drv_installapi_unsupported) << Triple.str();
4945-
4946-
CmdArgs.push_back("-installapi");
4947-
// Add necessary library arguments for InstallAPI.
4948-
if (const Arg *A = Args.getLastArg(options::OPT_install__name))
4949-
A->render(Args, CmdArgs);
4950-
if (const Arg *A = Args.getLastArg(options::OPT_current__version))
4951-
A->render(Args, CmdArgs);
4952-
49534942
} else {
49544943
assert((isa<CompileJobAction>(JA) || isa<BackendJobAction>(JA)) &&
49554944
"Invalid action for clang tool.");

clang/lib/Frontend/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ set(LLVM_LINK_COMPONENTS
77
ProfileData
88
Support
99
TargetParser
10-
TextAPI
1110
)
1211

1312
add_clang_library(clangFrontend
@@ -28,7 +27,6 @@ add_clang_library(clangFrontend
2827
HeaderIncludeGen.cpp
2928
InitPreprocessor.cpp
3029
LayoutOverrideSource.cpp
31-
InstallAPIConsumer.cpp
3230
LogDiagnosticPrinter.cpp
3331
ModuleDependencyCollector.cpp
3432
MultiplexConsumer.cpp
@@ -55,7 +53,6 @@ add_clang_library(clangFrontend
5553
clangBasic
5654
clangDriver
5755
clangEdit
58-
clangInstallAPI
5956
clangLex
6057
clangParse
6158
clangSema

0 commit comments

Comments
 (0)