Skip to content

Commit 73b4f81

Browse files
committed
Add data archive loading to the loading logic
1 parent 4060615 commit 73b4f81

File tree

4 files changed

+17
-44
lines changed

4 files changed

+17
-44
lines changed

eng/testing/tests.mobile.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
<PropertyGroup Condition="'$(TargetOS)' == 'Browser'">
1616
<!-- We need to set this in order to get extensibility on xunit category traits and other arguments we pass down to xunit via MSBuild properties -->
17-
<RunScriptCommand>$HARNESS_RUNNER wasm test --engine=$(JSEngine) $(JSEngineArgs) --js-file=runtime.js -v --output-directory=$XHARNESS_OUT -- --enable-zoneinfo --run WasmTestRunner.dll $(AssemblyName).dll</RunScriptCommand>
17+
<RunScriptCommand>$HARNESS_RUNNER wasm test --engine=$(JSEngine) $(JSEngineArgs) --js-file=runtime.js -v --output-directory=$XHARNESS_OUT -- --run WasmTestRunner.dll $(AssemblyName).dll</RunScriptCommand>
1818
</PropertyGroup>
1919

2020
<!-- Generate a self-contained app bundle for Android with tests. -->

src/mono/wasm/runtime-test.js

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,6 @@ while (true) {
130130
} else if (args [0] == "--disable-on-demand-gc") {
131131
enable_gc = false;
132132
args = args.slice (1);
133-
} else if (args [0] == "--enable-zoneinfo") {
134-
enable_zoneinfo = true;
135-
args = args.slice (1);
136133
} else {
137134
break;
138135
}
@@ -173,26 +170,6 @@ var Module = {
173170
if (!enable_gc) {
174171
Module.ccall ('mono_wasm_enable_on_demand_gc', 'void', ['number'], [0]);
175172
}
176-
if (enable_zoneinfo) {
177-
// The timezone file is generated by https://github.com/dotnet/blazor/tree/master/src/TimeZoneData.
178-
// The file format of the TZ file look like so
179-
//
180-
// [4-byte magic number]
181-
// [4 - byte length of manifest]
182-
// [json manifest]
183-
// [data bytes]
184-
//
185-
// The json manifest is an array that looks like so:
186-
//
187-
// [...["America/Fort_Nelson",2249],["America/Glace_Bay",2206]..]
188-
//
189-
// where the first token in each array is the relative path of the file on disk, and the second is the
190-
// length of the file. The starting offset of a file can be calculated using the lengths of all files
191-
// that appear prior to it.
192-
var zonedata = new Uint8Array(read ("dotnet.timezones.blat", "binary"));
193-
MONO.mono_wasm_load_data (zonedata, "/usr/share/zoneinfo");
194-
}
195-
196173

197174
config.loaded_cb = function () {
198175
App.init ();

src/mono/wasm/runtime/library_mono.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,6 @@ var MonoSupportLib = {
619619
: virtualName;
620620
if (fileName.startsWith("/"))
621621
fileName = fileName.substr(1);
622-
623622
if (parentDirectory) {
624623
if (ctx.tracing)
625624
console.log ("MONO_WASM: Creating directory '" + parentDirectory + "'");
@@ -634,11 +633,12 @@ var MonoSupportLib = {
634633
if (ctx.tracing)
635634
console.log ("MONO_WASM: Creating file '" + fileName + "' in directory '" + parentDirectory + "'");
636635

637-
var fileRet = ctx.createDataFile (
638-
parentDirectory, fileName,
639-
bytes, true /* canRead */, true /* canWrite */, true /* canOwn */
640-
);
641-
636+
if (!this.mono_wasm_load_data_archive (bytes, parentDirectory)) {
637+
var fileRet = ctx.createDataFile (
638+
parentDirectory, fileName,
639+
bytes, true /* canRead */, true /* canWrite */, true /* canOwn */
640+
);
641+
}
642642
break;
643643

644644
default:
@@ -1101,12 +1101,12 @@ var MonoSupportLib = {
11011101
return className.replace(/\//g, '.').replace(/`\d+/g, '');
11021102
},
11031103

1104-
mono_wasm_load_data: function (data, prefix) {
1104+
mono_wasm_load_data_archive: function (data, prefix) {
11051105
var dataview = new DataView(data.buffer);
11061106
var magic = dataview.getUint32(0, true);
11071107
// get magic number
11081108
if (magic != 0x626c6174) {
1109-
throw new Error ("File is of wrong type");
1109+
return false;
11101110
}
11111111
var manifestSize = dataview.getUint32(4, true);
11121112
var manifestContent = Module.UTF8ArrayToString(data, 8, manifestSize);
@@ -1118,18 +1118,13 @@ var MonoSupportLib = {
11181118
// /usr/share/zoneinfo/Africa
11191119
// /usr/share/zoneinfo/Asia
11201120
// ..
1121-
var p = prefix.slice(1).split('/');
1122-
p.forEach((v, i) => {
1123-
FS.mkdir(v);
1124-
Module['FS_createPath']("/" + p.slice(0, i).join('/'), v, true, true);
1125-
})
1121+
11261122
var folders = new Set()
11271123
manifest.filter(m => {
1128-
m = m[0].split('/')
1129-
if (m!= null) {
1130-
if (m.length > 2) folders.add(m.slice(0,m.length-1).join('/'));
1131-
folders.add(m[0]);
1132-
}
1124+
var file = m[0];
1125+
var last = file.lastIndexOf ("/");
1126+
var directory = file.slice (0, last);
1127+
folders.add(directory);
11331128
});
11341129
folders.forEach(folder => {
11351130
Module['FS_createPath'](prefix, folder, true, true);
@@ -1139,9 +1134,10 @@ var MonoSupportLib = {
11391134
var name = row[0];
11401135
var length = row[1];
11411136
var bytes = data.slice(0, length);
1142-
Module['FS_createDataFile'](`${prefix}/${name}`, null, bytes, true, true);
1137+
Module['FS_createDataFile'](prefix, name, bytes, true, true);
11431138
data = data.slice(length);
11441139
}
1140+
return true;
11451141
}
11461142
},
11471143

tools-local/tasks/mobile.tasks/WasmAppBuilder/WasmAppBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public override bool Execute ()
121121
var sEnableRemote = enableRemote ? "true" : "false";
122122

123123
sw.WriteLine($"\t\t{{ behavior: \"icu\", name: \"icudt.dat\", load_remote: {sEnableRemote} }},");
124-
124+
sw.WriteLine($"\t\t{{ behavior: \"vfs\", name: \"dotnet.timezones.blat\", virtual_path: \"/usr/share/zoneinfo/\" }}");
125125
sw.WriteLine ("\t],");
126126

127127
if (enableRemote) {

0 commit comments

Comments
 (0)