Przeglądaj źródła

Merge pull request #1163 from AtomicGameEngine/JME-ATOMIC-1142

Consistent AtomicNET.dll referencing regardless of build
JoshEngebretson 9 lat temu
rodzic
commit
991b6b7856

+ 11 - 0
Source/Atomic/IO/FileSystem.cpp

@@ -1314,7 +1314,18 @@ bool GetRelativePath(const String& fromPath, const String& toPath, String& outpu
     }
 
     if (startIdx == toParts.Size())
+    {
+        if (from.EndsWith("/") && to.EndsWith("/"))
+        {
+            for (unsigned i = 0; i < fromParts.Size() - startIdx; i++)
+            {
+                output += "../";
+            }
+
+            return true;
+        }
         return false;
+    }
 
     for (int i = 0; i < (int)fromParts.Size() - startIdx; i++)
     {

+ 4 - 1
Source/ToolCore/JSBind/JSBHeaderVisitor.h

@@ -644,7 +644,10 @@ public:
                 }
                 else
                 {
-                    ATOMIC_LOGINFOF("Warning: %s baseclass %s not in bindings", name.CString(), baseclassname.CString());
+                    if (!i)
+                    {
+                        ATOMIC_LOGINFOF("Warning: %s first baseclass %s not in bindings", name.CString(), baseclassname.CString());
+                    }
                 }
             }
             else

+ 4 - 2
Source/ToolCore/NETTools/NETBuildSystem.cpp

@@ -351,7 +351,7 @@ namespace ToolCore
 
             // close out quote
             compile += "\"";
-                
+
             args.Push(compile);
 
 #else
@@ -459,6 +459,8 @@ namespace ToolCore
         configurations.Push("Release");
 #endif
 
+        AtomicNETCopyAssemblies(context_, project->GetProjectPath() + "AtomicNET/Lib/");
+
         String solutionPath = project->GetProjectPath() + "AtomicNET/Solution/" + project->GetProjectSettings()->GetName() + ".sln";
 
         NETBuild* build = Build(solutionPath, platforms, configurations);
@@ -468,7 +470,7 @@ namespace ToolCore
             ProjectSettings* settings = project->GetProjectSettings();
 
             // This path is currently only hit when refreshing for desktop
-            if (settings->GetSupportsAndroid() || settings->GetSupportsIOS()) 
+            if (settings->GetSupportsAndroid() || settings->GetSupportsIOS())
             {
                 // Build the PCL, which will get copied to Resources
                 build->targets_.Push(project->GetProjectSettings()->GetName());

+ 105 - 61
Source/ToolCore/NETTools/NETProjectGen.cpp

@@ -34,6 +34,7 @@
 #include "../Project/Project.h"
 
 #include "NETProjectGen.h"
+#include "NETProjectSystem.h"
 
 namespace ToolCore
 {
@@ -164,16 +165,18 @@ namespace ToolCore
 
                 compile.SetAttribute("Include", path.CString());
 
+                String link = result[j];
+
                 // put generated files into generated folder
                 if (sourceFolder.Contains("Generated") && sourceFolder.Contains("CSharp") && sourceFolder.Contains("Packages"))
                 {
-                    compile.CreateChild("Link").SetValue("Generated\\" + result[j]);
-                }
-                else
-                {
-                    compile.CreateChild("Link").SetValue(result[j]);
+                    link = "Generated\\" + result[j];
                 }
 
+                link.Replace('/', '\\');
+
+                compile.CreateChild("Link").SetValue(link);
+
             }
 
         }
