| 365 | } |
| 366 | |
| 367 | static bool resolveLibraryRoot(TestReport::IOutput& console, StringSpan explicitOverride, bool explicitOverrideProvided, |
| 368 | StringSpan executablePath, StringSpan applicationRoot, StringPath& libraryRoot) |
| 369 | { |
| 370 | StartupAttempt attempts[16]; |
| 371 | size_t numAttempts = 0; |
| 372 | #if defined(SC_LIBRARY_ROOT) |
| 373 | const StringSpan compiledLibraryRoot = |
| 374 | StringSpan::fromNullTerminated(SC_COMPILER_LIBRARY_PATH, StringEncoding::Utf8); |
| 375 | #else |
| 376 | const StringSpan compiledLibraryRoot; |
| 377 | #endif |
| 378 | |
| 379 | if (explicitOverrideProvided) |
| 380 | { |
| 381 | StringPath candidate; |
| 382 | if (candidate.assign(explicitOverride)) |
| 383 | { |
| 384 | StringPath normalizedCandidate; |
| 385 | if (normalizeNativePath(candidate.view(), normalizedCandidate)) |
| 386 | { |
| 387 | candidate = move(normalizedCandidate); |
| 388 | } |
| 389 | recordAttempt(attempts, 16, numAttempts, "explicit override", candidate.view()); |
| 390 | if (validateLibraryRoot(candidate.view())) |
| 391 | { |
| 392 | return libraryRoot.assign(candidate.view()) ? true : false; |
| 393 | } |
| 394 | } |
| 395 | reportLibraryRootFailure(console, applicationRoot, attempts, numAttempts, explicitOverride, true, |
| 396 | compiledLibraryRoot); |
| 397 | return false; |
| 398 | } |
| 399 | |
| 400 | if (resolveCompiledLibraryRoot(executablePath, libraryRoot, attempts, 16, numAttempts)) |
| 401 | return true; |
| 402 | |
| 403 | if (resolveLibraryRootByWalkingParents(applicationRoot, "application root parent", libraryRoot, attempts, 16, |
| 404 | numAttempts)) |
| 405 | { |
| 406 | return true; |
| 407 | } |
| 408 | |
| 409 | StringPath executableDirectory; |
| 410 | if (getDirectoryName(executablePath, executableDirectory) and |
| 411 | resolveLibraryRootByWalkingParents(executableDirectory.view(), "executable directory parent", libraryRoot, |
| 412 | attempts, 16, numAttempts)) |
| 413 | { |
| 414 | return true; |
| 415 | } |
| 416 | |
| 417 | StringPath currentWorkingDirectory; |
| 418 | if (!getCurrentWorkingDirectory(currentWorkingDirectory).isEmpty() and |
| 419 | resolveLibraryRootByWalkingParents(currentWorkingDirectory.view(), "working directory parent", libraryRoot, |
| 420 | attempts, 16, numAttempts)) |
| 421 | { |
| 422 | return true; |
| 423 | } |
| 424 |
no test coverage detected