@@ -200,35 +200,11 @@ DependencyScanningCASFilesystem::getOriginal(cas::CASID InputDataID) {
200
200
return Blob.takeError ();
201
201
}
202
202
203
- // / Whitelist file extensions that should be minimized, treating no extension as
204
- // / a source file that should be minimized.
205
- // /
206
- // / This is kinda hacky, it would be better if we knew what kind of file Clang
207
- // / was expecting instead.
208
- static bool shouldScanForDirectivesBasedOnExtension (StringRef Filename) {
209
- StringRef Ext = llvm::sys::path::extension (Filename);
210
- if (Ext.empty ())
211
- return true ; // C++ standard library
212
- return llvm::StringSwitch<bool >(Ext)
213
- .CasesLower (" .c" , " .cc" , " .cpp" , " .c++" , " .cxx" , true )
214
- .CasesLower (" .h" , " .hh" , " .hpp" , " .h++" , " .hxx" , true )
215
- .CasesLower (" .m" , " .mm" , true )
216
- .CasesLower (" .i" , " .ii" , " .mi" , " .mmi" , true )
217
- .CasesLower (" .def" , " .inc" , true )
218
- .Default (false );
219
- }
220
-
221
203
static bool shouldCacheStatFailures (StringRef Filename) {
222
204
StringRef Ext = llvm::sys::path::extension (Filename);
223
205
if (Ext.empty ())
224
206
return false ; // This may be the module cache directory.
225
- return shouldScanForDirectivesBasedOnExtension (
226
- Filename); // Only cache stat failures on source files.
227
- }
228
-
229
- bool DependencyScanningCASFilesystem::shouldScanForDirectives (
230
- StringRef RawFilename) {
231
- return shouldScanForDirectivesBasedOnExtension (RawFilename);
207
+ return true ;
232
208
}
233
209
234
210
llvm::cas::CachingOnDiskFileSystem &
@@ -274,10 +250,6 @@ DependencyScanningCASFilesystem::lookupPath(const Twine &Path) {
274
250
return LookupPathResult{&Entry, std::error_code ()};
275
251
}
276
252
277
- if (shouldScanForDirectives (PathRef))
278
- scanForDirectives (*CAS.getReference (*FileID), PathRef, Entry.DepTokens ,
279
- Entry.DepDirectives );
280
-
281
253
Entry.Buffer = std::move (*Buffer);
282
254
Entry.Status = llvm::vfs::Status (
283
255
PathRef, MaybeStatus->getUniqueID (),
@@ -362,7 +334,18 @@ DependencyScanningCASFilesystem::openFileForRead(const Twine &Path) {
362
334
std::optional<ArrayRef<dependency_directives_scan::Directive>>
363
335
DependencyScanningCASFilesystem::getDirectiveTokens (const Twine &Path) {
364
336
LookupPathResult Result = lookupPath (Path);
365
- if (Result.Entry && !Result.Entry ->DepDirectives .empty ())
366
- return ArrayRef (Result.Entry ->DepDirectives );
337
+
338
+ if (Result.Entry ) {
339
+ if (Result.Entry ->DepDirectives .empty ()) {
340
+ SmallString<256 > PathStorage;
341
+ StringRef PathRef = Path.toStringRef (PathStorage);
342
+ FileEntry &Entry = const_cast <FileEntry &>(*Result.Entry );
343
+ scanForDirectives (*Entry.CASContents , PathRef, Entry.DepTokens ,
344
+ Entry.DepDirectives );
345
+ }
346
+
347
+ if (!Result.Entry ->DepDirectives .empty ())
348
+ return ArrayRef (Result.Entry ->DepDirectives );
349
+ }
367
350
return std::nullopt;
368
351
}
0 commit comments