|
31 | 31 |
|
32 | 32 | using namespace llvm;
|
33 | 33 | using namespace llbuild;
|
| 34 | +using namespace llbuild::basic; |
34 | 35 | using namespace llbuild::buildsystem;
|
35 | 36 | using namespace llbuild::unittests;
|
36 | 37 |
|
@@ -115,7 +116,8 @@ TEST(BuildSystemTaskTests, directoryContents) {
|
115 | 116 | /// Check the evaluation of directory signatures.
|
116 | 117 | TEST(BuildSystemTaskTests, directorySignature) {
|
117 | 118 | TmpDir tempDir{ __FUNCTION__ };
|
118 |
| - |
| 119 | + auto localFS = createLocalFileSystem(); |
| 120 | + |
119 | 121 | // Create a directory with sample files.
|
120 | 122 | SmallString<256> fileA{ tempDir.str() };
|
121 | 123 | sys::path::append(fileA, "fileA");
|
@@ -159,25 +161,39 @@ TEST(BuildSystemTaskTests, directorySignature) {
|
159 | 161 | // Modify the immediate directory and rebuild.
|
160 | 162 | SmallString<256> fileC{ tempDir.str() };
|
161 | 163 | sys::path::append(fileC, "fileC");
|
162 |
| - { |
| 164 | + |
| 165 | + // We must write the file in a loop until the directory actually changes (we |
| 166 | + // currently assume we can trust the directory file info to detect changes, |
| 167 | + // which is not always strictly true). |
| 168 | + auto dirFileInfo = localFS->getFileInfo(tempDir.str()); |
| 169 | + do { |
163 | 170 | std::error_code ec;
|
| 171 | + llvm::sys::fs::remove(fileC.str()); |
164 | 172 | llvm::raw_fd_ostream os(fileC, ec, llvm::sys::fs::F_Text);
|
165 | 173 | assert(!ec);
|
166 | 174 | os << "fileC";
|
167 |
| - } |
| 175 | + } while (dirFileInfo == localFS->getFileInfo(tempDir.str())); |
| 176 | + |
168 | 177 | auto resultB = system.build(keyToBuild);
|
169 | 178 | ASSERT_TRUE(resultB.hasValue() && resultB->isDirectoryTreeSignature());
|
170 | 179 | ASSERT_TRUE(resultA->toData() != resultB->toData());
|
171 | 180 |
|
172 | 181 | // Modify the subdirectory and rebuild.
|
173 | 182 | SmallString<256> subdirFileD{ subdirA };
|
174 | 183 | sys::path::append(subdirFileD, "fileD");
|
175 |
| - { |
| 184 | + |
| 185 | + // We must write the file in a loop until the directory actually changes (we |
| 186 | + // currently assume we can trust the directory file info to detect changes, |
| 187 | + // which is not always strictly true). |
| 188 | + dirFileInfo = localFS->getFileInfo(subdirA.str()); |
| 189 | + do { |
176 | 190 | std::error_code ec;
|
| 191 | + llvm::sys::fs::remove(subdirFileD.str()); |
177 | 192 | llvm::raw_fd_ostream os(subdirFileD, ec, llvm::sys::fs::F_Text);
|
178 | 193 | assert(!ec);
|
179 | 194 | os << "fileD";
|
180 |
| - } |
| 195 | + } while (dirFileInfo == localFS->getFileInfo(subdirA.str())); |
| 196 | + |
181 | 197 | auto resultC = system.build(keyToBuild);
|
182 | 198 | ASSERT_TRUE(resultC.hasValue() && resultC->isDirectoryTreeSignature());
|
183 | 199 | ASSERT_TRUE(resultA->toData() != resultB->toData());
|
|
0 commit comments