Skip to content

Commit

Permalink
Merge branch 'main' into http-compression-fix
Browse files Browse the repository at this point in the history
* main:
  [monodroid] Properly process satellite assemblies (dotnet#7823)
  Bump to xamarin/java.interop/main@77800dda (dotnet#7824)
  • Loading branch information
grendello committed Feb 28, 2023
2 parents bd862d9 + 922a369 commit eb92c4d
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 90 deletions.
6 changes: 0 additions & 6 deletions build-tools/installers/create-installers.targets
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jcw-gen.pdb" />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jit-times.exe" />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jit-times.pdb" />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jnimarshalmethod-gen.exe" />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)jnimarshalmethod-gen.pdb" />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Java.Interop.dll.config" />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Java.Runtime.Environment.dll" /> <!-- Required by jnimarshalmethod-gen.exe -->
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Java.Runtime.Environment.pdb" />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Java.Runtime.Environment.dll.config" Condition=" '$(HostOS)' != 'Windows' " />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)logcat-parse.exe" />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)logcat-parse.pdb" />
<_LegacyJIFiles Include="$(LegacyMSBuildSrcDir)Mono.CSharp.dll" /> <!-- Required by logcat-parse.exe -->
Expand Down
26 changes: 0 additions & 26 deletions build-tools/scripts/JavaInteropDllConfigs.targets

This file was deleted.

