Simplify icudat file lookup by specifying ICU_DAT_FILE_PATH as a RuntimeHostConfigurationOption (#18914)

Fixes https://github.com/xamarin/xamarin-macios/issues/18471
This commit is contained in:
Ivan Povazan 2023-09-08 16:46:32 +02:00 коммит произвёл GitHub
Родитель 33bee558da 1e06cef1e7
Коммит bf77022512
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 11 добавлений и 42 удалений

Просмотреть файл

@ -165,11 +165,6 @@
<TargetPlatformSupported Condition=" '$(TargetPlatformIdentifier)' == '$(_PlatformName)' ">true</TargetPlatformSupported>
</PropertyGroup>
<PropertyGroup Condition="'$(_GlobalizationDataFileLocation)' == ''">
<_GlobalizationDataFileLocation Condition="'$(_UseNativeAot)' == 'true'">Resource</_GlobalizationDataFileLocation>
<_GlobalizationDataFileLocation Condition="'$(_UseNativeAot)' != 'true'">Assembly</_GlobalizationDataFileLocation>
</PropertyGroup>
<!-- dotnet publish -->
<Import Project="Xamarin.Shared.Sdk.Publish.targets" />
@ -1090,7 +1085,6 @@
<!-- List all the properties passed to xamarin_bridge_vm_initialize in xamarin_vm_initialize (in runtime.m) -->
<_RuntimeConfigReservedProperties Include="APP_PATHS" />
<_RuntimeConfigReservedProperties Include="PINVOKE_OVERRIDE" />
<_RuntimeConfigReservedProperties Include="ICU_DAT_FILE_PATH" />
<_RuntimeConfigReservedProperties Include="TRUSTED_PLATFORM_ASSEMBLIES" />
<_RuntimeConfigReservedProperties Include="NATIVE_DLL_SEARCH_DIRECTORIES" />
<_RuntimeConfigReservedProperties Include="RUNTIME_IDENTIFIER" />
@ -1688,7 +1682,7 @@
'%(ResolvedFileToPublish.Filename)%(ResolvedFileToPublish.Extension)' == '$(_GlobalizationDataFile)' And
'%(ResolvedFileToPublish.NuGetPackageId)' == '$(_MonoNugetPackageId)'
"
PublishFolderType="$(_GlobalizationDataFileLocation)"
PublishFolderType="Assembly"
/>
<!-- Remove the libxamarin-*.dylib files we don't want -->

Просмотреть файл

@ -2870,6 +2870,10 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<!-- needed for GetTargetPath/Build/Rebuild task outputs -->
<_AppExtensionBundlePath>$(MSBuildProjectDirectory)\$(AppBundleDir)</_AppExtensionBundlePath>
</PropertyGroup>
<PropertyGroup>
<_GlobalizationDataFileAppBundleRelativePath Condition="'$(_AppContentsRelativePath)' == ''">$(_GlobalizationDataFile)</_GlobalizationDataFileAppBundleRelativePath>
<_GlobalizationDataFileAppBundleRelativePath Condition="'$(_AppContentsRelativePath)' != ''">$(_AppContentsRelativePath)\$(_GlobalizationDataFile)</_GlobalizationDataFileAppBundleRelativePath>
</PropertyGroup>
<ItemGroup Condition="'$(IsAppExtension)' == 'true'">
<_AppExtensionBundlePath Include="$(MSBuildProjectDirectory)\$(AppBundleDir)">
<!-- We need this metadata to fix the source in VS -->
@ -2877,6 +2881,10 @@ Copyright (C) 2018 Microsoft. All rights reserved.
<BuildServerPath>..\..\$(BuildAppName)\$(BuildSessionId)\$(AppBundleDir)</BuildServerPath>
</_AppExtensionBundlePath>
</ItemGroup>
<ItemGroup>
<!-- Replacing backslashes with slashes is required since MSBuild has some issue with resolving backslashes next to a property value: https://github.com/dotnet/msbuild/issues/9200 -->
<RuntimeHostConfigurationOption Include="ICU_DAT_FILE_PATH" Value="$(_GlobalizationDataFileAppBundleRelativePath.Replace('\','/'))" />
</ItemGroup>
</Target>
<Target Name="_CompileProductDefinition" Condition="$(CreatePackage)" DependsOnTargets="_WriteAppManifest;_ComputeTargetArchitectures">

Просмотреть файл

@ -55,9 +55,6 @@ bool xamarin_init_mono_debug = false;
#endif
int xamarin_log_level = 0;
const char *xamarin_executable_name = NULL;
#if DOTNET
const char *xamarin_icu_dat_file_name = NULL;
#endif
#if MONOMAC || TARGET_OS_MACCATALYST
NSString * xamarin_custom_bundle_name = @"MonoBundle";
#endif
@ -2585,22 +2582,6 @@ void
xamarin_vm_initialize ()
{
char *pinvokeOverride = xamarin_strdup_printf ("%p", &xamarin_pinvoke_override);
char *icu_dat_file_path = NULL;
int subtractPropertyCount = 0;
if (xamarin_icu_dat_file_name != NULL && *xamarin_icu_dat_file_name != 0) {
#if !defined (NATIVEAOT)
char path [1024];
if (!xamarin_locate_app_resource (xamarin_icu_dat_file_name, path, sizeof (path))) {
LOG (PRODUCT ": Could not locate the ICU data file '%s' in the app bundle.\n", xamarin_icu_dat_file_name);
} else {
icu_dat_file_path = strdup (path);
}
#endif // !defined (NATIVEAOT)
} else {
subtractPropertyCount++;
}
char *trusted_platform_assemblies = xamarin_compute_trusted_platform_assemblies ();
char *native_dll_search_directories = xamarin_compute_native_dll_search_directories ();
@ -2613,7 +2594,6 @@ xamarin_vm_initialize ()
"TRUSTED_PLATFORM_ASSEMBLIES",
"NATIVE_DLL_SEARCH_DIRECTORIES",
"RUNTIME_IDENTIFIER",
"ICU_DAT_FILE_PATH", // Must be last.
};
const char *propertyValues[] = {
xamarin_get_bundle_path (),
@ -2622,20 +2602,16 @@ xamarin_vm_initialize ()
trusted_platform_assemblies,
native_dll_search_directories,
RUNTIMEIDENTIFIER,
icu_dat_file_path, // might be NULL, if so we say we're passing one property less that what we really are (to skip this last one). This also means that this property must be the last one
};
static_assert (sizeof (propertyKeys) == sizeof (propertyValues), "The number of keys and values must be the same.");
int propertyCount = (int) (sizeof (propertyValues) / sizeof (propertyValues [0])) - subtractPropertyCount;
int propertyCount = (int) (sizeof (propertyValues) / sizeof (propertyValues [0]));
bool rv = xamarin_bridge_vm_initialize (propertyCount, propertyKeys, propertyValues);
xamarin_free (pinvokeOverride);
xamarin_free (pinvokeOverride);
xamarin_free (trusted_platform_assemblies);
xamarin_free (native_dll_search_directories);
if (icu_dat_file_path != NULL)
free (icu_dat_file_path);
if (!rv)
xamarin_assertion_message ("Failed to initialize the VM");
}

Просмотреть файл

@ -31,17 +31,8 @@ namespace Xamarin {
contents.AppendLine ("#include <stdlib.h>");
contents.AppendLine ();
contents.AppendLine ("extern \"C\" const char *xamarin_icu_dat_file_name;");
contents.AppendLine ();
contents.AppendLine ("static void xamarin_initialize_dotnet ()");
contents.AppendLine ("{");
if (Configuration.InvariantGlobalization) {
contents.AppendLine ("\tsetenv (\"DOTNET_SYSTEM_GLOBALIZATION_INVARIANT\", \"1\", 1);");
} else {
if (Configuration.HybridGlobalization)
contents.AppendLine ("\tsetenv (\"DOTNET_SYSTEM_GLOBALIZATION_HYBRID\", \"1\", 1);");
contents.AppendLine ($"\txamarin_icu_dat_file_name = \"{Configuration.GlobalizationDataFile}\";");
}
if (Configuration.Application.PackageManagedDebugSymbols && Configuration.Application.UseInterpreter)
contents.AppendLine ($"\tsetenv (\"DOTNET_MODIFIABLE_ASSEMBLIES\", \"debug\", 1);");
contents.AppendLine ("}");