refactor(srp): unify engine managed assembly discovery
This commit is contained in:
@@ -3,9 +3,12 @@
|
||||
#include "Platform/Win32Utf8.h"
|
||||
#include "Scripting/EditorScriptAssemblyBuilderUtils.h"
|
||||
|
||||
#include <XCEngine/Scripting/Mono/MonoScriptRuntime.h>
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -203,6 +206,42 @@ EditorScriptAssemblyBuildResult BuildFailure(const std::string& message) {
|
||||
return EditorScriptAssemblyBuildResult{false, message};
|
||||
}
|
||||
|
||||
bool WriteManagedEngineAssemblyManifest(
|
||||
const std::filesystem::path& outputPath,
|
||||
const std::vector<std::string>& assemblyNames,
|
||||
std::string& outError) {
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(outputPath.parent_path(), ec);
|
||||
if (ec) {
|
||||
outError =
|
||||
"Failed to create the engine assembly manifest directory: " +
|
||||
ScriptBuilderPathToUtf8(outputPath.parent_path());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::ofstream output(outputPath, std::ios::out | std::ios::trunc);
|
||||
if (!output.is_open()) {
|
||||
outError =
|
||||
"Failed to create the engine assembly manifest: " +
|
||||
ScriptBuilderPathToUtf8(outputPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const std::string& assemblyName : assemblyNames) {
|
||||
output << assemblyName << "\n";
|
||||
}
|
||||
|
||||
output.close();
|
||||
if (!output.good()) {
|
||||
outError =
|
||||
"Failed to write the engine assembly manifest: " +
|
||||
ScriptBuilderPathToUtf8(outputPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RunCSharpCompiler(
|
||||
const std::filesystem::path& dotnetExecutable,
|
||||
const std::filesystem::path& cscDllPath,
|
||||
@@ -252,6 +291,9 @@ EditorScriptAssemblyBuildResult EditorScriptAssemblyBuilder::RebuildProjectAssem
|
||||
const fs::path scriptCoreOutputPath = outputDirectory / "XCEngine.ScriptCore.dll";
|
||||
const fs::path renderPipelinesUniversalOutputPath =
|
||||
outputDirectory / "XCEngine.RenderPipelines.Universal.dll";
|
||||
const fs::path engineAssemblyManifestPath =
|
||||
outputDirectory /
|
||||
::XCEngine::Scripting::MonoScriptRuntime::EngineAssemblyManifestFileName;
|
||||
const fs::path gameScriptsOutputPath = outputDirectory / "GameScripts.dll";
|
||||
const fs::path corlibOutputPath = outputDirectory / "mscorlib.dll";
|
||||
const fs::path monoCorlibSourcePath = monoRoot / "binary" / "mscorlib.dll";
|
||||
@@ -346,6 +388,8 @@ EditorScriptAssemblyBuildResult EditorScriptAssemblyBuilder::RebuildProjectAssem
|
||||
}
|
||||
|
||||
std::string compileError;
|
||||
const std::vector<std::string> engineAssemblyNames = {
|
||||
"XCEngine.RenderPipelines.Universal"};
|
||||
if (!RunCSharpCompiler(
|
||||
dotnetExecutable,
|
||||
cscDllPath,
|
||||
@@ -402,6 +446,13 @@ EditorScriptAssemblyBuildResult EditorScriptAssemblyBuilder::RebuildProjectAssem
|
||||
return BuildFailure("Failed to build GameScripts.dll: " + compileError);
|
||||
}
|
||||
|
||||
if (!WriteManagedEngineAssemblyManifest(
|
||||
engineAssemblyManifestPath,
|
||||
engineAssemblyNames,
|
||||
compileError)) {
|
||||
return BuildFailure(compileError);
|
||||
}
|
||||
|
||||
return EditorScriptAssemblyBuildResult{
|
||||
true,
|
||||
"Rebuilt script assemblies in " + ScriptBuilderPathToUtf8(outputDirectory)
|
||||
|
||||
Reference in New Issue
Block a user