Browse Source

Added initial support to define which assets/resources should be included in the build. Work has not yet been properly tested. Realised before this commit that we are going to have to include .asset files as well to the AssetBuildConfig.json file.

Eugene 9 years ago
parent
commit
79908858d1

+ 13 - 0
Source/Atomic/Resource/Configuration.cpp

@@ -62,6 +62,19 @@ namespace Atomic
         return value;
     }
 
+    StringVector Configuration::GetArrayValue(const JSONArray & jarray, const StringVector & defaultValue)
+    {
+        StringVector value;
+
+        for (auto it = jarray.Begin(); it != jarray.End(); it++)
+        {
+            if (it->IsString())
+            {
+                value.Push(it->GetString());
+            }
+        }
+        return value;
+    }
 
     bool Configuration::LoadFromFile(Context *context, const String& filename)
     {

+ 2 - 1
Source/Atomic/Resource/Configuration.h

@@ -46,7 +46,8 @@ protected:
     static bool GetBoolValue(const JSONValue& jvalue, bool defaultValue);
     static int GetIntValue(const JSONValue& jvalue, int defaultValue);
     static String GetStringValue(const JSONValue& jvalue, const String& defaultValue);
-
+    static StringVector GetArrayValue(const JSONArray& jarray, const StringVector& defaultValue);
+    
     virtual bool LoadDesktopConfig(JSONValue root) { return true; };
 
     VariantMap valueMap_;

+ 70 - 0
Source/ToolCore/Build/AssetBuildConfig.cpp

@@ -0,0 +1,70 @@
+//
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#include "../../Atomic/Core/Context.h"
+#include "../../Atomic/IO/Log.h"
+#include "../../Atomic/IO/File.h"
+#include "../../Atomic/IO/FileSystem.h"
+#include "../Atomic/Resource/JSONFile.h"
+#include "../../Atomic/Graphics/GraphicsDefs.h"
+#include "AssetBuildConfig.h"
+
+namespace Atomic
+{
+    AssetBuildConfig AssetBuildConfig::assetBuildConfig_;
+
+    bool AssetBuildConfig::LoadAssetBuildTagArray(const JSONArray& tags)
+    {
+        if (tags.Empty())
+            return false;
+
+        for (auto it = tags.Begin(); it < tags.End(); ++it)
+        {
+            const JSONObject& resourceTag = (*it).GetObject();
+
+            String tag = resourceTag["Tag"]->GetString();
+
+            const JSONArray& resources = resourceTag["Resources"]->GetArray();
+
+            Vector<String> empty;
+            valueMap_[tag.CString()] = GetArrayValue(resources, empty);
+        }
+
+        return true;
+    }
+
+    bool AssetBuildConfig::LoadDesktopConfig(JSONValue root)
+    {
+        const JSONValue& assetBuildConfigRoot = root["AssetBuildConfig"];
+
+        if (!assetBuildConfigRoot.IsArray())
+            return false;
+
+        const JSONArray& assetTags = assetBuildConfigRoot.GetArray();
+
+        if (!assetTags.Empty())
+            LoadAssetBuildTagArray(assetTags);
+
+        return true;
+    }
+
+}

+ 54 - 0
Source/ToolCore/Build/AssetBuildConfig.h

@@ -0,0 +1,54 @@
+//
+// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+//
+
+#pragma once
+
+#include "../../Atomic/Core/Variant.h"
+#include "../../Atomic/Resource/JSONValue.h"
+#include "../../Atomic/Resource/Configuration.h"
+
+namespace Atomic
+{
+
+    class Context;
+
+    class AssetBuildConfig :
+        Configuration
+    {
+
+    public:
+
+        static bool LoadFromFile(Context* context, const String& filename) { return assetBuildConfig_.Configuration::LoadFromFile(context, filename); }
+        static bool LoadFromJSON(const String& json) { return assetBuildConfig_.Configuration::LoadFromJSON(json); }
+
+        /// 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); }
+
+    private:
+
+        virtual bool LoadDesktopConfig(JSONValue root);
+        bool LoadAssetBuildTagArray(const JSONArray& tags);
+
+        static AssetBuildConfig assetBuildConfig_;
+    };
+
+}

+ 90 - 1
Source/ToolCore/Build/BuildBase.cpp

@@ -31,6 +31,7 @@
 #include "BuildEvents.h"
 #include "BuildBase.h"
 #include "ResourcePackager.h"
+#include "AssetBuildConfig.h"
 
 namespace ToolCore
 {
@@ -38,13 +39,15 @@ namespace ToolCore
 BuildBase::BuildBase(Context * context, Project* project, PlatformID platform) : Object(context),
     platformID_(platform),
     containsMDL_(false),
-    buildFailed_(false)
+    buildFailed_(false),
+    assetBuildTag_(String::EMPTY)
 {
     if (UseResourcePackager())
         resourcePackager_ = new ResourcePackager(context, this);
 
     project_ = project;
 
+    ReadAssetBuildConfig();
 }
 
 BuildBase::~BuildBase()
@@ -317,6 +320,74 @@ void BuildBase::ScanResourceDirectory(const String& resourceDir)
     }
 }
 
