Skip to content

Commit

Permalink
moved template and project stuff into their own directories
Browse files Browse the repository at this point in the history
  • Loading branch information
DeaSTL committed Jan 24, 2024
1 parent a265516 commit 60632ae
Show file tree
Hide file tree
Showing 24 changed files with 160 additions and 22 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ CPMAddPackage(




file(GLOB_RECURSE SOURCES RELATIVE ${CMAKE_SOURCE_DIR}
"src/**.cpp"
"src/**.c"
Expand Down
2 changes: 1 addition & 1 deletion include/Frate/Generators.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once
#include <Frate/Interface.hpp>
#include <Frate/Project/Config.hpp>
#include <Frate/Project/TemplateMeta.hpp>
#include <Frate/Template/Meta.hpp>
#include <Frate/Utils/CLIPrompt.hpp>
#include <inja.hpp>
#include <vector>
Expand Down
58 changes: 58 additions & 0 deletions include/Frate/Project/Cache.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <string>
#include <nlohmann/json.hpp>
#include <Frate/FrateException.hpp>

namespace Frate::Project {
class OverrideHashFailure : public FrateException {
public:
OverrideHashFailure(const std::string &message) : FrateException(message) {}
};

class Config;
class Cache {
private:
std::string build_command{"cmake --build ."};
std::string test_command{"ctest"};
std::string run_command{"./bin/"};
std::string override_change_hash;
std::shared_ptr<Config> config;

public:
Cache(std::shared_ptr<Config> config) : config(config) {}



// Getters
std::string &getBuildCommand() { return build_command; }

std::string &getTestCommand() { return test_command; }

std::string &getRunCommand() { return run_command; }

std::string &getOverrideChangeHash() { return override_change_hash; }

// Setters

void setBuildCommand(const std::string &build_command) {
this->build_command = build_command;
}

void setTestCommand(const std::string &test_command) {
this->test_command = test_command;
}

void setRunCommand(const std::string &run_command) {
this->run_command = run_command;
}

void setOverrideChangeHash(const std::string &override_change_hash) {
this->override_change_hash = override_change_hash;
}

void generateOverrideChangeHash();

friend void from_json(const nlohmann::json &json_obj, Cache &cache_obj);

friend void to_json(nlohmann::json &json_obj, const Cache &cache_obj);
};
} // namespace Frate::Project
13 changes: 5 additions & 8 deletions include/Frate/Project/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "Frate/Dependency.hpp"
#include "Frate/Project/Mode.hpp"
#include "Frate/Project/ProjectPrompt.hpp"
#include "Frate/Project/TemplateConfig.hpp"
#include "Frate/Project/TemplateMeta.hpp"
#include "Frate/Template/Config.hpp"
#include "Frate/Template/Meta.hpp"
#include <Frate/Package.hpp>
#include <Frate/RemoteServer.hpp>
#include <filesystem>
Expand All @@ -13,12 +13,6 @@
#include <vector>

namespace Frate::Project {
class Cache {
private:
std::string build_command{"cmake --build ."};
std::string test_command{"ctest"};
std::string run_command{"./bin/"};
};

class Config {

Expand All @@ -42,9 +36,12 @@ namespace Frate::Project {
std::string compiler{"g++"};
std::string license{""};
std::string default_mode{"Release"};

//Moving to cache
std::string build_command{"cmake --build ."};
std::string test_command{"ctest"};
std::string run_command{"./bin/"};

std::vector<Mode> modes{Mode("Release", {"-O2"}), Mode("Debug", {"-g"}),
Mode("Test", {"-g"})};
std::vector<std::string> authors{};
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "Frate/Project/TemplateIndexEntry.hpp"
#include "Frate/Project/TemplateMeta.hpp"
#include "Frate/Template/IndexEntry.hpp"
#include "Frate/Template/Meta.hpp"
#include <Frate/Project/Config.hpp>
#include <vector>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "Frate/Constants.hpp"
#include "Frate/Project/TemplateIndexEntry.hpp"
#include "Frate/Template/IndexEntry.hpp"
#include <nlohmann/json.hpp>
#include <string>
#include <unordered_map>
Expand Down
2 changes: 1 addition & 1 deletion include/Frate/Utils/Config.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once
#include "Frate/System/Capabilities.hpp"
#include <Frate/Project/TemplateManager.hpp>
#include <Frate/Template/Manager.hpp>
#include <Frate/RemoteServer.hpp>
#include <vector>

Expand Down
25 changes: 25 additions & 0 deletions include/Frate/Utils/Crypto/md5.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once
#include <Frate/FrateException.hpp>
#include <array>
#include <openssl/md5.h>
#include <string>

namespace Frate::Utils {
class MD5FailedToEncode : public FrateException {
public:
MD5FailedToEncode(const std::string &message) : FrateException(message) {}
};

class MD5Encoder {
private:
std::array<unsigned char, MD5_DIGEST_LENGTH> md5_hash_buffer = {0};
std::string digest;

public:
MD5Encoder() = default;
MD5Encoder &intake(std::string &input);
[[nodiscard]] std::string &getDigest(){ return digest;}
};


} // namespace Frate::Utils
5 changes: 5 additions & 0 deletions src/Command/Helpers/Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Frate/Command/Actions/Run.hpp"
#include "Frate/Command/Actions/Update.hpp"
#include "Frate/Command/Actions/Watch.hpp"
#include <Frate/Project/Cache.hpp>
#include "Frate/Project/Config.hpp"
#include "Frate/Utils/Logging.hpp"
#include "cxxopts.hpp"
Expand Down Expand Up @@ -111,6 +112,10 @@ namespace Frate::Command {
//
// TargetPackageHandler add_handler(inter);

Project::Cache cache(inter->pro);

cache.generateOverrideChangeHash();

OptionsInit::Main(inter);
inter->parse();
if (inter->args->count("version")) {
Expand Down
37 changes: 37 additions & 0 deletions src/Project/Cache.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include "Frate/Utils/Crypto/md5.hpp"
#include <Frate/Project/Cache.hpp>
#include <Frate/Project/Config.hpp>
#include <Frate/Utils/Logging.hpp>
#include <Frate/Utils/Macros.hpp>
#include <openssl/md5.h>
#include <sstream>

namespace Frate::Project {
void from_json(const nlohmann::json &json_obj, Cache &cache_obj) {
FROM_JSON_FIELD(cache_obj, build_command);
FROM_JSON_FIELD(cache_obj, test_command);
FROM_JSON_FIELD(cache_obj, run_command);
FROM_JSON_FIELD(cache_obj, override_change_hash);
}

void to_json(nlohmann::json &json_obj, const Cache &cache_obj) {
TO_JSON_FIELD(cache_obj, build_command);
TO_JSON_FIELD(cache_obj, test_command);
TO_JSON_FIELD(cache_obj, run_command);
TO_JSON_FIELD(cache_obj, override_change_hash);
}

void Cache::generateOverrideChangeHash() {

Utils::MD5Encoder encoder;

std::stringstream entry_time;

for (auto &dir_entry : std::filesystem::recursive_directory_iterator(
this->config->path / "override")) {
entry_time << dir_entry.last_write_time().time_since_epoch().count();
}
std::string entry_time_str = entry_time.str();
this->override_change_hash = encoder.intake(entry_time_str).getDigest();
}
} // namespace Frate::Project
2 changes: 1 addition & 1 deletion src/Command/Helpers/Project.cpp → src/Project/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <Frate/Generators.hpp>
#include <Frate/Project/Config.hpp>
#include <Frate/Project/ProjectPrompt.hpp>
#include <Frate/Project/TemplateConfig.hpp>
#include <Frate/Template/Config.hpp>
#include <Frate/Utils/Macros.hpp>
#include <fstream>
#include <nlohmann/json_fwd.hpp>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <Frate/Project/Config.hpp>
#include <Frate/Project/TemplateConfig.hpp>
#include <Frate/Template/Config.hpp>
#include <Frate/Utils/Logging.hpp>
#include <Frate/Utils/Macros.hpp>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Frate/Project/TemplateIndexEntry.hpp>
#include <Frate/Template/IndexEntry.hpp>
#include <Frate/Utils/Logging.hpp>
#include <Frate/Utils/Macros.hpp>

Expand Down
8 changes: 4 additions & 4 deletions src/Project/TemplateManager.cpp → src/Template/Manager.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#include "Frate/Constants.hpp"
#include "Frate/Project/TemplateIndexEntry.hpp"
#include "Frate/Project/TemplateMeta.hpp"
#include "Frate/Template/IndexEntry.hpp"
#include "Frate/Template/Meta.hpp"
#include "Frate/System/GitProvider.hpp"
#include "Frate/Utils/CLIPrompt.hpp"
#include "Frate/Utils/General.hpp"
#include "Frate/Utils/Logging.hpp"
#include <Frate/Frate.hpp>
#include <Frate/Project/Exceptions.hpp>
#include <Frate/Project/TemplateManager.hpp>
#include <Frate/Template/Exceptions.hpp>
#include <Frate/Template/Manager.hpp>
#include <Frate/Utils/FileFilter.hpp>
#include <Frate/Utils/Macros.hpp>
#include <filesystem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#include "Frate/Lua/TemplateEnvironment.hpp"
#include "Frate/Utils/General.hpp"
#include <Frate/Project/Config.hpp>
#include <Frate/Project/Exceptions.hpp>
#include <Frate/Project/TemplateMeta.hpp>
#include <Frate/Template/Exceptions.hpp>
#include <Frate/Template/Meta.hpp>
#include <Frate/Utils/FileFilter.hpp>
#include <Frate/Utils/Logging.hpp>
#include <Frate/Utils/Macros.hpp>
Expand Down
13 changes: 13 additions & 0 deletions src/Utils/Crypto/md5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <Frate/Utils/Crypto/md5.hpp>
#include <format>

namespace Frate::Utils {
MD5Encoder& MD5Encoder::intake(std::string &input){
MD5((unsigned char *)input.c_str(), input.size(), md5_hash_buffer.data());
digest = "";
for (int i = 0; i < 16; i++) {
digest += std::format("{:02x}", md5_hash_buffer[i]);
}
return *this;
}
}
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// LUCAS PAY ATTENTION TO IF THE HEADER IS .hpp OR .h
#include <format>
#ifdef TEST
#include <Frate/Test/Test.hpp>
#include <catch2/catch_session.hpp>
#else
#include <Frate/Interface.hpp>
#include <openssl/md5.h>
#endif

int main(int argc, char **argv) {
Expand Down

0 comments on commit 60632ae

Please sign in to comment.