mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Revert "swift-api-digester: teach the tool to find framework-specific baselines from relative path"
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
// REQUIRES: swift_stdlib_asserts
|
||||
// RUN: %empty-directory(%t.tmp)
|
||||
// mkdir %t.tmp/module-cache && mkdir %t.tmp/dummy.sdk
|
||||
// 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
|
||||
// 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
|
||||
// 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
|
||||
// RUN: %clang -E -P -x c %S/Outputs/stability-stdlib-abi.without.asserts.swift.expected -o - > %t.tmp/stability-stdlib-abi.swift.expected
|
||||
// RUN: %clang -E -P -x c %S/Outputs/stability-stdlib-abi.asserts.additional.swift.expected -o - >> %t.tmp/stability-stdlib-abi.swift.expected
|
||||
// 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
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
// REQUIRES: OS=macosx
|
||||
// RUN: %empty-directory(%t.tmp)
|
||||
// mkdir %t.tmp/module-cache && mkdir %t.tmp/dummy.sdk
|
||||
// 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
|
||||
// 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
|
||||
// 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
|
||||
// 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
|
||||
// RUN: %clang -E -P -x c %t.tmp/changes.txt -o - | sed '/^\s*$/d' | sort > %t.tmp/changes.txt.tmp
|
||||
// RUN: diff -u %t.tmp/stability-stdlib-source.swift.expected %t.tmp/changes.txt.tmp
|
||||
|
||||
@@ -586,8 +586,8 @@ static StringRef getKeyContent(SDKContext &Ctx, KeyKind Kind) {
|
||||
SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
|
||||
llvm::yaml::MappingNode *Node) {
|
||||
static auto GetScalarString = [&](llvm::yaml::Node *N) -> StringRef {
|
||||
SmallString<64> Buffer;
|
||||
return Ctx.buffer(cast<llvm::yaml::ScalarNode>(N)->getValue(Buffer));
|
||||
auto WithQuote = cast<llvm::yaml::ScalarNode>(N)->getRawValue();
|
||||
return WithQuote.substr(1, WithQuote.size() - 2);
|
||||
};
|
||||
|
||||
static auto getAsInt = [&](llvm::yaml::Node *N) -> int {
|
||||
@@ -2102,6 +2102,7 @@ static parseJsonEmit(SDKContext &Ctx, StringRef FileName) {
|
||||
// previously dumped.
|
||||
void SwiftDeclCollector::deSerialize(StringRef Filename) {
|
||||
auto Pair = parseJsonEmit(Ctx, Filename);
|
||||
OwnedBuffers.push_back(std::move(Pair.first));
|
||||
RootNode = std::move(Pair.second);
|
||||
}
|
||||
|
||||
|
||||
@@ -230,6 +230,7 @@ public:
|
||||
CIs.emplace_back(new CompilerInstance());
|
||||
return *CIs.back();
|
||||
}
|
||||
|
||||
template<class YAMLNodeTy, typename ...ArgTypes>
|
||||
void diagnose(YAMLNodeTy node, Diag<ArgTypes...> ID,
|
||||
typename detail::PassArgument<ArgTypes>::type... args) {
|
||||
@@ -706,6 +707,7 @@ struct TypeInitInfo {
|
||||
|
||||
class SwiftDeclCollector: public VisibleDeclConsumer {
|
||||
SDKContext &Ctx;
|
||||
std::vector<std::unique_ptr<llvm::MemoryBuffer>> OwnedBuffers;
|
||||
SDKNode *RootNode;
|
||||
llvm::SetVector<Decl*> KnownDecls;
|
||||
// Collected and sorted after we get all of them.
|
||||
|
||||
@@ -234,11 +234,6 @@ static llvm::cl::list<std::string>
|
||||
PreferInterfaceForModules("use-interface-for-module", llvm::cl::ZeroOrMore,
|
||||
llvm::cl::desc("Prefer loading these modules via interface"),
|
||||
llvm::cl::cat(Category));
|
||||
|
||||
static llvm::cl::opt<std::string>
|
||||
BaselineFilePath("baseline-path",
|
||||
llvm::cl::desc("The path to the Json file that we should use as the baseline"),
|
||||
llvm::cl::cat(Category));
|
||||
} // namespace options
|
||||
|
||||
namespace {
|
||||
@@ -2534,77 +2529,6 @@ static bool hasBaselineInput() {
|
||||
!options::BaselineFrameworkPaths.empty() || !options::BaselineSDK.empty();
|
||||
}
|
||||
|
||||
enum class ComparisonInputMode: uint8_t {
|
||||
BothJson,
|
||||
BaselineJson,
|
||||
BothLoad,
|
||||
};
|
||||
|
||||
static ComparisonInputMode checkComparisonInputMode() {
|
||||
if (options::SDKJsonPaths.size() == 2)
|
||||
return ComparisonInputMode::BothJson;
|
||||
else if (hasBaselineInput())
|
||||
return ComparisonInputMode::BothLoad;
|
||||
else
|
||||
return ComparisonInputMode::BaselineJson;
|
||||
}
|
||||
|
||||
static SDKNodeRoot *getBaselineFromJson(const char *Main, SDKContext &Ctx) {
|
||||
SwiftDeclCollector Collector(Ctx);
|
||||
// If the baseline path has been given, honor that.
|
||||
if (!options::BaselineFilePath.empty()) {
|
||||
Collector.deSerialize(options::BaselineFilePath);
|
||||
return Collector.getSDKRoot();
|
||||
}
|
||||
CompilerInvocation Invok;
|
||||
llvm::StringSet<> Modules;
|
||||
// We need to call prepareForDump to parse target triple.
|
||||
if (prepareForDump(Main, Invok, Modules, true))
|
||||
return nullptr;
|
||||
|
||||
assert(Modules.size() == 1 &&
|
||||
"Cannot find builtin baseline for more than one module");
|
||||
// The path of the swift-api-digester executable.
|
||||
std::string ExePath = llvm::sys::fs::getMainExecutable(Main,
|
||||
reinterpret_cast<void *>(&anchorForGetMainExecutable));
|
||||
llvm::SmallString<128> BaselinePath(ExePath);
|
||||
llvm::sys::path::remove_filename(BaselinePath); // Remove /swift-api-digester
|
||||
llvm::sys::path::remove_filename(BaselinePath); // Remove /bin
|
||||
llvm::sys::path::append(BaselinePath, "lib", "swift", "FrameworkABIBaseline",
|
||||
Modules.begin()->getKey());
|
||||
// Look for ABI or API baseline
|
||||
if (Ctx.checkingABI())
|
||||
llvm::sys::path::append(BaselinePath, "ABI");
|
||||
else
|
||||
llvm::sys::path::append(BaselinePath, "API");
|
||||
// Look for deployment target specific baseline files.
|
||||
auto Triple = Invok.getLangOptions().Target;
|
||||
if (Triple.isMacCatalystEnvironment())
|
||||
llvm::sys::path::append(BaselinePath, "iosmac.json");
|
||||
else if (Triple.isMacOSX())
|
||||
llvm::sys::path::append(BaselinePath, "macos.json");
|
||||
else if (Triple.isiOS())
|
||||
llvm::sys::path::append(BaselinePath, "iphoneos.json");
|
||||
else if (Triple.isTvOS())
|
||||
llvm::sys::path::append(BaselinePath, "appletvos.json");
|
||||
else if (Triple.isWatchOS())
|
||||
llvm::sys::path::append(BaselinePath, "watchos.json");
|
||||
else {
|
||||
llvm::errs() << "Unsupported triple target\n";
|
||||
exit(1);
|
||||
}
|
||||
StringRef Path = BaselinePath.str();
|
||||
if (!fs::exists(Path)) {
|
||||
llvm::errs() << "Baseline at " << Path << " does not exist\n";
|
||||
exit(1);
|
||||
}
|
||||
if (options::Verbose) {
|
||||
llvm::errs() << "Using baseline at " << Path << "\n";
|
||||
}
|
||||
Collector.deSerialize(Path);
|
||||
return Collector.getSDKRoot();
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
PROGRAM_START(argc, argv);
|
||||
INITIALIZE_LLVM();
|
||||
@@ -2626,33 +2550,27 @@ int main(int argc, char *argv[]) {
|
||||
dumpSDKContent(InitInvok, Modules, options::OutputFile, Opts);
|
||||
case ActionType::MigratorGen:
|
||||
case ActionType::DiagnoseSDKs: {
|
||||
ComparisonInputMode Mode = checkComparisonInputMode();
|
||||
bool CompareJson = options::SDKJsonPaths.size() == 2;
|
||||
if (!CompareJson && !hasBaselineInput()) {
|
||||
llvm::errs() << "Only two SDK versions can be compared\n";
|
||||
llvm::cl::PrintHelpMessage();
|
||||
return 1;
|
||||
}
|
||||
llvm::StringSet<> protocolWhitelist;
|
||||
if (!options::ProtReqWhiteList.empty()) {
|
||||
if (readFileLineByLine(options::ProtReqWhiteList, protocolWhitelist))
|
||||
return 1;
|
||||
}
|
||||
if (options::Action == ActionType::MigratorGen) {
|
||||
assert(Mode == ComparisonInputMode::BothJson && "Only BothJson mode is supported");
|
||||
if (options::Action == ActionType::MigratorGen)
|
||||
return generateMigrationScript(options::SDKJsonPaths[0],
|
||||
options::SDKJsonPaths[1],
|
||||
options::OutputFile, IgnoredUsrs, Opts);
|
||||
}
|
||||
switch(Mode) {
|
||||
case ComparisonInputMode::BothJson: {
|
||||
else if (CompareJson)
|
||||
return diagnoseModuleChange(options::SDKJsonPaths[0],
|
||||
options::SDKJsonPaths[1],
|
||||
options::OutputFile, Opts,
|
||||
std::move(protocolWhitelist));
|
||||
}
|
||||
case ComparisonInputMode::BaselineJson: {
|
||||
SDKContext Ctx(Opts);
|
||||
return diagnoseModuleChange(Ctx, getBaselineFromJson(argv[0], Ctx),
|
||||
getSDKRoot(argv[0], Ctx, false),
|
||||
options::OutputFile,
|
||||
std::move(protocolWhitelist));
|
||||
}
|
||||
case ComparisonInputMode::BothLoad: {
|
||||
else {
|
||||
SDKContext Ctx(Opts);
|
||||
return diagnoseModuleChange(Ctx, getSDKRoot(argv[0], Ctx, true),
|
||||
getSDKRoot(argv[0], Ctx, false),
|
||||
@@ -2660,7 +2578,6 @@ int main(int argc, char *argv[]) {
|
||||
std::move(protocolWhitelist));
|
||||
}
|
||||
}
|
||||
}
|
||||
case ActionType::DeserializeSDK:
|
||||
case ActionType::DeserializeDiffItems: {
|
||||
if (options::SDKJsonPaths.size() != 1) {
|
||||
|
||||
Reference in New Issue
Block a user