mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user