|
2 | 2 | // SPDX-License-Identifier: MIT |
3 | 3 | #include "Plugin.h" |
4 | 4 |
|
5 | | -#include "../FileSystemIterator/FileSystemIterator.h" |
6 | 5 | #include "../Foundation/Deferred.h" |
7 | 6 | #include "../Process/Internal/StringsArena.h" |
8 | 7 | #include "../Process/Process.h" |
|
13 | 12 | #if SC_PLATFORM_WINDOWS |
14 | 13 | #include "Internal/DebuggerWindows.inl" |
15 | 14 | #include "Internal/VisualStudioPathFinder.h" |
| 15 | + |
16 | 16 | #endif |
17 | 17 | #include "Internal/DynamicLibrary.inl" |
| 18 | +#include "Internal/PluginFileSystemIterator.h" |
18 | 19 |
|
19 | 20 | struct SC::PluginCompilerEnvironment::Internal |
20 | 21 | { |
@@ -293,36 +294,52 @@ SC::Result SC::PluginScanner::scanDirectory(const StringView directory, Span<Plu |
293 | 294 | { |
294 | 295 | ScannerState scannerState = {definitions}; |
295 | 296 |
|
296 | | - FileSystemIterator::FolderState recurseStack[16]; |
297 | | - FileSystemIterator fsIterator; |
298 | | - fsIterator.options.recursive = false; // Manually recurse only first level dirs |
299 | | - SC_TRY(fsIterator.init(directory, recurseStack)); |
300 | | - // Iterate each directory at first level and tentatively build a Plugin PluginDefinition. |
301 | | - // A plugin will be valid if only a single Plugin PluginDefinition will be parsed. |
302 | | - // Both no plugin definition (identity.identifier.isEmpty()) and multiple contradictory plugin |
303 | | - // definitions (multipleDefinitions) will prevent creation of the Plugin PluginDefinition. |
304 | | - while (fsIterator.enumerateNext()) |
| 297 | + StringPath pathBuffer; |
| 298 | + SC_TRY(pathBuffer.assign(directory)); |
| 299 | + |
| 300 | + PluginFileSystemIterator iterator; |
| 301 | + SC_TRY(iterator.init(directory)); |
| 302 | + PluginFileSystemIterator::Entry entry; |
| 303 | + while (iterator.next(entry)) |
305 | 304 | { |
306 | | - const auto& item = fsIterator.get(); |
307 | | - if (item.isDirectory() and item.level == 0) |
| 305 | + if (entry.name == SC_NATIVE_STR(".") or entry.name == SC_NATIVE_STR("..")) |
308 | 306 | { |
309 | | - // Immediately recurse to find candidates (enumerateNext will list files inside this folder) |
310 | | - SC_TRY(fsIterator.recurseSubdirectory()); |
311 | | - SC_TRY(scannerState.storeTentativePluginFolder(item.path)); |
| 307 | + continue; // skip . and .. |
312 | 308 | } |
313 | | - if (item.level == 1 and StringView(item.name).endsWith(SC_NATIVE_STR(".cpp"))) |
| 309 | + StringPath fullPath = pathBuffer; |
| 310 | + SC_TRY(fullPath.append(iterator.pathSeparator)); |
| 311 | + SC_TRY(fullPath.append(entry.name)); |
| 312 | + if (entry.isDirectory) |
314 | 313 | { |
315 | | - // Inside any of the folder that have been tentatively added |
316 | | - if (scannerState.multipleDefinitions) |
| 314 | + // Immediately recurse to find candidates |
| 315 | + SC_TRY(scannerState.storeTentativePluginFolder(fullPath.view())); |
| 316 | + // Scan subdirectory for .cpp files |
| 317 | + PluginFileSystemIterator subIterator; |
| 318 | + SC_TRY(subIterator.init(fullPath.view())); |
| 319 | + PluginFileSystemIterator::Entry subEntry; |
| 320 | + while (subIterator.next(subEntry)) |
317 | 321 | { |
318 | | - continue; |
| 322 | + if (subEntry.name == SC_NATIVE_STR(".") or subEntry.name == SC_NATIVE_STR("..")) |
| 323 | + { |
| 324 | + continue; // skip . and .. |
| 325 | + } |
| 326 | + StringPath subFullPath = fullPath; |
| 327 | + SC_TRY(subFullPath.append(subIterator.pathSeparator)); |
| 328 | + SC_TRY(subFullPath.append(subEntry.name)); |
| 329 | + if (!subEntry.isDirectory and subEntry.name.endsWith(SC_NATIVE_STR(".cpp"))) |
| 330 | + { |
| 331 | + // It's a regular file ending with .cpp |
| 332 | + if (scannerState.multipleDefinitions) |
| 333 | + { |
| 334 | + continue; |
| 335 | + } |
| 336 | + SC_TRY(scannerState.tryParseCandidate(subFullPath.view(), move(tempFileBuffer))); |
| 337 | + } |
319 | 338 | } |
320 | | - SC_TRY(scannerState.tryParseCandidate(item.path, move(tempFileBuffer))); |
321 | 339 | } |
322 | 340 | } |
323 | | - |
324 | 341 | scannerState.writeDefinitions(foundDefinitions); |
325 | | - return fsIterator.checkErrors(); |
| 342 | + return Result(true); |
326 | 343 | } |
327 | 344 | #if SC_PLATFORM_WINDOWS |
328 | 345 | struct SC::PluginCompiler::CompilerFinder |
@@ -421,20 +438,21 @@ SC::Result SC::PluginCompiler::findBestCompiler(PluginCompiler& compiler) |
421 | 438 | CompilerFinder compilerFinder; |
422 | 439 | for (const auto& basePath : rootPaths) |
423 | 440 | { |
424 | | - FileSystemIterator::FolderState recurseStack[16]; |
425 | | - FileSystemIterator fsIterator; |
426 | | - |
427 | | - StringView base = basePath.view(); |
428 | | - if (not fsIterator.init(base, recurseStack)) |
| 441 | + StringView base = basePath.view(); |
| 442 | + PluginFileSystemIterator iterator; |
| 443 | + if (not iterator.init(base)) |
429 | 444 | continue; |
430 | | - while (fsIterator.enumerateNext()) |
| 445 | + PluginFileSystemIterator::Entry entry; |
| 446 | + while (iterator.next(entry)) |
431 | 447 | { |
432 | | - if (fsIterator.get().isDirectory()) |
| 448 | + if (entry.isDirectory and entry.name != SC_NATIVE_STR(".") and entry.name != SC_NATIVE_STR("..")) |
433 | 449 | { |
434 | | - const StringView candidate = fsIterator.get().name; |
435 | | - SC_TRY(compilerFinder.tryFindCompiler(base, candidate, compiler)); |
| 450 | + SC_TRY(compilerFinder.tryFindCompiler(base, entry.name, compiler)); |
| 451 | + if (compilerFinder.found) |
| 452 | + break; |
436 | 453 | } |
437 | 454 | } |
| 455 | + |
438 | 456 | if (compilerFinder.found) |
439 | 457 | { |
440 | 458 | break; |
@@ -718,19 +736,21 @@ SC::Result SC::PluginSysroot::findBestSysroot(PluginCompiler::Type compilerType, |
718 | 736 | StringView baseDirectory = SC_NATIVE_STR("C:\\Program Files (x86)\\Windows Kits\\10"); |
719 | 737 | StringView baseInclude = SC_NATIVE_STR("C:\\Program Files (x86)\\Windows Kits\\10\\include"); |
720 | 738 |
|
721 | | - FileSystemIterator::FolderState recurseStack[16]; |
722 | | - |
723 | | - FileSystemIterator fsIterator; |
724 | | - SC_TRY_MSG(fsIterator.init(baseInclude, recurseStack), "Missing Windows Kits 10 directory"); |
725 | 739 | StringPath windowsSdkVersion; |
726 | | - while (fsIterator.enumerateNext()) |
| 740 | + StringView searchPath = SC_NATIVE_STR("C:\\Program Files (x86)\\Windows Kits\\10\\include"); |
| 741 | + |
| 742 | + PluginFileSystemIterator iterator; |
| 743 | + SC_TRY(iterator.init(searchPath)); |
| 744 | + PluginFileSystemIterator::Entry entry; |
| 745 | + while (iterator.next(entry)) |
727 | 746 | { |
728 | | - if (fsIterator.get().isDirectory()) |
| 747 | + if (entry.isDirectory and entry.name != SC_NATIVE_STR(".") and entry.name != SC_NATIVE_STR("..")) |
729 | 748 | { |
730 | | - SC_TRY(windowsSdkVersion.assign(fsIterator.get().name)); |
| 749 | + SC_TRY(windowsSdkVersion.assign(entry.name)); |
731 | 750 | break; |
732 | 751 | } |
733 | 752 | } |
| 753 | + |
734 | 754 | SC_TRY_MSG(not windowsSdkVersion.isEmpty(), "Cannot find Windows Kits 10 include directory") |
735 | 755 | switch (compilerType) |
736 | 756 | { |
@@ -804,8 +824,7 @@ SC::Result SC::PluginDynamicLibrary::load(const PluginCompiler& compiler, const |
804 | 824 | ::Sleep(400); // Sometimes file is locked... |
805 | 825 | #endif |
806 | 826 | lastErrorLogCopy = {errorStorage, sizeof(errorStorage) - 1}; |
807 | | - SC_TRY_MSG(compiler.link(definition, sysroot, compilerEnvironment, executablePath, lastErrorLogCopy), |
808 | | - "Link failes"); |
| 827 | + SC_TRY_MSG(compiler.link(definition, sysroot, compilerEnvironment, executablePath, lastErrorLogCopy), "Link fails"); |
809 | 828 | deferWrite.disarm(); |
810 | 829 | StringPath buffer; |
811 | 830 | SC_TRY(definition.getDynamicLibraryAbsolutePath(buffer)); |
|
0 commit comments