Skip to content

Commit 5d062a5

Browse files
Merge pull request #33 from Neko-Box-Coder/TrackIncludes
Tracking Include Files
2 parents 070ba01 + d847435 commit 5d062a5

17 files changed

+1509
-95
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ add_library(runcpp2 STATIC
145145
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/runcpp2.cpp"
146146
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/BuildsManager.cpp"
147147
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/PipelineSteps.cpp"
148+
"${CMAKE_CURRENT_LIST_DIR}/Src/runcpp2/IncludeManager.cpp"
148149
)
149150

150151
target_include_directories(runcpp2 PUBLIC "${CMAKE_CURRENT_LIST_DIR}/Include")
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#ifndef RUNCPP2_UNIT_TESTS_INCLUDE_MANAGER_MOCK_COMPONENTS_HPP
2+
#define RUNCPP2_UNIT_TESTS_INCLUDE_MANAGER_MOCK_COMPONENTS_HPP
3+
4+
#include "ghc/filesystem.hpp"
5+
#include "CppOverride.hpp"
6+
7+
#include <sstream>
8+
#include <type_traits>
9+
10+
extern CO_DECLARE_INSTANCE(OverrideInstance);
11+
12+
namespace ghc
13+
{
14+
namespace filesystem
15+
{
16+
CO_OVERRIDE_METHOD( OverrideInstance,
17+
bool,
18+
Mock_exists,
19+
(const path&, std::error_code&),
20+
/* no prepend */,
21+
noexcept)
22+
23+
CO_OVERRIDE_METHOD( OverrideInstance,
24+
bool,
25+
Mock_create_directories,
26+
(const path&, std::error_code&),
27+
/* no prepend */,
28+
noexcept)
29+
30+
CO_OVERRIDE_METHOD( OverrideInstance,
31+
file_time_type,
32+
Mock_last_write_time,
33+
(const path&, std::error_code&),
34+
/* no prepend */,
35+
noexcept)
36+
}
37+
}
38+
39+
namespace std
40+
{
41+
class Mock_ifstream
42+
{
43+
public:
44+
CO_OVERRIDE_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ifstream, const ghc::filesystem::path&)
45+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, bool, is_open, ())
46+
};
47+
48+
class Mock_ofstream
49+
{
50+
public:
51+
std::stringstream StringStream;
52+
53+
CO_OVERRIDE_MEMBER_METHOD_CTOR(OverrideInstance, Mock_ofstream, const ghc::filesystem::path&)
54+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, bool, is_open, ())
55+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, void, close, ())
56+
57+
template<typename T>
58+
friend Mock_ofstream& operator<<(Mock_ofstream&, T const&);
59+
};
60+
61+
template<typename T>
62+
class Mock_hash
63+
{
64+
static_assert(std::is_same<T, std::string>::value, "We are only mocking std string");
65+
public:
66+
CO_OVERRIDE_MEMBER_METHOD(OverrideInstance, std::size_t, operator(), (T))
67+
};
68+
69+
template<typename T>
70+
inline Mock_ofstream& operator<<(Mock_ofstream& mockStream, T const& value)
71+
{
72+
mockStream.StringStream << value;
73+
return mockStream;
74+
}
75+
76+
inline Mock_ofstream& operator<<(Mock_ofstream& mockStream, std::ostream& (*pf)(std::ostream&))
77+
{
78+
mockStream.StringStream << pf;
79+
return mockStream;
80+
}
81+
82+
inline bool Mock_getline(Mock_ifstream& stream, std::string& line)
83+
{
84+
CO_OVERRIDE_IMPL(OverrideInstance, bool, (stream, line));
85+
return false;
86+
}
87+
}
88+
89+
#define exists Mock_exists
90+
#define create_directories Mock_create_directories
91+
#define last_write_time Mock_last_write_time
92+
#define ifstream Mock_ifstream
93+
#define ofstream Mock_ofstream
94+
#define hash Mock_hash
95+
#define getline Mock_getline
96+
97+
#if INTERNAL_RUNCPP2_UNDEF_MOCKS
98+
#undef exists
99+
#undef create_directories
100+
#undef last_write_time
101+
#undef ifstream
102+
#undef ofstream
103+
#undef hash
104+
#undef getline
105+
#endif
106+
107+
#endif

Include/runcpp2/IncludeManager.hpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef RUNCPP2_INCLUDE_MANAGER_HPP
2+
#define RUNCPP2_INCLUDE_MANAGER_HPP
3+
4+
#include "ghc/filesystem.hpp"
5+
#include <unordered_map>
6+
#include <vector>
7+
8+
#if INTERNAL_RUNCPP2_UNIT_TESTS
9+
class IncludeManagerAccessor;
10+
#endif
11+
12+
namespace runcpp2
13+
{
14+
class IncludeManager
15+
{
16+
public:
17+
IncludeManager() = default;
18+
~IncludeManager() = default;
19+
20+
bool Initialize(const ghc::filesystem::path& buildDir);
21+
22+
bool WriteIncludeRecord(const ghc::filesystem::path& sourceFile,
23+
const std::vector<ghc::filesystem::path>& includes);
24+
25+
bool ReadIncludeRecord( const ghc::filesystem::path& sourceFile,
26+
std::vector<ghc::filesystem::path>& outIncludes,
27+
ghc::filesystem::file_time_type& outRecordTime);
28+
29+
bool NeedsUpdate( const ghc::filesystem::path& sourceFile,
30+
const std::vector<ghc::filesystem::path>& includes,
31+
const ghc::filesystem::file_time_type& recordTime) const;
32+
33+
private:
34+
#if INTERNAL_RUNCPP2_UNIT_TESTS
35+
friend class ::IncludeManagerAccessor;
36+
#endif
37+
38+
ghc::filesystem::path GetRecordPath(const ghc::filesystem::path& sourceFile) const;
39+
40+
ghc::filesystem::path IncludeRecordDir;
41+
};
42+
}
43+
44+
#endif

