Bläddra i källkod

work on configurable asset include system for the biuld process.

Eugene 9 år sedan
förälder
incheckning
cef12b7ca4

+ 2 - 2
Source/ToolCore/Build/AssetBuildConfig.h

@@ -28,7 +28,6 @@
 
 namespace Atomic
 {
-
     class Context;
 
     class AssetBuildConfig :
@@ -43,6 +42,8 @@ namespace Atomic
         /// Apply the configuration to a setting variant map, values that exist will not be overriden
         static void ApplyConfig(VariantMap& settings, bool overwrite = false) { return assetBuildConfig_.Configuration::ApplyConfig(settings, overwrite); }
 
+        static const bool IsLoaded() { return assetBuildConfig_.Configuration::IsLoaded(); }
+
     private:
 
         virtual bool LoadDesktopConfig(JSONValue root);
@@ -50,5 +51,4 @@ namespace Atomic
 
         static AssetBuildConfig assetBuildConfig_;
     };
-
 }

+ 1 - 1
Source/ToolCore/Build/BuildAndroid.cpp

@@ -297,7 +297,7 @@ void BuildAndroid::Initialize()
     AddResourceDir(project->GetProjectPath() + "Cache/");
     AddResourceDir(projectResources);
 
-    BuildResourceEntries();
+    BuildDefaultResourceEntries();
 }
 
 void BuildAndroid::Build(const String& buildPath)

+ 146 - 74
Source/ToolCore/Build/BuildBase.cpp

@@ -22,10 +22,14 @@
 
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/FileSystem.h>
+#include <Atomic/Resource/JSONFile.h> // EGS:
+
 
 #include "../Subprocess/SubprocessSystem.h"
 #include "../Project/Project.h"
 #include "../ToolEnvironment.h"
+#include "../Assets/Asset.h" // EGS:
+
 
 #include "BuildSystem.h"
 #include "BuildEvents.h"
@@ -282,133 +286,195 @@ String BuildBase::GetSettingsDirectory()
 
 void BuildBase::ScanResourceDirectory(const String& resourceDir)
 {
-    Vector<String> fileNames;
-    FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    fileSystem->ScanDir(fileNames, resourceDir, "*.*", SCAN_FILES, true);
+    {
 
-    for (unsigned i = 0; i < fileNames.Size(); i++)
+        //LOGINFOF("Adding resource: %s : %s", newEntry->absolutePath_.CString(), newEntry->packagePath_.CString());
+    }
+}
+
+void BuildBase::BuildDefaultResourceEntries()
+{
+    for (unsigned i = 0; i < resourceDirs_.Size(); i++)
     {
-        const String& filename = fileNames[i];
+        String resourceDir = resourceDirs_[i];
+        Vector<String> fileNames;
+        FileSystem* fileSystem = GetSubsystem<FileSystem>();
+        fileSystem->ScanDir(fileNames, resourceDir, "*.*", SCAN_FILES, true);
 
-        for (unsigned j = 0; j < resourceEntries_.Size(); j++)
+        for (unsigned i = 0; i < fileNames.Size(); i++)
         {
-            const BuildResourceEntry* entry = resourceEntries_[j];
-
-            if (entry->packagePath_ == filename)
-            {
-                BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
+            const String& filename = fileNames[i];
+            
+            if (!CheckIncludeResourceFile(resourceDir, filename))
                 continue;
-            }
+
+            AddToResourcePackager(filename);
         }
+    }
+}
 
-        if (!CheckIncludeResourceFile(resourceDir, filename))
-            continue;
+void BuildBase::BuildProjectResourceEntries()
+{
+    if (AssetBuildConfig::IsLoaded() && !assetBuildTag_.Empty())
+    {
+        // add log comment
+        BuildFilteredProjectResourceEntries();
+    }
+    else
+    {
+        // add log comment
+        BuildAllProjectResourceEntries();
+    }
+}
 
