Skip to content

Commit dcbaa06

Browse files
committed
[WIP] Duplicate assemblies are treated as arch-specific ones
1 parent fd883c7 commit dcbaa06

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ public override bool RunTask ()
7878
return !Log.HasLoggedErrors;
7979
}
8080

81-
void SetAssemblyAbiMetadata (string abi, string assetType, ITaskItem assembly, ITaskItem? symbol)
81+
void SetAssemblyAbiMetadata (string abi, string assetType, ITaskItem assembly, ITaskItem? symbol, bool isDuplicate)
8282
{
83-
if (String.IsNullOrEmpty (abi) || String.Compare ("native", assetType, StringComparison.OrdinalIgnoreCase) != 0) {
83+
if (String.IsNullOrEmpty (abi) || (!isDuplicate && String.Compare ("native", assetType, StringComparison.OrdinalIgnoreCase) != 0)) {
8484
return;
8585
}
8686

@@ -90,7 +90,7 @@ void SetAssemblyAbiMetadata (string abi, string assetType, ITaskItem assembly, I
9090
}
9191
}
9292

93-
void SetAssemblyAbiMetadata (ITaskItem assembly, ITaskItem? symbol)
93+
void SetAssemblyAbiMetadata (ITaskItem assembly, ITaskItem? symbol, bool isDuplicate)
9494
{
9595
string assetType = assembly.GetMetadata ("AssetType");
9696
string rid = assembly.GetMetadata ("RuntimeIdentifier");
@@ -99,14 +99,14 @@ void SetAssemblyAbiMetadata (ITaskItem assembly, ITaskItem? symbol)
9999
return;
100100
}
101101

102-
SetAssemblyAbiMetadata (AndroidRidAbiHelper.RuntimeIdentifierToAbi (rid), assetType, assembly, symbol);
102+
SetAssemblyAbiMetadata (AndroidRidAbiHelper.RuntimeIdentifierToAbi (rid), assetType, assembly, symbol, isDuplicate);
103103
}
104104