+void BuildBase::BuildProjectResourceEntries()
+{
+    Vector<String> fileNames;
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    fileSystem->ScanDir(fileNames, project_->GetResourcePath(), "*.*", SCAN_FILES, true);
+    
+    VariantMap resourceTags;
+    AssetBuildConfig::ApplyConfig(resourceTags);
+
+    VariantMap::ConstIterator itr = resourceTags.Begin();
+
+    Vector<String> resources;
+    while (itr != resourceTags.End())
+    {
+        if (itr->first_ == assetBuildTag_)
+        {
+            resources = itr->second_.GetStringVector();
+            break;
+        }
+        itr++;
+    }
+
+    for (unsigned i = 0; i < fileNames.Size(); i++)
+    {
+        const String& filename = fileNames[i];
+
+        for (unsigned j = 0; j < resourceEntries_.Size(); j++)
+        {
+            const BuildResourceEntry* entry = resourceEntries_[j];
+
+            if (entry->packagePath_ == filename)
+            {
+                BuildWarn(ToString("Resource Path: %s already exists", filename.CString()));
+                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;
+
+                // 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);
+                resourcePackager_->AddResourceEntry(newEntry);
+
+                break;
+            }
+        }
+    }
+}
+
 void BuildBase::BuildResourceEntries()
 {
     for (unsigned i = 0; i < resourceDirs_.Size(); i++)
@@ -347,5 +418,23 @@ void BuildBase::AddResourceDir(const String& dir)
     resourceDirs_.Push(dir);
 }
 
+void BuildBase::ReadAssetBuildConfig()
+{
+    String projectPath = project_->GetProjectPath();
+    projectPath = RemoveTrailingSlash(projectPath);
+
+    String filename = projectPath + "Settings/AssetBuildConfig.json";
+
+    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    if (!fileSystem->FileExists(filename))
+        return;
+
+    if (AssetBuildConfig::LoadFromFile(context_, filename))
+    {
+        VariantMap assetBuildConfig;
+        AssetBuildConfig::ApplyConfig(assetBuildConfig);
+    }
+}
+
 
 }

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

@@ -64,6 +64,10 @@ public:
     /// Converts subprocess output event to a buildoutput event
     void HandleSubprocessOutputEvent(StringHash eventType, VariantMap& eventData);
 
+    /// Asset build tag used by the assetbuildconfig.json file to identify the assets to that should be include
+    /// in the build. If no tag is specified, then all resources are included.
+    void SetAssetBuildTag(const String assetBuildTag) { assetBuildTag_ = assetBuildTag; }
+
 protected:
 
     bool BuildClean(const String& path);
@@ -75,6 +79,7 @@ protected:
     void GenerateResourcePackage(const String& resourcePackagePath);
 
     void BuildResourceEntries();
+    void BuildProjectResourceEntries();
 
     void GetDefaultResourcePaths(Vector<String>& paths);
     String GetSettingsDirectory();
@@ -85,6 +90,8 @@ protected:
     bool containsMDL_;
     bool buildFailed_;
 
+    String assetBuildTag_;
+
 private:
 
     PlatformID platformID_;
@@ -99,6 +106,8 @@ private:
     SharedPtr<ResourcePackager> resourcePackager_;
     Vector<String> resourceDirs_;
 
+    void ReadAssetBuildConfig();
+
 };
 
 }

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

@@ -53,19 +53,23 @@ void BuildWindows::Initialize()
 
     Vector<String> defaultResourcePaths;
     GetDefaultResourcePaths(defaultResourcePaths);
-    String projectResources = project->GetResourcePath();
+    
 
     for (unsigned i = 0; i < defaultResourcePaths.Size(); i++)
     {
         AddResourceDir(defaultResourcePaths[i]);
     }
-
-    // TODO: smart filtering of cache
     AddResourceDir(project->GetProjectPath() + "Cache/");
-    AddResourceDir(projectResources);
-
     BuildResourceEntries();
 
+    String projectResources = project->GetResourcePath();
+    BuildProjectResourceEntries();
+    
+
+    // TODO: smart filtering of cache
+    
+    //AddResourceDir(projectResources);
+    //BuildResourceEntries();
 }
 
 void BuildWindows::BuildAtomicNET()

+ 9 - 0
Source/ToolCore/Command/BuildCmd.cpp

@@ -28,6 +28,7 @@
 #include "../Project/Project.h"
 #include "../Build/BuildEvents.h"
 #include "../Build/BuildSystem.h"
+#include "../Build/AssetBuildConfig.h"
 
 #include "BuildCmd.h"
 #include <Poco/File.h>
@@ -49,6 +50,7 @@ bool BuildCmd::Parse(const Vector<String>& arguments, unsigned startIndex, Strin
 {
     String argument = arguments[startIndex].ToLower();
     String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
+    String tag = startIndex + 2 < arguments.Size() ? arguments[startIndex + 2] : String::EMPTY;
 
     if (argument != "build")
     {
@@ -63,6 +65,7 @@ bool BuildCmd::Parse(const Vector<String>& arguments, unsigned startIndex, Strin
     }
 
     buildPlatform_ = value.ToLower();
+    assetsBuildTag_ = tag.ToLower();
 
     return true;
 }
@@ -78,6 +81,8 @@ void BuildCmd::HandleBuildComplete(StringHash eventType, VariantMap& eventData)
 
 }
 
+
+
 void BuildCmd::Run()
 {
     LOGINFOF("Building project for: %s", buildPlatform_.CString());
@@ -103,6 +108,10 @@ void BuildCmd::Run()
 
     // create the build
     BuildBase* buildBase = platform->NewBuild(project);
+    if (!assetsBuildTag_.Empty())
+    {
+        buildBase->SetAssetBuildTag(assetsBuildTag_);
+    }
 
     // add it to the build system
     BuildSystem* buildSystem = GetSubsystem<BuildSystem>();

+ 2 - 0
Source/ToolCore/Command/BuildCmd.h

@@ -45,8 +45,10 @@ public:
 private:
 
     void HandleBuildComplete(StringHash eventType, VariantMap& eventData);
+    
 
     String buildPlatform_;
+    String assetsBuildTag_;
 
 };