Skip to content

Commit 903a06f

Browse files
authored
Merge pull request swiftlang#33802 from nkcsgexi/remark-sdk-build-versions
ModuleInterface: remark potential version differences between SDK and prebuilt modules
2 parents 2b67a9d + 028a755 commit 903a06f

File tree

10 files changed

+85
-48
lines changed

10 files changed

+85
-48
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ ERROR(error_extracting_flags_from_module_interface,none,
366366
"error extracting flags from module interface", ())
367367
REMARK(rebuilding_module_from_interface,none,
368368
"rebuilding module '%0' from interface '%1'", (StringRef, StringRef))
369+
NOTE(sdk_version_pbm_version,none,
370+
"SDK build version is '%0'; prebuilt modules were "
371+
"built using SDK build version: '%1'", (StringRef, StringRef))
369372
NOTE(out_of_date_module_here,none,
370373
"%select{compiled|cached|forwarding|prebuilt}0 module is out of date: '%1'",
371374
(unsigned, StringRef))

include/swift/Basic/Platform.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ namespace swift {
106106
/// Retrieve the target SDK version for the given SDKInfo and target triple.
107107
llvm::VersionTuple getTargetSDKVersion(clang::driver::DarwinSDKInfo &SDKInfo,
108108
const llvm::Triple &triple);
109+
110+
/// Get SDK build version.
111+
std::string getSDKBuildVersion(StringRef SDKPath);
112+
std::string getSDKBuildVersionFromPlist(StringRef Path);
113+
114+
/// Get SDK name.
115+
std::string getSDKName(StringRef SDKPath);
109116
} // end namespace swift
110117

111118
#endif // SWIFT_BASIC_PLATFORM_H