105105
void SetMetadataForAssemblies (List<ITaskItem> output, Dictionary<string, ITaskItem> symbols)
106106
{
107107
foreach (var assembly in InputAssemblies) {
108108
var symbol = GetOrCreateSymbolItem (symbols, assembly);
109-
SetAssemblyAbiMetadata (assembly, symbol);
109+
SetAssemblyAbiMetadata (assembly, symbol, isDuplicate: false);
110110
symbol?.SetDestinationSubPath ();
111111
assembly.SetDestinationSubPath ();
112112
assembly.SetMetadata ("FrameworkAssembly", IsFrameworkAssembly (assembly).ToString ());
@@ -144,7 +144,7 @@ void DeduplicateAssemblies (List<ITaskItem> output, Dictionary<string, ITaskItem
144144
if (mvids.Count > 1) {
145145
foreach (var assembly in group) {
146146
var symbol = GetOrCreateSymbolItem (symbols, assembly);
147-
SetDestinationSubDirectory (assembly, group.Key, symbol);
147+
SetDestinationSubDirectory (assembly, group.Key, symbol, isDuplicate: true);
148148
output.Add (assembly);
149149
}
150150
} else {
@@ -158,6 +158,7 @@ void DeduplicateAssemblies (List<ITaskItem> output, Dictionary<string, ITaskItem
158158
symbol?.SetDestinationSubPath ();
159159
assembly.SetDestinationSubPath ();
160160
output.Add (assembly);
161+
SetAssemblyAbiMetadata (assembly, symbol, false);
161162
} else {
162163
symbols.Remove (Path.ChangeExtension (assembly.ItemSpec, ".pdb"));
163164
}
@@ -197,18 +198,16 @@ bool Filter (ITaskItem item)
197198
/// <summary>
198199
/// Sets %(DestinationSubDirectory) and %(DestinationSubPath) based on %(RuntimeIdentifier)
199200
/// </summary>
200-
void SetDestinationSubDirectory (ITaskItem assembly, string fileName, ITaskItem? symbol)
201+
void SetDestinationSubDirectory (ITaskItem assembly, string fileName, ITaskItem? symbol, bool isDuplicate)
201202
{
202203
var rid = assembly.GetMetadata ("RuntimeIdentifier");
203204
string assetType = assembly.GetMetadata ("AssetType");
204205

205206
// Satellite assemblies have `RuntimeIdentifier` set, but they shouldn't - they aren't specific to any architecture, so they should have none of the
206207
// abi-specific metadata set
207208
//
208-
// Likewise, only abi-specific assemblies (with `AssetType=native` metadata set) should have the `Destination*` metadata set
209209
if (!String.IsNullOrEmpty (assembly.GetMetadata ("Culture")) ||
210-
String.Compare ("resources", assetType, StringComparison.OrdinalIgnoreCase) == 0 ||
211-
String.Compare ("native", assetType, StringComparison.OrdinalIgnoreCase) != 0) {
210+
String.Compare ("resources", assetType, StringComparison.OrdinalIgnoreCase) == 0) {
212211
rid = String.Empty;
213212
}
214213

@@ -223,7 +222,7 @@ void SetDestinationSubDirectory (ITaskItem assembly, string fileName, ITaskItem?
223222
symbol.SetMetadata ("DestinationSubPath", Path.Combine (destination, Path.GetFileName (symbol.ItemSpec)));
224223
}
225224

226-
SetAssemblyAbiMetadata (abi, assetType, assembly, symbol);
225+
SetAssemblyAbiMetadata (abi, assetType, assembly, symbol, isDuplicate);
227226
} else {
228227
Log.LogDebugMessage ($"Android ABI not found for: {assembly.ItemSpec}");
229228
assembly.SetDestinationSubPath ();

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/PackagingTest.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ public void CheckIncludedAssemblies ([Values (false, true)] bool usesAssemblySto
8888
"Java.Interop.dll",
8989
"Mono.Android.dll",
9090
"rc.bin",
91-
"System.Console.dll",
9291
"System.Private.CoreLib.dll",
9392
"System.Runtime.dll",
9493
"System.Linq.dll",

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ sealed class Store
2121

2222
// NOTE: when/if we have parallel BuildApk these should become concurrent collections
2323
readonly Dictionary<string, Store> stores = new Dictionary<string, Store> (StringComparer.Ordinal);
24-
readonly HashSet<string> seenAssemblies = new HashSet<string> (StringComparer.OrdinalIgnoreCase);
2524

2625
AssemblyStore indexStore;
2726

@@ -45,12 +44,6 @@ public AssemblyStoreGenerator (string archiveAssembliesPrefix, TaskLoggingHelper
4544

4645
public void Add (string apkName, AssemblyStoreAssemblyInfo storeAssembly)
4746
{
48-
if (seenAssemblies.Contains (storeAssembly.FilesystemAssemblyPath)) {
49-
log.LogMessage (MessageImportance.Low, $"Ignoring duplicate assembly {storeAssembly.FilesystemAssemblyPath} when adding to assembly store set '{apkName}'");
50-
return;
51-
}
52-
seenAssemblies.Add (storeAssembly.FilesystemAssemblyPath);
53-
5447
if (String.IsNullOrEmpty (apkName)) {
5548
throw new ArgumentException ("must not be null or empty", nameof (apkName));
5649
}

tools/decompress-assemblies/main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static bool UncompressDLL (Stream inputStream, string fileName, string filePath,
5656
Directory.CreateDirectory (outputDir);
5757
}
5858
using (var fs = File.Open (outputFile, FileMode.Create, FileAccess.Write)) {
59-
fs.Write (assemblyBytes, 0, assemblyBytes.Length);
59+
fs.Write (assemblyBytes, 0, decoded);
6060
fs.Flush ();
6161
}
6262
Console.WriteLine ($" uncompressed to: {outputFile}");

0 commit comments

Comments
 (0)