Skip to content

Commit 29bc645

Browse files
author
Harlan Haskins
authored
[TBDGen] Set installapi flag only when building in installapi (#27315)
Previously, we would unconditionally set the `installapi` flag, which hard errors when trying to merge with a TAPI-generated TBD file that was generated during the install phase. Fixes rdar://42406088
1 parent 49179e4 commit 29bc645

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ def tbd_compatibility_version
8686
def tbd_compatibility_version_EQ : Joined<["-"], "tbd-compatibility-version=">,
8787
Alias<tbd_compatibility_version>;
8888

89+
def tbd_is_installapi: Flag<["-"], "tbd-is-installapi">,
90+
HelpText<"If the TBD file should indicate it's being generated during "
91+
"InstallAPI">;
92+
8993
def verify : Flag<["-"], "verify">,
9094
HelpText<"Verify diagnostics against expected-{error|warning|note} "
9195
"annotations">;

include/swift/TBDGen/TBDGen.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ struct TBDGenOptions {
3333
/// Whether this compilation has multiple IRGen instances.
3434
bool HasMultipleIGMs;
3535

36+
/// Whether this compilation is producing a TBD for InstallAPI.
37+
bool IsInstallAPI;
38+
3639
/// The install_name to use in the TBD file.
3740
std::string InstallName;
3841

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,8 @@ static bool ParseTBDGenArgs(TBDGenOptions &Opts, ArgList &Args,
940940
Opts.InstallName = A->getValue();
941941
}
942942

943+
Opts.IsInstallAPI = Args.hasArg(OPT_tbd_is_installapi);
944+
943945
if (const Arg *A = Args.getLastArg(OPT_tbd_compatibility_version)) {
944946
if (auto vers = version::Version::parseVersionString(
945947
A->getValue(), SourceLoc(), &Diags)) {

lib/TBDGen/TBDGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ static void enumeratePublicSymbolsAndWrite(ModuleDecl *M, FileUnit *singleFile,
613613
file.setPlatform(tapi::internal::mapToSinglePlatform(target));
614614
auto arch = tapi::internal::getArchType(target.getArchName());
615615
file.setArch(arch);
616-
file.setInstallAPI();
616+
file.setInstallAPI(opts.IsInstallAPI);
617617

618618
TBDGenVisitor visitor(file, arch, symbols, linkInfo, M, opts);
619619

test/TBD/installapi-flag.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
3+
// 1. Emit two TBDs, one with -tbd-is-installapi set, and one without
4+
5+
// RUN: %target-swift-frontend -emit-ir -o /dev/null %s -tbd-is-installapi -emit-tbd -emit-tbd-path %t/flag-provided.tbd
6+
// RUN: %target-swift-frontend -emit-ir -o /dev/null %s -emit-tbd -emit-tbd-path %t/flag-omitted.tbd
7+
8+
// 2. Ensure that the file with -tbd-is-installapi passed includes the installapi flag
9+
10+
// RUN: %FileCheck %s --check-prefix FLAG-PROVIDED < %t/flag-provided.tbd
11+
12+
// 3. Ensure that the file without -tbd-is-installapi passed does not include the installapi flag
13+
14+
// RUN: %FileCheck %s --check-prefix FLAG-OMITTED < %t/flag-omitted.tbd
15+
16+
// FLAG-PROVIDED: installapi
17+
// FLAG-OMITTED-NOT: installapi

0 commit comments

Comments
 (0)