Browse Source

Merge pull request #1135 from AtomicGameEngine/JME-ATOMIC-1081

Get AtomicTool (net compile) running outside of the build tree, for example on a CI box
JoshEngebretson 9 years ago
parent
commit
92bccd06bd

+ 1 - 1
Build/Scripts/BuildAtomicNET.js

@@ -64,7 +64,7 @@ namespace('build', function() {
 
         var cmds = [];
 
-        var netCmd = host.atomicTool + " net compile " + atomicRoot + "Script/AtomicNET/AtomicNETProject.json " + platforms + " -config " + config["config"];
+        var netCmd = host.atomicTool + " net compile " + atomicRoot + "Script/AtomicNET/AtomicNETProject.json " + platforms + " -config " + config["config"] + " -toolbootstrap";
 
         console.log(netCmd);
 

+ 4 - 0
Build/Scripts/BuildWindows.js

@@ -27,6 +27,10 @@ function copyAtomicEditor() {
     fs.copySync(buildDir + "Source/AtomicEditor/" + config["config"],
     config.artifactsRoot + "AtomicEditor");
 
+    // copy AtomicTool
+    fs.copySync(buildDir +  "Source/AtomicTool/" + config["config"] +"/AtomicTool.exe",
+    editorAppFolder + "AtomicTool.exe");
+    
     // We need some resources to run
     fs.copySync(atomicRoot + "Resources/CoreData",
     editorAppFolder + "Resources/CoreData");

+ 1 - 12
Source/AtomicEditor/Application/AEEditorApp.cpp

@@ -89,18 +89,7 @@ namespace AtomicEditor
         ToolEnvironment* env = new ToolEnvironment(context_);
         context_->RegisterSubsystem(env);
 
-#ifdef ATOMIC_DEV_BUILD
-
-        if (!env->InitFromJSON())
-        {
-            ErrorExit(ToString("Unable to initialize tool environment from %s", env->GetDevConfigFilename().CString()));
-            return;
-        }
-#else
-
-        env->InitFromPackage();
-
-#endif
+        env->Initialize();
 
         ToolSystem* system = new ToolSystem(context_);
         context_->RegisterSubsystem(system);

+ 5 - 44
Source/AtomicTool/AtomicTool.cpp

@@ -59,35 +59,8 @@ void AtomicTool::Setup()
 {
     const Vector<String>& arguments = GetArguments();
 
-    for (unsigned i = 0; i < arguments.Size(); ++i)
-    {
-        if (arguments[i].Length() > 1)
-        {
-            String argument = arguments[i].ToLower();
-            String value = i + 1 < arguments.Size() ? arguments[i + 1] : String::EMPTY;
-
-            if (argument == "--cli-data-path")
-            {
-                if (!value.Length())
-                    ErrorExit("Unable to parse --cli-data-path");
-
-                cliDataPath_ = AddTrailingSlash(value);
-            }
-            else if (argument == "--activate")
-            {
-                if (!value.Length())
-                    ErrorExit("Unable to parse --activation product key");
-
-                activationKey_ = value;
-            }
-            else if (argument == "--deactivate")
-            {
-                deactivate_ = true;
-            }
-
-        }
-
-    }
+    if (arguments.Contains("-toolbootstrap"))
+        ToolEnvironment::SetBootstrapping();
 
     engineParameters_["Headless"] = true;
     engineParameters_["LogLevel"] = LOG_INFO;
@@ -220,25 +193,13 @@ void AtomicTool::Start()
     ToolEnvironment* env = new ToolEnvironment(context_);
     context_->RegisterSubsystem(env);
 
-//#ifdef ATOMIC_DEV_BUILD
-
-    if (!env->InitFromJSON())
+    // Initialize the ToolEnvironment
+    if (!env->Initialize(true))
     {
-        ErrorExit(ToString("Unable to initialize tool environment from %s", env->GetDevConfigFilename().CString()));
+        ErrorExit("Unable to initialize tool environment");
         return;
     }
 
-    if (!cliDataPath_.Length())
-    {
-        cliDataPath_ = env->GetRootSourceDir() + "/Resources/";
-    }
-
-//#endif
-
-    tsystem->SetCLI();
-    tsystem->SetDataPath(cliDataPath_);
-
-
     if (activationKey_.Length())
     {
         DoActivation();

+ 1 - 3
Source/AtomicTool/AtomicTool.h

@@ -35,7 +35,7 @@ namespace AtomicTool
 
 class AtomicTool : public Application
 {
-    ATOMIC_OBJECT(AtomicTool, Application);
+    ATOMIC_OBJECT(AtomicTool, Application)
 
 public:
 
@@ -69,8 +69,6 @@ private:
     void DoActivation();
     void DoDeactivation();
 
-    // use a variant map instead?
-    String cliDataPath_;
     String activationKey_;
     bool deactivate_;
 

+ 1 - 29
Source/ToolCore/Command/NewProjectCmd.cpp

@@ -68,35 +68,7 @@ bool NewProjectCmd::Parse(const Vector<String>& arguments, unsigned startIndex,
 
 void NewProjectCmd::Run()
 {
-    Poco::File projectDest(projectPath_.CString());
-
-    if (projectDest.exists())
-    {
-        Error(ToString("New project path: %s already exists", projectPath_.CString()));
-        return;
-    }
-
-    ToolSystem* tsystem = GetSubsystem<ToolSystem>();
-    String templateDir = tsystem->GetDataPath();
-    templateDir += "ProjectTemplates/Project2D/Resources";
-
-    Poco::File projectSrc(templateDir.CString());
-    if (!projectSrc.exists() || !projectSrc.isDirectory())
-    {
-        Error(ToString("New project path: %s source does not exist", templateDir.CString()));
-        return;
-    }
-
-    ATOMIC_LOGINFOF("Creating new project in: %s", projectPath_.CString());
-
-    projectDest.createDirectory();
-    projectSrc.copyTo((projectPath_ + "/Resources").CString());
-
-    String filename("NewProject");
-    SharedPtr<ProjectFile> pfile(new ProjectFile(context_));
-    pfile->WriteNewProject(projectPath_ + "/" + filename + ".atomic");
-
-    Finished();
+    Error("NewProjectCmd is under maintenance, please use the AtomicEditor to create a new project");
 }
 
 }

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

@@ -240,6 +240,7 @@ namespace ToolCore
 
             StringVector stringVector;
             String platforms;
+            StringVector processedPlatforms;
             String configs;
 
             for (unsigned i = 0; i < curBuild_->configurations_.Size(); i++)
@@ -255,6 +256,20 @@ namespace ToolCore
                 // map platform
                 String platform = curBuild_->platforms_[i];
 
+                if (platform == "windows" || platform == "macosx" || platform == "linux")
+                {
+                    ATOMIC_LOGINFOF("Platform \"%s\" mapped to \"desktop\"", platform.CString());
+                    platform = "desktop";
+                }
+
+                if (processedPlatforms.Contains(platform))
+                {
+                    ATOMIC_LOGWARNINGF("Platform \"%s\" is duplicated, skipping", platform.CString());
+                    continue;
+                }
+
+                processedPlatforms.Push(platform);
+
                 if (platform == "desktop" || platform == "android")
                 {
                     platform = "\"Any CPU\"";

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

@@ -31,6 +31,7 @@
 #include <Atomic/Resource/JSONFile.h>
 
 #include "../ToolSystem.h"
+#include "../ToolEnvironment.h"
 #include "../ToolEvents.h"
 #include "../Platform/Platform.h"
 
@@ -74,13 +75,14 @@ void Project::SaveUserPrefs()
 bool Project::LoadUserPrefs()
 {
     ToolSystem* tsystem = GetSubsystem<ToolSystem>();
+    ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
 
     String path = GetProjectPath() + "UserPrefs.json";
 
     userPrefs_->Load(path);
 
     // If we're in CLI mode, the Build folder is always relative to project
-    if (tsystem->IsCLI())
+    if (tenv->GetCLI())
     {
         String path = GetPath(projectFilePath_) + "Build";
         userPrefs_->SetLastBuildPath(path);

+ 19 - 62
Source/ToolCore/ToolEnvironment.cpp

@@ -37,7 +37,10 @@ using namespace rapidjson;
 namespace ToolCore
 {
 
+bool ToolEnvironment::bootstrapping_ = false;
+
 ToolEnvironment::ToolEnvironment(Context* context) : Object(context),
+    cli_(false),
     toolPrefs_(new ToolPrefs(context))
 {
 
@@ -48,7 +51,7 @@ ToolEnvironment::~ToolEnvironment()
 
 }
 
-bool ToolEnvironment::InitFromPackage()
+bool ToolEnvironment::InitFromDistribution()
 {
     toolPrefs_->Load();
 
@@ -75,8 +78,6 @@ bool ToolEnvironment::InitFromPackage()
 
     // AtomicNET
 
-    // atomicNETNuGetBinary_ = ToString("%sBuild/Managed/nuget/nuget.exe", rootSourceDir_.CString());       
-
 #ifdef ATOMIC_DEBUG
     String config = "Debug";
 #else
@@ -94,77 +95,35 @@ bool ToolEnvironment::InitFromPackage()
     return true;
 }
 
-bool ToolEnvironment::InitFromJSON(bool atomicTool)
+bool ToolEnvironment::Initialize(bool cli)
 {
+    bool result = true;
 
+    cli_ = cli;
     toolPrefs_->Load();
 
-    // make sure config path is initialized
-    GetDevConfigFilename();
+#ifdef ATOMIC_DEV_BUILD
 
-    FileSystem* fileSystem = GetSubsystem<FileSystem>();
+    SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
+    SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
+
+#else
 
-    if (atomicTool || !fileSystem->FileExists(devConfigFilename_))
+    if (!bootstrapping_)
     {
-        // default to build directories
+        result = InitFromDistribution();
 
+    }
+    else
+    {
         SetRootSourceDir(ATOMIC_ROOT_SOURCE_DIR);
         SetRootBuildDir(ATOMIC_ROOT_BUILD_DIR, true);
 
-        return true;
     }
-
-    File jsonFile(context_, devConfigFilename_);
-
-    if (!jsonFile.IsOpen())
-        return false;
-
-    String json;
-    jsonFile.ReadText(json);
-
-    if (!json.Length())
-        return false;
-
-    rapidjson::Document document;
-    if (document.Parse<0>(json.CString()).HasParseError())
-    {
-        return false;
-    }
-
-    const Value::Member* rootSourceDir = document.FindMember("rootSourceDir");
-    if (rootSourceDir && rootSourceDir->value.IsString())
-        SetRootSourceDir(rootSourceDir->value.GetString());
-    else
-        return false;
-
-    const Value::Member* rootBuildDir = document.FindMember("rootBuildDir");
-    if (rootBuildDir && rootBuildDir->value.IsString())
-        SetRootBuildDir(rootBuildDir->value.GetString(), true);
-    else
-        return false;
-
-
-    return true;
-
-}
-
-
-const String& ToolEnvironment::GetDevConfigFilename()
-{
-    if (devConfigFilename_.Length())
-        return devConfigFilename_;
-
-    FileSystem* fileSystem = GetSubsystem<FileSystem>();
-
-#ifdef ATOMIC_PLATFORM_OSX
-    devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
-#elif ATOMIC_PLATFORM_WINDOWS
-    devConfigFilename_ = fileSystem->GetUserDocumentsDir() + "AtomicGameEngine/toolEnv.json";
-#else
-    devConfigFilename_ = fileSystem->GetUserDocumentsDir() + ".atomicgameengine/toolEnv.json";
 #endif
 
-    return devConfigFilename_;
+    return result;
+
 }
 
 void ToolEnvironment::SetRootSourceDir(const String& sourceDir)
@@ -266,8 +225,6 @@ void ToolEnvironment::Dump()
 
     ATOMIC_LOGINFOF("Deployment Data Dir: %s", deploymentDataDir_.CString());
 
-    ATOMIC_LOGINFOF("Dev Config File: %s", devConfigFilename_.CString());
-
 }
 
 }

+ 12 - 7
Source/ToolCore/ToolEnvironment.h

@@ -46,10 +46,7 @@ public:
     ToolEnvironment(Context* context);
     virtual ~ToolEnvironment();
 
-    bool InitFromPackage();
-
-    // dev build init env from json
-    bool InitFromJSON(bool atomicTool = false);
+    bool Initialize(bool cli = false);
 
     /// Root source and build directories for development source tree builds
     void SetRootSourceDir(const String& sourceDir);
@@ -77,7 +74,8 @@ public:
 
     const String& GetToolDataDir() { return toolDataDir_; }
 
-    const String& GetDevConfigFilename();
+    // Returns true if we running from a command line tool (aka: AtomicTool)
+    bool GetCLI() { return cli_; }
 
     // AtomicNET
 
@@ -94,8 +92,15 @@ public:
 
     void Dump();
 
+    static void SetBootstrapping() { bootstrapping_ = true; }
+
 private:
 
+    bool InitFromDistribution();
+
+    // Whether we are running from a command line tool, such as AtomicTool
+    bool cli_;
+
     // root source directory (for development builds)
     String rootSourceDir_;
 
@@ -137,8 +142,6 @@ private:
     String iosBuildDir_;
     String webBuildDir_;
 
-    String devConfigFilename_;
-
     // AtomicNET
     String atomicNETRootDir_;
     String atomicNETCoreAssemblyDir_;
@@ -146,6 +149,8 @@ private:
     String monoExecutableDir_;
 
     SharedPtr<ToolPrefs> toolPrefs_;
+
+    static bool bootstrapping_;
 };
 
 }

+ 0 - 1
Source/ToolCore/ToolSystem.cpp

@@ -50,7 +50,6 @@ namespace ToolCore
 {
 
 ToolSystem::ToolSystem(Context* context) : Object(context),
-    cli_(false),
     updateDelta_(0.0f)
 {
     context_->RegisterSubsystem(new AssetDatabase(context_));

+ 0 - 11
Source/ToolCore/ToolSystem.h

@@ -47,9 +47,6 @@ public:
     Project* GetProject() { return project_; }
     void CloseProject();
 
-    const String& GetDataPath() { return dataPath_; }
-    void SetDataPath(const String& path) { dataPath_ = path; }
-
     // Platforms
     void RegisterPlatform(Platform* platform);
     Platform* GetPlatformByID(PlatformID platform);
@@ -58,16 +55,10 @@ public:
     void SetCurrentPlatform(PlatformID platform);
     Platform* GetCurrentPlatform();
 
-    void SetCLI() { cli_ = true; }
-    bool IsCLI() { return cli_; }
-
 private:
 
     void HandleUpdate(StringHash eventType, VariantMap& eventData);
 
-    /// Full path to data files
-    String dataPath_;
-
     SharedPtr<Platform> currentPlatform_;
 
     // PlatformID -> platform
@@ -75,8 +66,6 @@ private:
 
     SharedPtr<Project> project_;
 
-    bool cli_;
-
     float updateDelta_;
 
 };