Browse Source

Working on CLI

Josh Engebretson 10 years ago
parent
commit
7963ba2741

+ 14 - 0
CLI/cli.js

@@ -68,6 +68,20 @@ cmd.setDefaults({action: function (args) {
     });
 }});
 
+var cmd = commands.addParser("platform-add", {help: "Adds a platform to the project",
+    description: "Adds a platform to the project"});
+cmd.addArgument(["platform"], {help: "The platform to add (windows|mac|ios|android|ios)"});
+cmd.setDefaults({action: function (args) {
+    cli.addPlatform(args.platform)
+    .then(function () {
+        console.log("Platform added " + path.resolve(args.path));
+    })
+    .catch(function (error) {
+        console.error("Error: Platform Could not be added " + path.resolve(args.path));
+        process.exit(1);
+    });
+}});
+
 
 // GO!
 if (process.argv.length > 2) {

+ 5 - 1
CLI/index.js

@@ -58,4 +58,8 @@ exports.newProject = function (output) {
 
 exports.build = function (platform) {
   return atomictool(["build", platform], {output:true});
-};;
+};
+
+exports.addPlatform = function (platform) {
+  return atomictool(["platform-add", platform], {output:true});
+};

+ 33 - 1
Source/AtomicTool/AtomicTool.cpp

@@ -1,6 +1,7 @@
 
 #include <Atomic/Core/ProcessUtils.h>
 #include <Atomic/IO/Log.h>
+#include <Atomic/IO/FileSystem.h>
 #include <Atomic/Engine/Engine.h>
 
 #include <ToolCore/ToolSystem.h>
@@ -86,6 +87,7 @@ void AtomicTool::Start()
     tsystem->SetDataPath(cliDataPath_);
 
     SharedPtr<CommandParser> parser(new CommandParser(context_));
+
     SharedPtr<Command> cmd(parser->Parse(arguments));
     if (!cmd)
     {
@@ -95,10 +97,40 @@ void AtomicTool::Start()
             error = parser->GetErrorMessage();
 
         ErrorExit(error);
+        return;
+    }
+
+    if (cmd->RequiresProjectLoad())
+    {
+        FileSystem* fileSystem = GetSubsystem<FileSystem>();
+
+        String projectDirectory = fileSystem->GetCurrentDir();
+
+        Vector<String> projectFiles;
+        fileSystem->ScanDir(projectFiles, projectDirectory, "*.atomic", SCAN_FILES, false);
+        if (!projectFiles.Size())
+        {
+            ErrorExit(ToString("No .atomic project file in %s", projectDirectory.CString()));
+            return;
+        }
+        else if (projectFiles.Size() > 1)
+        {
+            ErrorExit(ToString("Multiple .atomic project files found in %s", projectDirectory.CString()));
+            return;
+        }
+
+        String projectFile = projectDirectory + "/" + projectFiles[0];
+
+        if (!tsystem->LoadProject(projectFile))
+        {
+            ErrorExit(ToString("Failed to load project: %s", projectFile.CString()));
+            return;
+        }
+
     }
 
     // BEGIN LICENSE MANAGEMENT
-    GetSubsystem<LicenseSystem>()->Initialize();
+    // GetSubsystem<LicenseSystem>()->Initialize();
     // END LICENSE MANAGEMENT
 
     cmd->Run();

+ 3 - 3
Source/ToolCore/Build/BuildBase.cpp

@@ -6,19 +6,19 @@
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/FileSystem.h>
 
+#include "../Project/Project.h"
 #include "BuildBase.h"
 #include "ResourcePackager.h"
 
 namespace ToolCore
 {
 
-BuildBase::BuildBase(Context * context) : Object(context), containsMDL_(false)
+BuildBase::BuildBase(Context * context, Project* project) : Object(context), containsMDL_(false)
 {
-
     if (UseResourcePackager())
         resourcePackager_ = new ResourcePackager(context, this);
 
-    BuildLog("Build Started");
+    project_ = project;
 
 }
 

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

@@ -13,6 +13,7 @@ namespace ToolCore
 {
 
 class ResourcePackager;
+class Project;
 
 class BuildBase : public Object
 {
@@ -20,7 +21,7 @@ class BuildBase : public Object
 
 public:
 
-    BuildBase(Context* context);
+    BuildBase(Context* context, Project* project);
     virtual ~BuildBase();
 
     virtual void Build(const String& buildPath) = 0;
@@ -55,6 +56,7 @@ private:
 
     void ScanResourceDirectory(const String& resourceDir);
 
+    SharedPtr<Project> project_;
     SharedPtr<ResourcePackager> resourcePackager_;
     Vector<String> resourceDirs_;
 

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

@@ -12,7 +12,7 @@
 namespace ToolCore
 {
 
-BuildMac::BuildMac(Context * context) : BuildBase(context)
+BuildMac::BuildMac(Context * context, Project *project) : BuildBase(context, project)
 {
 
 }

+ 3 - 1
Source/ToolCore/Build/BuildMac.h

@@ -9,13 +9,15 @@
 namespace ToolCore
 {
 
+class Project;
+
 class BuildMac : public BuildBase
 {
     OBJECT(BuildMac);
 
 public:
 
-    BuildMac(Context* context);
+    BuildMac(Context* context, Project* project);
     virtual ~BuildMac();
 
     void Build(const String& buildPath);

+ 5 - 7
Source/ToolCore/Build/BuildSystem.cpp

@@ -26,6 +26,11 @@ BuildSystem::~BuildSystem()
 
 }
 
+void BuildSystem::QueueBuild(BuildBase* buildBase)
+{
+    queuedBuilds_.Push(SharedPtr<BuildBase>(buildBase));
+}
+
 void BuildSystem::BuildComplete(PlatformID platform, const String &buildFolder, bool success, bool fail3D)
 {
 
@@ -38,13 +43,6 @@ void BuildSystem::BuildComplete(PlatformID platform, const String &buildFolder,
 }
 
 
-void BuildSystem::DoBuildWeb(const String& buildPath)
-{
-    currentBuild_ = SharedPtr<BuildBase>(new BuildWeb(context_));
-    currentBuild_->Build(buildPath);
-
-}
-
 void BuildSystem::LoadBuildSettings(rapidjson::Value::Member* jobject)
 {
     buildSettings_->Load(jobject);

+ 3 - 1
Source/ToolCore/Build/BuildSystem.h

@@ -27,6 +27,8 @@ public:
 
     BuildSettings* GetBuildSettings() { return buildSettings_; }
 
+    void QueueBuild(BuildBase* buildBase);
+
     void LoadBuildSettings(rapidjson::Value::Member* jobject);
     void SaveBuildSettings(rapidjson::PrettyWriter<rapidjson::FileStream>& writer);
 
@@ -35,7 +37,7 @@ public:
 
 private:
 
-    void DoBuildWeb(const String& buildPath);
+    List<SharedPtr<BuildBase>> queuedBuilds_;
 
     SharedPtr<BuildSettings> buildSettings_;
     SharedPtr<BuildBase> currentBuild_;

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

@@ -13,7 +13,7 @@
 namespace ToolCore
 {
 
-BuildWeb::BuildWeb(Context * context) : BuildBase(context)
+BuildWeb::BuildWeb(Context* context, Project* project) : BuildBase(context, project)
 {
 
 }

+ 3 - 1
Source/ToolCore/Build/BuildWeb.h

@@ -9,13 +9,15 @@
 namespace ToolCore
 {
 
+class Project;
+
 class BuildWeb : public BuildBase
 {
     OBJECT(BuildWeb);
 
 public:
 
-    BuildWeb(Context* context);
+    BuildWeb(Context* context, Project* project);
     virtual ~BuildWeb();
 
     void Build(const String& buildPath);

+ 25 - 2
Source/ToolCore/Command/BuildCmd.cpp

@@ -4,9 +4,9 @@
 #include <Atomic/IO/File.h>
 
 #include "../ToolSystem.h"
+#include "../Build/BuildSystem.h"
 
 #include "BuildCmd.h"
-
 #include <Poco/File.h>
 
 namespace ToolCore
@@ -39,7 +39,7 @@ bool BuildCmd::Parse(const Vector<String>& arguments, unsigned startIndex, Strin
         return false;
     }
 
-    buildPlatform_ = value;
+    buildPlatform_ = value.ToLower();
 
     return true;
 }
@@ -48,6 +48,29 @@ void BuildCmd::Run()
 {
     LOGINFOF("Building project for: %s", buildPlatform_.CString());
 
+    ToolSystem* tsystem = GetSubsystem<ToolSystem>();
+    Project* project = tsystem->GetProject();
+
+    Platform* platform = NULL;
+
+    if (buildPlatform_ == "mac")
+        platform = tsystem->GetPlatformByID(PLATFORMID_MAC);
+
+    if (!platform)
+    {
+        Error(ToString("Unknown build platform: %s", buildPlatform_.CString()));
+        return;
+    }
+
+    // create the build
+    BuildBase* buildBase = platform->NewBuild(project);
+
+    // add it to the build system
+    BuildSystem* buildSystem = GetSubsystem<BuildSystem>();
+    buildSystem->QueueBuild(buildBase);
+
+    // clear the current platform
+    tsystem->SetCurrentPlatform(PLATFORMID_UNDEFINED);
     Finished();
 }
 

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

@@ -38,6 +38,8 @@ public:
 
     virtual void Cancel() {}
 
+    virtual bool RequiresProjectLoad() { return true; }
+
 private:
 
     float timeOut_;

+ 6 - 0
Source/ToolCore/Command/CommandParser.cpp

@@ -2,6 +2,7 @@
 #include "CommandParser.h"
 
 #include "NewProjectCmd.h"
+#include "PlatformAddCmd.h"
 #include "BuildCmd.h"
 
 namespace ToolCore
@@ -35,6 +36,11 @@ Command* CommandParser::Parse(const Vector<String>& arguments)
             {
                 cmd = new BuildCmd(context_);
             }
+            else if (argument == "platform-add")
+            {
+                cmd = new PlatformAddCmd(context_);
+            }
+
         }
 
         if (cmd)

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

@@ -21,6 +21,8 @@ public:
 
     void Run();
 
+    bool RequiresProjectLoad() { return false; }
+
 private:
 
     String projectPath_;

+ 59 - 0
Source/ToolCore/Command/PlatformAddCmd.cpp

@@ -0,0 +1,59 @@
+
+#include <Atomic/Core/StringUtils.h>
+#include <Atomic/IO/Log.h>
+#include <Atomic/IO/File.h>
+
+#include "../ToolSystem.h"
+
+#include "PlatformAddCmd.h"
+
+#include <Poco/File.h>
+
+namespace ToolCore
+{
+
+PlatformAddCmd::PlatformAddCmd(Context* context) : Command(context)
+{
+
+}
+
+PlatformAddCmd::~PlatformAddCmd()
+{
+
+}
+
+bool PlatformAddCmd::Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg)
+{
+    String argument = arguments[startIndex].ToLower();
+    String value = startIndex + 1 < arguments.Size() ? arguments[startIndex + 1] : String::EMPTY;
+
+    if (argument != "platform-add")
+    {
+        errorMsg = "Unable to parse build command";
+        return false;
+    }
+
+    if (!value.Length())
+    {
+        errorMsg = "Unable to parse build platform";
+        return false;
+    }
+
+    platformToAdd_ = value.ToLower();
+
+    return true;
+}
+
+void PlatformAddCmd::Run()
+{
+    LOGINFOF("Adding platform: %s", platformToAdd_.CString());
+
+    ToolSystem* tsystem = GetSubsystem<ToolSystem>();
+    Project* project = tsystem->GetProject();
+
+    Platform* platform = NULL;
+
+    Finished();
+}
+
+}

+ 30 - 0
Source/ToolCore/Command/PlatformAddCmd.h

@@ -0,0 +1,30 @@
+
+#pragma once
+
+#include "Command.h"
+
+using namespace Atomic;
+
+namespace ToolCore
+{
+
+class PlatformAddCmd: public Command
+{
+    OBJECT(PlatformAddCmd);
+
+public:
+
+    PlatformAddCmd(Context* context);
+    virtual ~PlatformAddCmd();
+
+    bool Parse(const Vector<String>& arguments, unsigned startIndex, String& errorMsg);
+
+    void Run();
+
+private:
+
+    String platformToAdd_;
+
+};
+
+}

+ 5 - 0
Source/ToolCore/Platform/Platform.h

@@ -8,6 +8,9 @@ using namespace Atomic;
 namespace ToolCore
 {
 
+class BuildBase;
+class Project;
+
 enum PlatformID
 {
     PLATFORMID_UNDEFINED,
@@ -30,6 +33,8 @@ public:
     virtual String GetName() = 0;
     virtual PlatformID GetPlatformID() = 0;
 
+    virtual BuildBase* NewBuild(Project* project) = 0;
+
 private:
 
     bool validLicense_;

+ 24 - 0
Source/ToolCore/Platform/PlatformMac.cpp

@@ -0,0 +1,24 @@
+
+#include "../Project/Project.h"
+#include "../Build/BuildMac.h"
+#include "PlatformMac.h"
+
+namespace ToolCore
+{
+
+PlatformMac::PlatformMac(Context* context) : Platform(context)
+{
+
+}
+
+PlatformMac::~PlatformMac()
+{
+
+}
+
+BuildBase* PlatformMac::NewBuild(Project *project)
+{
+    return new BuildMac(context_, project);
+}
+
+}

+ 25 - 0
Source/ToolCore/Platform/PlatformMac.h

@@ -0,0 +1,25 @@
+
+#pragma once
+
+#include "Platform.h"
+
+namespace ToolCore
+{
+
+class PlatformMac : public Platform
+{
+    OBJECT(PlatformMac);
+
+public:
+
+    PlatformMac(Context* context);
+    virtual ~PlatformMac();
+
+    String GetName() { return "MAC"; }
+    PlatformID GetPlatformID() { return PLATFORMID_MAC; }
+
+    BuildBase* NewBuild(Project* project);
+
+};
+
+}

+ 8 - 0
Source/ToolCore/Platform/PlatformWeb.cpp

@@ -1,4 +1,6 @@
 
+
+#include "../Build/BuildWeb.h"
 #include "PlatformWeb.h"
 
 namespace ToolCore
@@ -14,4 +16,10 @@ PlatformWeb::~PlatformWeb()
 
 }
 
+BuildBase* PlatformWeb::NewBuild(Project *project)
+{
+    return new BuildWeb(context_, project);
+}
+
+
 }

+ 2 - 0
Source/ToolCore/Platform/PlatformWeb.h

@@ -18,6 +18,8 @@ public:
     String GetName() { return "WEB"; }
     PlatformID GetPlatformID() { return PLATFORMID_WEB; }
 
+    BuildBase* NewBuild(Project *project);
+
 };
 
 }

+ 32 - 1
Source/ToolCore/Project/Project.cpp

@@ -10,6 +10,8 @@
 #include <Atomic/IO/Log.h>
 #include <Atomic/IO/File.h>
 
+#include <Atomic/Resource/JSONFile.h>
+
 #include "Project.h"
 
 using namespace rapidjson;
@@ -131,6 +133,35 @@ void Project::SaveUserPrefs(const String& fullpath)
     fclose(file);
 }
 
+void Project::SaveBuildSettings(const String& path)
+{
+    SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
+
+    jsonFile->CreateRoot();
+
+    SharedPtr<File> file(new File(context_, path, FILE_WRITE));
+
+    jsonFile->Save(*file, String("   "));
+
+    file->Close();
+
+}
+
+bool Project::LoadBuildSettings(const String& path)
+{
+    return false;
+}
+
+void Project::AddPlatform(PlatformID platformID)
+{
+
+}
+
+void Project::RemovePlatform(PlatformID platformID)
+{
+
+}
+
 void Project::Load(const String& fullpath)
 {
     projectFilePath_ = fullpath;
@@ -178,7 +209,7 @@ String Project::GetUserPrefsFullPath(const String& projectPath)
 {
     String path = GetPath(projectPath);
     String filename = GetFileName(projectPath);
-    String prefsPath = path + "/" + filename + ".atomic.userprefs";
+    String prefsPath = path + filename + ".atomic.userprefs";
     return prefsPath;
 }
 

+ 16 - 2
Source/ToolCore/Project/Project.h

@@ -3,6 +3,8 @@
 
 using namespace Atomic;
 
+#include "../Platform/Platform.h"
+
 namespace ToolCore
 {
 
@@ -16,6 +18,10 @@ public:
     /// Destruct.
     virtual ~Project();
 
+    void Load(const String& fullpath);
+    void Save(const String& fullpath = "");
+
+    /// Paths
     const String GetResourcePath() { return resourcePath_; }
     void SetResourcePath(const String& resourcePath)
     {
@@ -24,8 +30,6 @@ public:
         scriptsPath_ = resourcePath_ + "Scripts";
         modulesPath_ = resourcePath_ + "Modules";
     }
-    void Load(const String& fullpath);
-    void Save(const String& fullpath = "");
 
     const String& GetComponentsPath() { return componentsPath_; }
     const String& GetScriptsPath() { return scriptsPath_; }
@@ -40,6 +44,12 @@ public:
     const String& GetLastBuildPath() { return lastBuildPath_; }
     void SetLastBuildPath(const String& path) { lastBuildPath_ = path; }
 
+    void SaveBuildSettings(const String& path);
+    bool LoadBuildSettings(const String& path);
+
+    void AddPlatform(PlatformID platformID);
+    void RemovePlatform(PlatformID platformID);
+
 private:
 
     void LoadUserPrefs(const String& fullpath);
@@ -55,6 +65,10 @@ private:
 
     String lastBuildPath_;
 
+    VariantMap buildSettings_;
+
+    List<SharedPtr<Platform>> platforms_;
+
 };
 
 }

+ 31 - 4
Source/ToolCore/ToolSystem.cpp

@@ -4,6 +4,7 @@
 #include <Atomic/Resource/ResourceCache.h>
 
 #include "Platform/PlatformWeb.h"
+#include "Platform/PlatformMac.h"
 #include "Net/CurlManager.h"
 #include "License/LicenseSystem.h"
 #include "Build/BuildSystem.h"
@@ -23,6 +24,7 @@ ToolSystem::ToolSystem(Context* context) : Object(context)
     context_->RegisterSubsystem(new BuildSystem(context_));
 
     // platform registration
+    RegisterPlatform(new PlatformMac(context));
     RegisterPlatform(new PlatformWeb(context));
 }
 
@@ -52,6 +54,12 @@ bool ToolSystem::LoadProject(const String& fullpath)
 
 void ToolSystem::SetCurrentPlatform(PlatformID platform)
 {
+    if (platform == PLATFORMID_UNDEFINED)
+    {
+        currentPlatform_ = NULL;
+        return;
+    }
+
     if (!platforms_.Contains((unsigned) platform))
         return;
 
@@ -59,12 +67,31 @@ void ToolSystem::SetCurrentPlatform(PlatformID platform)
 
 }
 
-PlatformID ToolSystem::GetCurrentPlatform()
+Platform* ToolSystem::GetPlatformByID(PlatformID platform)
+{
+    if (!platforms_.Contains((unsigned) platform))
+        return NULL;
+
+    return platforms_[(unsigned)platform];
+
+}
+
+Platform* ToolSystem::GetPlatformByName(const String& name)
 {
-    if (currentPlatform_.Null())
-        return PLATFORMID_UNDEFINED;
+    HashMap<unsigned, SharedPtr<Platform> >::Iterator itr = platforms_.Begin();
+    while (itr != platforms_.End())
+    {
+        if ((*itr).second_->GetName().ToLower()== name.ToLower())
+            return (*itr).second_;
+        itr++;
+    }
+
+    return NULL;
+}
 
-    return currentPlatform_->GetPlatformID();
+Platform *ToolSystem::GetCurrentPlatform()
+{
+    return currentPlatform_;
 }
 
 void ToolSystem::RegisterPlatform(Platform* platform)

+ 4 - 1
Source/ToolCore/ToolSystem.h

@@ -30,8 +30,11 @@ public:
 
     // Platforms
     void RegisterPlatform(Platform* platform);
+    Platform* GetPlatformByID(PlatformID platform);
+    Platform* GetPlatformByName(const String& name);
+
     void SetCurrentPlatform(PlatformID platform);
-    PlatformID GetCurrentPlatform();
+    Platform* GetCurrentPlatform();
 
 private: