In immediate mode, detect the host OS version on Apple platforms.

This allows script mode to pick up the current version of macOS
instead of defaulting to 10.9, making it unnecessary to write #available.
A -target flag can still override this if you're trying to write a
portable script.

The logic is a little tortured to avoid having to actually link to
Foundation.framework or libobjc.

Finishes rdar://problem/29433205.
This commit is contained in:
Jordan Rose
2016-12-21 19:54:22 -08:00
parent fdd02f61d3
commit 23f25e1de7
6 changed files with 160 additions and 0 deletions

View File

@@ -12,6 +12,10 @@
#include "swift/Frontend/Frontend.h"
#if __APPLE__
# include "AppleHostVersionDetection.h"
#endif
#include "swift/Strings.h"
#include "swift/AST/DiagnosticsFrontend.h"
#include "swift/Basic/Platform.h"
@@ -904,6 +908,21 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Target = llvm::Triple(A->getValue());
TargetArg = A->getValue();
}
#if __APPLE__
else if (FrontendOpts.actionIsImmediate()) {
clang::VersionTuple currentOSVersion = inferAppleHostOSVersion();
if (currentOSVersion.getMajor() != 0) {
llvm::Triple::OSType currentOS = Target.getOS();
if (currentOS == llvm::Triple::Darwin)
currentOS = llvm::Triple::MacOSX;
SmallString<16> newOSBuf;
llvm::raw_svector_ostream newOS(newOSBuf);
newOS << llvm::Triple::getOSTypeName(currentOS) << currentOSVersion;
Target.setOSName(newOS.str());
}
}
#endif
Opts.EnableObjCInterop = Target.isOSDarwin();
if (auto A = Args.getLastArg(OPT_enable_objc_interop,