Skip to content

Commit

Permalink
Merge pull request #9 from mwasplund/mwasplund/tasks
Browse files Browse the repository at this point in the history
Mwasplund/tasks
  • Loading branch information
mwasplund authored Dec 28, 2019
2 parents e4c405e + e0dfdb0 commit 9e062d1
Show file tree
Hide file tree
Showing 87 changed files with 4,824 additions and 3,355 deletions.
2 changes: 1 addition & 1 deletion Dependencies/SoupBuildEx
2 changes: 1 addition & 1 deletion Dependencies/SoupTest
2 changes: 1 addition & 1 deletion Scripts/soupd.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
SET ScriptsDir=%~dp0
SET BinaryDir=%ScriptsDir%..\Source\Client\out\bin
REM - Use a copy of the final binary in case we are re-buiding itself
copy %BinaryDir%\Clang\Debug\Soup.exe %BinaryDir%\Soup.exe > nul
copy %BinaryDir%\MSVC\Debug\Soup.exe %BinaryDir%\Soup.exe > nul
copy %ClientDir%\LocalUserConfig.json %BinaryDir%\LocalUserConfig.json > nul
%BinaryDir%\Soup.exe %*
163 changes: 163 additions & 0 deletions Source/Build/Extension/BuildGraphNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// <copyright file="BuildGraphNode.h" company="Soup">
// Copyright (c) Soup. All rights reserved.
// </copyright>

#pragma once

namespace Soup::Build
{
/// <summary>
/// A graph node that represents a single operation in the build
/// </summary>
export class BuildGraphNode
{
private:
inline static std::atomic<int> UniqueId = 0;

public:
BuildGraphNode(
std::string title,
Path program,
std::string arguments,
Path workingDirectory,
std::vector<Path> inputFiles,
std::vector<Path> outputFiles) :
_id(UniqueId++),
_title(std::move(title)),
_program(std::move(program)),
_arguments(std::move(arguments)),
_workingDirectory(std::move(workingDirectory)),
_inputFiles(std::move(inputFiles)),
_outputFiles(std::move(outputFiles)),
_children()
{
}

BuildGraphNode(
std::string title,
Path program,
std::string arguments,
Path workingDirectory,
std::vector<Path> inputFiles,
std::vector<Path> outputFiles,
std::vector<std::shared_ptr<BuildGraphNode>> children) :
_id(UniqueId++),
_title(std::move(title)),
_program(std::move(program)),
_arguments(std::move(arguments)),
_workingDirectory(std::move(workingDirectory)),
_inputFiles(std::move(inputFiles)),
_outputFiles(std::move(outputFiles)),
_children(std::move(children))
{
}

static void AddLeafChild(
std::shared_ptr<BuildGraphNode>& parent,
std::shared_ptr<BuildGraphNode>& child)
{
if (parent == child)
{
// TODO: Clean up, the node has been added through a different path
return;
}

if (parent->_children.empty())
{
// Add the new leaf node
parent->_children.push_back(child);
}
else
{
// Continue on to the current parents children
AddLeafChild(parent->_children, child);
}
}

static void AddLeafChild(
std::vector<std::shared_ptr<BuildGraphNode>>& parents,
std::shared_ptr<BuildGraphNode>& child)
{
for (auto& parent : parents)
{
AddLeafChild(parent, child);
}
}

static void AddLeafChildren(
std::shared_ptr<BuildGraphNode>& parent,
std::vector<std::shared_ptr<BuildGraphNode>>& children)
{
if (parent->_children.empty())
{
// Add the new leaf node
parent->_children.insert(parent->_children.end(), children.begin(), children.end());
}
else
{
// Continue on to the current parents children
AddLeafChildren(parent->_children, children);
}
}

static void AddLeafChildren(
std::vector<std::shared_ptr<BuildGraphNode>>& parents,
std::vector<std::shared_ptr<BuildGraphNode>>& children)
{
for (auto& parent : parents)
{
AddLeafChildren(parent, children);
}
}

int GetId() const
{
return _id;
}

const std::string& GetTitle() const
{
return _title;
}

const Path& GetProgram() const
{
return _program;
}

const std::string& GetArguments() const
{
return _arguments;
}

const Path& GetWorkingDirectory() const
{
return _workingDirectory;
}

const std::vector<Path>& GetInputFiles() const
{
return _inputFiles;
}

const std::vector<Path>& GetOutputFiles() const
{
return _outputFiles;
}

const std::vector<std::shared_ptr<BuildGraphNode>>& GetChildren() const
{
return _children;
}

private:
int _id;
std::string _title;
Path _program;
std::string _arguments;
Path _workingDirectory;
std::vector<Path> _inputFiles;
std::vector<Path> _outputFiles;
std::vector<std::shared_ptr<BuildGraphNode>> _children;
};
}
21 changes: 21 additions & 0 deletions Source/Build/Extension/IBuildState.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// <copyright file="IBuildState.h" company="Soup">
// Copyright (c) Soup. All rights reserved.
// </copyright>

#pragma once

namespace Soup::Build
{
/// <summary>
/// Build State Extension interface
/// </summary>
class IBuildState
{
public:
virtual bool HasProperty(const char* name) = 0;
virtual const std::any& GetProperty(const char* name) = 0;
virtual void SetProperty(const char* name, std::any value) = 0;

virtual void AddBuildNode(std::shared_ptr<BuildGraphNode> node) = 0;
};
}
17 changes: 17 additions & 0 deletions Source/Build/Extension/IBuildSystem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// <copyright file="IBuildSystem.h" company="Soup">
// Copyright (c) Soup. All rights reserved.
// </copyright>

