Skip to content

Commit 2537790

Browse files
committed
Move more assembly packaging code to the helper class
1 parent 9b77fee commit 2537790

File tree

2 files changed

+41
-42
lines changed

2 files changed

+41
-42
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs

+28-40
Original file line numberDiff line numberDiff line change
@@ -459,58 +459,46 @@ void AddAssemblies (ZipArchiveEx apk, bool debug, bool compress, IDictionary<And
459459
AddFileToArchiveIfNewer (apk, wrappedSourcePath, inArchivePath, GetCompressionMethod (inArchivePath));
460460
}
461461

462-
void DoAddAssembliesFromArchCollection (AndroidTargetArch arch, Dictionary<string, ITaskItem> assemblies)
462+
void DoAddAssembliesFromArchCollection (TaskLoggingHelper log, AndroidTargetArch arch, ITaskItem assembly)
463463
{
464464
// In the "all assemblies are per-RID" world, assemblies, pdb and config are disguised as shared libraries (that is,
465465
// their names end with the .so extension) so that Android allows us to put them in the `lib/{ARCH}` directory.
466466
// For this reason, they have to be treated just like other .so files, as far as compression rules are concerned.
467467
// Thus, we no longer just store them in the apk but we call the `GetCompressionMethod` method to find out whether
468468
// or not we're supposed to compress .so files.
469-
foreach (ITaskItem assembly in assemblies.Values) {
470-
if (MonoAndroidHelper.IsReferenceAssembly (assembly.ItemSpec, Log)) {
471-
Log.LogCodedWarning ("XA0107", assembly.ItemSpec, 0, Properties.Resources.XA0107, assembly.ItemSpec);
472-
}
473-
474-
sourcePath = CompressAssembly (assembly);
475-
if (UseAssemblyStore) {
476-
storeBuilder.AddAssembly (sourcePath, assembly, includeDebugSymbols: debug);
477-
continue;
478-
}
469+
sourcePath = CompressAssembly (assembly);
470+
if (UseAssemblyStore) {
471+
storeBuilder.AddAssembly (sourcePath, assembly, includeDebugSymbols: debug);
472+
return;
473+
}
479474

480-
// Add assembly
481-
(string assemblyPath, string assemblyDirectory) = GetInArchiveAssemblyPath (assembly);
482-
string wrappedSourcePath = DSOWrapperGenerator.WrapIt (arch, sourcePath, Path.GetFileName (assemblyPath), this);
483-
AddFileToArchiveIfNewer (apk, wrappedSourcePath, assemblyPath, compressionMethod: GetCompressionMethod (assemblyPath));
475+
// Add assembly
476+
(string assemblyPath, string assemblyDirectory) = GetInArchiveAssemblyPath (assembly);
477+
string wrappedSourcePath = DSOWrapperGenerator.WrapIt (arch, sourcePath, Path.GetFileName (assemblyPath), this);
478+
AddFileToArchiveIfNewer (apk, wrappedSourcePath, assemblyPath, compressionMethod: GetCompressionMethod (assemblyPath));
484479

485-
// Try to add config if exists
486-
var config = Path.ChangeExtension (assembly.ItemSpec, "dll.config");
487-
AddAssemblyConfigEntry (apk, arch, assemblyDirectory, config);
480+
// Try to add config if exists
481+
var config = Path.ChangeExtension (assembly.ItemSpec, "dll.config");
482+
AddAssemblyConfigEntry (apk, arch, assemblyDirectory, config);
488483

489-
// Try to add symbols if Debug
490-
if (!debug) {
491-
continue;
492-
}
484+
// Try to add symbols if Debug
485+
if (!debug) {
486+
return;
487+
}
493488

494-
string symbols = Path.ChangeExtension (assembly.ItemSpec, "pdb");
495-
if (!File.Exists (symbols)) {
496-
string archiveSymbolsPath = assemblyDirectory + MonoAndroidHelper.MakeDiscreteAssembliesEntryName (Path.GetFileName (symbols));
497-
string wrappedSymbolsPath = DSOWrapperGenerator.WrapIt (arch, symbols, Path.GetFileName (archiveSymbolsPath), this);
498-
AddFileToArchiveIfNewer (
499-
apk,
500-
wrappedSymbolsPath,
501-
archiveSymbolsPath,
502-
compressionMethod: GetCompressionMethod (archiveSymbolsPath)
503-
);
504-
}
489+
string symbols = Path.ChangeExtension (assembly.ItemSpec, "pdb");
490+
if (!File.Exists (symbols)) {
491+
return;
505492
}
506-
}
507493

508-
void EnsureCompressedAssemblyData (string sourcePath, uint descriptorIndex)
509-
{
510-
if (compressedAssembly == null)
511-
compressedAssembly = new AssemblyCompression.AssemblyData (sourcePath, descriptorIndex);
512-
else
513-
compressedAssembly.SetData (sourcePath, descriptorIndex);
494+
string archiveSymbolsPath = assemblyDirectory + MonoAndroidHelper.MakeDiscreteAssembliesEntryName (Path.GetFileName (symbols));
495+
string wrappedSymbolsPath = DSOWrapperGenerator.WrapIt (arch, symbols, Path.GetFileName (archiveSymbolsPath), this);
496+
AddFileToArchiveIfNewer (
497+
apk,
498+
wrappedSymbolsPath,
499+
archiveSymbolsPath,
500+
compressionMethod: GetCompressionMethod (archiveSymbolsPath)
501+
);
514502
}
515503

516504
string CompressAssembly (ITaskItem assembly)

src/Xamarin.Android.Build.Tasks/Utilities/AssemblyPackagingHelper.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Xamarin.Android.Tasks;
1010

1111
static class AssemblyPackagingHelper
1212
{
13-
public static void AddAssembliesFromCollection (TaskLoggingHelper Log, ICollection<string> SupportedAbis, ICollection<ITaskItem> assemblies, Action<AndroidTargetArch, Dictionary<string, ITaskItem>> doAddAssemblies)
13+
public static void AddAssembliesFromCollection (TaskLoggingHelper Log, ICollection<string> SupportedAbis, ICollection<ITaskItem> assemblies, Action<TaskLoggingHelper, AndroidTargetArch, ITaskItem> doAddAssembly)
1414
{
1515
Dictionary<AndroidTargetArch, Dictionary<string, ITaskItem>> perArchAssemblies = MonoAndroidHelper.GetPerArchAssemblies (
1616
assemblies,
@@ -28,7 +28,18 @@ public static void AddAssembliesFromCollection (TaskLoggingHelper Log, ICollecti
2828

2929
foreach (var kvp in perArchAssemblies) {
3030
Log.LogDebugMessage ($"Adding assemblies for architecture '{kvp.Key}'");
31-
doAddAssemblies (kvp.Key, kvp.Value);
31+
DoAddAssembliesFromArchCollection (Log, kvp.Key, kvp.Value, doAddAssembly);
32+
}
33+
}
34+
35+
static void DoAddAssembliesFromArchCollection (TaskLoggingHelper Log, AndroidTargetArch arch, Dictionary<string, ITaskItem> assemblies, Action<TaskLoggingHelper, AndroidTargetArch, ITaskItem> doAddAssembly)
36+
{
37+
foreach (ITaskItem assembly in assemblies.Values) {
38+
if (MonoAndroidHelper.IsReferenceAssembly (assembly.ItemSpec, Log)) {
39+
Log.LogCodedWarning ("XA0107", assembly.ItemSpec, 0, Properties.Resources.XA0107, assembly.ItemSpec);
40+
}
41+
42+
doAddAssembly (Log, arch, assembly);
3243
}
3344
}
3445
}

0 commit comments

Comments
 (0)