@@ -205,6 +208,7 @@ namespace ToolCore
     void NETCSProject::CreateReferencesItemGroup(XMLElement &projectRoot)
     {
         ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
+        const String atomicProjectPath = projectGen_->GetAtomicProjectPath();
 
         XMLElement xref;
         XMLElement igroup = projectRoot.CreateChild("ItemGroup");
@@ -213,13 +217,9 @@ namespace ToolCore
         {
             String ref = references_[i];
 
-            // project reference
-            if (projectGen_->GetCSProjectByName(ref))
-                continue;
-
             String platform;
 
-            if (projectGen_->GetAtomicProjectPath().Length() && ref.StartsWith("AtomicNET"))
+            if (ref.StartsWith("AtomicNET"))
             {
                 if (GetIsPCL())
                 {
@@ -244,12 +244,45 @@ namespace ToolCore
                     platform = "iOS";
                 }
 
+                // When building Atomic Projects, assemblies will be in the Lib folder
+                String config = "Lib";
+
+                // If we're not building a project, assemblies will be either Debug or Release
+                if (!atomicProjectPath.Length())
+                {
+#ifdef ATOMIC_DEBUG
+                    config = "Debug";
+#else
+                    config = "Release";
+#endif
+                }
 
                 if (platform.Length())
                 {
-                    String atomicNETAssembly = tenv->GetAtomicNETCoreAssemblyDir() + ToString("%s/%s.dll", platform.CString(), ref.CString());
-                    xref = igroup.CreateChild("Reference");
-                    xref.SetAttribute("Include", atomicNETAssembly);
+                    String relativeAssemblyPath;
+
+                    if (GetRelativePath(projectPath_, GetParentPath(projectGen_->GetSolution()->GetOutputPath()), relativeAssemblyPath))
+                    {
+                        xref = igroup.CreateChild("Reference");
+                        xref.SetAttribute("Include", ref);                        
+
+                        // Specify the assembly path, which is the same based on native build
+                        String assemblyPath = relativeAssemblyPath + ToString("%s/%s/%s.dll", config.CString(), platform.CString(), ref.CString());
+
+                        // Setup hint paths with both release/debug config, although they point to same assembly, they don't need to
+                        XMLElement hintPath = xref.CreateChild("HintPath");
+                        hintPath.SetAttribute("Condition", "'$(Configuration)' == 'Release'");
+                        hintPath.SetValue(assemblyPath);
+
+                        hintPath = xref.CreateChild("HintPath");
+                        hintPath.SetAttribute("Condition", "'$(Configuration)' == 'Debug'");
+                        hintPath.SetValue(assemblyPath);
+                    }
+                    else
+                    {
+                        ATOMIC_LOGERRORF("NETCSProject::CreateReferencesItemGroup - Unable to get relative path from %s to solution", projectPath_.CString());
+                    }
+
                 }
 
                 continue;
@@ -277,8 +310,6 @@ namespace ToolCore
 
         }
 
-        const String atomicProjectPath = projectGen_->GetAtomicProjectPath();
-
         if (atomicProjectPath.Length())
         {
             String resourceDir = AddTrailingSlash(atomicProjectPath) + "Resources/";
@@ -308,32 +339,6 @@ namespace ToolCore
 
     }
 
-    void NETCSProject::CreateProjectReferencesItemGroup(XMLElement &projectRoot)
-    {
-
-        XMLElement igroup = projectRoot.CreateChild("ItemGroup");
-
-        for (unsigned i = 0; i < references_.Size(); i++)
-        {
-            const String& ref = references_[i];
-            NETCSProject* project = projectGen_->GetCSProjectByName(ref);
-
-            if (!project)
-                continue;
-
-
-            XMLElement projectRef = igroup.CreateChild("ProjectReference");
-            projectRef.SetAttribute("Include", ToString("..\\%s\\%s.csproj", ref.CString(), ref.CString()));
-
-            XMLElement xproject = projectRef.CreateChild("Project");
-            xproject.SetValue(ToString("{%s}", project->GetProjectGUID().ToLower().CString()));
-
-            XMLElement xname = projectRef.CreateChild("Name");
-            xname.SetValue(project->GetName());
-        }
-    }
-
-
     void NETCSProject::CreatePackagesItemGroup(XMLElement &projectRoot)
     {
         if (!packages_.Size())
@@ -404,6 +409,20 @@ namespace ToolCore
         String outputPath = assemblyOutputPath_;
         outputPath.Replace("$ATOMIC_CONFIG$", "Release");
 
+        if (IsAbsolutePath(outputPath))
+        {
+
+            String atomicProjectPath = projectGen_->GetAtomicProjectPath();
+
+            if (atomicProjectPath.Length())
+            {
+                if (!GetRelativeProjectPath(outputPath, projectPath_, outputPath))
+                {
+                    ATOMIC_LOGERRORF("NETCSProject::CreateReleasePropertyGroup - unable to get relative output path");
+                }
+            }
+        }
+
         pgroup.CreateChild("OutputPath").SetValue(outputPath);
 
         Vector<String> constants;
@@ -419,8 +438,9 @@ namespace ToolCore
         pgroup.CreateChild("ConsolePause").SetValue("false");
         pgroup.CreateChild("AllowUnsafeBlocks").SetValue("true");
 
-        // Don't warn on missing XML documentation
-        pgroup.CreateChild("NoWarn").SetValue("1591");
+        // 1591 - Don't warn on missing documentation 
+        // 1570 - malformed xml, remove once (https://github.com/AtomicGameEngine/AtomicGameEngine/issues/1161) resolved
+        pgroup.CreateChild("NoWarn").SetValue("1591;1570");
 
         if (genAssemblyDocFile_)
         {
@@ -496,6 +516,20 @@ namespace ToolCore
         String outputPath = assemblyOutputPath_;
         outputPath.Replace("$ATOMIC_CONFIG$", "Debug");
 
+        if (IsAbsolutePath(outputPath))
+        {
+            String atomicProjectPath = projectGen_->GetAtomicProjectPath();
+
+            if (atomicProjectPath.Length())
+            {
+                if (!GetRelativeProjectPath(outputPath, projectPath_, outputPath))
+                {
+                    ATOMIC_LOGERRORF("NETCSProject::CreateDebugPropertyGroup - unable to get relative output path");
+                }
+            }
+
+        }
+
         pgroup.CreateChild("OutputPath").SetValue(outputPath);
 
         Vector<String> constants;
@@ -512,8 +546,9 @@ namespace ToolCore
         pgroup.CreateChild("ConsolePause").SetValue("false");
         pgroup.CreateChild("AllowUnsafeBlocks").SetValue("true");
 
-        // Don't warn on missing XML documentation
-        pgroup.CreateChild("NoWarn").SetValue("1591");
+        // 1591 - Don't warn on missing documentation 
+        // 1570 - malformed xml, remove once (https://github.com/AtomicGameEngine/AtomicGameEngine/issues/1161) resolved
+        pgroup.CreateChild("NoWarn").SetValue("1591;1570");
 
         pgroup.CreateChild("DebugSymbols").SetValue("true");
 
@@ -609,24 +644,31 @@ namespace ToolCore
             String platform = "Linux";
             String filename = "libAtomicNETNative.so";
 #endif
+            String relativeNativePath;
 
-#ifdef ATOMIC_DEV_BUILD
+            String configPath = config;
 
-            String nativePath = AddTrailingSlash(tenv->GetAtomicNETRootDir()) + config + "/Native/" + platform + "/" + filename;
-#else
-            String nativePath = AddTrailingSlash(tenv->GetAtomicNETRootDir()) + config + "/Native/" + platform + "/" + filename;
-#endif
-            atomicNETNativeDLL.SetAttribute("Include", nativePath);
-            atomicNETNativeDLL.CreateChild("Link").SetValue(filename);
-            atomicNETNativeDLL.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
+            if (projectGen_->GetAtomicProjectPath().Length())
+                configPath = "Lib";
+
+            if (GetRelativePath(projectPath_, GetParentPath(projectGen_->GetSolution()->GetOutputPath()), relativeNativePath))
+            {
+                String nativePath = relativeNativePath + configPath + "/Native/" + platform + "/" + filename;
+
+                atomicNETNativeDLL.SetAttribute("Include", nativePath);
+                atomicNETNativeDLL.CreateChild("Link").SetValue(filename);
+                atomicNETNativeDLL.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
 
 #ifdef ATOMIC_PLATFORM_WINDOWS
-            XMLElement d3dCompilerDLL = itemGroup.CreateChild("None");
-            String d3dCompilerPath = AddTrailingSlash(tenv->GetAtomicNETRootDir()) + config + "/Native/" + platform + "/D3DCompiler_47.dll";
-            d3dCompilerDLL.SetAttribute("Include", d3dCompilerPath);
-            d3dCompilerDLL.CreateChild("Link").SetValue("D3DCompiler_47.dll");
-            d3dCompilerDLL.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
+                XMLElement d3dCompilerDLL = itemGroup.CreateChild("None");
+                String d3dCompilerPath = relativeNativePath + configPath + "/Native/" + platform + "/D3DCompiler_47.dll";
+                d3dCompilerDLL.SetAttribute("Include", d3dCompilerPath);
+                d3dCompilerDLL.CreateChild("Link").SetValue("D3DCompiler_47.dll");
+                d3dCompilerDLL.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
 #endif
+
+            }
+
         }
         else
         {
@@ -1074,7 +1116,6 @@ namespace ToolCore
         CreateDebugPropertyGroup(project);
         CreateReleasePropertyGroup(project);
         CreateReferencesItemGroup(project);
-        CreateProjectReferencesItemGroup(project);
         CreateCompileItemGroup(project);
         CreatePackagesItemGroup(project);
 
@@ -1743,9 +1784,9 @@ namespace ToolCore
 
         return LoadProject(jvalue);
     }
-
+\
     bool NETProjectGen::LoadAtomicProject(const String& atomicProjectPath)
-    {
+    {        
         ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
         ToolSystem* tsystem = GetSubsystem<ToolSystem>();
 
@@ -1790,8 +1831,11 @@ namespace ToolCore
 
         if (!JSONFile::ParseJSON(netJSONString, netJSON))
             return false;
+
 #endif
 
+        AtomicNETCopyAssemblies(context_, atomicProjectPath_ + "AtomicNET/Lib/");
+
 #ifdef ATOMIC_DEV_BUILD
 
         String projectPath = tenv->GetRootSourceDir() + "Script/AtomicNET/AtomicProject.json";

+ 0 - 1
Source/ToolCore/NETTools/NETProjectGen.h

@@ -95,7 +95,6 @@ namespace ToolCore
 
         void CreateCompileItemGroup(XMLElement &projectRoot);
         void CreateReferencesItemGroup(XMLElement &projectRoot);
-        void CreateProjectReferencesItemGroup(XMLElement & projectRoot);
         void CreatePackagesItemGroup(XMLElement &projectRoot);
         void CreateMainPropertyGroup(XMLElement &projectRoot);
         void CreateDebugPropertyGroup(XMLElement &projectRoot);

+ 68 - 8
Source/ToolCore/NETTools/NETProjectSystem.cpp

@@ -30,6 +30,7 @@
 #include <Atomic/Resource/ResourceEvents.h>
 
 #include "../ToolSystem.h"
+#include "../ToolEnvironment.h"
 #include "../Assets/AssetEvents.h"
 #include "../Assets/AssetDatabase.h"
 #include "../Project/Project.h"
@@ -321,25 +322,25 @@ namespace ToolCore
     {
         using namespace ProjectLoaded;
 
-        String projectPath = eventData[P_PROJECTPATH].GetString();
+        projectPath_ = eventData[P_PROJECTPATH].GetString();
         Project* project = static_cast<Project*>(eventData[P_PROJECT].GetPtr());
 
-        if (GetExtension(projectPath) == ".atomic")
-            projectPath = GetParentPath(projectPath);
+        if (GetExtension(projectPath_) == ".atomic")
+            projectPath_ = GetParentPath(projectPath_);
 
         String projectName = project->GetProjectSettings()->GetName();
 
-        solutionPath_ = AddTrailingSlash(projectPath) + "AtomicNET/Solution/" + projectName + ".sln";
-        projectAssemblyPath_ = AddTrailingSlash(projectPath) + "Resources/" + projectName + ".dll";
+        solutionPath_ = AddTrailingSlash(projectPath_) + "AtomicNET/Solution/" + projectName + ".sln";
+        projectAssemblyPath_ = AddTrailingSlash(projectPath_) + "Resources/" + projectName + ".dll";
 
         FileSystem* fileSystem = GetSubsystem<FileSystem>();
 
         // TODO: We need a better way of marking C# projects
         StringVector results;
-        fileSystem->ScanDir(results, AddTrailingSlash(projectPath) + "Resources", "*.cs", SCAN_FILES, true);
+        fileSystem->ScanDir(results, AddTrailingSlash(projectPath_) + "Resources", "*.cs", SCAN_FILES, true);
         if (!results.Size())
         {
-            fileSystem->ScanDir(results, AddTrailingSlash(projectPath) + "Resources", "*.dll", SCAN_FILES, true);
+            fileSystem->ScanDir(results, AddTrailingSlash(projectPath_) + "Resources", "*.dll", SCAN_FILES, true);
             if (!results.Size())
             {
                 solutionPath_.Clear();
@@ -413,7 +414,7 @@ namespace ToolCore
 
     void NETProjectSystem::HandleAssetMoved(StringHash eventType, VariantMap& eventData)
     {
-
+        
     }
 
     void NETProjectSystem::Initialize()
@@ -475,5 +476,64 @@ namespace ToolCore
 
     }
 
+    bool AtomicNETCopyAssemblies(Context* context, const String& dstFolder)
+    {
+        FileSystem* fileSystem = context->GetSubsystem<FileSystem>();
+        ToolEnvironment* tenv = context->GetSubsystem<ToolEnvironment>();
+
+        StringVector results;
+        fileSystem->ScanDir(results, tenv->GetAtomicNETCoreAssemblyDir(), "*", SCAN_FILES, true);
+
+        for (unsigned i = 0; i < results.Size(); i++)
+        {
+            String srcFile = tenv->GetAtomicNETCoreAssemblyDir() + results[i];
+            String dstFile = dstFolder + results[i];
+
+            unsigned srcModifiedTime = 0;
+
+            if (fileSystem->FileExists(srcFile))
+            {
+                srcModifiedTime = fileSystem->GetLastModifiedTime(srcFile);
+            }
+
+            // skip if same modified time
+            if (srcModifiedTime && fileSystem->FileExists(dstFile))
+            {
+
+                if (srcModifiedTime == fileSystem->GetLastModifiedTime(dstFile))
+                {
+                    ATOMIC_LOGDEBUGF("NETProjectSystem::CopyAtomicAssemblies - Skipping AtomicNET %s as %s exists and has same modified time", srcFile.CString(), dstFile.CString());
+                    continue;
+                }
+
+                ATOMIC_LOGDEBUGF("NETProjectSystem::CopyAtomicAssemblies - %u %u", srcModifiedTime, fileSystem->GetLastModifiedTime(dstFile));
+
+            }
+
+            String dstPath = GetPath(dstFile);
+
+            if (!fileSystem->CreateDirsRecursive(dstPath))
+            {
+                ATOMIC_LOGERRORF("NETProjectGen::CopyAtomicAssemblies - Unable to create folder: %s", dstPath.CString());
+                continue;
+            }
+
+            if (!fileSystem->Copy(srcFile, dstFile))
+            {
+                ATOMIC_LOGERRORF("NETProjectGen::CopyAtomicAssemblies - Unable to copy file from: %s to %s", srcFile.CString(), dstPath.CString());
+                continue;
+            }
+
+            // Update time so we don't needlessly copy
+            if (srcModifiedTime)
+                fileSystem->SetLastModifiedTime(dstFile, srcModifiedTime);
+
+            ATOMIC_LOGDEBUGF(" NETProjectSystem::CopyAtomicAssemblies - Copied AtomicNET %s to %s", srcFile.CString(), dstPath.CString());
+        }
+
+        return true;
+
+    }
+
 
 }

+ 4 - 0
Source/ToolCore/NETTools/NETProjectSystem.h

@@ -92,6 +92,7 @@ namespace ToolCore
 
         String idePath_;
 
+        String projectPath_;
         String solutionPath_;
         String projectAssemblyPath_;
 
@@ -105,4 +106,7 @@ namespace ToolCore
 
     };
 
+    /// Copies the core Atomic NET assemblies to a specified folder
+    bool AtomicNETCopyAssemblies(Context* context, const String& dstFolder);
+
 }