Include/runcpp2/ParseUtil.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ namespace runcpp2
3636
std::string GetValue(ryml::ConstNodeRef node);
3737
std::string GetKey(ryml::ConstNodeRef node);
3838
std::string GetEscapedYAMLString(const std::string& input);
39+
40+
bool ParseIncludes(const std::string& line, std::string& outIncludePath);
3941
}
4042

4143
#endif

Include/runcpp2/PipelineSteps.hpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
#include "runcpp2/Data/CmdOptions.hpp"
99

1010
#include "runcpp2/BuildsManager.hpp"
11+
#include "runcpp2/IncludeManager.hpp"
1112

1213
#include "ghc/filesystem.hpp"
1314

1415
#include <string>
1516
#include <vector>
17+
#include <unordered_map>
1618

1719
namespace runcpp2
1820
{
@@ -50,7 +52,8 @@ namespace runcpp2
5052
const ghc::filesystem::path& absoluteScriptPath,
5153
bool useLocalBuildDir,
5254
BuildsManager& outBuildsManager,
53-
ghc::filesystem::path& outBuildDir);
55+
ghc::filesystem::path& outBuildDir,
56+
IncludeManager& outIncludeManager);
5457

5558
PipelineResult CheckScriptInfoChanges( const ghc::filesystem::path& buildDir,
5659
const Data::ScriptInfo& scriptInfo,
@@ -116,6 +119,12 @@ namespace runcpp2
116119
const Data::Profile& currentProfile,
117120
const std::vector<Data::DependencyInfo*>& dependencies,
118121
std::vector<ghc::filesystem::path>& outIncludePaths);
122+
123+
using SourceIncludeMap = std::unordered_map<std::string, std::vector<ghc::filesystem::path>>;
124+
125+
bool GatherFilesIncludes( const std::vector<ghc::filesystem::path>& files,
126+
const std::vector<ghc::filesystem::path>& includePaths,
127+
SourceIncludeMap& outSourceIncludes);
119128
}
120129

121130

Include/runcpp2/runcpp2.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ namespace runcpp2
2525

2626
void SetLogLevel(const std::string& logLevel);
2727

28-
PipelineResult GetLatestSourceWriteTime(const std::string& scriptPath,
28+
PipelineResult CheckSourcesNeedUpdate( const std::string& scriptPath,
2929
const std::vector<Data::Profile>& profiles,
3030
const std::string& configPreferredProfile,
3131
const Data::ScriptInfo& scriptInfo,
32-
int64_t& outWriteTime);
32+
const std::unordered_map<CmdOptions, std::string>& currentOptions,
33+
bool& outNeedsUpdate);
3334

3435
PipelineResult StartPipeline( const std::string& scriptPath,
3536
const std::vector<Data::Profile>& profiles,

Src/Tests/BuildsManagerTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ int main(int argc, char** argv)
379379
ssTEST_OUTPUT_ASSERT( "CreateBuildMapping should succeed",
380380
buildsManager->CreateBuildMapping(scriptsPaths.at(2)), true);
381381
ssTEST_OUTPUT_ASSERT( "Hash script path", hashResult->LastStatusSucceed());
382-
ssLOG_DEBUG("hashResult->GetStatusCount(): " << hashResult->GetStatusCount());
382+
383+
ssTEST_OUTPUT_VALUES_WHEN_FAILED(hashResult->GetStatusCount());
383384

384385
ssTEST_OUTPUT_ASSERT( "New build mapping doesn't exist",
385386
newMappedBuildPathExistsResult->LastStatusSucceed());

Src/Tests/CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ target_include_directories(BuildsManagerTest PRIVATE "${CMAKE_CURRENT_LIST_DIR}/
66
target_compile_options(BuildsManagerTest PRIVATE "${STANDARD_COMPILE_FLAGS}")
77
target_link_libraries(BuildsManagerTest PRIVATE ghc_filesystem CppOverride ssTest ssLogger)
88
target_compile_definitions(BuildsManagerTest PRIVATE INTERNAL_RUNCPP2_UNIT_TESTS=1)
9-
# set_target_properties(BuildsManagerTest PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
10-
# LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests"
11-
# RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/tests")
9+
10+
add_executable(IncludeManagerTest "${CMAKE_CURRENT_LIST_DIR}/../runcpp2/IncludeManager.cpp"
11+
"${CMAKE_CURRENT_LIST_DIR}/IncludeManagerTest.cpp")
12+
13+
target_include_directories(IncludeManagerTest PRIVATE "${CMAKE_CURRENT_LIST_DIR}/../../Include")
14+
target_compile_options(IncludeManagerTest PRIVATE "${STANDARD_COMPILE_FLAGS}")
15+
target_link_libraries(IncludeManagerTest PRIVATE ghc_filesystem CppOverride ssTest ssLogger)
16+
target_compile_definitions(IncludeManagerTest PRIVATE INTERNAL_RUNCPP2_UNIT_TESTS=1)
1217

1318
function(create_data_test TEST_NAME)
1419
add_executable("${TEST_NAME}" "${CMAKE_CURRENT_LIST_DIR}/Data/${TEST_NAME}.cpp")

0 commit comments

Comments
 (0)