未验证 提交 69c1038b 编写于 作者: T Tammy Qiu 提交者: GitHub

Incorporate timezone data from runtime-assets (#41524)

* Incorporate timezone data from runtime-assets
* Change CreateWasmBundle name & create separate timezones.props file
上级 b25b2bc6
......@@ -51,13 +51,13 @@
<AppleAppBuilderDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'AppleAppBuilder', 'Debug', '$(NetCoreAppCurrent)'))</AppleAppBuilderDir>
<AndroidAppBuilderDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'AndroidAppBuilder', 'Debug', '$(NetCoreAppCurrent)'))</AndroidAppBuilderDir>
<WasmAppBuilderDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'WasmAppBuilder', 'Debug', '$(NetCoreAppCurrent)', 'publish'))</WasmAppBuilderDir>
<CreateWasmBundleDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'CreateWasmBundle', 'Debug', '$(NetCoreAppCurrent)', 'publish'))</CreateWasmBundleDir>
<GenerateWasmBundleDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'GenerateWasmBundle', 'Debug', '$(NetCoreAppCurrent)', 'publish'))</GenerateWasmBundleDir>
<MonoAOTCompilerDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsBinDir)', 'MonoAOTCompiler', 'Debug', '$(NetCoreAppCurrent)'))</MonoAOTCompilerDir>
<AppleAppBuilderTasksAssemblyPath>$([MSBuild]::NormalizePath('$(AppleAppBuilderDir)', 'AppleAppBuilder.dll'))</AppleAppBuilderTasksAssemblyPath>
<AndroidAppBuilderTasksAssemblyPath>$([MSBuild]::NormalizePath('$(AndroidAppBuilderDir)', 'AndroidAppBuilder.dll'))</AndroidAppBuilderTasksAssemblyPath>
<WasmAppBuilderTasksAssemblyPath>$([MSBuild]::NormalizePath('$(WasmAppBuilderDir)', 'WasmAppBuilder.dll'))</WasmAppBuilderTasksAssemblyPath>
<CreateCreateWasmBundlesAssemblyPath>$([MSBuild]::NormalizePath('$(CreateWasmBundleDir)', 'CreateWasmBundle.dll'))</CreateCreateWasmBundlesAssemblyPath>
<GenerateWasmBundlesAssemblyPath>$([MSBuild]::NormalizePath('$(GenerateWasmBundleDir)', 'GenerateWasmBundle.dll'))</GenerateWasmBundlesAssemblyPath>
<MonoAOTCompilerTasksAssemblyPath>$([MSBuild]::NormalizePath('$(MonoAOTCompilerDir)', 'MonoAOTCompiler.dll'))</MonoAOTCompilerTasksAssemblyPath>
</PropertyGroup>
......
......@@ -114,6 +114,10 @@
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>436a2ae5c082f68a3fbff98bfe097b13902ea3f1</Sha>
</Dependency>
<Dependency Name="System.Runtime.TimeZoneData" Version="5.0.0-beta.20451.1">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>436a2ae5c082f68a3fbff98bfe097b13902ea3f1</Sha>
</Dependency>
<Dependency Name="System.Security.Cryptography.X509Certificates.TestData" Version="5.0.0-beta.20451.1">
<Uri>https://github.com/dotnet/runtime-assets</Uri>
<Sha>436a2ae5c082f68a3fbff98bfe097b13902ea3f1</Sha>
......
......@@ -109,6 +109,7 @@
<SystemIOPackagingTestDataVersion>5.0.0-beta.20451.1</SystemIOPackagingTestDataVersion>
<SystemNetTestDataVersion>5.0.0-beta.20451.1</SystemNetTestDataVersion>
<SystemPrivateRuntimeUnicodeDataVersion>5.0.0-beta.20451.1</SystemPrivateRuntimeUnicodeDataVersion>
<SystemRuntimeTimeZoneDataVersion>5.0.0-beta.20451.1</SystemRuntimeTimeZoneDataVersion>
<SystemSecurityCryptographyX509CertificatesTestDataVersion>5.0.0-beta.20451.1</SystemSecurityCryptographyX509CertificatesTestDataVersion>
<SystemWindowsExtensionsTestDataVersion>5.0.0-beta.20451.1</SystemWindowsExtensionsTestDataVersion>
<!-- Standard dependencies -->
......
......@@ -151,22 +151,20 @@
AssemblySearchPaths="@(AssemblySearchPaths)" />
</Target>
<UsingTask TaskName="DownloadTimeZoneData"
AssemblyFile="$(CreateCreateWasmBundlesAssemblyPath)" />
<Import Project="$(MonoProjectRoot)wasm\timezones.props" Condition="'$(TargetOS)' == 'Browser'" />
<UsingTask TaskName="CompileTimeZoneData"
AssemblyFile="$(GenerateWasmBundlesAssemblyPath)" />
<Target Condition="'$(TargetOS)' == 'Browser'" Name="LoadTimeZone" >
<PropertyGroup>
<TimeZoneDataVersion>2020a</TimeZoneDataVersion>
</PropertyGroup>
<DownloadTimeZoneData
InputDirectory="$(BundleDir)obj/data/input"
OutputDirectory="$(BundleDir)obj/data/output"
Version="$(TimeZoneDataVersion)"/>
<CompileTimeZoneData
TimeZones="@(TimeZoneToBundle)"
InputDirectory="$([MSBuild]::NormalizePath('$(GenerateWasmBundleDir)', '..', 'data'))"
OutputDirectory="$(BundleDir)obj/data/output"/>
</Target>
<UsingTask TaskName="CreateWasmBundle"
AssemblyFile="$(CreateCreateWasmBundlesAssemblyPath)" />
<UsingTask TaskName="GenerateWasmBundle"
AssemblyFile="$(GenerateWasmBundlesAssemblyPath)" />
<Target Condition="'$(TargetOS)' == 'Browser'" Name="BundleWasmTestData" DependsOnTargets="LoadTimeZone">
<CreateWasmBundle
<GenerateWasmBundle
InputDirectory="$(BundleDir)obj/data/output"
OutputFileName="$(MicrosoftNetCoreAppRuntimePackRidDir)dotnet.timezones.blat" />
</Target>
......
......@@ -134,7 +134,7 @@ app-builder:
$(DOTNET) build $(TOP)/tools-local/tasks/mobile.tasks/WasmAppBuilder
bundle-task:
$(DOTNET) build $(TOP)/tools-local/tasks/mobile.tasks/CreateWasmBundle
$(DOTNET) build $(TOP)/tools-local/tasks/mobile.tasks/GenerateWasmBundle
run-tests-v8-%:
PATH="$(JSVU):$(PATH)" $(DOTNET) build $(TOP)/src/libraries/$*/tests/ /t:Test /p:TargetOS=Browser /p:TargetArchitecture=wasm /p:Configuration=$(CONFIG) /p:JSEngine=V8 $(MSBUILD_ARGS)
......
<Project>
<ItemGroup>
<TimeZoneToBundle Include="africa" />
<TimeZoneToBundle Include="antarctica" />
<TimeZoneToBundle Include="asia" />
<TimeZoneToBundle Include="australasia" />
<TimeZoneToBundle Include="etcetera" />
<TimeZoneToBundle Include="europe" />
<TimeZoneToBundle Include="northamerica" />
<TimeZoneToBundle Include="southamerica" />
</ItemGroup>
</Project>
\ No newline at end of file
......@@ -35,20 +35,23 @@
OutputPath="$(WasmPInvokeTablePath)" />
</Target>
<UsingTask TaskName="DownloadTimeZoneData" AssemblyFile="$([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'CreateWasmBundle', 'Debug', '$(NetCoreAppCurrent)', 'publish', 'CreateWasmBundle.dll'))"/>
<Import Project="timezones.props" Condition="'$(TargetOS)' == 'Browser'" />
<UsingTask TaskName="CompileTimeZoneData"
AssemblyFile="$(GenerateWasmBundlesAssemblyPath)"/>
<Target Name="LoadTimeZones" DependsOnTargets="CheckEnv">
<DownloadTimeZoneData
InputDirectory="$(ArtifactsObjDir)wasm/data/input"
OutputDirectory="$(ArtifactsObjDir)wasm/data/output"
Version="2020a" />
<CompileTimeZoneData
TimeZones="@(TimeZoneToBundle)"
InputDirectory="$([MSBuild]::NormalizePath('$(GenerateWasmBundleDir)', '..', 'data'))"
OutputDirectory="$(ArtifactsObjDir)wasm/data/output" />
</Target>
<UsingTask TaskName="CreateWasmBundle" AssemblyFile="$([MSBuild]::NormalizePath('$(ArtifactsBinDir)', 'CreateWasmBundle', 'Debug', '$(NetCoreAppCurrent)', 'publish', 'CreateWasmBundle.dll'))"/>
<UsingTask TaskName="GenerateWasmBundle"
AssemblyFile="$(GenerateWasmBundlesAssemblyPath)"/>
<Target Name="BundleWasm" DependsOnTargets="CheckEnv;LoadTimeZones">
<PropertyGroup>
<TimeZonesDataPath>$(NativeBinDir)dotnet.timezones.blat</TimeZonesDataPath>
</PropertyGroup>
<CreateWasmBundle
<GenerateWasmBundle
InputDirectory="$(ArtifactsObjDir)wasm/data/output"
OutputFileName="$(TimeZonesDataPath)" />
</Target>
......
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Net;
using System.Reflection;
using System.Diagnostics;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class CompileTimeZoneData : Task
{
[Required]
public string? InputDirectory { get; set; }
[Required]
public string? OutputDirectory { get; set; }
[Required]
public string[]? TimeZones { get; set; }
private const string ZoneTabFileName = "zone1970.tab";
private void CompileTimeZoneDataSource()
{
using (Process process = new Process())
{
process.StartInfo.UseShellExecute = false;
process.StartInfo.FileName = "zic";
foreach (var f in TimeZones!)
{
process.StartInfo.Arguments = $"-d \"{OutputDirectory}\" \"{Path.Combine(InputDirectory!, f)}\"";
process.Start();
process.WaitForExit();
}
}
}
private void FilterTimeZoneData()
{
// Remove unnecessary timezone files in the root dir
// for ex: `CST6CDT`, `MST`, etc.
foreach (var entry in new DirectoryInfo (OutputDirectory!).EnumerateFiles())
{
File.Delete(entry.FullName);
}
}
private void FilterZoneTab(string[] filters, string ZoneTabFile)
{
var path = Path.Combine(OutputDirectory!, "zone.tab");
using (StreamReader sr = new StreamReader(ZoneTabFile))
using (StreamWriter sw = new StreamWriter(path))
{
string? line;
while ((line = sr.ReadLine()) != null) {
if (filters.Any(x => Regex.IsMatch(line, $@"\b{x}\b")))
{
sw.WriteLine(line);
}
}
}
}
public override bool Execute()
{
string ZoneTabFile = Path.Combine(InputDirectory!, ZoneTabFileName);
if (!Directory.Exists(OutputDirectory))
Directory.CreateDirectory(OutputDirectory!);
if (!File.Exists(ZoneTabFile))
{
Log.LogError($"Could not find required file {ZoneTabFile}");
return false;
}
CompileTimeZoneDataSource();
string[] filtered = new string[] { "America/Los_Angeles", "Australia/Sydney", "Europe/London", "Pacific/Tongatapu",
"America/Sao_Paulo", "Australia/Perth", "Africa/Nairobi", "Europe/Berlin",
"Europe/Moscow", "Africa/Tripoli", "America/Argentina/Catamarca", "Europe/Lisbon",
"America/St_Johns"};
FilterTimeZoneData();
FilterZoneTab(filtered, ZoneTabFile);
return !Log.HasLoggedErrors;
}
}
\ No newline at end of file
using System;
using System.Buffers.Binary;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Linq;
using System.Text.RegularExpressions;
using System.Net;
using System.Reflection;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
public class GenerateWasmBundle : Task
{
[Required]
public string? InputDirectory { get; set; }
[Required]
public string? OutputFileName { get; set; }
private (byte[] json_bytes, MemoryStream stream) EnumerateData()
{
var indices = new List<object[]>();
var stream = new MemoryStream();
var directoryInfo = new DirectoryInfo(InputDirectory!);
foreach (var entry in directoryInfo.EnumerateFiles("*", SearchOption.AllDirectories))
{
var relativePath = Path.GetRelativePath(InputDirectory!, entry.FullName);
indices.Add(new object[] { relativePath, entry.Length });
using (var readStream = entry.OpenRead())
readStream.CopyTo(stream);
}
stream.Position = 0;
var jsonBytes = JsonSerializer.SerializeToUtf8Bytes(indices);
return (jsonBytes, stream);
}
public override bool Execute()
{
if (!Directory.Exists(InputDirectory))
{
Log.LogError($"Input directory '{InputDirectory}' does not exist");
return false;
}
(byte[] json_bytes, MemoryStream stream) data = EnumerateData();
using (var file = File.Open(OutputFileName!, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
{
var lengthBytes = new byte[4];
var magicBytes = Encoding.ASCII.GetBytes("talb");
BinaryPrimitives.WriteInt32LittleEndian(lengthBytes, data.json_bytes.Length);
file.Write(magicBytes);
file.Write(lengthBytes);
file.Write(data.json_bytes);
data.stream.CopyTo(file);
}
return true;
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<OutputType>Library</OutputType>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="$(RefOnlyMicrosoftBuildVersion)" />
<PackageReference Include="Microsoft.Build.Framework" Version="$(RefOnlyMicrosoftBuildFrameworkVersion)" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="$(RefOnlyMicrosoftBuildTasksCoreVersion)" />
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="$(RefOnlyMicrosoftBuildUtilitiesCoreVersion)" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.TimeZoneData" Version="$(SystemRuntimeTimeZoneDataVersion)" PrivateAssets="all" />
</ItemGroup>
<Target Name="PublishBuilder"
AfterTargets="Build"
DependsOnTargets="Publish" />
</Project>
......@@ -7,7 +7,7 @@
Condition="'$(TargetOS)' != 'iOS' and '$(TargetOS)' != 'tvOS'" />
<ProjectReference Remove="$(MSBuildThisFileDirectory)mobile.tasks\WasmAppBuilder\WasmAppBuilder.csproj"
Condition="'$(TargetOS)' != 'Browser'" />
<ProjectReference Remove="$(MSBuildThisFileDirectory)mobile.tasks\CreateWasmBundle\CreateWasmBundle.csproj"
<ProjectReference Remove="$(MSBuildThisFileDirectory)mobile.tasks\GenerateWasmBundle\GenerateWasmBundle.csproj"
Condition="'$(TargetOS)' != 'Browser'" />
<ProjectReference Remove="$(MSBuildThisFileDirectory)mobile.tasks\AotCompilerTask\MonoAOTCompiler.csproj"
Condition="'$(TargetsMobile)' != 'true'" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册