Skip to content

Commit 7f0e227

Browse files
committed
[readtapi] Add option to ignore architecture slices to ignore (llvm#110615)
For qualification purposes, it's helpful to ignore certain slices that can be expected to differ. (cherry picked from commit 5134048)
1 parent e6ffc9e commit 7f0e227

File tree

3 files changed

+114
-6
lines changed

3 files changed

+114
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
; RUN: rm -rf %t
2+
; RUN: split-file %s %t
3+
4+
; RUN: llvm-readtapi --compare %t/all_archs.tbd %t/missing_archs.tbd --ignore-arch armv7 --ignore-arch armv7s 2>&1 | FileCheck %s --allow-empty --implicit-check-not warning: --implicit-check-not error:
5+
; RUN: not llvm-readtapi --compare %t/all_archs.tbd %t/missing_archs.tbd --ignore-arch armv7s 2>&1 | FileCheck %s --check-prefix ARMV7
6+
7+
all_archs.tbd
8+
; ARMV7: < {{.*}}all_archs.tbd
9+
; ARMV7: > {{.*}}missing_archs.tbd
10+
11+
; ARMV7: Reexported Libraries
12+
; ARMV7-NEXT: armv7-apple-ios
13+
; ARMV7: Symbols
14+
; ARMV7-NEXT: armv7-apple-ios
15+
; ARMV7: Inlined Reexported Frameworks/Libraries
16+
; ARMV7-NEXT: /System/Library/Frameworks/FooCore.framework/FooCore
17+
; ARMV7: Symbols
18+
; ARMV7-NEXT: armv7-apple-ios
19+
20+
;--- all_archs.tbd
21+
--- !tapi-tbd
22+
tbd-version: 4
23+
targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
24+
install-name: '/System/Library/Frameworks/Foo.framework/Foo'
25+
current-version: 1986.34.9
26+
reexported-libraries:
27+
- targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
28+
libraries: [ '/System/Library/Frameworks/FooCore.framework/FooCore' ]
29+
exports:
30+
- targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
31+
symbols: [ _AllRequestsKeyPathFragment, _AnalyticsLoggingSubsystem, _AnyRequestKeyPathFragment,
32+
_bar_getBarPointSize_ints, _bar_newBarMessage, _bar_serialize ]
33+
- targets: [ arm64-ios, arm64e-ios ]
34+
symbols: [ __ZN3lingo11MapEdgeRoad6lengthEv,
35+
__ZTVN3lingo11MapEdgeRoadE, __ZTVN3lingo7MapNodeE, __ZTVN5bar19GeometryPathElementE ]
36+
--- !tapi-tbd
37+
tbd-version: 4
38+
targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
39+
install-name: '/System/Library/Frameworks/FooCore.framework/FooCore'
40+
current-version: 1986.34.9
41+
exports:
42+
- targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
43+
symbols: [ _sym, _workgroupsym, _taskgroup_sim, meta_sim ]
44+
...
45+
46+
;--- missing_archs.tbd
47+
--- !tapi-tbd
48+
tbd-version: 4
49+
targets: [ arm64-ios, arm64e-ios ]
50+
install-name: '/System/Library/Frameworks/Foo.framework/Foo'
51+
current-version: 1986.34.9
52+
reexported-libraries:
53+
- targets: [ arm64-ios, arm64e-ios ]
54+
libraries: [ '/System/Library/Frameworks/FooCore.framework/FooCore' ]
55+
exports:
56+
- targets: [ arm64-ios, arm64e-ios ]
57+
symbols: [ _AllRequestsKeyPathFragment, _AnalyticsLoggingSubsystem, _AnyRequestKeyPathFragment,
58+
_bar_getBarPointSize_ints, _bar_newBarMessage, _bar_serialize, __ZN3lingo11MapEdgeRoad6lengthEv,
59+
__ZTVN3lingo11MapEdgeRoadE, __ZTVN3lingo7MapNodeE, __ZTVN5bar19GeometryPathElementE ]
60+
--- !tapi-tbd
61+
tbd-version: 4
62+
targets: [ arm64-ios, arm64e-ios ]
63+
install-name: '/System/Library/Frameworks/FooCore.framework/FooCore'
64+
current-version: 1986.34.9
65+
exports:
66+
- targets: [ arm64-ios, arm64e-ios ]
67+
symbols: [ _sym, _workgroupsym, _taskgroup_sim, meta_sim ]
68+
...

llvm/tools/llvm-readtapi/TapiOpts.td

+5
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,8 @@ def delete_input : FF<"delete-input", "delete and replace input file on success"
3535
def delete_private_libraries : FF<"delete-private-libraries", "delete private system dynamic libraries and frameworks">;
3636
def t: FF<"t", "logs each library loaded, useful for debugging problems with search paths where the wrong library is loaded">;
3737

38+
39+
//
40+
// Compare options
41+
//
42+
defm ignore_arch : JS<"ignore-arch", "<architecture> slice to ignore for comparison", "<architecture>">;

llvm/tools/llvm-readtapi/llvm-readtapi.cpp

+41-6
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,14 @@ struct StubOptions {
7171
bool TraceLibs = false;
7272
};
7373

74+
struct CompareOptions {
75+
ArchitectureSet ArchsToIgnore;
76+
};
77+
7478
struct Context {
7579
std::vector<std::string> Inputs;
7680
StubOptions StubOpt;
81+
CompareOptions CmpOpt;
7782
std::unique_ptr<llvm::raw_fd_stream> OutStream;
7883
FileType WriteFT = FileType::TBD_V5;
7984
bool Compact = false;
@@ -160,6 +165,28 @@ static bool handleCompareAction(const Context &Ctx) {
160165
auto LeftIF = getInterfaceFile(Ctx.Inputs.front());
161166
auto RightIF = getInterfaceFile(Ctx.Inputs.at(1));
162167

168+
// Remove all architectures to ignore before running comparison.
169+
auto removeArchFromIF = [](auto &IF, const ArchitectureSet &ArchSet,
170+
const Architecture ArchToRemove) {
171+
if (!ArchSet.has(ArchToRemove))
172+
return;
173+
if (ArchSet.count() == 1)
174+
return;
175+
auto OutIF = IF->remove(ArchToRemove);
176+
if (!OutIF)
177+
ExitOnErr(OutIF.takeError());
178+
IF = std::move(*OutIF);
179+
};
180+
181+
if (!Ctx.CmpOpt.ArchsToIgnore.empty()) {
182+
const ArchitectureSet LeftArchs = LeftIF->getArchitectures();
183+
const ArchitectureSet RightArchs = RightIF->getArchitectures();
184+
for (const auto Arch : Ctx.CmpOpt.ArchsToIgnore) {
185+
removeArchFromIF(LeftIF, LeftArchs, Arch);
186+
removeArchFromIF(RightIF, RightArchs, Arch);
187+
}
188+
}
189+
163190
raw_ostream &OS = Ctx.OutStream ? *Ctx.OutStream : outs();
164191
return DiffEngine(LeftIF.get(), RightIF.get()).compareFiles(OS);
165192
}
@@ -497,12 +524,20 @@ int main(int Argc, char **Argv) {
497524
reportError("unsupported filetype '" + FT + "'");
498525
}
499526

500-
if (opt::Arg *A = Args.getLastArg(OPT_arch_EQ)) {
501-
StringRef Arch = A->getValue();
502-
Ctx.Arch = getArchitectureFromName(Arch);
503-
if (Ctx.Arch == AK_unknown)
504-
reportError("unsupported architecture '" + Arch);
505-
}
527+
auto SanitizeArch = [&](opt::Arg *A) {
528+
StringRef ArchStr = A->getValue();
529+
auto Arch = getArchitectureFromName(ArchStr);
530+
if (Arch == AK_unknown)
531+
reportError("unsupported architecture '" + ArchStr);
532+
return Arch;
533+
};
534+
535+
if (opt::Arg *A = Args.getLastArg(OPT_arch_EQ))
536+
Ctx.Arch = SanitizeArch(A);
537+
538+
for (opt::Arg *A : Args.filtered(OPT_ignore_arch_EQ))
539+
Ctx.CmpOpt.ArchsToIgnore.set(SanitizeArch(A));
540+
506541
// Handle top level and exclusive operation.
507542
SmallVector<opt::Arg *, 1> ActionArgs(Args.filtered(OPT_action_group));
508543

0 commit comments

Comments
 (0)