Skip to content

Try dotnet/java-interop#1302 #9750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
[submodule "external/Java.Interop"]
path = external/Java.Interop
url = https://github.com/dotnet/java-interop
branch = main
branch = dev/jonp/jonp-dotnet-requires-plus-not-slash
[submodule "external/libunwind"]
path = external/libunwind
url = https://github.com/libunwind/libunwind.git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public sealed class CheckApiCompatibility : Task
// In case API diffs vary between e.g. Classic MonoAndroid & .NET 6+
public string TargetFramework { get; set; }

// What's missing from acceptableIssuesFile?
public string LinesToAdd { get; set; }

// This Build tasks validates that changes are not breaking Api
public override bool Execute ()
{
Expand Down Expand Up @@ -260,6 +263,7 @@ void dataReceived (object sender, DataReceivedEventArgs args)
}

LogError ($"CheckApiCompatibility found nonacceptable Api breakages for ApiLevel: {ApiLevel}.{Environment.NewLine}{string.Join (Environment.NewLine, lines)}");
ReportMissingLines (acceptableIssuesFile.FullName, lines);

var missingItems = CodeGenDiff.GenerateMissingItems (CodeGenPath, contractAssembly.FullName, implementationAssembly.FullName);
if (missingItems.Any ()) {
Expand All @@ -285,6 +289,21 @@ void dataReceived (object sender, DataReceivedEventArgs args)
}
}

void ReportMissingLines (string acceptableIssuesFile, List<string> lines)
{
if (string.IsNullOrWhiteSpace (LinesToAdd)) {
return;
}
var known = new HashSet<string> (File.ReadAllLines (acceptableIssuesFile), StringComparer.Ordinal);
using var writer = File.CreateText (LinesToAdd);
foreach (var line in lines) {
if (known.Contains (line)) {
continue;
}
writer.WriteLine (line);
}
}

void LogError (string errorMessage)
{
if (!string.IsNullOrWhiteSpace (compatApiCommand)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.Android.Sdk.ILLink/MarkJavaObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ string TypeNameWithoutKey (string name)

bool CheckInvokerType (TypeDefinition type, string name)
{
return TypeNameWithoutKey (name) == TypeNameWithoutKey ($"{ type.FullName}, { type.Module.Assembly.FullName}");
return TypeNameWithoutKey (name.Replace ('+', '/')) == TypeNameWithoutKey ($"{ type.FullName}, { type.Module.Assembly.FullName}");
}

void PreserveInterfaceMethods (TypeDefinition type, TypeDefinition invoker)
Expand Down
1 change: 1 addition & 0 deletions src/Mono.Android/Mono.Android.targets
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
TargetImplementationPath="$(OutputPath)"
ApiCompatibilityPath="$(ApiCompatibilityDir)"
TargetFramework="$(TargetFramework)"
LinesToAdd="$(MSBuildThisFileDirectory)ApiCompatLinesToAdd.txt"
/>
<Touch
Files="$(IntermediateOutputPath)CheckApiCompatibility.stamp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static MethodDefinition GetMethod (TypeDefinition type, string name, stri

public static TypeDefinition GetType (AssemblyDefinition assembly, string typeName)
{
return assembly.MainModule.GetType (typeName);
return assembly.MainModule.GetType (typeName.Replace ('+', '/'));
}

public static bool Implements (this TypeReference self, string interfaceName, IMetadataResolver resolver)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ public ConnectorInfo (string spec)

string fullTypeName = connectorSpec[1];
int comma = fullTypeName.IndexOf (',');
TypeName = fullTypeName.Substring (0, comma);

// Need to use IL convention, not Reflection convention
TypeName = fullTypeName.Substring (0, comma).Replace ('+', '/');
AssemblyName = AssemblyNameReference.Parse (fullTypeName.Substring (comma + 1).Trim ());
}
}
Expand Down
622 changes: 622 additions & 0 deletions tests/api-compatibility/acceptable-breakages-vReference-net10.0.txt

Large diffs are not rendered by default.

Loading