-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into dev/grendel/clr-host
* main: [XABT] Create separate assembly preparation tasks. (#9637) Add `activity-alias` support (#9654) [CI] Grab 'dotnet-install.sh' script directly from GitHub. (#9699)
- Loading branch information
Showing
12 changed files
with
464 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DevDiv/android-platform-support:main@3b4e16f197ff3e102ffb59af0b0f056046cc7658 | ||
DevDiv/android-platform-support:main@cc26de2b33292462ab2daa70c593c78ef2a241e7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
224 changes: 0 additions & 224 deletions
224
src/Xamarin.Android.Build.Tasks/Tasks/CollectAssemblyFilesForArchive.cs
This file was deleted.
Oops, something went wrong.
108 changes: 108 additions & 0 deletions
108
src/Xamarin.Android.Build.Tasks/Tasks/CompressAssemblies.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.Android.Build.Tasks; | ||
using Microsoft.Build.Framework; | ||
using Xamarin.Android.Tools; | ||
|
||
namespace Xamarin.Android.Tasks; | ||
|
||
/// <summary> | ||
/// Compresses assemblies using LZ4 compression before placing them in the APK. | ||
/// Note this is independent of whether they are stored compressed with ZIP in the APK. | ||
/// Our runtime bits will LZ4 decompress them at assembly load time. | ||
/// </summary> | ||
public class CompressAssemblies : AndroidTask | ||
{ | ||
public override string TaskPrefix => "CAS"; | ||
|
||
[Required] | ||
public string ApkOutputPath { get; set; } = ""; | ||
|
||
public bool EmbedAssemblies { get; set; } | ||
|
||
[Required] | ||
public bool EnableCompression { get; set; } | ||
|
||
public bool IncludeDebugSymbols { get; set; } | ||
|
||
[Required] | ||
public string ProjectFullPath { get; set; } = ""; | ||
|
||
[Required] | ||
public ITaskItem [] ResolvedFrameworkAssemblies { get; set; } = []; | ||
|
||
[Required] | ||
public ITaskItem [] ResolvedUserAssemblies { get; set; } = []; | ||
|
||
[Required] | ||
public string [] SupportedAbis { get; set; } = []; | ||
|
||
[Output] | ||
public ITaskItem [] ResolvedFrameworkAssembliesOutput { get; set; } = []; | ||
|
||
[Output] | ||
public ITaskItem [] ResolvedUserAssembliesOutput { get; set; } = []; | ||
|
||
public override bool RunTask () | ||
{ | ||
if (IncludeDebugSymbols || !EnableCompression || !EmbedAssemblies) { | ||
ResolvedFrameworkAssembliesOutput = ResolvedFrameworkAssemblies; | ||
ResolvedUserAssembliesOutput = ResolvedUserAssemblies; | ||
return true; | ||
} | ||
|
||
var compressed_assemblies_info = GetCompressedAssemblyInfo (); | ||
|
||
// Get all the user and framework assemblies we may need to compresss | ||
var assemblies = ResolvedFrameworkAssemblies.Concat (ResolvedUserAssemblies).Where (asm => !(ShouldSkipAssembly (asm))).ToArray (); | ||
var per_arch_assemblies = MonoAndroidHelper.GetPerArchAssemblies (assemblies, SupportedAbis, true); | ||
var compressed_output_dir = Path.GetFullPath (Path.Combine (Path.GetDirectoryName (ApkOutputPath), "..", "lz4")); | ||
|
||
foreach (var kvp in per_arch_assemblies) { | ||
Log.LogDebugMessage ($"Compressing assemblies for architecture '{kvp.Key}'"); | ||
|
||
foreach (var asm in kvp.Value.Values) { | ||
MonoAndroidHelper.LogIfReferenceAssembly (asm, Log); | ||
|
||
var compressed_assembly = AssemblyCompression.Compress (Log, asm, compressed_assemblies_info, compressed_output_dir); | ||
|
||
if (compressed_assembly.HasValue ()) { | ||
Log.LogDebugMessage ($"Compressed '{asm.ItemSpec}' to '{compressed_assembly}'."); | ||
asm.SetMetadata ("CompressedAssembly", compressed_assembly); | ||
} | ||
} | ||
} | ||
|
||
ResolvedFrameworkAssembliesOutput = ResolvedFrameworkAssemblies; | ||
ResolvedUserAssembliesOutput = ResolvedUserAssemblies; | ||
|
||
return !Log.HasLoggedErrors; | ||
} | ||
|
||
IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>> GetCompressedAssemblyInfo () | ||
{ | ||
var key = CompressedAssemblyInfo.GetKey (ProjectFullPath); | ||
Log.LogDebugMessage ($"Retrieving assembly compression info with key '{key}'"); | ||
|
||
var compressedAssembliesInfo = BuildEngine4.UnregisterTaskObjectAssemblyLocal<IDictionary<AndroidTargetArch, Dictionary<string, CompressedAssemblyInfo>>> (key, RegisteredTaskObjectLifetime.Build); | ||
|
||
if (compressedAssembliesInfo is null) | ||
throw new InvalidOperationException ($"Assembly compression info not found for key '{key}'. Compression will not be performed."); | ||
|
||
return compressedAssembliesInfo; | ||
} | ||
|
||
bool ShouldSkipAssembly (ITaskItem asm) | ||
{ | ||
var should_skip = asm.GetMetadataOrDefault ("AndroidSkipAddToPackage", false); | ||
|
||
if (should_skip) | ||
Log.LogDebugMessage ($"Skipping {asm.ItemSpec} due to 'AndroidSkipAddToPackage' == 'true' "); | ||
|
||
return should_skip; | ||
} | ||
} |
Oops, something went wrong.