@@ -1888,16 +1888,23 @@ struct DarwinPlatform {
1888
1888
case TargetArg:
1889
1889
case MTargetOSArg:
1890
1890
case OSVersionArg:
1891
- case InferredFromSDK:
1892
- case InferredFromArch:
1893
1891
assert (Arg && " OS version argument not yet inferred" );
1894
1892
return Arg->getAsString (Args);
1895
1893
case DeploymentTargetEnv:
1896
1894
return (llvm::Twine (EnvVarName) + " =" + OSVersionStr).str ();
1895
+ case InferredFromSDK:
1896
+ case InferredFromArch:
1897
+ llvm_unreachable (" Cannot print arguments for inferred OS version" );
1897
1898
}
1898
1899
llvm_unreachable (" Unsupported Darwin Source Kind" );
1899
1900
}
1900
1901
1902
+ // Returns the inferred source of how the OS version was resolved.
1903
+ std::string getInferredSource () {
1904
+ assert (!isExplicitlySpecified () && " OS version was not inferred" );
1905
+ return InferredSource.str ();
1906
+ }
1907
+
1901
1908
void setEnvironment (llvm::Triple::EnvironmentType EnvType,
1902
1909
const VersionTuple &OSVersion,
1903
1910
const std::optional<DarwinSDKInfo> &SDKInfo) {
@@ -1971,19 +1978,24 @@ struct DarwinPlatform {
1971
1978
Result.EnvVarName = EnvVarName;
1972
1979
return Result;
1973
1980
}
1974
- static DarwinPlatform createFromSDK (DarwinPlatformKind Platform,
1981
+ static DarwinPlatform createFromSDK (StringRef SDKRoot,
1982
+ DarwinPlatformKind Platform,
1975
1983
StringRef Value,
1976
1984
bool IsSimulator = false ) {
1977
1985
DarwinPlatform Result (InferredFromSDK, Platform,
1978
1986
getVersionFromString (Value));
1979
1987
if (IsSimulator)
1980
1988
Result.Environment = DarwinEnvironmentKind::Simulator;
1981
1989
Result.InferSimulatorFromArch = false ;
1990
+ Result.InferredSource = SDKRoot;
1982
1991
return Result;
1983
1992
}
1984
- static DarwinPlatform createFromArch (llvm::Triple::OSType OS,
1993
+ static DarwinPlatform createFromArch (StringRef Arch, llvm::Triple::OSType OS,
1985
1994
VersionTuple Version) {
1986
- return DarwinPlatform (InferredFromArch, getPlatformFromOS (OS), Version);
1995
+ auto Result =
1996
+ DarwinPlatform (InferredFromArch, getPlatformFromOS (OS), Version);
1997
+ Result.InferredSource = Arch;
1998
+ return Result;
1987
1999
}
1988
2000
1989
2001
// / Constructs an inferred SDKInfo value based on the version inferred from
@@ -2069,6 +2081,9 @@ struct DarwinPlatform {
2069
2081
bool InferSimulatorFromArch = true ;
2070
2082
std::pair<Arg *, std::string> Arguments;
2071
2083
StringRef EnvVarName;
2084
+ // If the DarwinPlatform information is derived from an inferred source, this
2085
+ // captures what that source input was for error reporting.
2086
+ StringRef InferredSource;
2072
2087
// When compiling for a zippered target, this value represents the target
2073
2088
// triple encoded in the target variant.
2074
2089
std::optional<llvm::Triple> TargetVariantTriple;
@@ -2237,26 +2252,27 @@ inferDeploymentTargetFromSDK(DerivedArgList &Args,
2237
2252
[&](StringRef SDK) -> std::optional<DarwinPlatform> {
2238
2253
if (SDK.starts_with (" iPhoneOS" ) || SDK.starts_with (" iPhoneSimulator" ))
2239
2254
return DarwinPlatform::createFromSDK (
2240
- Darwin::IPhoneOS, Version,
2255
+ isysroot, Darwin::IPhoneOS, Version,
2241
2256
/* IsSimulator=*/ SDK.starts_with (" iPhoneSimulator" ));
2242
2257
else if (SDK.starts_with (" MacOSX" ))
2243
- return DarwinPlatform::createFromSDK (Darwin::MacOS,
2258
+ return DarwinPlatform::createFromSDK (isysroot, Darwin::MacOS,
2244
2259
getSystemOrSDKMacOSVersion (Version));
2245
2260
else if (SDK.starts_with (" WatchOS" ) || SDK.starts_with (" WatchSimulator" ))
2246
2261
return DarwinPlatform::createFromSDK (
2247
- Darwin::WatchOS, Version,
2262
+ isysroot, Darwin::WatchOS, Version,
2248
2263
/* IsSimulator=*/ SDK.starts_with (" WatchSimulator" ));
2249
2264
else if (SDK.starts_with (" AppleTVOS" ) ||
2250
2265
SDK.starts_with (" AppleTVSimulator" ))
2251
2266
return DarwinPlatform::createFromSDK (
2252
- Darwin::TvOS, Version,
2267
+ isysroot, Darwin::TvOS, Version,
2253
2268
/* IsSimulator=*/ SDK.starts_with (" AppleTVSimulator" ));
2254
2269
else if (SDK.starts_with (" XR" ))
2255
2270
return DarwinPlatform::createFromSDK (
2256
- Darwin::XROS, Version,
2271
+ isysroot, Darwin::XROS, Version,
2257
2272
/* IsSimulator=*/ SDK.contains (" Simulator" ));
2258
2273
else if (SDK.starts_with (" DriverKit" ))
2259
- return DarwinPlatform::createFromSDK (Darwin::DriverKit, Version);
2274
+ return DarwinPlatform::createFromSDK (isysroot, Darwin::DriverKit,
2275
+ Version);
2260
2276
return std::nullopt;
2261
2277
};
2262
2278
if (auto Result = CreatePlatformFromSDKName (SDK))
@@ -2329,7 +2345,7 @@ inferDeploymentTargetFromArch(DerivedArgList &Args, const Darwin &Toolchain,
2329
2345
if (OSTy == llvm::Triple::UnknownOS)
2330
2346
return std::nullopt;
2331
2347
return DarwinPlatform::createFromArch (
2332
- OSTy, getInferredOSVersion (OSTy, Triple, TheDriver));
2348
+ MachOArchName, OSTy, getInferredOSVersion (OSTy, Triple, TheDriver));
2333
2349
}
2334
2350
2335
2351
// / Returns the deployment target that's specified using the -target option.
@@ -2548,9 +2564,15 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
2548
2564
}
2549
2565
2550
2566
assert (PlatformAndVersion && " Unable to infer Darwin variant" );
2551
- if (!PlatformAndVersion->isValidOSVersion ())
2552
- getDriver ().Diag (diag::err_drv_invalid_version_number)
2553
- << PlatformAndVersion->getAsString (Args, Opts);
2567
+ if (!PlatformAndVersion->isValidOSVersion ()) {
2568
+ if (PlatformAndVersion->isExplicitlySpecified ())
2569
+ getDriver ().Diag (diag::err_drv_invalid_version_number)
2570
+ << PlatformAndVersion->getAsString (Args, Opts);
2571
+ else
2572
+ getDriver ().Diag (diag::err_drv_invalid_version_number_inferred)
2573
+ << PlatformAndVersion->getOSVersion ().getAsString ()
2574
+ << PlatformAndVersion->getInferredSource ();
2575
+ }
2554
2576
// After the deployment OS version has been resolved, set it to the canonical
2555
2577
// version before further error detection and converting to a proper target
2556
2578
// triple.
0 commit comments