Browse Source

Cleanup some CoreCLR folder init

JoshEngebretson 10 years ago
parent
commit
bec6be24ce

+ 10 - 1
Source/AtomicEditor/Application/AEEditorCommon.cpp

@@ -17,6 +17,7 @@
 #include <AtomicJS/Javascript/Javascript.h>
 #include <AtomicJS/Javascript/Javascript.h>
 
 
 #ifdef ATOMIC_DOTNET
 #ifdef ATOMIC_DOTNET
+#include <AtomicNET/NETCore/NETHost.h>
 #include <AtomicNET/NETCore/NETCore.h>
 #include <AtomicNET/NETCore/NETCore.h>
 #endif
 #endif
 
 
@@ -79,7 +80,11 @@ void AEEditorCommon::Setup()
     String  assemblyLoadPaths = GetNativePath(ToString("%s/Artifacts/AtomicNET/", ATOMIC_ROOT_SOURCE_DIR));
     String  assemblyLoadPaths = GetNativePath(ToString("%s/Artifacts/AtomicNET/", ATOMIC_ROOT_SOURCE_DIR));
 
 
 #ifdef ATOMIC_PLATFORM_WINDOWS
 #ifdef ATOMIC_PLATFORM_WINDOWS
+
     String  coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/Windows/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR));
     String  coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/Windows/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR));
+    String coreCLRTPAPaths = ToString("%s/Submodules/CoreCLR/Windows/Debug/AnyCPU/TPA/", ATOMIC_ROOT_SOURCE_DIR);
+    coreCLRTPAPaths += ToString(";%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR);
+
 #else
 #else
     String  coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/OSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR);
     String  coreCLRAbsPath = GetNativePath(ToString("%s/Submodules/CoreCLR/OSX/Debug/x64/", ATOMIC_ROOT_SOURCE_DIR);
 #endif
 #endif
@@ -88,7 +93,11 @@ void AEEditorCommon::Setup()
     assert(0);
     assert(0);
 #endif
 #endif
 
 
-    if (!netCore->Initialize(coreCLRAbsPath, assemblyLoadPaths,  netCoreErrorMsg))
+    NETHost::SetCoreCLRFilesAbsPath(coreCLRAbsPath);
+    NETHost::SetCoreCLRTPAPaths(coreCLRTPAPaths);
+    NETHost::SetCoreCLRAssemblyLoadPaths(assemblyLoadPaths);
+
+    if (!netCore->Initialize(netCoreErrorMsg))
     {
     {
         LOGERRORF("NetCore: Unable to initialize! %s", netCoreErrorMsg.CString());
         LOGERRORF("NetCore: Unable to initialize! %s", netCoreErrorMsg.CString());
         context_->RemoveSubsystem(NETCore::GetTypeStatic());
         context_->RemoveSubsystem(NETCore::GetTypeStatic());

+ 6 - 4
Source/AtomicNET/NETCore/NETCore.cpp

@@ -102,6 +102,7 @@ NETCore::~NETCore()
 
 
 void NETCore::GenerateTPAList(String& tpaList)
 void NETCore::GenerateTPAList(String& tpaList)
 {
 {
+#ifdef disabled
     tpaList = String::EMPTY;
     tpaList = String::EMPTY;
 
 
     FileSystem* fs = GetSubsystem<FileSystem>();
     FileSystem* fs = GetSubsystem<FileSystem>();
@@ -123,6 +124,7 @@ void NETCore::GenerateTPAList(String& tpaList)
     tpaList.Join(trustedAssemblies, ":");
     tpaList.Join(trustedAssemblies, ":");
 
 
     // LOGINFOF("NetCore:: TPALIST - %s", tpaList.CString());
     // LOGINFOF("NetCore:: TPALIST - %s", tpaList.CString());
+#endif
 
 
 }
 }
 
 
@@ -152,6 +154,7 @@ void NETCore::Shutdown()
 
 
 bool NETCore::InitCoreCLRDLL(String& errorMsg)
 bool NETCore::InitCoreCLRDLL(String& errorMsg)
 {
 {
+#ifdef disabled
     String coreClrDllPath = AddTrailingSlash(coreCLRFilesAbsPath_) + sCoreClrDll;
     String coreClrDllPath = AddTrailingSlash(coreCLRFilesAbsPath_) + sCoreClrDll;
 
 
     coreCLRDLLHandle_ = SDL_LoadObject(coreClrDllPath.CString());
     coreCLRDLLHandle_ = SDL_LoadObject(coreClrDllPath.CString());
@@ -195,6 +198,7 @@ bool NETCore::InitCoreCLRDLL(String& errorMsg)
         errorMsg = ToString("NETCore: Unable to get coreclr_execute_assembly entry point in %s", coreClrDllPath.CString());
         errorMsg = ToString("NETCore: Unable to get coreclr_execute_assembly entry point in %s", coreClrDllPath.CString());
         return false;
         return false;
     }
     }
+#endif
 
 
     return true;
     return true;
 }
 }
@@ -290,16 +294,14 @@ bool NETCore::CreateDelegate(const String& assemblyName, const String& qualified
 
 
 }
 }
 
 
