Skip to content

Commit

Permalink
Remove a lot of code to handle packaging of individual assemblies
Browse files Browse the repository at this point in the history
  • Loading branch information
grendello committed Oct 24, 2024
1 parent 9bb00af commit 69a8829
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 588 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ public class GeneratePackageManagerJava : AndroidTask

public ITaskItem[] SatelliteAssemblies { get; set; }

public bool UseAssemblyStore { get; set; }

[Required]
public string OutputDirectory { get; set; }

Expand Down Expand Up @@ -204,21 +202,7 @@ void AddEnvironment ()
throw new InvalidOperationException ($"Unsupported BoundExceptionType value '{BoundExceptionType}'");
}

int assemblyNameWidth = 0;
Encoding assemblyNameEncoding = Encoding.UTF8;

Action<ITaskItem> updateNameWidth = (ITaskItem assembly) => {
if (UseAssemblyStore) {
return;
}

string assemblyName = Path.GetFileName (assembly.ItemSpec);
int nameBytes = assemblyNameEncoding.GetBytes (assemblyName).Length;
if (nameBytes > assemblyNameWidth) {
assemblyNameWidth = nameBytes;
}
};

int assemblyCount = 0;
bool enableMarshalMethods = EnableMarshalMethods;
HashSet<string> archAssemblyNames = null;
Expand Down Expand Up @@ -249,7 +233,6 @@ void AddEnvironment ()

