Skip to content

[readtapi] Add option to ignore architecture slices to ignore #110615

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions llvm/test/tools/llvm-readtapi/compare-ignore-archs.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
; RUN: rm -rf %t
; RUN: split-file %s %t

; 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:
; RUN: not llvm-readtapi --compare %t/all_archs.tbd %t/missing_archs.tbd --ignore-arch armv7s 2>&1 | FileCheck %s --check-prefix ARMV7

all_archs.tbd
; ARMV7: < {{.*}}all_archs.tbd
; ARMV7: > {{.*}}missing_archs.tbd

; ARMV7: Reexported Libraries
; ARMV7-NEXT: armv7-apple-ios
; ARMV7: Symbols
; ARMV7-NEXT: armv7-apple-ios
; ARMV7: Inlined Reexported Frameworks/Libraries
; ARMV7-NEXT: /System/Library/Frameworks/FooCore.framework/FooCore
; ARMV7: Symbols
; ARMV7-NEXT: armv7-apple-ios

;--- all_archs.tbd
--- !tapi-tbd
tbd-version: 4
targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
install-name: '/System/Library/Frameworks/Foo.framework/Foo'
current-version: 1986.34.9
reexported-libraries:
- targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
libraries: [ '/System/Library/Frameworks/FooCore.framework/FooCore' ]
exports:
- targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
symbols: [ _AllRequestsKeyPathFragment, _AnalyticsLoggingSubsystem, _AnyRequestKeyPathFragment,
_bar_getBarPointSize_ints, _bar_newBarMessage, _bar_serialize ]
- targets: [ arm64-ios, arm64e-ios ]
symbols: [ __ZN3lingo11MapEdgeRoad6lengthEv,
__ZTVN3lingo11MapEdgeRoadE, __ZTVN3lingo7MapNodeE, __ZTVN5bar19GeometryPathElementE ]
--- !tapi-tbd
tbd-version: 4
targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
install-name: '/System/Library/Frameworks/FooCore.framework/FooCore'
current-version: 1986.34.9
exports:
- targets: [ armv7-ios, armv7s-ios, arm64-ios, arm64e-ios ]
symbols: [ _sym, _workgroupsym, _taskgroup_sim, meta_sim ]
...

;--- missing_archs.tbd
--- !tapi-tbd
tbd-version: 4
targets: [ arm64-ios, arm64e-ios ]
install-name: '/System/Library/Frameworks/Foo.framework/Foo'
current-version: 1986.34.9
reexported-libraries:
- targets: [ arm64-ios, arm64e-ios ]
libraries: [ '/System/Library/Frameworks/FooCore.framework/FooCore' ]
exports:
- targets: [ arm64-ios, arm64e-ios ]
symbols: [ _AllRequestsKeyPathFragment, _AnalyticsLoggingSubsystem, _AnyRequestKeyPathFragment,
_bar_getBarPointSize_ints, _bar_newBarMessage, _bar_serialize, __ZN3lingo11MapEdgeRoad6lengthEv,
__ZTVN3lingo11MapEdgeRoadE, __ZTVN3lingo7MapNodeE, __ZTVN5bar19GeometryPathElementE ]
--- !tapi-tbd
tbd-version: 4
targets: [ arm64-ios, arm64e-ios ]
install-name: '/System/Library/Frameworks/FooCore.framework/FooCore'
current-version: 1986.34.9
exports:
- targets: [ arm64-ios, arm64e-ios ]
symbols: [ _sym, _workgroupsym, _taskgroup_sim, meta_sim ]
...
5 changes: 5 additions & 0 deletions llvm/tools/llvm-readtapi/TapiOpts.td
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,8 @@ def delete_input : FF<"delete-input", "delete and replace input file on success"
def delete_private_libraries : FF<"delete-private-libraries", "delete private system dynamic libraries and frameworks">;
def t: FF<"t", "logs each library loaded, useful for debugging problems with search paths where the wrong library is loaded">;


//
// Compare options
//
defm ignore_arch : JS<"ignore-arch", "<architecture> slice to ignore for comparison", "<architecture>">;
47 changes: 41 additions & 6 deletions llvm/tools/llvm-readtapi/llvm-readtapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ struct StubOptions {
bool TraceLibs = false;
};

struct CompareOptions {
ArchitectureSet ArchsToIgnore;
};

struct Context {
std::vector<std::string> Inputs;
StubOptions StubOpt;
CompareOptions CmpOpt;
std::unique_ptr<llvm::raw_fd_stream> OutStream;
FileType WriteFT = FileType::TBD_V5;
bool Compact = false;
Expand Down Expand Up @@ -160,6 +165,28 @@ static bool handleCompareAction(const Context &Ctx) {
auto LeftIF = getInterfaceFile(Ctx.Inputs.front());
auto RightIF = getInterfaceFile(Ctx.Inputs.at(1));

// Remove all architectures to ignore before running comparison.
auto removeArchFromIF = [](auto &IF, const ArchitectureSet &ArchSet,
const Architecture ArchToRemove) {
if (!ArchSet.has(ArchToRemove))
return;
if (ArchSet.count() == 1)
return;
auto OutIF = IF->remove(ArchToRemove);
if (!OutIF)
ExitOnErr(OutIF.takeError());
IF = std::move(*OutIF);
};

if (!Ctx.CmpOpt.ArchsToIgnore.empty()) {
const ArchitectureSet LeftArchs = LeftIF->getArchitectures();
const ArchitectureSet RightArchs = RightIF->getArchitectures();
for (const auto Arch : Ctx.CmpOpt.ArchsToIgnore) {
removeArchFromIF(LeftIF, LeftArchs, Arch);
removeArchFromIF(RightIF, RightArchs, Arch);
}
}

raw_ostream &OS = Ctx.OutStream ? *Ctx.OutStream : outs();
return DiffEngine(LeftIF.get(), RightIF.get()).compareFiles(OS);
}
Expand Down Expand Up @@ -497,12 +524,20 @@ int main(int Argc, char **Argv) {
reportError("unsupported filetype '" + FT + "'");
}

if (opt::Arg *A = Args.getLastArg(OPT_arch_EQ)) {
StringRef Arch = A->getValue();
Ctx.Arch = getArchitectureFromName(Arch);
if (Ctx.Arch == AK_unknown)
reportError("unsupported architecture '" + Arch);
}
auto SanitizeArch = [&](opt::Arg *A) {
StringRef ArchStr = A->getValue();
auto Arch = getArchitectureFromName(ArchStr);
if (Arch == AK_unknown)
reportError("unsupported architecture '" + ArchStr);
return Arch;
};

if (opt::Arg *A = Args.getLastArg(OPT_arch_EQ))
Ctx.Arch = SanitizeArch(A);

for (opt::Arg *A : Args.filtered(OPT_ignore_arch_EQ))
Ctx.CmpOpt.ArchsToIgnore.set(SanitizeArch(A));

// Handle top level and exclusive operation.
SmallVector<opt::Arg *, 1> ActionArgs(Args.filtered(OPT_action_group));

Expand Down
Loading