Skip to content

Commit 12b33f6

Browse files
authored
Merge pull request #26984 from apple/revert-26977-api-digester-use-builtin-baseline
Revert "swift-api-digester: teach the tool to find framework-specific baselines from relative path"
2 parents 2570af6 + 63a3cee commit 12b33f6

File tree

7 files changed

+18
-96
lines changed

7 files changed

+18
-96
lines changed

test/api-digester/stability-stdlib-abi-with-asserts.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
// REQUIRES: swift_stdlib_asserts
33
// RUN: %empty-directory(%t.tmp)
44
// mkdir %t.tmp/module-cache && mkdir %t.tmp/dummy.sdk
5-
// RUN: %api-digester -diagnose-sdk -module Swift -o %t.tmp/changes.txt -module-cache-path %t.tmp/module-cache -sdk %t.tmp/dummy.sdk -abi -avoid-location
5+
// RUN: %api-digester -dump-sdk -module Swift -o %t.tmp/current-stdlib.json -module-cache-path %t.tmp/module-cache -sdk %t.tmp/dummy.sdk -abi -avoid-location
6+
// RUN: %api-digester -diagnose-sdk -input-paths %S/Inputs/stdlib-stable-abi.json -input-paths %t.tmp/current-stdlib.json -abi -o %t.tmp/changes.txt -v
67
// RUN: %clang -E -P -x c %S/Outputs/stability-stdlib-abi.without.asserts.swift.expected -o - > %t.tmp/stability-stdlib-abi.swift.expected
78
// RUN: %clang -E -P -x c %S/Outputs/stability-stdlib-abi.asserts.additional.swift.expected -o - >> %t.tmp/stability-stdlib-abi.swift.expected
89
// RUN: %clang -E -P -x c %t.tmp/stability-stdlib-abi.swift.expected -o - | sed '/^\s*$/d' | sort > %t.tmp/stability-stdlib-abi.swift.expected.sorted
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// REQUIRES: OS=macosx
22
// RUN: %empty-directory(%t.tmp)
33
// mkdir %t.tmp/module-cache && mkdir %t.tmp/dummy.sdk
4-
// RUN: %api-digester -diagnose-sdk -module Swift -o %t.tmp/changes.txt -module-cache-path %t.tmp/module-cache -sdk %t.tmp/dummy.sdk -avoid-location
4+
// RUN: %api-digester -dump-sdk -module Swift -o %t.tmp/current-stdlib.json -module-cache-path %t.tmp/module-cache -sdk %t.tmp/dummy.sdk -avoid-location
5+
// RUN: %api-digester -diagnose-sdk -input-paths %S/Inputs/stdlib-stable.json -input-paths %t.tmp/current-stdlib.json -o %t.tmp/changes.txt -v
56
// RUN: %clang -E -P -x c %S/Outputs/stability-stdlib-source.swift.expected -o - | sed '/^\s*$/d' | sort > %t.tmp/stability-stdlib-source.swift.expected
67
// RUN: %clang -E -P -x c %t.tmp/changes.txt -o - | sed '/^\s*$/d' | sort > %t.tmp/changes.txt.tmp
78
// RUN: diff -u %t.tmp/stability-stdlib-source.swift.expected %t.tmp/changes.txt.tmp