-        BuildResourceEntry* newEntry = new BuildResourceEntry;
+void BuildBase::BuildAllProjectResourceEntries()
+{
+    for (unsigned i = 0; i < projectResourceDir_.Size(); i++)
+    {
+        String projectResourceDir = projectResourceDir_[i];
+        Vector<String> fileNamesInProject;
+        FileSystem* fileSystem = GetSubsystem<FileSystem>();
+        fileSystem->ScanDir(fileNamesInProject, projectResourceDir, "*.*", SCAN_FILES, true);
 
-// BEGIN LICENSE MANAGEMENT
-        if (GetExtension(filename) == ".mdl")
+        for (unsigned i = 0; i < fileNamesInProject.Size(); i++)
         {
-            containsMDL_ = true;
+            AddToResourcePackager(fileNamesInProject[i]);
         }
-// END LICENSE MANAGEMENT
-
-        newEntry->absolutePath_ = resourceDir + filename;
-        newEntry->resourceDir_ = resourceDir;
-
-        newEntry->packagePath_ = filename;
-
-        resourceEntries_.Push(newEntry);
-
-        //LOGINFOF("Adding resource: %s : %s", newEntry->absolutePath_.CString(), newEntry->packagePath_.CString());
     }
+    
 }
 
-void BuildBase::BuildProjectResourceEntries()
+void BuildBase::BuildFilteredProjectResourceEntries()
 {
-    Vector<String> fileNames;
-    FileSystem* fileSystem = GetSubsystem<FileSystem>();
-    fileSystem->ScanDir(fileNames, project_->GetResourcePath(), "*.*", SCAN_FILES, true);
-    
+    // Loading up the assetbuildconfig.json,
+    // obtaining a list of files to include in the build.
     VariantMap resourceTags;
     AssetBuildConfig::ApplyConfig(resourceTags);
-
+    Vector<String> resourceFilesToInclude;
     VariantMap::ConstIterator itr = resourceTags.Begin();
 
-    Vector<String> resources;
     while (itr != resourceTags.End())
     {
         if (itr->first_ == assetBuildTag_)
         {
-            resources = itr->second_.GetStringVector();
+            resourceFilesToInclude = itr->second_.GetStringVector();
             break;
         }
+        
         itr++;
+        if (itr == resourceTags.End())
+        {
+            LOGERRORF("BuildBase::BuildFilteredProjectResourceEntries - Asset Build Tag \"%s\" not defined in .\\Settings\\assetbuildconfig.json", assetBuildTag_.CString());
+        }
     }
 
-    for (unsigned i = 0; i < fileNames.Size(); i++)
-    {
-        const String& filename = fileNames[i];
+    // check if the files in assetbuildconfig.json exist,
+    // as well as their corresponding .asset file
+    Vector<String> filesInResourceFolder;
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    fileSystem->ScanDir(filesInResourceFolder, project_->GetResourcePath(), "*.*", SCAN_FILES, true);
 
-        for (unsigned j = 0; j < resourceEntries_.Size(); j++)
+    for (auto itr = resourceFilesToInclude.Begin(); itr != resourceFilesToInclude.End(); ++itr)
+    {
+        // .asset file is of primary importance since we used it to identify the associated cached file.
+        // without the .asset file the resource becomes redundant.
+        if (!filesInResourceFolder.Contains(*itr + ".asset"))
         {
-            const BuildResourceEntry* entry = resourceEntries_[j];
-
-            if (entry->packagePath_ == filename)
+            BuildWarn(ToString("BuildBase::BuildFilteredProjectResourceEntries - File \"%s\" associated .asset file not found in the Resources folder.\nRemoving \"%s\" from build pakcage", (*itr).CString()));
+            if (filesInResourceFolder.Contains(*itr))
             {
-                BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
+                resourceFilesToInclude.Remove(*itr);
+                itr--;
                 continue;
             }
         }
 
-        for (auto it = resources.Begin(); it != resources.End(); ++it)
-        {
-            if (filename == (*it))
-            {
-                // TODO: Add additional filters
-                if (GetExtension(filename) == ".psd")
-                    break;
-
-                BuildResourceEntry* newEntry = new BuildResourceEntry;
+        resourceFilesToInclude.Push(*itr + ".asset");
+    }
 
-                // BEGIN LICENSE MANAGEMENT
-                if (GetExtension(filename) == ".mdl")
-                {
-                    containsMDL_ = true;
-                }
-                // END LICENSE MANAGEMENT
+    // Get associated cache GUID from the asset file
+    Vector<String> filesWithGUIDtoInclude;
+    for (auto it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
+    {
+        if (GetExtension(*it) == ".asset");
+        {
+            SharedPtr<File> file(new File(context_, *it));
+            SharedPtr<JSONFile> json(new JSONFile(context_));
+            json->Load(*file);
+            file->Close();
 
-                newEntry->absolutePath_ = project_->GetResourcePath() + filename;
-                newEntry->resourceDir_ = project_->GetResourcePath();
+            JSONValue root = json->GetRoot();
 
-                newEntry->packagePath_ = filename;
+            assert(root.Get("version").GetInt() == ASSET_VERSION);
 
-                resourceEntries_.Push(newEntry);
-                resourcePackager_->AddResourceEntry(newEntry);
+            String guid = root.Get("guid").GetString();
+            filesWithGUIDtoInclude.Push(guid);
+        }
+    }
+    
+    // obtain files in cache folder,
+    // check if the file contains the guid, and add it to the resourceFilesToInclude
+    Vector<String> filesInCacheFolder;
+    fileSystem->ScanDir(filesInCacheFolder, project_->GetProjectPath() + "Cache/", "*.*", SCAN_FILES, true);
 
-                break;
+    for (unsigned i = 0; i < filesWithGUIDtoInclude.Size(); i++)
+    {
+        String &guid = filesWithGUIDtoInclude[i];
+        for (unsigned j = 0; j < filesInCacheFolder.Size(); j++)
+        {
+            String &filename = GetFileName(filesInCacheFolder[j]);
+            if (filename.Contains(guid))
+            {
+                resourceFilesToInclude.Push(filesInCacheFolder[j]);
+                // do not continue...
+                // there might be multiple files with the same guid
             }
         }
     }
-}
 
-void BuildBase::BuildResourceEntries()
-{
-    for (unsigned i = 0; i < resourceDirs_.Size(); i++)
+    for (auto it = resourceFilesToInclude.Begin(); it != resourceFilesToInclude.End(); ++it)
     {
-        ScanResourceDirectory(resourceDirs_[i]);
+        AddToResourcePackager(*it);
     }
+}
 
-    if (resourcePackager_.NotNull())
+void BuildBase::AddToResourcePackager(const String& filename)
+{
+    // Check if the file is already included in the resourceEntries_ list
+    for (unsigned j = 0; j < resourceEntries_.Size(); j++)
     {
-        for (unsigned i = 0; i < resourceEntries_.Size(); i++)
+        const BuildResourceEntry* entry = resourceEntries_[j];
+
+        if (entry->packagePath_ == filename)
         {
-            BuildResourceEntry* entry = resourceEntries_[i];
-            resourcePackager_->AddResourceEntry(entry);
+            BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
+            continue;
         }
+    }
+
+    // Add the file to the resourceEntries_ list
+    // TODO: Add additional filters
+    if (GetExtension(filename) == ".psd")
+        return;
+
+    BuildResourceEntry* newEntry = new BuildResourceEntry;
 
+    // BEGIN LICENSE MANAGEMENT
+    if (GetExtension(filename) == ".mdl")
+    {
+        containsMDL_ = true;
     }
+    // END LICENSE MANAGEMENT
+
+    newEntry->absolutePath_ = project_->GetResourcePath() + filename;
+    newEntry->resourceDir_ = project_->GetResourcePath();
+
+    newEntry->packagePath_ = filename;
 
+    resourceEntries_.Push(newEntry);
+    
+    assert(resourcePackager_.NotNull());
+    resourcePackager_->AddResourceEntry(newEntry);
 }
 
 void BuildBase::GenerateResourcePackage(const String& resourcePackagePath)
@@ -422,6 +488,12 @@ void BuildBase::AddResourceDir(const String& dir)
     resourceDirs_.Push(dir);
 }
 
+void BuildBase::AddProjectResourceDir(const String& dir)
+{
+    assert(!projectResourceDir_.Contains(dir));
+    projectResourceDir_.Push(dir);
+}
+
 void BuildBase::ReadAssetBuildConfig()
 {
     String projectPath = project_->GetProjectPath();

+ 9 - 1
Source/ToolCore/Build/BuildBase.h

@@ -53,6 +53,7 @@ public:
     // add in search order, first added is first searched
     // will warn on name conflicts
     void AddResourceDir(const String& dir);
+    void AddProjectResourceDir(const String& dir);
 
     void BuildLog(const String& message, bool sendEvent = true);
     void BuildWarn(const String& warning, bool sendEvent = true);
@@ -78,9 +79,11 @@ protected:
 
     void GenerateResourcePackage(const String& resourcePackagePath);
 
-    void BuildResourceEntries();
+    void BuildDefaultResourceEntries();
     void BuildProjectResourceEntries();
 
+    void AddToResourcePackager(const String& filename);
+
     void GetDefaultResourcePaths(Vector<String>& paths);
     String GetSettingsDirectory();
 
@@ -90,9 +93,13 @@ protected:
     bool containsMDL_;
     bool buildFailed_;
 
+    // EGS: I think I added this for the assetBuildConfiguraton file
     String assetBuildTag_;
 
 private:
+    void BuildFilteredProjectResourceEntries();
+    void BuildAllProjectResourceEntries();
+    
 
     PlatformID platformID_;
 
@@ -105,6 +112,7 @@ private:
     SharedPtr<Project> project_;
     SharedPtr<ResourcePackager> resourcePackager_;
     Vector<String> resourceDirs_;
+    Vector<String> projectResourceDir_;
 
     void ReadAssetBuildConfig();
 

+ 1 - 1
Source/ToolCore/Build/BuildIOS.cpp

@@ -160,7 +160,7 @@ void BuildIOS::Initialize()
     AddResourceDir(project->GetProjectPath() + "Cache/");
     AddResourceDir(projectResources);
 
-    BuildResourceEntries();
+    BuildDefaultResourceEntries();
 
 }
 

+ 1 - 1
Source/ToolCore/Build/BuildMac.cpp

@@ -64,7 +64,7 @@ void BuildMac::Initialize()
     AddResourceDir(project->GetProjectPath() + "Cache/");
     AddResourceDir(projectResources);
 
-    BuildResourceEntries();
+    BuildDefaultResourceEntries();
 
 }
 

+ 1 - 1
Source/ToolCore/Build/BuildWeb.cpp

@@ -65,7 +65,7 @@ void BuildWeb::Initialize()
     AddResourceDir(project->GetProjectPath() + "Cache/");
     AddResourceDir(projectResources);
 
-    BuildResourceEntries();
+    BuildDefaultResourceEntries();
 }
 void BuildWeb::Build(const String& buildPath)
 {

+ 5 - 12
Source/ToolCore/Build/BuildWindows.cpp

@@ -49,28 +49,21 @@ BuildWindows::~BuildWindows()
 void BuildWindows::Initialize()
 {
     ToolSystem* tsystem = GetSubsystem<ToolSystem>();
-
     Project* project = tsystem->GetProject();
 
     Vector<String> defaultResourcePaths;
     GetDefaultResourcePaths(defaultResourcePaths);
     
-
     for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
     {
         AddResourceDir(defaultResourcePaths[i]);
     }
-    AddResourceDir(project->GetProjectPath() + "Cache/");
-    BuildResourceEntries();
-
-    String projectResources = project->GetResourcePath();
-    BuildProjectResourceEntries();
-    
-
-    // TODO: smart filtering of cache
+    BuildDefaultResourceEntries();
     
-    //AddResourceDir(projectResources);
-    //BuildResourceEntries();
+    // EGS: Build the project resources and cache
+    AddProjectResourceDir(project->GetProjectPath());
+    AddProjectResourceDir(project->GetProjectPath() + "Cache/");
+    BuildProjectResourceEntries();
 }
 
 bool BuildWindows::CheckIncludeResourceFile(const String& resourceDir, const String& fileName)