Skip to content
Merged
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
20 changes: 20 additions & 0 deletions build-tools/automation/templates/core-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ steps:
continueOnError: true
retryCountOnTaskFailure: 1

- task: DotNetCoreCLI@2
displayName: 'jnimarshalmethod-gen Java.Base-Tests.dll'
condition: or(eq('${{ parameters.runNativeDotnetTests }}', 'true'), eq('${{ parameters.runNativeTests }}', 'true'))
inputs:
command: custom
custom: bin/$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/jnimarshalmethod-gen.dll
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Java.Base-Tests.dll -v -v --keeptemp
continueOnError: true
retryCountOnTaskFailure: 1

- task: DotNetCoreCLI@2
displayName: 'Tests: Java.Base'
condition: or(eq('${{ parameters.runNativeDotnetTests }}', 'true'), eq('${{ parameters.runNativeTests }}', 'true'))
inputs:
command: test
testRunTitle: Java.Base ($(DotNetTargetFramework) - ${{ parameters.platformName }})
arguments: bin/Test$(Build.Configuration)$(NetCoreTargetFrameworkPathSuffix)/Java.Base-Tests.dll
continueOnError: true
retryCountOnTaskFailure: 1

- task: DotNetCoreCLI@2
displayName: 'Tests: java-source-utils'
inputs:
Expand Down
48 changes: 18 additions & 30 deletions tools/jnimarshalmethod-gen/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,14 @@ void CreateMarshalMethodAssembly (string path)
continue;

var existingMarshalMethodsType = td.GetNestedType (TypeMover.NestedName);
if (existingMarshalMethodsType != null && !forceRegeneration) {
Warning (Message.WarningMarshalMethodsTypeAlreadyExists, existingMarshalMethodsType.GetAssemblyQualifiedName (cache), assemblyName);
if (existingMarshalMethodsType != null) {

return;
if (forceRegeneration) {
td.NestedTypes.Remove (existingMarshalMethodsType);
} else {
Warning (Message.WarningMarshalMethodsTypeAlreadyExists, existingMarshalMethodsType.GetAssemblyQualifiedName (cache), assemblyName);
return;
}
}

if (Verbose)
Expand Down Expand Up @@ -512,7 +516,7 @@ void CreateMarshalMethodAssembly (string path)

if (exportObj != null) {
dynamic e = exportObj;
name = e.Name;
name = "n_" + methodName;
signature = e.Signature;
}
else {
Expand Down Expand Up @@ -550,15 +554,14 @@ void CreateMarshalMethodAssembly (string path)
Log (TraceLevel.Verbose, $"## Dumping contents of marshal method for `{td.FullName}::{method.Name}({string.Join (", ", method.GetParameters ().Select (p => p.ParameterType))})`:");
Console.WriteLine (lambda.ToCSharpCode ());
#endif // _DUMP_REGISTER_NATIVE_MEMBERS
name = export?.Name ?? method.Name;

var mmDef = assemblyBuilder.Compile (lambda);
mmDef.Name = name;
mmTypeDef.Methods.Add (mmDef);

signature = export?.Signature ?? builder.GetJniMethodSignature (method);

registrations.Add (new ExpressionMethodRegistration ("n_" + method.Name, signature, mmDef));
registrations.Add (new ExpressionMethodRegistration (name, signature, mmDef));

addedMethods.Add (methodName);
}
Expand Down Expand Up @@ -739,35 +742,19 @@ public static MethodDefinition GetMethodDefinition (this TypeDefinition td, Meth

static bool CheckMethod (MethodDefinition m, ref string name, ref string methodName, ref string signature)
{
foreach (var registerAttribute in m.GetCustomAttributes ("Android.Runtime.RegisterAttribute")) {
var registerAttrs = m.GetCustomAttributes ("Android.Runtime.RegisterAttribute")
.Concat (m.GetCustomAttributes ("Java.Interop.JniMethodSignatureAttribute"));
foreach (var registerAttribute in registerAttrs) {
if (registerAttribute == null || !registerAttribute.HasConstructorArguments)
continue;

var constructorParameters = registerAttribute.Constructor.Parameters.ToArray ();
var constructorArguments = registerAttribute.ConstructorArguments.ToArray ();

for (int i = 0; i < constructorArguments.Length; i++) {
switch (constructorParameters [i].Name) {
case "name":
name = constructorArguments [i].Value.ToString ();
break;
case "signature":
signature = constructorArguments [i].Value.ToString ();
break;
}

}

if ((string.IsNullOrEmpty (name) || string.IsNullOrEmpty (signature)) && constructorArguments.Length != 3)
if (registerAttribute.ConstructorArguments.Count < 2)
continue;

if (string.IsNullOrEmpty (name))
name = constructorArguments [0].Value.ToString ();

if (string.IsNullOrEmpty (signature))
signature = constructorArguments [1].Value.ToString ();
name = registerAttribute.ConstructorArguments [0].Value.ToString ();
signature = registerAttribute.ConstructorArguments [1].Value.ToString ();

if (string.IsNullOrEmpty (name) || string.IsNullOrEmpty (signature))
if ((string.IsNullOrEmpty (name) || string.IsNullOrEmpty (signature)))
continue;

methodName = MarshalMemberBuilder.GetMarshalMethodName (name, signature);
Expand Down Expand Up @@ -808,13 +795,14 @@ public static bool NeedsMarshalMethod (this MethodDefinition md, DirectoryAssemb
continue;
}

for (int i = 0; i < ifaceMap.TargetMethods.Length; i++)
for (int i = 0; i < ifaceMap.TargetMethods.Length; i++) {
if (ifaceMap.TargetMethods [i] == method) {
var imd = id.GetMethodDefinition (ifaceMap.InterfaceMethods [i]);

if (CheckMethod (imd, ref name, ref methodName, ref signature))
return true;
}
}
}

return false;
Expand Down