-bool NETCore::Initialize(const String &coreCLRFilesAbsPath, const String &assemblyLoadPaths, String& errorMsg)
+bool NETCore::Initialize(String& errorMsg)
 {
 {
-    coreCLRFilesAbsPath_ = AddTrailingSlash(coreCLRFilesAbsPath);
-
 #ifdef ATOMIC_PLATFORM_WINDOWS
 #ifdef ATOMIC_PLATFORM_WINDOWS
     netHost_ = new NETHostWindows(context_);
     netHost_ = new NETHostWindows(context_);
 #else
 #else
 #endif
 #endif
 
 
-    netHost_->Initialize(coreCLRFilesAbsPath_, assemblyLoadPaths);
+    netHost_->Initialize();
 
 
     SharedPtr<NETManaged> managed(new NETManaged(context_));
     SharedPtr<NETManaged> managed(new NETManaged(context_));
     context_->RegisterSubsystem(managed);
     context_->RegisterSubsystem(managed);

+ 2 - 2
Source/AtomicNET/NETCore/NETCore.h

@@ -41,10 +41,11 @@ public:
     /// Destruct.
     /// Destruct.
     virtual ~NETCore();
     virtual ~NETCore();
 
 
-    bool Initialize(const String& coreCLRFilesAbsPath, const String& assemblyLoadPaths, String &errorMsg);
+    bool Initialize(String &errorMsg);
     void Shutdown();
     void Shutdown();
 
 
     void AddAssemblyLoadPath(const String& assemblyPath);
     void AddAssemblyLoadPath(const String& assemblyPath);
+
     bool CreateDelegate(const String& assemblyName, const String& qualifiedClassName, const String& methodName, void** funcOut);
     bool CreateDelegate(const String& assemblyName, const String& qualifiedClassName, const String& methodName, void** funcOut);
     void WaitForDebuggerConnect();
     void WaitForDebuggerConnect();
 
 
@@ -59,7 +60,6 @@ private:
     bool InitCoreCLRDLL(String &errorMsg);
     bool InitCoreCLRDLL(String &errorMsg);
     void GenerateTPAList(String& tpaList);
     void GenerateTPAList(String& tpaList);
 
 
-    String coreCLRFilesAbsPath_;
     void* coreCLRDLLHandle_;
     void* coreCLRDLLHandle_;
     void* hostHandle_;
     void* hostHandle_;
     unsigned domainId_;
     unsigned domainId_;

+ 4 - 0
Source/AtomicNET/NETCore/NETHost.cpp

@@ -4,6 +4,10 @@
 namespace Atomic
 namespace Atomic
 {
 {
 
 
+String NETHost::coreCLRFilesAbsPath_;
+String NETHost::coreCLRAssemblyLoadPaths_;
+String NETHost::coreCLRTPAPaths_;
+
 NETHost::NETHost(Context* context) :
 NETHost::NETHost(Context* context) :
     Object(context)
     Object(context)
 {
 {

+ 15 - 1
Source/AtomicNET/NETCore/NETHost.h

@@ -2,6 +2,7 @@
 #pragma once
 #pragma once
 
 
 #include <Atomic/Core/Object.h>
 #include <Atomic/Core/Object.h>
+#include <Atomic/IO/FileSystem.h>
 
 
 namespace Atomic
 namespace Atomic
 {
 {
@@ -17,10 +18,23 @@ public:
     /// Destruct.
     /// Destruct.
     virtual ~NETHost();
     virtual ~NETHost();
 
 
-    virtual bool Initialize(const String& coreCLRFilesAbsPath, const String& assemblyLoadPaths) = 0;
+    // It is important all these paths use native folder delimiter when passed to CoreCLR
+    static void SetCoreCLRFilesAbsPath(const String& path) { coreCLRFilesAbsPath_ = GetNativePath(AddTrailingSlash(path)); }
+    // ; (semicolon)  delimited list of paths to loads assemblies from
+    static void SetCoreCLRAssemblyLoadPaths(const String& path) { coreCLRAssemblyLoadPaths_ = path; }
+    // ; (semicolon) delimited list of paths to trusted platform assemblies
+    static void SetCoreCLRTPAPaths(const String& path) { coreCLRTPAPaths_ = path; }
+
+    virtual bool Initialize() = 0;
     virtual bool CreateDelegate(const String& assemblyName, const String& qualifiedClassName, const String& methodName, void** funcOut) = 0;
     virtual bool CreateDelegate(const String& assemblyName, const String& qualifiedClassName, const String& methodName, void** funcOut) = 0;
     virtual void WaitForDebuggerConnect() = 0;
     virtual void WaitForDebuggerConnect() = 0;
 
 
+protected:
+
+    static String coreCLRFilesAbsPath_;
+    static String coreCLRAssemblyLoadPaths_;
+    static String coreCLRTPAPaths_;
+
 };
 };
 
 
 }
 }

+ 17 - 13
Source/AtomicNET/NETCore/Platforms/Windows/NETHostWindows.cpp

@@ -42,11 +42,19 @@ bool NETHostWindows::CreateDelegate(const String& assemblyName, const String& qu
     return true;
     return true;
 }
 }
 
 
-bool NETHostWindows::Initialize(const String& coreCLRFilesAbsPath, const String &assemblyLoadPaths)
+bool NETHostWindows::Initialize()
 {
 {
     // It is very important that this is the native path "\\" vs "/" as find files will return "/" or "\" depending
     // It is very important that this is the native path "\\" vs "/" as find files will return "/" or "\" depending
     // on what you give it, which will result in the domain failing to initialize as coreclr can't handle "/" on init
     // on what you give it, which will result in the domain failing to initialize as coreclr can't handle "/" on init
-    coreCLRFilesAbsPath_ = GetNativePath(AddTrailingSlash(coreCLRFilesAbsPath));
+
+    if (!coreCLRFilesAbsPath_.Length())
+        return false;
+
+    if (!coreCLRTPAPaths_.Length())
+        return false;
+
+    if (!coreCLRAssemblyLoadPaths_.Length())
+        return false;
 
 
     if (!LoadCLRDLL())
     if (!LoadCLRDLL())
         return false;
         return false;
@@ -79,7 +87,7 @@ bool NETHostWindows::Initialize(const String& coreCLRFilesAbsPath, const String
 
 
     if (result)
     if (result)
     {
     {
-        startup(assemblyLoadPaths.CString());
+        startup(coreCLRAssemblyLoadPaths_.CString());
     }
     }
 
 
     // MOVE THIS!
     // MOVE THIS!
@@ -137,7 +145,7 @@ bool NETHostWindows::LoadCLRDLL()
 
 
 bool NETHostWindows::CreateAppDomain()
 bool NETHostWindows::CreateAppDomain()
 {
 {
-    wchar_t appPath[MAX_LONGPATH] = W("C:\\Dev\\atomic\\AtomicGameEngine\\Artifacts\\AtomicNET\\");
+    wchar_t appPath[MAX_LONGPATH] = W("");
     wchar_t appNiPath[MAX_LONGPATH * 2] = W("");
     wchar_t appNiPath[MAX_LONGPATH * 2] = W("");
 
 
     //wcscpy_s(appPath, WString(coreCLRFilesAbsPath_).CString());
     //wcscpy_s(appPath, WString(coreCLRFilesAbsPath_).CString());
@@ -414,15 +422,11 @@ bool NETHostWindows::GenerateTPAList()
 
 
     AddFilesFromDirectoryToTPAList(WString(coreCLRFilesAbsPath_).CString(), rgTPAExtensions, _countof(rgTPAExtensions));
     AddFilesFromDirectoryToTPAList(WString(coreCLRFilesAbsPath_).CString(), rgTPAExtensions, _countof(rgTPAExtensions));
 
 
-#ifdef ATOMIC_DEV_BUILD
-    WString  tpaAbsPath(GetNativePath(ToString("%s/Submodules/CoreCLR/Windows/Debug/AnyCPU/TPA/", ATOMIC_ROOT_SOURCE_DIR)));
-    WString  atomicTPAAbsPath(GetNativePath(ToString("%s/Artifacts/AtomicNET/TPA/", ATOMIC_ROOT_SOURCE_DIR)));
-#else
-    assert(0);
-#endif
-
-    AddFilesFromDirectoryToTPAList(tpaAbsPath.CString(), rgTPAExtensions, _countof(rgTPAExtensions));
-    AddFilesFromDirectoryToTPAList(atomicTPAAbsPath.CString(), rgTPAExtensions, _countof(rgTPAExtensions));
+    Vector<String> paths = coreCLRTPAPaths_.Split(';');
+    for (unsigned i = 0; i < paths.Size(); i++)
+    {
+        AddFilesFromDirectoryToTPAList(WString(GetNativePath(paths[i])).CString(), rgTPAExtensions, _countof(rgTPAExtensions));
+    }
 
 
     return true;
     return true;
 
 

+ 1 - 4
Source/AtomicNET/NETCore/Platforms/Windows/NETHostWindows.h

@@ -63,7 +63,7 @@ public:
     /// Destruct.
     /// Destruct.
     virtual ~NETHostWindows();
     virtual ~NETHostWindows();
 
 
-    bool Initialize(const String& coreCLRFilesAbsPath, const String& assemblyLoadPaths);
+    bool Initialize();
 
 
     bool CreateDelegate(const String& assemblyName, const String& qualifiedClassName, const String& methodName, void** funcOut);
     bool CreateDelegate(const String& assemblyName, const String& qualifiedClassName, const String& methodName, void** funcOut);
 
 
@@ -80,9 +80,6 @@ private:
     bool GenerateTPAList();
     bool GenerateTPAList();
     bool CreateAppDomain();
     bool CreateAppDomain();
 
 
-    // this path MUST use "\" and not "/" as CoreCLR requires "\" usage in init
-    String coreCLRFilesAbsPath_;
-
     ICLRRuntimeHost2* clrRuntimeHost_;
     ICLRRuntimeHost2* clrRuntimeHost_;
     HMODULE clrModule_;
     HMODULE clrModule_;
     DWORD appDomainID_;
     DWORD appDomainID_;