Skip to content

migrator: emit error messages when migration scripts are missing. #16843

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
May 25, 2018
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
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsDriver.def
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ WARNING(warn_emit_public_type_metadata_accessors_deprecated, none,

REMARK(remark_using_batch_mode,none, "using batch mode", ())

ERROR(cannot_find_migration_script, none,
"missing migration script from path '%0'", (StringRef))

#ifndef DIAG_NO_UNDEF
# if defined(DIAG)
# undef DIAG
Expand Down
4 changes: 3 additions & 1 deletion include/swift/IDE/APIDigesterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "llvm/Support/raw_ostream.h"

namespace swift {
class DiagnosticEngine;

namespace ide {
namespace api {

Expand Down Expand Up @@ -370,7 +372,7 @@ struct APIDiffItemStore {
static void serialize(llvm::raw_ostream &os, ArrayRef<APIDiffItem*> Items);
static void serialize(llvm::raw_ostream &os, ArrayRef<NameCorrectionInfo> Items);
APIDiffItemStore(const APIDiffItemStore& that) = delete;
APIDiffItemStore();
APIDiffItemStore(DiagnosticEngine &Diags);
~APIDiffItemStore();
ArrayRef<APIDiffItem*> getDiffItems(StringRef Key) const;
ArrayRef<APIDiffItem*> getAllDiffItems() const;
Expand Down
4 changes: 3 additions & 1 deletion include/swift/Migrator/ASTMigratorPass.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace swift {
class SourceManager;
struct MigratorOptions;
class DiagnosticEngine;

namespace migrator {
class ASTMigratorPass {
Expand All @@ -34,12 +35,13 @@ class ASTMigratorPass {
const StringRef Filename;
const unsigned BufferID;
SourceManager &SM;
DiagnosticEngine &Diags;

ASTMigratorPass(EditorAdapter &Editor, SourceFile *SF,
const MigratorOptions &Opts)
: Editor(Editor), SF(SF), Opts(Opts), Filename(SF->getFilename()),
BufferID(SF->getBufferID().getValue()),
SM(SF->getASTContext().SourceMgr) {}
SM(SF->getASTContext().SourceMgr), Diags(SF->getASTContext().Diags) {}
};

/// Run a general pass to migrate code based on SDK differences in the previous
Expand Down
12 changes: 9 additions & 3 deletions lib/IDE/APIDigesterData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include "llvm/Support/MemoryBuffer.h"
#include "swift/Basic/JSONSerialization.h"
#include "swift/IDE/APIDigesterData.h"
#include "swift/AST/DiagnosticEngine.h"
#include "swift/AST/DiagnosticsDriver.h"

using namespace swift;
using namespace ide;
Expand Down Expand Up @@ -481,6 +483,7 @@ serialize(llvm::raw_ostream &os, ArrayRef<NameCorrectionInfo> Items) {

struct swift::ide::api::APIDiffItemStore::Implementation {
private:
DiagnosticEngine &Diags;
llvm::SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 2> AllBuffer;
llvm::BumpPtrAllocator Allocator;

Expand All @@ -500,6 +503,7 @@ struct swift::ide::api::APIDiffItemStore::Implementation {
}

public:
Implementation(DiagnosticEngine &Diags): Diags(Diags) {}
llvm::StringMap<std::vector<APIDiffItem*>> Data;
bool PrintUsr;
std::vector<APIDiffItem*> AllItems;
Expand All @@ -509,7 +513,9 @@ struct swift::ide::api::APIDiffItemStore::Implementation {
{
auto FileBufOrErr = llvm::MemoryBuffer::getFileOrSTDIN(FileName);
if (!FileBufOrErr) {
llvm_unreachable("Failed to read JSON file");
Diags.diagnose(SourceLoc(), diag::cannot_find_migration_script,
FileName);
return;
}
pMemBuffer = FileBufOrErr->get();
AllBuffer.push_back(std::move(FileBufOrErr.get()));
Expand Down Expand Up @@ -546,8 +552,8 @@ getDiffItems(StringRef Key) const {
ArrayRef<APIDiffItem*> swift::ide::api::APIDiffItemStore::
getAllDiffItems() const { return Impl.AllItems; }

swift::ide::api::APIDiffItemStore::APIDiffItemStore() :
Impl(*new Implementation()) {}
swift::ide::api::APIDiffItemStore::APIDiffItemStore(DiagnosticEngine &Diags) :
Impl(*new Implementation(Diags)) {}

swift::ide::api::APIDiffItemStore::~APIDiffItemStore() { delete &Impl; }

Expand Down
2 changes: 1 addition & 1 deletion lib/Migrator/APIDiffMigratorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
SourceLoc FileEndLoc;
APIDiffMigratorPass(EditorAdapter &Editor, SourceFile *SF,
const MigratorOptions &Opts):
ASTMigratorPass(Editor, SF, Opts),
ASTMigratorPass(Editor, SF, Opts), DiffStore(Diags),
FileEndLoc(SM.getRangeForBuffer(BufferID).getEnd()) {
SmallVector<Decl*, 16> TopDecls;
SF->getTopLevelDecls(TopDecls);
Expand Down
3 changes: 3 additions & 0 deletions test/Migrator/missing_script.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// RUN: %empty-directory(%t) && not %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/Inputs/NoSuchFile.json -emit-migrated-file-path %t/missing_script.swift.result -emit-remap-file-path %t/missing_script.swift.remap -o /dev/null &> %t.diag
// RUN: %FileCheck %s < %t.diag
// CHECK: missing migration script from path
17 changes: 11 additions & 6 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4104,8 +4104,8 @@ static void readIgnoredUsrs(llvm::StringSet<> &IgnoredUsrs) {
readFileLineByLine(Path, IgnoredUsrs);
}

static int deserializeDiffItems(StringRef DiffPath, StringRef OutputPath) {
APIDiffItemStore Store;
static int deserializeDiffItems(APIDiffItemStore &Store, StringRef DiffPath,
StringRef OutputPath) {
Store.addStorePath(DiffPath);
std::error_code EC;
llvm::raw_fd_ostream FS(OutputPath, EC, llvm::sys::fs::F_None);
Expand Down Expand Up @@ -4222,13 +4222,18 @@ int main(int argc, char *argv[]) {
llvm::cl::PrintHelpMessage();
return 1;
}
if (options::Action == ActionType::DeserializeDiffItems)
return deserializeDiffItems(options::SDKJsonPaths[0], options::OutputFile);
else
if (options::Action == ActionType::DeserializeDiffItems) {
CompilerInstance CI;
APIDiffItemStore Store(CI.getDiags());
return deserializeDiffItems(Store, options::SDKJsonPaths[0],
options::OutputFile);
} else {
return deserializeSDKDump(options::SDKJsonPaths[0], options::OutputFile);
}
}
case ActionType::GenerateNameCorrectionTemplate: {
APIDiffItemStore Store;
CompilerInstance CI;
APIDiffItemStore Store(CI.getDiags());
auto &Paths = options::SDKJsonPaths;
for (unsigned I = 0; I < Paths.size(); I ++)
Store.addStorePath(Paths[I]);
Expand Down