include/swift/IDE/Utils.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,6 @@ void walkOverriddenDecls(const ValueDecl *VD,
101101

102102
void collectModuleNames(StringRef SDKPath, std::vector<std::string> &Modules);
103103

104-
std::string getSDKName(StringRef Path);
105-
106-
std::string getSDKVersion(StringRef Path);
107-
108104
struct PlaceholderOccurrence {
109105
/// The complete placeholder string.
110106
StringRef FullPlaceholder;

lib/Basic/Platform.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,3 +473,47 @@ swift::getTargetSDKVersion(clang::driver::DarwinSDKInfo &SDKInfo,
473473

474474
return SDKVersion;
475475
}
476+
477+
static std::string getPlistEntry(const llvm::Twine &Path, StringRef KeyName) {
478+
auto BufOrErr = llvm::MemoryBuffer::getFile(Path);
479+
if (!BufOrErr) {
480+
// FIXME: diagnose properly
481+
return {};
482+
}
483+
484+
std::string Key = "<key>";
485+
Key += KeyName;
486+
Key += "</key>";
487+
488+
StringRef Lines = BufOrErr.get()->getBuffer();
489+
while (!Lines.empty()) {
490+
StringRef CurLine;
491+
std::tie(CurLine, Lines) = Lines.split('\n');
492+
if (CurLine.find(Key) != StringRef::npos) {
493+
std::tie(CurLine, Lines) = Lines.split('\n');
494+
unsigned Begin = CurLine.find("<string>") + strlen("<string>");
495+
unsigned End = CurLine.find("</string>");
496+
return CurLine.substr(Begin, End - Begin).str();
497+
}
498+
}
499+
500+
return {};
501+
}
502+
503+
std::string swift::getSDKBuildVersionFromPlist(StringRef Path) {
504+
return getPlistEntry(Path, "ProductBuildVersion");
505+
}
506+
507+
std::string swift::getSDKBuildVersion(StringRef Path) {
508+
return getSDKBuildVersionFromPlist((llvm::Twine(Path) +
509+
"/System/Library/CoreServices/SystemVersion.plist").str());
510+
}
511+
512+
std::string swift::getSDKName(StringRef Path) {
513+
std::string Name = getPlistEntry(llvm::Twine(Path)+"/SDKSettings.plist",
514+
"CanonicalName");
515+
if (Name.empty() && Path.endswith(".sdk")) {
516+
Name = llvm::sys::path::filename(Path).drop_back(strlen(".sdk")).str();
517+
}
518+
return Name;
519+
}

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,10 +286,18 @@ struct ModuleRebuildInfo {
286286
/// Emits a diagnostic for all out-of-date compiled or forwarding modules
287287
/// encountered while trying to load a module.
288288
void diagnose(ASTContext &ctx, SourceLoc loc, StringRef moduleName,
289-
StringRef interfacePath) {
289+
StringRef interfacePath, StringRef prebuiltCacheDir) {
290290
ctx.Diags.diagnose(loc, diag::rebuilding_module_from_interface,
291291
moduleName, interfacePath);
292-
292+
auto SDKVer = getSDKBuildVersion(ctx.SearchPathOpts.SDKPath);
293+
llvm::SmallString<64> buffer = prebuiltCacheDir;
294+
llvm::sys::path::append(buffer, "SystemVersion.plist");
295+
auto PBMVer = getSDKBuildVersionFromPlist(buffer.str());
296+
if (!SDKVer.empty() && !PBMVer.empty()) {
297+
// Remark the potential version difference.
298+
ctx.Diags.diagnose(loc, diag::sdk_version_pbm_version, SDKVer,
299+
PBMVer);
300+
}
293301
// We may have found multiple failing modules, that failed for different
294302
// reasons. Emit a note for each of them.
295303
for (auto &mod : outOfDateModules) {
@@ -911,7 +919,7 @@ class ModuleInterfaceLoaderImpl {
911919
// Diagnose that we didn't find a loadable module, if we were asked to.
912920
auto remarkRebuild = [&]() {
913921
rebuildInfo.diagnose(ctx, diagnosticLoc, moduleName,
914-
interfacePath);
922+
interfacePath, prebuiltCacheDir);
915923
};
916924
// If we found an out-of-date .swiftmodule, we still want to add it as
917925
// a dependency of the .swiftinterface. That way if it's updated, but

lib/IDE/Utils.cpp

Lines changed: 1 addition & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "swift/IDE/Utils.h"
1414
#include "swift/Basic/Edit.h"
1515
#include "swift/Basic/SourceManager.h"
16+
#include "swift/Basic/Platform.h"
1617
#include "swift/ClangImporter/ClangModule.h"
1718
#include "swift/Driver/FrontendUtil.h"
1819
#include "swift/Frontend/Frontend.h"
@@ -664,46 +665,6 @@ ide::replacePlaceholders(std::unique_ptr<llvm::MemoryBuffer> InputBuf,
664665
});
665666
}
666667

667-
static std::string getPlistEntry(const llvm::Twine &Path, StringRef KeyName) {
668-
auto BufOrErr = llvm::MemoryBuffer::getFile(Path);
669-
if (!BufOrErr) {
670-
llvm::errs() << "could not open '" << Path << "': " << BufOrErr.getError().message() << '\n';
671-
return {};
672-
}
673-
674-
std::string Key = "<key>";
675-
Key += KeyName;
676-
Key += "</key>";
677-
678-
StringRef Lines = BufOrErr.get()->getBuffer();
679-
while (!Lines.empty()) {
680-
StringRef CurLine;
681-
std::tie(CurLine, Lines) = Lines.split('\n');
682-
if (CurLine.find(Key) != StringRef::npos) {
683-
std::tie(CurLine, Lines) = Lines.split('\n');
684-
unsigned Begin = CurLine.find("<string>") + strlen("<string>");
685-
unsigned End = CurLine.find("</string>");
686-
return CurLine.substr(Begin, End - Begin).str();
687-
}
688-
}
689-
690-
return {};
691-
}
692-
693-
std::string ide::getSDKName(StringRef Path) {
694-
std::string Name = getPlistEntry(llvm::Twine(Path)+"/SDKSettings.plist",
695-
"CanonicalName");
696-
if (Name.empty() && Path.endswith(".sdk")) {
697-
Name = llvm::sys::path::filename(Path).drop_back(strlen(".sdk")).str();
698-
}
699-
return Name;
700-
}
701-
702-
std::string ide::getSDKVersion(StringRef Path) {
703-
return getPlistEntry(llvm::Twine(Path)+"/System/Library/CoreServices/"
704-
"SystemVersion.plist", "ProductBuildVersion");
705-
}
706-
707668
// Modules failing to load are commented-out.
708669
static const char *OSXModuleList[] = {
709670
"AGL",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<plist version="1.0">
2+
<dict>
3+
<key>ProductBuildVersion</key>
4+
<string>11111</string>
5+
</dict>
6+
</plist>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<plist version="1.0">
2+
<dict>
3+
<key>ProductBuildVersion</key>
4+
<string>22222</string>
5+
</dict>
6+
</plist>

test/ModuleInterface/ModuleCache/RebuildRemarks/out-of-date-forwarding-module.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// RUN: %empty-directory(%t/ModuleCache)
22
// RUN: %empty-directory(%t/Build)
33
// RUN: %empty-directory(%t/PrebuiltCache)
4+
// RUN: %empty-directory(%t/System/Library/CoreServices)
5+
6+
// RUN: cp %S/../Inputs/sdk-build-ver.1.plist %t/System/Library/CoreServices/SystemVersion.plist
7+
// RUN: cp %S/../Inputs/sdk-build-ver.2.plist %t/PrebuiltCache/SystemVersion.plist
48

59
// 1. Create a dummy module
610
// RUN: echo 'public func publicFunction() {}' > %t/TestModule.swift
@@ -30,3 +34,4 @@ import TestModule // expected-remark {{rebuilding module 'TestModule' from inter
3034
// expected-note @-2 {{dependency is out of date}}
3135
// expected-note @-3 {{prebuilt module is out of date}}
3236
// expected-note @-4 {{dependency is out of date}}
37+
// expected-note @-5 {{SDK build version is '11111'; prebuilt modules were built using SDK build version: '22222'}}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
// can be reflected as source-breaking changes for API users. If they are,
2727
// the output of api-digester will include such changes.
2828

29+
#include "swift/Basic/Platform.h"
2930
#include "swift/Frontend/PrintingDiagnosticConsumer.h"
3031
#include "swift/Frontend/SerializedDiagnosticConsumer.h"
3132
#include "swift/AST/DiagnosticsModuleDiffer.h"
@@ -2704,7 +2705,7 @@ static CheckerOptions getCheckOpts(int argc, char *argv[]) {
27042705
Opts.ToolArgs.push_back(argv[i]);
27052706

27062707
if (!options::SDK.empty()) {
2707-
auto Ver = getSDKVersion(options::SDK);
2708+
auto Ver = getSDKBuildVersion(options::SDK);
27082709
if (!Ver.empty()) {
27092710
Opts.ToolArgs.push_back("-sdk-version");
27102711
Opts.ToolArgs.push_back(Ver);

0 commit comments

Comments
 (0)