#pragma once

namespace Soup::Build
{
/// <summary>
/// Build System Extension interface
/// </summary>
export class IBuildSystem
{
public:
virtual void RegisterTask(std::shared_ptr<IBuildTask> task) = 0;
};
}
19 changes: 19 additions & 0 deletions Source/Build/Extension/IBuildTask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// <copyright file="IBuildTask.h" company="Soup">
// Copyright (c) Soup. All rights reserved.
// </copyright>

#pragma once
#include "IBuildState.h"

namespace Soup::Build
{
/// <summary>
/// Build Task Extension interface
/// </summary>
class IBuildTask
{
public:
virtual const char* GetName() = 0;
virtual void Execute(IBuildState& state) = 0;
};
}
16 changes: 16 additions & 0 deletions Source/Build/Extension/Module.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module;

#include <any>
#include <atomic>
#include <memory>
#include <string>
#include <vector>

export module SoupBuildExtension;
import Opal;

using namespace Opal;

#include "BuildGraphNode.h"
#include "IBuildTask.h"
#include "IBuildSystem.h"
1 change: 1 addition & 0 deletions Source/Build/Extension/Module.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "Module.cpp"
8 changes: 8 additions & 0 deletions Source/Build/Extension/Recipe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "SoupBuildExtension",
"version": "1.0.0",
"public": "Module.cpp",
"dependencies": [
"../../Opal/"
]
}
11 changes: 6 additions & 5 deletions Source/Client/Commands/BuildCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ namespace Soup::Client
// Load the user config
auto config = LocalUserConfigExtensions::LoadFromFile();

auto systemCompiler = std::make_shared<Compiler::Clang::Compiler>(
Path(config.GetClangToolPath()));
std::shared_ptr<ICompiler> runtimeCompiler = nullptr;
if (config.GetRuntimeCompiler() == "clang")
{
Expand All @@ -53,6 +51,9 @@ namespace Soup::Client
throw std::runtime_error("Unknown compiler.");
}

// TODOL Use the same system compiler for now
auto systemCompiler = runtimeCompiler;

auto workingDirectory = Path();
if (_options.Path.empty())
{
Expand Down Expand Up @@ -83,10 +84,10 @@ namespace Soup::Client
// Setup the build arguments
auto arguments = RecipeBuildArguments();
arguments.ForceRebuild = _options.Force;
if (!_options.Configuration.empty())
arguments.Configuration = _options.Configuration;
if (!_options.Flavor.empty())
arguments.Flavor = _options.Flavor;
else
arguments.Configuration = "release";
arguments.Flavor = "release";

// TODO: Hard coded to windows MSVC runtime libraries
// And we only trust the contig today
Expand Down
8 changes: 7 additions & 1 deletion Source/Client/Commands/RunCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,16 @@ namespace Soup::Client
return;
}

auto arguments = std::stringstream();
for (auto& argument : _options.Arguments)
{
arguments << argument << " ";
}

// Execute the requested target
auto result = System::IProcessManager::Current().Execute(
executablePath,
_options.Arguments,
arguments.str(),
workingDirectory);

// TODO: Directly pipe to output and make sure there is no extra newline
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Commands/VersionCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Soup::Client

// TODO var version = Assembly.GetExecutingAssembly().GetName().Version;
// Log::Message($"{version.Major}.{version.Minor}.{version.Build}");
Log::HighPriority("0.3.2");
Log::HighPriority("0.3.3");
}

private:
Expand Down
8 changes: 4 additions & 4 deletions Source/Client/Options/ArgumentsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ namespace Soup::Client
}

options->Verbosity = CheckVerbosity(unusedArgs);
options->Force = IsFlagSet("f", unusedArgs);
options->Force = IsFlagSet("force", unusedArgs);

auto configValue = std::string();
if (TryGetValueArgument("c", unusedArgs, configValue))
auto flavorValue = std::string();
if (TryGetValueArgument("flavor", unusedArgs, flavorValue))
{
options->Configuration = std::move(configValue);
options->Flavor = std::move(flavorValue);
}

result = std::move(options);
Expand Down
8 changes: 4 additions & 4 deletions Source/Client/Options/BuildOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ namespace Soup::Client
/// <summary>
/// Gets or sets a value indicating whether to force a build
/// </summary>
[[Args::Option('f', "force", Default = false, HelpText = "Force a rebuild.")]]
[[Args::Option("force", Default = false, HelpText = "Force a rebuild.")]]
bool Force;

/// <summary>
/// Gets or sets a value indicating what configuration to use
/// Gets or sets a value indicating what flavor to use
/// </summary>
[[Args::Option('c', "config", Default = false, HelpText = "Configuration.")]]
std::string Configuration;
[[Args::Option('f', "flavor", Default = false, HelpText = "Flavor.")]]
std::string Flavor;
};
}
4 changes: 3 additions & 1 deletion Source/Client/Recipe.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
{
"name": "Soup",
"version": "0.3.2",
"version": "0.3.3",
"type": "Executable",
"dependencies": [
"../Core",
"../Compiler/Clang",
"../Compiler/MSVC"
],
"devDependencies": [
],
"source": [
"Main.cpp"
],
Expand Down
Loading

0 comments on commit 9e062d1

Please sign in to comment.