2 changes: 1 addition & 1 deletion external/Java.Interop
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,9 @@ void AddEnvironment ()
HashSet<string> archAssemblyNames = null;
HashSet<string> uniqueAssemblyNames = new HashSet<string> (StringComparer.OrdinalIgnoreCase);
Action<ITaskItem> updateAssemblyCount = (ITaskItem assembly) => {
string assemblyName = Path.GetFileName (assembly.ItemSpec);
// We need to use the 'RelativePath' metadata, if found, because it will give us the correct path for satellite assemblies - with the culture in the path.
string? relativePath = assembly.GetMetadata ("RelativePath");
string assemblyName = String.IsNullOrEmpty (relativePath) ? Path.GetFileName (assembly.ItemSpec) : relativePath;
if (!uniqueAssemblyNames.Contains (assemblyName)) {
uniqueAssemblyNames.Add (assemblyName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,12 +807,18 @@ public void MissingSatelliteAssemblyInLibrary ()
new BuildItem ("EmbeddedResource", "Foo.resx") {
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancel</value></data>")
},
new BuildItem ("EmbeddedResource", "Foo.es.resx") {
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancelar</value></data>")
}
}
};

var languages = new string[] {"es", "de", "fr", "he", "it", "pl", "pt", "ru", "sl" };
foreach (string lang in languages) {
lib.OtherBuildItems.Add (
new BuildItem ("EmbeddedResource", $"Foo.{lang}.resx") {
TextContent = () => InlineData.ResxWithContents ($"<data name=\"CancelButton\"><value>{lang}</value></data>")
}
);
}

var app = new XamarinAndroidApplicationProject {
IsRelease = true,
};
Expand All @@ -829,7 +835,10 @@ public void MissingSatelliteAssemblyInLibrary ()
var apk = Path.Combine (Root, appBuilder.ProjectDirectory,
app.OutputPath, $"{app.PackageName}-Signed.apk");
var helper = new ArchiveAssemblyHelper (apk);
Assert.IsTrue (helper.Exists ($"assemblies/es/{lib.ProjectName}.resources.dll"), "Apk should contain satellite assemblies!");

foreach (string lang in languages) {
Assert.IsTrue (helper.Exists ($"assemblies/{lang}/{lib.ProjectName}.resources.dll"), $"Apk should contain satellite assembly for language '{lang}'!");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,8 @@ void WriteHashes<T> () where T: struct
uint index = 0;

foreach (string name in uniqueAssemblyNames) {
string clippedName = Path.GetFileNameWithoutExtension (name);
// We must make sure we keep the possible culture prefix, which will be treated as "directory" path here
string clippedName = Path.Combine (Path.GetDirectoryName (name) ?? String.Empty, Path.GetFileNameWithoutExtension (name));
ulong hashFull = HashName (name, is64Bit);
ulong hashClipped = HashName (clippedName, is64Bit);

Expand Down
17 changes: 1 addition & 16 deletions src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets
Original file line number Diff line number Diff line change
Expand Up @@ -1456,22 +1456,7 @@ because xbuild doesn't support framework reference assemblies.
DependsOnTargets="_GetReferenceAssemblyPaths;_SetLatestTargetFrameworkVersion"
Inputs="$(_AndroidBuildPropertiesCache);@(ResolvedUserAssemblies)"
Outputs="$(_AndroidStampDirectory)_GenerateJniMarshalMethods.stamp">
<ItemGroup>
<_JniFrameworkAssembly Include="Mono.Android.dll" />
<_JniFrameworkAssembly Include="OpenTK.dll" />
<_JniFrameworkAssembly Include="Xamarin.Android.NUnitLite.dll" />
<_AssembliesToProcess Include="@(ResolvedUserAssemblies)" />
<_AssembliesToProcess Include="@(ResolvedFrameworkAssemblies)" Condition=" '%(Filename)' == '@(_JniFrameworkAssembly->'%(Filename)')' " />
</ItemGroup>
<RemoveDirFixed Directories="$(_JniMarshalMethodsOutputDir)" />
<MakeDir Directories="$(_JniMarshalMethodsOutputDir)" />
<Exec
Command="DYLD_LIBRARY_PATH=&quot;$(MonoAndroidLibDirectory)&quot; MONO_CONFIG=&quot;$(MonoAndroidBinDirectory)mono.config&quot; MONO_PATH=&quot;$(MonoAndroidBinDirectory)\bcl&quot;:&quot;$(MonoAndroidBinDirectory)\bcl\Facades&quot;:&quot;$(_XATargetFrameworkDirectories)&quot; &quot;$(MonoAndroidBinDirectory)mono&quot; --debug &quot;$(MonoAndroidToolsDirectory)\jnimarshalmethod-gen.exe&quot; --jvm=&quot;$(JdkJvmPath)&quot; @(ResolvedAssemblies->'--r=&quot;%(Identity)&quot;', ' ') --o=&quot;$(_JniMarshalMethodsOutputDir)&quot; $(AndroidGenerateJniMarshalMethodsAdditionalArguments) @(_AssembliesToProcess->'&quot;%(Identity)&quot;', ' ')"
/>
<Touch Files="$(_AndroidStampDirectory)_GenerateJniMarshalMethods.stamp" AlwaysCreate="True" />
<ItemGroup>
<FileWrites Include="$(_AssembliesToProcess)" />
</ItemGroup>
<Error Text="%24(AndroidGenerateJniMarshalMethods)=True is not supported at this time." />
</Target>

<Target Name="_LinkAssembliesNoShrinkInputs">
Expand Down
12 changes: 4 additions & 8 deletions src/monodroid/jni/xamarin-android-app-context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ MonodroidRuntime::get_method_name (uint32_t mono_image_index, uint32_t method_to
{
uint64_t id = (static_cast<uint64_t>(mono_image_index) << 32) | method_token;

log_debug (LOG_ASSEMBLY, "Looking for name of method with id 0x%llx, in mono image at index %u", id, mono_image_index);
log_debug (LOG_ASSEMBLY, "MM: looking for name of method with id 0x%llx, in mono image at index %u", id, mono_image_index);
size_t i = 0;
while (mm_method_names[i].id != 0) {
if (mm_method_names[i].id == id) {
Expand Down Expand Up @@ -58,19 +58,15 @@ MonodroidRuntime::get_function_pointer (uint32_t mono_image_index, uint32_t clas
// We need to do that, as Mono APIs cannot be invoked from threads that aren't attached to the runtime.
mono_thread_attach (mono_get_root_domain ());

// We don't check for valid return values from image loader, class and method lookup because if any
// of them fails to find the requested entity, they will return `null`. In consequence, we can pass
// these pointers without checking all the way to `mono_method_get_unmanaged_callers_only_ftnptr`, after
// which call we check for errors. This saves some time (not much, but definitely more than zero)
MonoImage *image = MonoImageLoader::get_from_index (mono_image_index);
MarshalMethodsManagedClass &klass = marshal_methods_class_cache[class_index];
if (klass.klass == nullptr) {
klass.klass = mono_class_get (image, klass.token);
klass.klass = image != nullptr ? mono_class_get (image, klass.token) : nullptr;
}

MonoMethod *method = mono_get_method (image, method_token, klass.klass);
MonoMethod *method = klass.klass != nullptr ? mono_get_method (image, method_token, klass.klass) : nullptr;
MonoError error;
void *ret = mono_method_get_unmanaged_callers_only_ftnptr (method, &error);
void *ret = method != nullptr ? mono_method_get_unmanaged_callers_only_ftnptr (method, &error) : nullptr;

if (XA_LIKELY (ret != nullptr)) {
if constexpr (NeedsLocking) {
Expand Down
10 changes: 0 additions & 10 deletions src/monodroid/monodroid.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,5 @@

<ItemGroup>
<ProjectReference Include="..\java-runtime\java-runtime.csproj" ReferenceOutputAssembly="False" />
<!--
`jnimarshalmethod-gen.exe` needs to be built first because our
`_CreateJavaInteropDllConfigs` target replaces
`Java.Runtime.Environment.dll.config`, which will be created as
part of the `jnimarshalmethod-gen.exe` build.
We don't want our updated version to be replaced by the
`jnimarshalmethod-gen.exe` build.
-->
<ProjectReference Include="..\..\external\Java.Interop\tools\jnimarshalmethod-gen\Xamarin.Android.Tools.JniMarshalMethodGenerator.csproj" ReferenceOutputAssembly="False" />
</ItemGroup>
</Project>
3 changes: 1 addition & 2 deletions src/monodroid/monodroid.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
<Import Project="..\..\external\Java.Interop\bin\Build$(Configuration)\JdkInfo.props" Condition="Exists('..\..\external\Java.Interop\bin\Build$(Configuration)\JdkInfo.props')"/>
<Import Project="..\..\bin\Build$(Configuration)\cmake-config.props" Condition="Exists('..\..\bin\Build$(Configuration)\cmake-config.props')" />
<Import Project="monodroid.projitems" />
<Import Project="..\..\build-tools\scripts\JavaInteropDllConfigs.targets" />
<UsingTask AssemblyFile="$(BootstrapTasksAssembly)" TaskName="Xamarin.Android.Tools.BootstrapTasks.GenerateMonoDroidIncludes" />
<UsingTask AssemblyFile="$(BootstrapTasksAssembly)" TaskName="Xamarin.Android.Tools.BootstrapTasks.RunParallelCmds" />
<UsingTask AssemblyFile="$(PrepTasksAssembly)" TaskName="Xamarin.Android.BuildTools.PrepTasks.ReplaceFileContents" />
Expand Down Expand Up @@ -207,7 +206,7 @@
</Target>

<Target Name="_BuildHostRuntimes"
DependsOnTargets="_CreateJavaInteropDllConfigs;_BuildHostRuntimesInputs"
DependsOnTargets="_BuildHostRuntimesInputs"
Inputs="@(_BuildHostRuntimesInputs)"
Outputs="@(_BuildHostRuntimesOutputs)">
<Message Text="Building host runtime %(_HostRuntime.Identity) in $(OutputPath)%(_HostRuntime.OutputDirectory)"/>
Expand Down
47 changes: 47 additions & 0 deletions tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,56 @@ public void Teardown ()
Directory.Delete (builder.ProjectDirectory, recursive: true);

builder?.Dispose ();
builder = null;
proj = null;
}

[Test]
public void NativeAssemblyCacheWithSatelliteAssemblies ()
{
var path = Path.Combine ("temp", TestName);
var lib = new XamarinAndroidLibraryProject {
ProjectName = "Localization",
OtherBuildItems = {
new BuildItem ("EmbeddedResource", "Foo.resx") {
TextContent = () => InlineData.ResxWithContents ("<data name=\"CancelButton\"><value>Cancel</value></data>")
},
}
};

var languages = new string[] {"es", "de", "fr", "he", "it", "pl", "pt", "ru", "sl" };
foreach (string lang in languages) {
lib.OtherBuildItems.Add (
new BuildItem ("EmbeddedResource", $"Foo.{lang}.resx") {
TextContent = () => InlineData.ResxWithContents ($"<data name=\"CancelButton\"><value>{lang}</value></data>")
}
);
}

proj = new XamarinAndroidApplicationProject {
IsRelease = true,
};
proj.References.Add (new BuildItem.ProjectReference ($"..\\{lib.ProjectName}\\{lib.ProjectName}.csproj", lib.ProjectName, lib.ProjectGuid));
proj.SetAndroidSupportedAbis ("armeabi-v7a", "arm64-v8a", "x86", "x86_64");

using (var libBuilder = CreateDllBuilder (Path.Combine (path, lib.ProjectName))) {
builder = CreateApkBuilder (Path.Combine (path, proj.ProjectName));
Assert.IsTrue (libBuilder.Build (lib), "Library Build should have succeeded.");
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");

var apk = Path.Combine (Root, builder.ProjectDirectory, proj.OutputPath, $"{proj.PackageName}-Signed.apk");
var helper = new ArchiveAssemblyHelper (apk);

foreach (string lang in languages) {
Assert.IsTrue (helper.Exists ($"assemblies/{lang}/{lib.ProjectName}.resources.dll"), $"Apk should contain satellite assembly for language '{lang}'!");
}

Assert.True (builder.RunTarget (proj, "_Run"), "Project should have run.");
Assert.True (WaitForActivityToStart (proj.PackageName, "MainActivity",
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30), "Activity should have started.");
}
}

[Test]
public void GlobalLayoutEvent_ShouldRegisterAndFire_OnActivityLaunch ([Values (false, true)] bool isRelease)
{
Expand Down
9 changes: 0 additions & 9 deletions tests/Mono.Android-Tests/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,4 @@
<Exec Command="&quot;$(NdkBuildPath)&quot;" WorkingDirectory="$(MSBuildThisFileDirectory)"/>
</Target>

<Import Project="$(MSBuildThisFileDirectory)..\..\build-tools\scripts\JavaInteropDllConfigs.targets" />

<!-- Not required when testing against a system installation of XA. -->
<Target Name="EnsureJavaInteropDllConfigs"
Condition="Exists ('$(XAInstallPrefix)xbuild\Xamarin\Android\Java.Interop.dll')"
BeforeTargets="_GenerateJniMarshalMethods"
DependsOnTargets="_CreateJavaInteropDllConfigs">
</Target>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,4 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Xamarin.Forms.Performance.Integration.Droid.projitems" />
<Import Project="$(XamarinAndroidSourcePath)build-tools\scripts\TestApks.targets" />
<Import Project="$(XamarinAndroidSourcePath)build-tools\scripts\JavaInteropDllConfigs.targets" />
<Target Name="EnsureJavaInteropDllConfigs"
Condition="Exists ('$(XAInstallPrefix)xbuild\Xamarin\Android\Java.Interop.dll')"
BeforeTargets="_GenerateJniMarshalMethods"
DependsOnTargets="_CreateJavaInteropDllConfigs">
</Target>
</Project>

0 comments on commit eb92c4d

Please sign in to comment.