MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / resolveLibraryRoot

Function resolveLibraryRoot

Libraries/Testing/Testing.cpp:367–428  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

365}
366
367static 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

Callers 1

TestReportMethod · 0.85

Calls 12

fromNullTerminatedFunction · 0.85
normalizeNativePathFunction · 0.85
recordAttemptFunction · 0.85
validateLibraryRootFunction · 0.85
reportLibraryRootFailureFunction · 0.85
getDirectoryNameFunction · 0.85
assignMethod · 0.45
viewMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected