Skip to content

Commit 7ee66f7

Browse files
Merge pull request #7 from Neko-Box-Coder/CacheBuildsInConfig
Cache builds in config
2 parents a82b5d6 + fbbd1ea commit 7ee66f7

File tree

16 files changed

+1320
-128
lines changed

16 files changed

+1320
-128
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@
1919
[submodule "dylib"]
2020
path = External/dylib
2121
url = https://github.com/martin-olivier/dylib.git
22+
[submodule "ssTest"]
23+
path = External/ssTest
24+
url = https://github.com/Neko-Box-Coder/ssTest.git
25+
[submodule "CppOverride"]
26+
path = External/CppOverride
27+
url = https://github.com/Neko-Box-Coder/CppOverride.git

CMakeLists.txt

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ project(runcpp2)
88
set(CMAKE_CXX_STANDARD 11)
99

1010
option(RUNCPP2_UPDATE_DEFAULT_YAMLS "Update default yaml files" OFF)
11+
option(RUNCPP2_BUILD_TESTS "Build runcpp2 tests" OFF)
1112

1213
# =========================================================================
1314
# External Dependencies
@@ -26,6 +27,13 @@ configure_file( "${CMAKE_CURRENT_LIST_DIR}/External/cfgpath/cfgpath.h"
2627
"${CMAKE_CURRENT_LIST_DIR}/Include/cfgpath.h" COPYONLY)
2728

2829

30+
31+
if(RUNCPP2_BUILD_TESTS)
32+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/ssTest")
33+
endif()
34+
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/External/CppOverride")
35+
36+
2937
# =========================================================================
3038
# Generate yaml files as c
3139
# =========================================================================
@@ -85,11 +93,13 @@ add_executable(runcpp2
8593
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/PlatformUtil.cpp"
8694
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/runcpp2.cpp"
8795
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/StringUtil.cpp"
96+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/BuildsManager.cpp"
97+
8898
)
8999

90-
target_include_directories(runcpp2 PRIVATE "${CMAKE_CURRENT_LIST_DIR}/Include")
100+
target_include_directories(runcpp2 PRIVATE "${CMAKE_CURRENT_LIST_DIR}/Include")
91101

92-
target_link_libraries(runcpp2 PRIVATE ssLogger ghc_filesystem System2 ryml::ryml dylib)
102+
target_link_libraries(runcpp2 PRIVATE ssLogger ghc_filesystem System2 ryml::ryml dylib CppOverride)
93103

94104
if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
95105
set(STANDARD_COMPILE_FLAGS "/utf-8;/W1")
@@ -108,3 +118,24 @@ else()
108118
endif()
109119

110120
target_compile_options(runcpp2 PRIVATE ${STANDARD_COMPILE_FLAGS})
121+
122+
123+
124+
# TODO: Maybe move this to the UnitTests sub folder
125+
# Unit Tests
126+
if(RUNCPP2_BUILD_TESTS)
127+
add_executable(BuildsManagerTest "${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/BuildsManager.cpp"
128+
"${CMAKE_CURRENT_LIST_DIR}/Src/UnitTests/BuildsManagerTest.cpp")
129+
# "${CMAKE_CURRENT_LIST_DIR}/Src/UnitTests/BuildsManager/MockComponents.cpp")
130+
131+
target_include_directories(BuildsManagerTest PRIVATE "${CMAKE_CURRENT_LIST_DIR}/Include")
132+
target_compile_options(BuildsManagerTest PRIVATE "${STANDARD_COMPILE_FLAGS}")
133+
target_link_libraries(BuildsManagerTest PRIVATE ghc_filesystem CppOverride ssTest ssLogger)
134+
target_compile_definitions(BuildsManagerTest PRIVATE INTERNAL_RUNCPP2_UNIT_TESTS=1)
135+
# set_target_properties(BuildsManagerTest PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
136+
# LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
137+
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
138+
endif()
139+
140+
141+

External/CppOverride

Submodule CppOverride added at 67a2a50

External/ssTest

Submodule ssTest added at 4450794
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#ifndef RUNCPP2_UNIT_TESTS_BUILDS_MANAGER_MOCK_COMPONENTS_HPP
2+
#define RUNCPP2_UNIT_TESTS_BUILDS_MANAGER_MOCK_COMPONENTS_HPP
3+
4+
#include "ghc/filesystem.hpp"
5+
6+
#include "CppOverride.hpp"
7+
8+
#include <sstream>
9+
#include <type_traits>
10+
11+
extern CO_DECLARE_INSTANCE(OverrideInstance);
12+
13+
namespace ghc
14+
{
15+
namespace filesystem
16+
{
17+
CO_OVERRIDE_METHOD( OverrideInstance,
18+
bool,
19+
Mock_exists,
20+
(const path&, std::error_code&),
21+
/* no prepend */,
22+
noexcept)
23+
24+
CO_OVERRIDE_METHOD( OverrideInstance,
25+
bool,
26+
Mock_create_directories,
27+
(const path&, std::error_code&),
28+
/* no prepend */,
29+
noexcept)
30+
31+
CO_OVERRIDE_METHOD( OverrideInstance,
32+
bool,
33+
Mock_remove_all,
34+
(const path&, std::error_code&),
35+
/* no prepend */,
36+
noexcept)
37+
}
38+
}
39+
40+
namespace std
41+
{
42+
class Mock_ifstream
43+
{
44+
public:
45+
CO_OVERRIDE_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ifstream, const ghc::filesystem::path&)
46+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, std::string, rdbuf, ())
47+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, bool, is_open, ())
48+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, void, close, ())
49+
};
50+
51+
class Mock_ofstream
52+
{
53+
public:
54+
std::stringstream StringStream;
55+
56+
CO_OVERRIDE_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ofstream, const ghc::filesystem::path&)
57+
58+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, bool, is_open, ())
59+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, void, close, ())
60+
61+
template<typename T>
62+
friend Mock_ofstream& operator<<(Mock_ofstream&, T const&);
63+
};
64+
65+
template<typename T>
66+
class Mock_hash
67+
{
68+
static_assert(std::is_same<T, std::string>::value, "We are only mocking std string");
69+
public:
70+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, std::size_t, operator(), (T))
71+
};
72+
73+
template<typename T>
74+
inline Mock_ofstream& operator<<(Mock_ofstream& mockStream, T const& value)
75+
{
76+
//CO_OVERRIDE_IMPL(FreeFunctionOverrideInstance, Mock_ofstream&, (mockStream, value));
77+
mockStream.StringStream << value;
78+
return mockStream;
79+
}
80+
81+
inline Mock_ofstream& operator<<(Mock_ofstream& mockStream, std::ostream& (*pf)(std::ostream&))
82+
{
83+
//NOTE: This is called when std::endl is passed to the << operator.
84+
// Unfortunately function pointer is not tested/implemented yet for CppOverride
85+
// void* will do for now
86+
//void* dummyPointer = nullptr;
87+
//CO_OVERRIDE_IMPL(FreeFunctionOverrideInstance, Mock_ofstream&, (mockStream, dummyPointer));
88+
89+
mockStream.StringStream << pf;
90+
return mockStream;
91+
}
92+
}
93+
94+
#define exists Mock_exists
95+
#define create_directories Mock_create_directories
96+
#define remove_all Mock_remove_all
97+
#define ifstream Mock_ifstream
98+
#define ofstream Mock_ofstream
99+
#define hash Mock_hash
100+
101+
#if INTERNAL_RUNCPP2_UNDEF_MOCKS
102+
#undef exists
103+
#undef create_directories
104+
#undef remove_all
105+
#undef ifstream
106+
#undef ofstream
107+
#undef hash
108+
#endif
109+
110+
#endif

Include/runcpp2/BuildsManager.hpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#ifndef RUNCPP2_BUILDS_MANAGER_HPP
2+
#define RUNCPP2_BUILDS_MANAGER_HPP
3+
4+
#include "ghc/filesystem.hpp"
5+
6+
#include <unordered_map>
7+
8+
#if INTERNAL_RUNCPP2_UNIT_TESTS
9+
class BuildsManagerAccessor;
10+
#endif
11+
12+
namespace runcpp2
13+
{
14+
class BuildsManager
15+
{
16+
#if INTERNAL_RUNCPP2_UNIT_TESTS
17+
friend class ::BuildsManagerAccessor;
18+
#endif
19+
20+
private:
21+
const ghc::filesystem::path ConfigDirectory;
22+
23+
std::unordered_map<std::string, std::string> Mappings;
24+
std::unordered_map<std::string, std::string> ReverseMappings;
25+
26+
27+
const ghc::filesystem::path BuildDirectory;
28+
const ghc::filesystem::path MappingsFile;
29+
bool Initialized;
30+
31+
bool ParseMappings(const std::string& mappingsContent);
32+
33+
public:
34+
BuildsManager(const ghc::filesystem::path& configDirectory);
35+
BuildsManager(const BuildsManager& other);
36+
~BuildsManager();
37+
38+
bool Initialize();
39+
bool CreateBuildMapping(const ghc::filesystem::path& scriptPath);
40+
bool RemoveBuildMapping(const ghc::filesystem::path& scriptPath);
41+
bool HasBuildMapping(const ghc::filesystem::path& scriptPath);
42+
bool GetBuildMapping( const ghc::filesystem::path& scriptPath,
43+
ghc::filesystem::path& outPath);
44+
bool RemoveAllBuildsMappings();
45+
bool SaveBuildsMappings();
46+
};
47+
}
48+
49+
#endif

Include/runcpp2/CompilingLinking.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33

44
#include "runcpp2/Data/Profile.hpp"
55
#include "runcpp2/Data/ScriptInfo.hpp"
6+
7+
#include "ghc/filesystem.hpp"
8+
69
#include <string>
710

811
namespace runcpp2
912
{
10-
bool CompileAndLinkScript( const std::string& scriptPath,
13+
bool CompileAndLinkScript( const ghc::filesystem::path& buildDir,
14+
const std::string& scriptPath,
1115
const Data::ScriptInfo& scriptInfo,
1216
const std::vector<Data::DependencyInfo*>& availableDependencies,
1317
const Data::Profile& profile,

Include/runcpp2/DependenciesHelper.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,38 @@
44
#include "runcpp2/Data/DependencyInfo.hpp"
55
#include "runcpp2/Data/ScriptInfo.hpp"
66
#include "runcpp2/Data/Profile.hpp"
7+
8+
#include "ghc/filesystem.hpp"
79
#include <vector>
810

911
namespace runcpp2
1012
{
1113
bool GetDependenciesPaths( const std::vector<Data::DependencyInfo*>& availableDependencies,
1214
std::vector<std::string>& outCopiesPaths,
1315
std::vector<std::string>& outSourcesPaths,
14-
const std::string& scriptPath);
16+
const ghc::filesystem::path& scriptPath,
17+
const ghc::filesystem::path& buildDir);
1518

1619
bool IsDependencyAvailableForThisPlatform(const Data::DependencyInfo& dependency);
1720

1821
bool CleanupDependencies( const runcpp2::Data::Profile& profile,
19-
const std::string& scriptPath,
2022
const Data::ScriptInfo& scriptInfo,
2123
const std::vector<Data::DependencyInfo*>& availableDependencies,
2224
const std::vector<std::string>& dependenciesLocalCopiesPaths);
2325

2426
bool SetupDependencies( const runcpp2::Data::Profile& profile,
25-
const std::string& scriptPath,
27+
const ghc::filesystem::path& buildDir,
2628
const Data::ScriptInfo& scriptInfo,
2729
std::vector<Data::DependencyInfo*>& availableDependencies,
2830
const std::vector<std::string>& dependenciesLocalCopiesPaths,
2931
const std::vector<std::string>& dependenciesSourcePaths);
3032

3133
bool BuildDependencies( const runcpp2::Data::Profile& profile,
32-
const std::string& scriptPath,
3334
const Data::ScriptInfo& scriptInfo,
3435
const std::vector<Data::DependencyInfo*>& availableDependencies,
3536
const std::vector<std::string>& dependenciesLocalCopiesPaths);
3637

37-
bool CopyDependenciesBinaries( const std::string& scriptPath,
38+
bool CopyDependenciesBinaries( const ghc::filesystem::path& buildDir,
3839
const std::vector<Data::DependencyInfo*>& availableDependencies,
3940
const std::vector<std::string>& dependenciesCopiesPaths,
4041
const Data::Profile& profile,

Include/runcpp2/runcpp2.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace runcpp2
1717
EXECUTABLE,
1818
HELP,
1919
REMOVE_DEPENDENCIES,
20+
LOCAL,
2021
COUNT
2122
};
2223

0 commit comments

Comments
 (0)