MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / OnPostProcess

Method OnPostProcess

Source/Editor/Cooker/Platform/Web/WebPlatformTools.cpp:137–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137bool WebPlatformTools::OnPostProcess(CookingData& data)
138{
139 const auto gameSettings = GameSettings::Get();
140 const auto platformSettings = WebPlatformSettings::Get();
141 const auto platformDataPath = data.GetPlatformBinariesRoot();
142
143 // Get name of the output binary (JavaScript and WebAssembly files match)
144 String gameJs;
145 {
146 Array<String> files;
147 FileSystem::DirectoryGetFiles(files, data.OriginalOutputPath, TEXT("*"), DirectorySearchOption::TopDirectoryOnly);
148 for (const String& file : files)
149 {
150 if (file.EndsWith(TEXT(".js")))
151 {
152 String outputWasm = String(StringUtils::GetPathWithoutExtension(file)) + TEXT(".wasm");
153 if (files.Contains(outputWasm))
154 {
155 gameJs = file;
156 break;
157 }
158 }
159 }
160 }
161 if (gameJs.IsEmpty())
162 {
163 data.Error(TEXT("Failed to find the main JavaScript for the output game"));
164 return true;
165 }
166
167 // Move .wasm assemblies into the data files in order for dlopen to work (blocking)
168 {
169 Array<String> files;
170 FileSystem::DirectoryGetFiles(files, data.OriginalOutputPath, TEXT("*.wasm"), DirectorySearchOption::AllDirectories);
171 StringView gameWasm = StringUtils::GetFileNameWithoutExtension(gameJs);
172 for (const String& file : files)
173 {
174 if (StringUtils::GetFileNameWithoutExtension(file) == gameWasm)
175 continue; // Skip the main game module
176 FileSystem::MoveFile(data.DataOutputPath / StringUtils::GetFileName(file), file, true);
177 }
178 }
179
180 // Pack data files into a single file using Emscripten's file_packager tool
181 {
182 CreateProcessSettings procSettings;
183 String emscriptenSdk = TEXT("EMSDK");
184 Platform::GetEnvironmentVariable(emscriptenSdk, emscriptenSdk);
185 procSettings.FileName = emscriptenSdk / TEXT("upstream/emscripten/tools/file_packager");
186 procSettings.Arguments = String::Format(TEXT("files.data --preload \"{}@/\" --lz4 --js-output=files.js"), data.DataOutputPath);
187 procSettings.WorkingDirectory = data.OriginalOutputPath;
188#if PLATFORM_MAC || PLATFORM_WINDOWS
189 // Use python bundled with SDK (python from min-spec XCode 16.4 is 3.9.6 which is < 3.10 needed by SDK 5.0)
190 Array<String> pythons;
191 FileSystem::GetChildDirectories(pythons, emscriptenSdk / TEXT("/python"));
192 if (pythons.HasItems())
193 {
194 procSettings.Arguments = procSettings.FileName + TEXT(".py ") + procSettings.Arguments;

Callers 1

PerformMethod · 0.45

Calls 14

TrimTrailingMethod · 0.80
GetFunction · 0.50
StringClass · 0.50
FormatFunction · 0.50
EndsWithMethod · 0.45
ContainsMethod · 0.45
IsEmptyMethod · 0.45
ErrorMethod · 0.45
HasItemsMethod · 0.45
HasCharsMethod · 0.45
FindMethod · 0.45

Tested by

no test coverage detected