[wasi] Fixes to enable more tests (#82966)
authorAnkit Jain <radical@gmail.com>
Wed, 8 Mar 2023 16:26:04 +0000 (11:26 -0500)
committerGitHub <noreply@github.com>
Wed, 8 Mar 2023 16:26:04 +0000 (11:26 -0500)
* [wasi] Copy WasmFilesToIncludeInFileSystem to the bundle too

This could be changed in the future to include in the single file bundle

* [wasi] Enable System.IO.Packaging, and System.Data.DataSetExtensions tests

* WasiAppBuilder: Create an empty /tmp

* Disable System.Runtime.Serialization.Xml.XsdDataContractExporterTests.ExporterTypesTests.TypesTest_Negative - Issue: https://github.com/dotnet/runtime/issues/82967

* Enable System.Runtime.Serialization.Xml.Tests, and System.Runtime.Serialization.Xml.ReflectionOnly.Tests

Remaining fixed by adding `/tmp`

src/libraries/System.Runtime.Serialization.Xml/tests/XsdDataContractExporterTests/ExporterTypesTests.cs
src/libraries/tests.proj
src/mono/wasi/build/WasiApp.targets
src/tasks/WasmAppBuilder/WasmAppBuilder.cs
src/tasks/WasmAppBuilder/WasmAppBuilderBaseTask.cs
src/tasks/WasmAppBuilder/wasi/WasiAppBuilder.cs

index 6c9ac36..c21b315 100644 (file)
@@ -81,6 +81,7 @@ namespace System.Runtime.Serialization.Xml.XsdDataContractExporterTests
 
         [Theory]
         [SkipOnPlatform(TestPlatforms.Browser, "Inconsistent and unpredictable results.")]  // TODO - Why does 'TypeWithReadWriteCollectionAndNoCtorOnCollection' only cause an exception sometimes, but not all the time? What's special about wasm here?
+        [ActiveIssue("https://github.com/dotnet/runtime/issues/82967", TestPlatforms.Wasi)]
         [InlineData(typeof(NoDataContractWithoutParameterlessConstructor), typeof(InvalidDataContractException), @"Type 'System.Runtime.Serialization.Xml.XsdDataContractExporterTests.ExporterTypesTests+NoDataContractWithoutParameterlessConstructor' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.")]
         [InlineData(typeof(DataContractWithInvalidMember), typeof(InvalidDataContractException), @"Type 'System.Runtime.Serialization.Xml.XsdDataContractExporterTests.ExporterTypesTests+NoDataContractWithoutParameterlessConstructor' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.")]
         [InlineData(typeof(SerializableWithInvalidMember), typeof(InvalidDataContractException), @"Type 'System.Runtime.Serialization.Xml.XsdDataContractExporterTests.ExporterTypesTests+NoDataContractWithoutParameterlessConstructor' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. Alternatively, you can ensure that the type is public and has a parameterless constructor - all public members of the type will then be serialized, and no attributes will be required.")]
index 47fc849..21221cf 100644 (file)
     <SmokeTestProject Include="$(MSBuildThisFileDirectory)System.Runtime.Serialization.Json\tests\System.Runtime.Serialization.Json.Tests.csproj" />
     <SmokeTestProject Include="$(MSBuildThisFileDirectory)System.Globalization\tests\System.Globalization.Tests.csproj" />
     <SmokeTestProject Include="$(MSBuildThisFileDirectory)System.Globalization\tests\Invariant\Invariant.Tests.csproj" />
+    <SmokeTestProject Include="$(MSBuildThisFileDirectory)System.IO.Packaging\tests\System.IO.Packaging.Tests.csproj" />
+    <SmokeTestProject Include="$(MSBuildThisFileDirectory)System.Data.DataSetExtensions\tests\System.Data.DataSetExtensions.Tests.csproj" />
+    <SmokeTestProject Include="$(MSBuildThisFileDirectory)System.Runtime.Serialization.Xml\tests\System.Runtime.Serialization.Xml.Tests.csproj" />
+    <SmokeTestProject Include="$(MSBuildThisFileDirectory)System.Runtime.Serialization.Xml\tests\ReflectionOnly\System.Runtime.Serialization.Xml.ReflectionOnly.Tests.csproj" />
   </ItemGroup>
 
   <ItemGroup Condition="'$(TestNativeAot)' == 'true'">
index 6085aa2..81b5b8a 100644 (file)
       InvariantGlobalization="$(InvariantGlobalization)"
       SatelliteAssemblies="@(_WasmSatelliteAssemblies)"
       IcuDataFileNames="@(WasmIcuDataFileNames)"
+      FilesToIncludeInFileSystem="@(WasmFilesToIncludeInFileSystem)"
       ExtraFilesToDeploy="@(WasmExtraFilesToDeploy)"
       NativeAssets="@(WasmNativeAsset)"
       DebugLevel="$(WasmDebugLevel)"
index b744139..40a74d7 100644 (file)
@@ -18,7 +18,6 @@ namespace Microsoft.WebAssembly.Build.Tasks;
 
 public class WasmAppBuilder : WasmAppBuilderBaseTask
 {
-    public ITaskItem[]? FilesToIncludeInFileSystem { get; set; }
     public ITaskItem[]? RemoteSources { get; set; }
     public bool IncludeThreadsWorker {get; set; }
     public int PThreadPoolSize {get; set; }
@@ -265,7 +264,7 @@ public class WasmAppBuilder : WasmAppBuilderBaseTask
             }
         });
 
