[llvm] 5134048 - [readtapi] Add option to ignore architecture slices to ignore (#110615)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 1 14:31:25 PDT 2024
Author: Cyndy Ishida
Date: 2024-10-01T14:31:22-07:00
New Revision: 513404806646ad07f76b0fda3c11a9847fc5ce84
URL: https://github.com/llvm/llvm-project/commit/513404806646ad07f76b0fda3c11a9847fc5ce84
DIFF: https://github.com/llvm/llvm-project/commit/513404806646ad07f76b0fda3c11a9847fc5ce84.diff
LOG: [readtapi] Add option to ignore architecture slices to ignore (#110615)
For qualification purposes, it's helpful to ignore certain slices that
can be expected to differ.
Added:
llvm/test/tools/llvm-readtapi/compare-ignore-archs.test
Modified:
llvm/tools/llvm-readtapi/TapiOpts.td
llvm/tools/llvm-readtapi/llvm-readtapi.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-readtapi/compare-ignore-archs.test b/llvm/test/tools/llvm-readtapi/compare-ignore-archs.test
new file mode 100644
index 00000000000000..a9a79128caadcf
--- /dev/null
+++ b/llvm/test/tools/llvm-readtapi/compare-ignore-archs.test
@@ -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 ]
+...
diff --git a/llvm/tools/llvm-readtapi/TapiOpts.td b/llvm/tools/llvm-readtapi/TapiOpts.td
index 3b8f26579bd4af..3d13dc99fc9633 100644
--- a/llvm/tools/llvm-readtapi/TapiOpts.td
+++ b/llvm/tools/llvm-readtapi/TapiOpts.td
@@ -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>">;
diff --git a/llvm/tools/llvm-readtapi/llvm-readtapi.cpp b/llvm/tools/llvm-readtapi/llvm-readtapi.cpp
index c287dac4cd239a..6e42ed76949ff5 100644
--- a/llvm/tools/llvm-readtapi/llvm-readtapi.cpp
+++ b/llvm/tools/llvm-readtapi/llvm-readtapi.cpp
@@ -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;
@@ -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);
}
@@ -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));
More information about the llvm-commits
mailing list