Pārlūkot izejas kodu

Working on removing absolute paths from Atomic C# project files, also removing project references in favor of binary references with dependencies

Josh Engebretson 9 gadi atpakaļ
vecāks
revīzija
cf69c914aa

+ 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++)
     {

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

@@ -459,6 +459,8 @@ namespace ToolCore
         configurations.Push("Release");
 #endif
 
+        AtomicNETCopyAssemblies(context_, project->GetProjectPath() + "Lib/");
+
         String solutionPath = project->GetProjectPath() + "AtomicNET/Solution/" + project->GetProjectSettings()->GetName() + ".sln";
 
         NETBuild* build = Build(solutionPath, platforms, configurations);

+ 86 - 52
Source/ToolCore/NETTools/NETProjectGen.cpp

@@ -34,6 +34,7 @@
 #include "../Project/Project.h"
 
 #include "NETProjectGen.h"
+#include "NETProjectSystem.h"
 
 namespace ToolCore
 {
@@ -205,6 +206,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 +215,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 +242,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 +308,6 @@ namespace ToolCore
 
         }
 
-        const String atomicProjectPath = projectGen_->GetAtomicProjectPath();
-
         if (atomicProjectPath.Length())
         {
             String resourceDir = AddTrailingSlash(atomicProjectPath) + "Resources/";
@@ -308,32 +337,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 +407,16 @@ namespace ToolCore
         String outputPath = assemblyOutputPath_;
         outputPath.Replace("$ATOMIC_CONFIG$", "Release");
 
+        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;
@@ -496,6 +509,16 @@ namespace ToolCore
         String outputPath = assemblyOutputPath_;
         outputPath.Replace("$ATOMIC_CONFIG$", "Debug");
 
+        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;
@@ -609,24 +632,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 +1104,6 @@ namespace ToolCore
         CreateDebugPropertyGroup(project);
         CreateReleasePropertyGroup(project);
         CreateReferencesItemGroup(project);
-        CreateProjectReferencesItemGroup(project);
         CreateCompileItemGroup(project);
         CreatePackagesItemGroup(project);
 
@@ -1743,9 +1772,9 @@ namespace ToolCore
 
         return LoadProject(jvalue);
     }
-
+\
     bool NETProjectGen::LoadAtomicProject(const String& atomicProjectPath)
-    {
+    {        
         ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
         ToolSystem* tsystem = GetSubsystem<ToolSystem>();
 
@@ -1790,6 +1819,11 @@ namespace ToolCore
 
         if (!JSONFile::ParseJSON(netJSONString, netJSON))
             return false;
+
+#else
+
+        AtomicNETCopyAssemblies(context_, atomicProjectPath_ + "AtomicNET/Lib/");
+
 #endif
 
 #ifdef ATOMIC_DEV_BUILD

+ 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);
+
 }