tools/swift-api-digester/ModuleAnalyzerNodes.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -586,8 +586,8 @@ static StringRef getKeyContent(SDKContext &Ctx, KeyKind Kind) {
586586
SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
587587
llvm::yaml::MappingNode *Node) {
588588
static auto GetScalarString = [&](llvm::yaml::Node *N) -> StringRef {
589-
SmallString<64> Buffer;
590-
return Ctx.buffer(cast<llvm::yaml::ScalarNode>(N)->getValue(Buffer));
589+
auto WithQuote = cast<llvm::yaml::ScalarNode>(N)->getRawValue();
590+
return WithQuote.substr(1, WithQuote.size() - 2);
591591
};
592592

593593
static auto getAsInt = [&](llvm::yaml::Node *N) -> int {
@@ -2102,6 +2102,7 @@ static parseJsonEmit(SDKContext &Ctx, StringRef FileName) {
21022102
// previously dumped.
21032103
void SwiftDeclCollector::deSerialize(StringRef Filename) {
21042104
auto Pair = parseJsonEmit(Ctx, Filename);
2105+
OwnedBuffers.push_back(std::move(Pair.first));
21052106
RootNode = std::move(Pair.second);
21062107
}
21072108

tools/swift-api-digester/ModuleAnalyzerNodes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ class SDKContext {
230230
CIs.emplace_back(new CompilerInstance());
231231
return *CIs.back();
232232
}
233+
233234
template<class YAMLNodeTy, typename ...ArgTypes>
234235
void diagnose(YAMLNodeTy node, Diag<ArgTypes...> ID,
235236
typename detail::PassArgument<ArgTypes>::type... args) {
@@ -706,6 +707,7 @@ struct TypeInitInfo {
706707

707708
class SwiftDeclCollector: public VisibleDeclConsumer {
708709
SDKContext &Ctx;
710+
std::vector<std::unique_ptr<llvm::MemoryBuffer>> OwnedBuffers;
709711
SDKNode *RootNode;
710712
llvm::SetVector<Decl*> KnownDecls;
711713
// Collected and sorted after we get all of them.

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 9 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ static llvm::cl::list<std::string>
234234
PreferInterfaceForModules("use-interface-for-module", llvm::cl::ZeroOrMore,
235235
llvm::cl::desc("Prefer loading these modules via interface"),
236236
llvm::cl::cat(Category));
237-
238-
static llvm::cl::opt<std::string>
239-
BaselineFilePath("baseline-path",
240-
llvm::cl::desc("The path to the Json file that we should use as the baseline"),
241-
llvm::cl::cat(Category));
242237
} // namespace options
243238

244239
namespace {
@@ -2534,77 +2529,6 @@ static bool hasBaselineInput() {
25342529
!options::BaselineFrameworkPaths.empty() || !options::BaselineSDK.empty();
25352530
}
25362531

2537-
enum class ComparisonInputMode: uint8_t {
2538-
BothJson,
2539-
BaselineJson,
2540-
BothLoad,
2541-
};
2542-
2543-
static ComparisonInputMode checkComparisonInputMode() {
2544-
if (options::SDKJsonPaths.size() == 2)
2545-
return ComparisonInputMode::BothJson;
2546-
else if (hasBaselineInput())
2547-
return ComparisonInputMode::BothLoad;
2548-
else
2549-
return ComparisonInputMode::BaselineJson;
2550-
}
2551-
2552-
static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
2553-
SwiftDeclCollector Collector(Ctx);
2554-
// If the baseline path has been given, honor that.
2555-
if (!options::BaselineFilePath.empty()) {
2556-
Collector.deSerialize(options::BaselineFilePath);
2557-
return Collector.getSDKRoot();
2558-
}
2559-
CompilerInvocation Invok;
2560-
llvm::StringSet<> Modules;
2561-
// We need to call prepareForDump to parse target triple.
2562-
if (prepareForDump(Main, Invok, Modules, true))
2563-
return nullptr;
2564-
2565-
assert(Modules.size() == 1 &&
2566-
"Cannot find builtin baseline for more than one module");
2567-
// The path of the swift-api-digester executable.
2568-
std::string ExePath = llvm::sys::fs::getMainExecutable(Main,
2569-
reinterpret_cast<void *>(&anchorForGetMainExecutable));
2570-
llvm::SmallString<128> BaselinePath(ExePath);
2571-
llvm::sys::path::remove_filename(BaselinePath); // Remove /swift-api-digester
2572-
llvm::sys::path::remove_filename(BaselinePath); // Remove /bin
2573-
llvm::sys::path::append(BaselinePath, "lib", "swift", "FrameworkABIBaseline",
2574-
Modules.begin()->getKey());
2575-
// Look for ABI or API baseline
2576-
if (Ctx.checkingABI())
2577-
llvm::sys::path::append(BaselinePath, "ABI");
2578-
else
2579-
llvm::sys::path::append(BaselinePath, "API");
2580-
// Look for deployment target specific baseline files.
2581-
auto Triple = Invok.getLangOptions().Target;
2582-
if (Triple.isMacCatalystEnvironment())
2583-
llvm::sys::path::append(BaselinePath, "iosmac.json");
2584-
else if (Triple.isMacOSX())
2585-
llvm::sys::path::append(BaselinePath, "macos.json");
2586-
else if (Triple.isiOS())
2587-
llvm::sys::path::append(BaselinePath, "iphoneos.json");
2588-
else if (Triple.isTvOS())
2589-
llvm::sys::path::append(BaselinePath, "appletvos.json");
2590-
else if (Triple.isWatchOS())
2591-
llvm::sys::path::append(BaselinePath, "watchos.json");
2592-
else {
2593-
llvm::errs() << "Unsupported triple target\n";
2594-
exit(1);
2595-
}
2596-
StringRef Path = BaselinePath.str();
2597-
if (!fs::exists(Path)) {
2598-
llvm::errs() << "Baseline at " << Path << " does not exist\n";
2599-
exit(1);
2600-
}
2601-
if (options::Verbose) {
2602-
llvm::errs() << "Using baseline at " << Path << "\n";
2603-
}
2604-
Collector.deSerialize(Path);
2605-
return Collector.getSDKRoot();
2606-
}
2607-
26082532
int main(int argc, char *argv[]) {
26092533
PROGRAM_START(argc, argv);
26102534
INITIALIZE_LLVM();
@@ -2626,40 +2550,33 @@ int main(int argc, char *argv[]) {
26262550
dumpSDKContent(InitInvok, Modules, options::OutputFile, Opts);
26272551
case ActionType::MigratorGen:
26282552
case ActionType::DiagnoseSDKs: {
2629-
ComparisonInputMode Mode = checkComparisonInputMode();
2553+
bool CompareJson = options::SDKJsonPaths.size() == 2;
2554+
if (!CompareJson && !hasBaselineInput()) {
2555+
llvm::errs() << "Only two SDK versions can be compared\n";
2556+
llvm::cl::PrintHelpMessage();
2557+
return 1;
2558+
}
26302559
llvm::StringSet<> protocolWhitelist;
26312560
if (!options::ProtReqWhiteList.empty()) {
26322561
if (readFileLineByLine(options::ProtReqWhiteList, protocolWhitelist))
26332562
return 1;
26342563
}
2635-
if (options::Action == ActionType::MigratorGen) {
2636-
assert(Mode == ComparisonInputMode::BothJson && "Only BothJson mode is supported");
2564+
if (options::Action == ActionType::MigratorGen)
26372565
return generateMigrationScript(options::SDKJsonPaths[0],
26382566
options::SDKJsonPaths[1],
26392567
options::OutputFile, IgnoredUsrs, Opts);
2640-
}
2641-
switch(Mode) {
2642-
case ComparisonInputMode::BothJson: {
2568+
else if (CompareJson)
26432569
return diagnoseModuleChange(options::SDKJsonPaths[0],
26442570
options::SDKJsonPaths[1],
26452571
options::OutputFile, Opts,
26462572
std::move(protocolWhitelist));
2647-
}
2648-
case ComparisonInputMode::BaselineJson: {
2649-
SDKContext Ctx(Opts);
2650-
return diagnoseModuleChange(Ctx, getBaselineFromJson(argv[0], Ctx),
2651-
getSDKRoot(argv[0], Ctx, false),
2652-
options::OutputFile,
2653-
std::move(protocolWhitelist));
2654-
}
2655-
case ComparisonInputMode::BothLoad: {
2573+
else {
26562574
SDKContext Ctx(Opts);
26572575
return diagnoseModuleChange(Ctx, getSDKRoot(argv[0], Ctx, true),
26582576
getSDKRoot(argv[0], Ctx, false),
26592577
options::OutputFile,
26602578
std::move(protocolWhitelist));
26612579
}
2662-
}
26632580
}
26642581
case ActionType::DeserializeSDK:
26652582
case ActionType::DeserializeDiffItems: {

0 commit comments

Comments
 (0)