[src/tools] Propagate the BackwardsCompatibleCodeGeneration field from Protocol attributes in bindings to the generated code. (#20804)

Also fix the MustSetBackwardsCompatibleCodeGenerationToFalse test to skip
protocols that actually set BackwardsCompatibleCodeGeneration=false.
This commit is contained in:
Rolf Bjarne Kvinge 2024-07-03 20:18:13 +02:00 коммит произвёл GitHub
Родитель 323d28c220
Коммит 6da82734ee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 30 добавлений и 4 удалений

Просмотреть файл

@ -4879,11 +4879,13 @@ public partial class Generator : IMemberGatherer {
WriteDocumentation (type);
PrintAttributes (type, platform: true, preserve: true, advice: true);
print ("[Protocol (Name = \"{1}\", WrapperType = typeof ({0}Wrapper){2}{3})]",
print ("[Protocol (Name = \"{1}\", WrapperType = typeof ({0}Wrapper){2}{3}{4})]",
TypeName,
protocol_name,
protocolAttribute.IsInformal ? ", IsInformal = true" : string.Empty,
protocolAttribute.FormalSince is not null ? $", FormalSince = \"{protocolAttribute.FormalSince}\"" : string.Empty);
protocolAttribute.FormalSince is not null ? $", FormalSince = \"{protocolAttribute.FormalSince}\"" : string.Empty,
backwardsCompatibleCodeGeneration ? string.Empty : ", BackwardsCompatibleCodeGeneration = false"
);
var sb = new StringBuilder ();

Просмотреть файл

@ -30,13 +30,24 @@ namespace Cecil.Tests {
continue;
var hasProtocolAttribute = false;
var hasProtocolMemberAttribute = false;
bool? isBackwardsCompatible = null;
foreach (var ca in type.CustomAttributes) {
hasProtocolAttribute |= ca.AttributeType.Is ("Foundation", "ProtocolAttribute");
if (ca.AttributeType.Is ("Foundation", "ProtocolAttribute")) {
hasProtocolAttribute = true;
foreach (var prop in ca.Properties) {
if (prop.Name == "BackwardsCompatibleCodeGeneration") {
isBackwardsCompatible = (bool) prop.Argument.Value;
break;
}
}
}
hasProtocolMemberAttribute |= ca.AttributeType.Is ("Foundation", "ProtocolMemberAttribute");
}
if (!hasProtocolAttribute)
continue;
if (!hasProtocolMemberAttribute)
continue; // doesn't need to be compatible if it doesn't have any members.
if (isBackwardsCompatible == false)
continue;
found.Add (type.FullName);
}
@ -1146,7 +1157,12 @@ namespace Cecil.Tests {
};
var unexpectedFailures = found.Except (expectedFailures);
Assert.That (unexpectedFailures, Is.Empty, $"{found.Count} new protocols found where 'BackwardsCompatibleCodeGeneration' should be set to 'false'.");
if (unexpectedFailures.Any ()) {
Console.WriteLine ("Protocols missing 'BackwardsCompatibleCodeGeneration = false':");
foreach (var f in unexpectedFailures.OrderBy (v => v))
Console.WriteLine ($" {f}");
}
Assert.That (unexpectedFailures, Is.Empty, $"{unexpectedFailures.Count ()} new protocols found where 'BackwardsCompatibleCodeGeneration' should be set to 'false'.");
}
}
}

Просмотреть файл

@ -1427,6 +1427,11 @@ namespace Registrar {
throw ErrorHelper.CreateError (4147, Errors.MT4147, "ProtocolAttribute", type.FullName);
rv.FormalSinceVersion = version;
break;
#if !XAMCORE_5_0
case "BackwardsCompatibleCodeGeneration":
rv.BackwardsCompatibleCodeGeneration = (bool) prop.Argument.Value;
break;
#endif
default:
throw ErrorHelper.CreateError (4147, Errors.MT4147, "ProtocolAttribute", type.FullName);
}
@ -5790,6 +5795,9 @@ namespace Registrar {
public string Name { get; set; }
public bool IsInformal { get; set; }
public Version FormalSinceVersion { get; set; }
#if !XAMCORE_5_0
public bool BackwardsCompatibleCodeGeneration { get; set; }
#endif
}
class BlockProxyAttribute : Attribute {