if (SatelliteAssemblies != null) {
foreach (ITaskItem assembly in SatelliteAssemblies) {
updateNameWidth (assembly);
updateAssemblyCount (assembly);
}
}
Expand All @@ -258,7 +241,6 @@ void AddEnvironment ()
int jnienv_initialize_method_token = -1;
int jnienv_registerjninatives_method_token = -1;
foreach (var assembly in ResolvedAssemblies) {
updateNameWidth (assembly);
updateAssemblyCount (assembly);

if (android_runtime_jnienv_class_token != -1) {
Expand All @@ -272,17 +254,6 @@ void AddEnvironment ()
GetRequiredTokens (assembly.ItemSpec, out android_runtime_jnienv_class_token, out jnienv_initialize_method_token, out jnienv_registerjninatives_method_token);
}

if (!UseAssemblyStore) {
int abiNameLength = 0;
foreach (string abi in SupportedAbis) {
if (abi.Length <= abiNameLength) {
continue;
}
abiNameLength = abi.Length;
}
assemblyNameWidth += abiNameLength + 2; // room for '/' and the terminating NUL
}

MonoComponent monoComponents = MonoComponent.None;
if (MonoComponents != null && MonoComponents.Length > 0) {
foreach (ITaskItem item in MonoComponents) {
Expand Down Expand Up @@ -334,10 +305,8 @@ void AddEnvironment ()
JniAddNativeMethodRegistrationAttributePresent = NativeCodeGenState.Template != null ? NativeCodeGenState.Template.JniAddNativeMethodRegistrationAttributePresent : false,
HaveRuntimeConfigBlob = haveRuntimeConfigBlob,
NumberOfAssembliesInApk = assemblyCount,
BundledAssemblyNameWidth = assemblyNameWidth,
MonoComponents = (MonoComponent)monoComponents,
NativeLibraries = uniqueNativeLibraries,
HaveAssemblyStore = UseAssemblyStore,
AndroidRuntimeJNIEnvToken = android_runtime_jnienv_class_token,
JNIEnvInitializeToken = jnienv_initialize_method_token,
JNIEnvRegisterJniNativesToken = jnienv_registerjninatives_method_token,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ public sealed class ApplicationConfig
public bool broken_exception_transitions;
public bool jni_add_native_method_registration_attribute_present;
public bool have_runtime_config_blob;
public bool have_assemblies_blob;
public bool marshal_methods_enabled;
public bool ignore_split_configs;
public byte bound_stream_io_exception_type;
public uint package_naming_policy;
public uint environment_variable_count;
public uint system_property_count;
public uint number_of_assemblies_in_apk;
public uint bundled_assembly_name_width;
public uint number_of_assembly_store_files;
public uint number_of_dso_cache_entries;
public uint number_of_aot_cache_entries;
Expand All @@ -67,7 +65,7 @@ public sealed class ApplicationConfig
public string android_package_name = String.Empty;
}

const uint ApplicationConfigFieldCount = 26;
const uint ApplicationConfigFieldCount = 24;

const string ApplicationConfigSymbolName = "application_config";
const string AppEnvironmentVariablesSymbolName = "app_environment_variables";
Expand Down Expand Up @@ -241,97 +239,87 @@ static ApplicationConfig ReadApplicationConfig (EnvironmentFile envFile)
ret.have_runtime_config_blob = ConvertFieldToBool ("have_runtime_config_blob", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 7: // have_assemblies_blob: bool / .byte
AssertFieldType (envFile.Path, parser.SourceFilePath, ".byte", field [0], item.LineNumber);
ret.have_assemblies_blob = ConvertFieldToBool ("have_assemblies_blob", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 8: // marshal_methods_enabled: bool / .byte
case 7: // marshal_methods_enabled: bool / .byte
AssertFieldType (envFile.Path, parser.SourceFilePath, ".byte", field [0], item.LineNumber);
ret.marshal_methods_enabled = ConvertFieldToBool ("marshal_methods_enabled", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 9: // ignore_split_configs: bool / .byte
case 8: // ignore_split_configs: bool / .byte
AssertFieldType (envFile.Path, parser.SourceFilePath, ".byte", field [0], item.LineNumber);
ret.ignore_split_configs = ConvertFieldToBool ("ignore_split_configs", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 10: // bound_stream_io_exception_type: byte / .byte
case 9: // bound_stream_io_exception_type: byte / .byte
AssertFieldType (envFile.Path, parser.SourceFilePath, ".byte", field [0], item.LineNumber);
ret.bound_stream_io_exception_type = ConvertFieldToByte ("bound_stream_io_exception_type", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 11: // package_naming_policy: uint32_t / .word | .long
case 10: // package_naming_policy: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.package_naming_policy = ConvertFieldToUInt32 ("package_naming_policy", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 12: // environment_variable_count: uint32_t / .word | .long
case 11: // environment_variable_count: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.environment_variable_count = ConvertFieldToUInt32 ("environment_variable_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 13: // system_property_count: uint32_t / .word | .long
case 12: // system_property_count: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.system_property_count = ConvertFieldToUInt32 ("system_property_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 14: // number_of_assemblies_in_apk: uint32_t / .word | .long
case 13: // number_of_assemblies_in_apk: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.number_of_assemblies_in_apk = ConvertFieldToUInt32 ("number_of_assemblies_in_apk", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 15: // bundled_assembly_name_width: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.bundled_assembly_name_width = ConvertFieldToUInt32 ("bundled_assembly_name_width", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 16: // number_of_assembly_store_files: uint32_t / .word | .long
case 14: // number_of_assembly_store_files: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.number_of_assembly_store_files = ConvertFieldToUInt32 ("number_of_assembly_store_files", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 17: // number_of_dso_cache_entries: uint32_t / .word | .long
case 15: // number_of_dso_cache_entries: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.number_of_dso_cache_entries = ConvertFieldToUInt32 ("number_of_dso_cache_entries", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 18: // number_of_aot_cache_entries: uint32_t / .word | .long
case 16: // number_of_aot_cache_entries: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.number_of_aot_cache_entries = ConvertFieldToUInt32 ("number_of_aot_cache_entries", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 19: // android_runtime_jnienv_class_token: uint32_t / .word | .long
case 17: // android_runtime_jnienv_class_token: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.android_runtime_jnienv_class_token = ConvertFieldToUInt32 ("android_runtime_jnienv_class_token", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 20: // jnienv_initialize_method_token: uint32_t / .word | .long
case 18: // jnienv_initialize_method_token: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.jnienv_initialize_method_token = ConvertFieldToUInt32 ("jnienv_initialize_method_token", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 21: // jnienv_registerjninatives_method_token: uint32_t / .word | .long
case 19: // jnienv_registerjninatives_method_token: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.jnienv_registerjninatives_method_token = ConvertFieldToUInt32 ("jnienv_registerjninatives_method_token", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 22: // jni_remapping_replacement_type_count: uint32_t / .word | .long
case 20: // jni_remapping_replacement_type_count: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.jni_remapping_replacement_type_count = ConvertFieldToUInt32 ("jni_remapping_replacement_type_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 23: // jni_remapping_replacement_method_index_entry_count: uint32_t / .word | .long
case 21: // jni_remapping_replacement_method_index_entry_count: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.jni_remapping_replacement_method_index_entry_count = ConvertFieldToUInt32 ("jni_remapping_replacement_method_index_entry_count", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 24: // mono_components_mask: uint32_t / .word | .long
case 22: // mono_components_mask: uint32_t / .word | .long
Assert.IsTrue (expectedUInt32Types.Contains (field [0]), $"Unexpected uint32_t field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
ret.mono_components_mask = ConvertFieldToUInt32 ("mono_components_mask", envFile.Path, parser.SourceFilePath, item.LineNumber, field [1]);
break;

case 25: // android_package_name: string / [pointer type]
case 23: // android_package_name: string / [pointer type]
Assert.IsTrue (expectedPointerTypes.Contains (field [0]), $"Unexpected pointer field type in '{envFile.Path}:{item.LineNumber}': {field [0]}");
pointers.Add (field [1].Trim ());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ sealed class ApplicationConfig
public bool broken_exception_transitions;
public bool jni_add_native_method_registration_attribute_present;
public bool have_runtime_config_blob;
public bool have_assemblies_blob;
public bool marshal_methods_enabled;
public bool ignore_split_configs;
public byte bound_stream_io_exception_type;
public uint package_naming_policy;
public uint environment_variable_count;
public uint system_property_count;
public uint number_of_assemblies_in_apk;
public uint bundled_assembly_name_width;
public uint number_of_dso_cache_entries;
public uint number_of_aot_cache_entries;
public uint number_of_shared_libraries;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,7 @@ sealed class XamarinAndroidBundledAssembly
public global::Android.Runtime.BoundExceptionType BoundExceptionType { get; set; }
public bool JniAddNativeMethodRegistrationAttributePresent { get; set; }
public bool HaveRuntimeConfigBlob { get; set; }
public bool HaveAssemblyStore { get; set; }
public int NumberOfAssembliesInApk { get; set; }
public int BundledAssemblyNameWidth { get; set; } // including the trailing NUL
public int AndroidRuntimeJNIEnvToken { get; set; }
public int JNIEnvInitializeToken { get; set; }
public int JNIEnvRegisterJniNativesToken { get; set; }
Expand Down Expand Up @@ -227,7 +225,6 @@ protected override void Construct (LlvmIrModule module)
broken_exception_transitions = BrokenExceptionTransitions,
jni_add_native_method_registration_attribute_present = JniAddNativeMethodRegistrationAttributePresent,
have_runtime_config_blob = HaveRuntimeConfigBlob,
have_assemblies_blob = HaveAssemblyStore,
marshal_methods_enabled = MarshalMethodsEnabled,
ignore_split_configs = IgnoreSplitConfigs,
bound_stream_io_exception_type = (byte)BoundExceptionType,
Expand All @@ -236,7 +233,6 @@ protected override void Construct (LlvmIrModule module)
system_property_count = (uint)(systemProperties == null ? 0 : systemProperties.Count * 2),
number_of_assemblies_in_apk = (uint)NumberOfAssembliesInApk,
number_of_shared_libraries = (uint)NativeLibraries.Count,
bundled_assembly_name_width = (uint)BundledAssemblyNameWidth,
number_of_dso_cache_entries = (uint)dsoCache.Count,
number_of_aot_cache_entries = (uint)aotDsoCache.Count,
android_runtime_jnienv_class_token = (uint)AndroidRuntimeJNIEnvToken,
Expand Down Expand Up @@ -269,36 +265,12 @@ protected override void Construct (LlvmIrModule module)
};
module.Add (dso_apk_entries);

if (!HaveAssemblyStore) {
xamarinAndroidBundledAssemblies = new List<StructureInstance<XamarinAndroidBundledAssembly>> (NumberOfAssembliesInApk);

var emptyBundledAssemblyData = new XamarinAndroidBundledAssembly {
file_fd = -1,
data_offset = 0,
data_size = 0,
data = 0,
name_length = (uint)BundledAssemblyNameWidth,
name = null,
};

for (int i = 0; i < NumberOfAssembliesInApk; i++) {
xamarinAndroidBundledAssemblies.Add (new StructureInstance<XamarinAndroidBundledAssembly> (xamarinAndroidBundledAssemblyStructureInfo, emptyBundledAssemblyData));
}
}

string bundledBuffersSize = xamarinAndroidBundledAssemblies == null ? "empty (unused when assembly stores are enabled)" : $"{BundledAssemblyNameWidth} bytes long";
var bundled_assemblies = new LlvmIrGlobalVariable (typeof(List<StructureInstance<XamarinAndroidBundledAssembly>>), "bundled_assemblies", LlvmIrVariableOptions.GlobalWritable) {
Value = xamarinAndroidBundledAssemblies,
Comment = $" Bundled assembly name buffers, all {bundledBuffersSize}",
};
module.Add (bundled_assemblies);

AddAssemblyStores (module);
}

void AddAssemblyStores (LlvmIrModule module)
{
ulong itemCount = (ulong)(HaveAssemblyStore ? NumberOfAssembliesInApk : 0);
ulong itemCount = (ulong)NumberOfAssembliesInApk;
var assembly_store_bundled_assemblies = new LlvmIrGlobalVariable (typeof(List<StructureInstance<AssemblyStoreSingleAssemblyRuntimeData>>), "assembly_store_bundled_assemblies", LlvmIrVariableOptions.GlobalWritable) {
ZeroInitializeArray = true,
ArrayItemCount = itemCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,6 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.

<PropertyGroup>
<_AndroidAotStripLibraries Condition=" '$(_AndroidAotStripLibraries)' == '' And '$(AndroidIncludeDebugSymbols)' != 'true' ">True</_AndroidAotStripLibraries>
<AndroidUseAssemblyStore Condition=" '$(EmbedAssembliesIntoApk)' != 'true' ">false</AndroidUseAssemblyStore>
<AndroidUseAssemblyStore Condition=" '$(EmbedAssembliesIntoApk)' != 'true' ">true</AndroidUseAssemblyStore>
<AndroidAotEnableLazyLoad Condition=" '$(AndroidAotEnableLazyLoad)' == '' And '$(AotAssemblies)' == 'true' And '$(AndroidIncludeDebugSymbols)' != 'true' ">True</AndroidAotEnableLazyLoad>
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' and ('$(UsingMicrosoftNETSdkRazor)' == 'true') ">False</AndroidEnableMarshalMethods>
<AndroidEnableMarshalMethods Condition=" '$(AndroidEnableMarshalMethods)' == '' ">False</AndroidEnableMarshalMethods>
Expand Down Expand Up @@ -1742,7 +1740,6 @@ because xbuild doesn't support framework reference assemblies.
PackageNamingPolicy="$(AndroidPackageNamingPolicy)"
BoundExceptionType="$(AndroidBoundExceptionType)"
RuntimeConfigBinFilePath="$(_BinaryRuntimeConfigPath)"
UseAssemblyStore="$(AndroidUseAssemblyStore)"
EnableMarshalMethods="$(_AndroidUseMarshalMethods)"
CustomBundleConfigFile="$(AndroidBundleConfigurationFile)"
>
Expand Down
Loading

0 comments on commit 69a8829

Please sign in to comment.