Skip to content

Commit 43fa4e9

Browse files
authored
Merge pull request #16843 from nkcsgexi/diag-missing-script
2 parents ca9c68d + 7312fea commit 43fa4e9

File tree

7 files changed

+33
-12
lines changed

7 files changed

+33
-12
lines changed

include/swift/AST/DiagnosticsDriver.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ WARNING(warn_emit_public_type_metadata_accessors_deprecated, none,
161161

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

164+
ERROR(cannot_find_migration_script, none,
165+
"missing migration script from path '%0'", (StringRef))
166+
164167
#ifndef DIAG_NO_UNDEF
165168
# if defined(DIAG)
166169
# undef DIAG

include/swift/IDE/APIDigesterData.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "llvm/Support/raw_ostream.h"
2323

2424
namespace swift {
25+
class DiagnosticEngine;
26+
2527
namespace ide {
2628
namespace api {
2729

@@ -370,7 +372,7 @@ struct APIDiffItemStore {
370372
static void serialize(llvm::raw_ostream &os, ArrayRef<APIDiffItem*> Items);
371373
static void serialize(llvm::raw_ostream &os, ArrayRef<NameCorrectionInfo> Items);
372374
APIDiffItemStore(const APIDiffItemStore& that) = delete;
373-
APIDiffItemStore();
375+
APIDiffItemStore(DiagnosticEngine &Diags);
374376
~APIDiffItemStore();
375377
ArrayRef<APIDiffItem*> getDiffItems(StringRef Key) const;
376378
ArrayRef<APIDiffItem*> getAllDiffItems() const;

include/swift/Migrator/ASTMigratorPass.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
namespace swift {
2525
class SourceManager;
2626
struct MigratorOptions;
27+
class DiagnosticEngine;
2728

2829
namespace migrator {
2930
class ASTMigratorPass {
@@ -34,12 +35,13 @@ class ASTMigratorPass {
3435
const StringRef Filename;
3536
const unsigned BufferID;
3637
SourceManager &SM;
38+
DiagnosticEngine &Diags;
3739

3840
ASTMigratorPass(EditorAdapter &Editor, SourceFile *SF,
3941
const MigratorOptions &Opts)
4042
: Editor(Editor), SF(SF), Opts(Opts), Filename(SF->getFilename()),
4143
BufferID(SF->getBufferID().getValue()),
42-
SM(SF->getASTContext().SourceMgr) {}
44+
SM(SF->getASTContext().SourceMgr), Diags(SF->getASTContext().Diags) {}
4345
};
4446

4547
/// Run a general pass to migrate code based on SDK differences in the previous

lib/IDE/APIDigesterData.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "llvm/Support/MemoryBuffer.h"
1717
#include "swift/Basic/JSONSerialization.h"
1818
#include "swift/IDE/APIDigesterData.h"
19+
#include "swift/AST/DiagnosticEngine.h"
20+
#include "swift/AST/DiagnosticsDriver.h"
1921

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

482484
struct swift::ide::api::APIDiffItemStore::Implementation {
483485
private:
486+
DiagnosticEngine &Diags;
484487
llvm::SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 2> AllBuffer;
485488
llvm::BumpPtrAllocator Allocator;
486489

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

502505
public:
506+
Implementation(DiagnosticEngine &Diags): Diags(Diags) {}
503507
llvm::StringMap<std::vector<APIDiffItem*>> Data;
504508
bool PrintUsr;
505509
std::vector<APIDiffItem*> AllItems;
@@ -509,7 +513,9 @@ struct swift::ide::api::APIDiffItemStore::Implementation {
509513
{
510514
auto FileBufOrErr = llvm::MemoryBuffer::getFileOrSTDIN(FileName);
511515
if (!FileBufOrErr) {
512-
llvm_unreachable("Failed to read JSON file");
516+
Diags.diagnose(SourceLoc(), diag::cannot_find_migration_script,
517+
FileName);
518+
return;
513519
}
514520
pMemBuffer = FileBufOrErr->get();
515521
AllBuffer.push_back(std::move(FileBufOrErr.get()));
@@ -546,8 +552,8 @@ getDiffItems(StringRef Key) const {
546552
ArrayRef<APIDiffItem*> swift::ide::api::APIDiffItemStore::
547553
getAllDiffItems() const { return Impl.AllItems; }
548554

549-
swift::ide::api::APIDiffItemStore::APIDiffItemStore() :
550-
Impl(*new Implementation()) {}
555+
swift::ide::api::APIDiffItemStore::APIDiffItemStore(DiagnosticEngine &Diags) :
556+
Impl(*new Implementation(Diags)) {}
551557

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

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
332332
SourceLoc FileEndLoc;
333333
APIDiffMigratorPass(EditorAdapter &Editor, SourceFile *SF,
334334
const MigratorOptions &Opts):
335-
ASTMigratorPass(Editor, SF, Opts),
335+
ASTMigratorPass(Editor, SF, Opts), DiffStore(Diags),
336336
FileEndLoc(SM.getRangeForBuffer(BufferID).getEnd()) {
337337
SmallVector<Decl*, 16> TopDecls;
338338
SF->getTopLevelDecls(TopDecls);

test/Migrator/missing_script.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// 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
2+
// RUN: %FileCheck %s < %t.diag
3+
// CHECK: missing migration script from path

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4104,8 +4104,8 @@ static void readIgnoredUsrs(llvm::StringSet<> &IgnoredUsrs) {
41044104
readFileLineByLine(Path, IgnoredUsrs);
41054105
}
41064106

4107-
static int deserializeDiffItems(StringRef DiffPath, StringRef OutputPath) {
4108-
APIDiffItemStore Store;
4107+
static int deserializeDiffItems(APIDiffItemStore &Store, StringRef DiffPath,
4108+
StringRef OutputPath) {
41094109
Store.addStorePath(DiffPath);
41104110
std::error_code EC;
41114111
llvm::raw_fd_ostream FS(OutputPath, EC, llvm::sys::fs::F_None);
@@ -4222,13 +4222,18 @@ int main(int argc, char *argv[]) {
42224222
llvm::cl::PrintHelpMessage();
42234223
return 1;
42244224
}
4225-
if (options::Action == ActionType::DeserializeDiffItems)
4226-
return deserializeDiffItems(options::SDKJsonPaths[0], options::OutputFile);
4227-
else
4225+
if (options::Action == ActionType::DeserializeDiffItems) {
4226+
CompilerInstance CI;
4227+
APIDiffItemStore Store(CI.getDiags());
4228+
return deserializeDiffItems(Store, options::SDKJsonPaths[0],
4229+
options::OutputFile);
4230+
} else {
42284231
return deserializeSDKDump(options::SDKJsonPaths[0], options::OutputFile);
4232+
}
42294233
}
42304234
case ActionType::GenerateNameCorrectionTemplate: {
4231-
APIDiffItemStore Store;
4235+
CompilerInstance CI;
4236+
APIDiffItemStore Store(CI.getDiags());
42324237
auto &Paths = options::SDKJsonPaths;
42334238
for (unsigned I = 0; I < Paths.size(); I ++)
42344239
Store.addStorePath(Paths[I]);

0 commit comments

Comments
 (0)