Skip to content

Commit c036aa4

Browse files
authored
Refresh wrappers after modifying source files. (#545)
* Refresh wrappers after change source files. * Move similar code to function.
1 parent dadb5e9 commit c036aa4

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

server/src/Synchronizer.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ Synchronizer::Synchronizer(BaseTestGen *testGen,
4444
: testGen(testGen), sizeContext(sizeContext) {
4545
}
4646

47-
bool Synchronizer::isProbablyOutdated(const fs::path &srcFilePath) const {
47+
long long Synchronizer::getFileOutdatedTime(const fs::path &filePath) const {
48+
return TimeUtils::convertFileToSystemClock(fs::last_write_time(filePath))
49+
.time_since_epoch()
50+
.count();
51+
}
52+
53+
bool Synchronizer::isProbablyOutdatedStubs(const fs::path &srcFilePath) const {
4854
fs::path stubFilePath = Paths::sourcePathToStubPath(testGen->projectContext, srcFilePath);
4955
if (!fs::exists(stubFilePath)) {
5056
return true;
@@ -58,22 +64,33 @@ bool Synchronizer::isProbablyOutdated(const fs::path &srcFilePath) const {
5864
} catch (...) {
5965
return true;
6066
}
61-
srcTimestamp = TimeUtils::convertFileToSystemClock(fs::last_write_time(srcFilePath))
62-
.time_since_epoch()
63-
.count();
67+
srcTimestamp = Synchronizer::getFileOutdatedTime(srcFilePath);
6468
return stubTimestamp <= srcTimestamp;
6569
}
6670

71+
bool Synchronizer::isProbablyOutdatedWrappers(const fs::path &srcFilePath) const {
72+
fs::path wrapperFilePath = Paths::getWrapperFilePath(testGen->projectContext, srcFilePath);
73+
if (!fs::exists(wrapperFilePath)) {
74+
return true;
75+
}
76+
long long wrapperTimestamp, srcTimestamp;
77+
wrapperTimestamp = Synchronizer::getFileOutdatedTime(wrapperFilePath);
78+
srcTimestamp = Synchronizer::getFileOutdatedTime(srcFilePath);
79+
return wrapperTimestamp <= srcTimestamp;
80+
}
81+
6782
CollectionUtils::FileSet Synchronizer::getOutdatedSourcePaths() const {
68-
return CollectionUtils::filterOut(getTargetSourceFiles(), [this](fs::path const &sourcePath) {
69-
return !isProbablyOutdated(sourcePath);
83+
auto allFiles = getTargetSourceFiles();
84+
auto outdatedSources = CollectionUtils::filterOut(getTargetSourceFiles(), [this](fs::path const &sourcePath) {
85+
return !isProbablyOutdatedWrappers(sourcePath);
7086
});
87+
return outdatedSources;
7188
}
7289

7390
StubSet Synchronizer::getOutdatedStubs() const {
7491
auto allFiles = getStubsFiles();
7592
auto outdatedStubs = CollectionUtils::filterOut(allFiles, [this](StubOperator const &stubOperator) {
76-
return !isProbablyOutdated(stubOperator.getSourceFilePath());
93+
return !isProbablyOutdatedStubs(stubOperator.getSourceFilePath());
7794
});
7895
return outdatedStubs;
7996
}

server/src/Synchronizer.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ class Synchronizer {
2727

2828
[[nodiscard]] std::unordered_set<StubOperator, HashUtils::StubHash> getOutdatedStubs() const;
2929

30-
bool isProbablyOutdated(const fs::path &srcFilePath) const;
30+
long long getFileOutdatedTime(const fs::path &filePath) const;
31+
32+
bool isProbablyOutdatedStubs(const fs::path &srcFilePath) const;
33+
34+
bool isProbablyOutdatedWrappers(const fs::path &srcFilePath) const;
3135

3236
bool removeStubIfSourceAbsent(const StubOperator &stub) const;
3337

0 commit comments

Comments
 (0)