-        if (FilesToIncludeInFileSystem != null)
+        if (FilesToIncludeInFileSystem.Length > 0)
         {
             string supportFilesDir = Path.Combine(AppDir, "supportFiles");
             Directory.CreateDirectory(supportFilesDir);
@@ -366,29 +365,26 @@ public class WasmAppBuilder : WasmAppBuilderBaseTask
         Utils.CopyIfDifferent(tmpMonoConfigPath, monoConfigPath, useHash: false);
         _fileWrites.Add(monoConfigPath);
 
-        if (ExtraFilesToDeploy != null)
+        foreach (ITaskItem item in ExtraFilesToDeploy!)
         {
-            foreach (ITaskItem item in ExtraFilesToDeploy!)
-            {
-                string src = item.ItemSpec;
-                string dst;
-
-                string tgtPath = item.GetMetadata("TargetPath");
-                if (!string.IsNullOrEmpty(tgtPath))
-                {
-                    dst = Path.Combine(AppDir!, tgtPath);
-                    string? dstDir = Path.GetDirectoryName(dst);
-                    if (!string.IsNullOrEmpty(dstDir) && !Directory.Exists(dstDir))
-                        Directory.CreateDirectory(dstDir!);
-                }
-                else
-                {
-                    dst = Path.Combine(AppDir!, Path.GetFileName(src));
-                }
+            string src = item.ItemSpec;
+            string dst;
 
-                if (!FileCopyChecked(src, dst, "ExtraFilesToDeploy"))
-                    return false;
+            string tgtPath = item.GetMetadata("TargetPath");
+            if (!string.IsNullOrEmpty(tgtPath))
+            {
+                dst = Path.Combine(AppDir!, tgtPath);
+                string? dstDir = Path.GetDirectoryName(dst);
+                if (!string.IsNullOrEmpty(dstDir) && !Directory.Exists(dstDir))
+                    Directory.CreateDirectory(dstDir!);
             }
+            else
+            {
+                dst = Path.Combine(AppDir!, Path.GetFileName(src));
+            }
+
+            if (!FileCopyChecked(src, dst, "ExtraFilesToDeploy"))
+                return false;
         }
 
         UpdateRuntimeConfigJson();
index 5372ee5..4eb709a 100644 (file)
@@ -39,6 +39,7 @@ public abstract class WasmAppBuilderBaseTask : Task
     public int DebugLevel { get; set; }
     public ITaskItem[] SatelliteAssemblies { get; set; } = Array.Empty<ITaskItem>();
     public bool InvariantGlobalization { get; set; }
+    public ITaskItem[] FilesToIncludeInFileSystem { get; set; } = Array.Empty<ITaskItem>();
     public ITaskItem[] ExtraFilesToDeploy { get; set; } = Array.Empty<ITaskItem>();
 
     public string? DefaultHostConfig { get; set; }
index 8ad5ee7..5d13cba 100644 (file)
@@ -62,6 +62,7 @@ public class WasiAppBuilder : WasmAppBuilderBaseTask
             }
         }
 
+        // TODO: Files on disk are not solved for IsSingleFileBundle yet
         foreach (ITaskItem item in NativeAssets)
         {
             string dest = Path.Combine(AppDir, Path.GetFileName(item.ItemSpec));
@@ -77,30 +78,43 @@ public class WasiAppBuilder : WasmAppBuilderBaseTask
             FileCopyChecked(args.fullPath, Path.Combine(directory, name), "SatelliteAssemblies");
         });
 
-        foreach (ITaskItem item in ExtraFilesToDeploy!)
-        {
-            string src = item.ItemSpec;
-            string dst;
+        if (!DeployFiles(ExtraFilesToDeploy, nameof(ExtraFilesToDeploy)))
+            return false;
+        if (!DeployFiles(FilesToIncludeInFileSystem, nameof(FilesToIncludeInFileSystem)))
+            return false;
 
-            string tgtPath = item.GetMetadata("TargetPath");
-            if (!string.IsNullOrEmpty(tgtPath))
-            {
-                dst = Path.Combine(AppDir!, tgtPath);
-                string? dstDir = Path.GetDirectoryName(dst);
-                if (!string.IsNullOrEmpty(dstDir) && !Directory.Exists(dstDir))
-                    Directory.CreateDirectory(dstDir!);
-            }
-            else
+        Directory.CreateDirectory(Path.Combine(AppDir, "tmp"));
+
+        UpdateRuntimeConfigJson();
+        return !Log.HasLoggedErrors;
+
+        bool DeployFiles(ITaskItem[] fileItems, string label)
+        {
+            foreach (ITaskItem item in fileItems)
             {
-                dst = Path.Combine(AppDir!, Path.GetFileName(src));
+                string src = item.ItemSpec;
+                string dst;
+
+                string tgtPath = item.GetMetadata("TargetPath");
+                if (!string.IsNullOrEmpty(tgtPath))
+                {
+                    dst = Path.Combine(AppDir!, tgtPath);
+                    string? dstDir = Path.GetDirectoryName(dst);
+                    if (!string.IsNullOrEmpty(dstDir) && !Directory.Exists(dstDir))
+                        Directory.CreateDirectory(dstDir!);
+                }
+                else
+                {
+                    dst = Path.Combine(AppDir!, Path.GetFileName(src));
+                }
+
+                if (!FileCopyChecked(src, dst, label))
+                    return false;
             }
 
-            if (!FileCopyChecked(src, dst, "ExtraFilesToDeploy"))
-                return false;
+            return true;
         }
 
-        UpdateRuntimeConfigJson();
-        return !Log.HasLoggedErrors;
     }
 
     protected override void AddToRuntimeConfig(JsonObject wasmHostProperties, JsonArray runtimeArgsArray, JsonArray perHostConfigs)