diff --git a/llvm/lib/TextAPI/TextStubV5.cpp b/llvm/lib/TextAPI/TextStubV5.cpp --- a/llvm/lib/TextAPI/TextStubV5.cpp +++ b/llvm/lib/TextAPI/TextStubV5.cpp @@ -27,7 +27,7 @@ "target_info": [ # Required: target information { "target": "x86_64-macos", - "min_deployment": "10.14" # Required: minimum OS deployment version + "min_deployment": "10.14" # Optional: minOS defaults to 0 }, { "target": "arm64-macos", @@ -283,17 +283,16 @@ getRequiredValue(TBDKey::Target, Obj, &Object::getString); if (!TargetStr) return make_error(getParseErrorMsg(TBDKey::Target)); - auto VersionStr = getRequiredValue(TBDKey::Deployment, Obj, - &Object::getString); - if (!VersionStr) - return make_error(getParseErrorMsg(TBDKey::Deployment)); - VersionTuple Version; - if (Version.tryParse(*VersionStr)) - return make_error(getParseErrorMsg(TBDKey::Deployment)); auto TargetOrErr = Target::create(*TargetStr); if (!TargetOrErr) return make_error(getParseErrorMsg(TBDKey::Target)); + + auto VersionStr = Obj->getString(Keys[TBDKey::Deployment]); + VersionTuple Version; + if (VersionStr && Version.tryParse(*VersionStr)) + return make_error(getParseErrorMsg(TBDKey::Deployment)); TargetOrErr->MinDeployment = Version; + // Convert to LLVM::Triple to accurately compute minOS + platform + arch // pairing. IFTargets.push_back( diff --git a/llvm/unittests/TextAPI/TextStubV5Tests.cpp b/llvm/unittests/TextAPI/TextStubV5Tests.cpp --- a/llvm/unittests/TextAPI/TextStubV5Tests.cpp +++ b/llvm/unittests/TextAPI/TextStubV5Tests.cpp @@ -1104,6 +1104,53 @@ EXPECT_EQ("invalid exported_symbols section\n", ErrorMessage); } +TEST(TBDv5, DefaultMinOS) { + static const char TBDv5File[] = R"({ +"tapi_tbd_version": 5, +"main_library": { + "target_info": [ + { + "target": "arm64-ios-simulator" + } + ], + "install_names":[ + { "name":"/S/L/F/Foo.framework/Foo" } + ] +}})"; + + Expected Result = + TextAPIReader::get(MemoryBufferRef(TBDv5File, "Test.tbd")); + EXPECT_TRUE(!!Result); + TBDFile File = std::move(Result.get()); + EXPECT_EQ(FileType::TBD_V5, File->getFileType()); + EXPECT_EQ(std::string("/S/L/F/Foo.framework/Foo"), File->getInstallName()); + EXPECT_TRUE(File->targets().begin() != File->targets().end()); + EXPECT_EQ(*File->targets().begin(), + Target(AK_arm64, PLATFORM_IOSSIMULATOR, VersionTuple(0, 0))); +} + +TEST(TBDv5, InvalidMinOS) { + static const char TBDv5File[] = R"({ +"tapi_tbd_version": 5, +"main_library": { + "target_info": [ + { + "target": "arm64-ios-simulator", + "min_deployment": "swift-abi" + } + ], + "install_names":[ + { "name":"/S/L/F/Foo.framework/Foo" } + ] +}})"; + + Expected Result = + TextAPIReader::get(MemoryBufferRef(TBDv5File, "Test.tbd")); + EXPECT_FALSE(!!Result); + std::string ErrorMessage = toString(Result.takeError()); + EXPECT_EQ("invalid min_deployment section\n", ErrorMessage); +} + TEST(TBDv5, MergeIF) { static const char TBDv5FileA[] = R"({ "tapi_tbd_version": 5,