Skip to content

Commit 7b1f9a3

Browse files
authored
Merge pull request #2475 from Fusioon/versioned-so
Allow versioned .so in ImportAttribute
2 parents 80bba4b + 03f1afd commit 7b1f9a3

1 file changed

Lines changed: 46 additions & 6 deletions

File tree

IDEHelper/Compiler/BfSystem.cpp

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -522,16 +522,56 @@ BfMethodDef::~BfMethodDef()
522522

523523
BfImportKind BfMethodDef::GetImportKindFromPath(const StringImpl& filePath)
524524
{
525-
String fileExt = GetFileExtension(filePath);
526-
527-
if ((fileExt.Equals(".DYLIB", StringImpl::CompareKind_OrdinalIgnoreCase)) ||
528-
(fileExt.Equals(".SO", StringImpl::CompareKind_OrdinalIgnoreCase)) ||
529-
(fileExt.Equals(".DLL", StringImpl::CompareKind_OrdinalIgnoreCase)) ||
530-
(fileExt.Equals(".EXE", StringImpl::CompareKind_OrdinalIgnoreCase)))
525+
if ((filePath.EndsWith(".DYLIB", StringImpl::CompareKind_OrdinalIgnoreCase)) ||
526+
(filePath.EndsWith(".SO", StringImpl::CompareKind_OrdinalIgnoreCase)) ||
527+
(filePath.EndsWith(".DLL", StringImpl::CompareKind_OrdinalIgnoreCase)) ||
528+
(filePath.EndsWith(".EXE", StringImpl::CompareKind_OrdinalIgnoreCase)))
531529
{
532530
return BfImportKind_Import_Dynamic;
533531
}
534532

533+
if ((filePath.EndsWith(".A", StringImpl::CompareKind_OrdinalIgnoreCase)) ||
534+
(filePath.EndsWith(".LIB", StringImpl::CompareKind_OrdinalIgnoreCase)))
535+
{
536+
return BfImportKind_Import_Static;
537+
}
538+
539+
540+
// Check for versioned .so libs
541+
const int pathLength = filePath.length();
542+
int allowedDotsRemaining = 4; // Allow 3 version numbers + .so
543+
int lastDotIndex = pathLength;
544+
545+
for (int i = pathLength - 1; i >= 0; i--)
546+
{
547+
char c = filePath[i];
548+
549+
if ((c == '/') || (c == '\\'))
550+
{
551+
break;
552+
}
553+
554+
if ((c == '.'))
555+
{
556+
if ((--allowedDotsRemaining >= 0) && (i != lastDotIndex - 1))
557+
{
558+
lastDotIndex = i;
559+
continue;
560+
}
561+
562+
break;
563+
}
564+
}
565+
566+
if ((lastDotIndex != pathLength))
567+
{
568+
String fileExt = filePath.Substring(lastDotIndex);
569+
if ((fileExt.StartsWith(".SO.", StringImpl::CompareKind_OrdinalIgnoreCase)))
570+
{
571+
return BfImportKind_Import_Dynamic;
572+
}
573+
}
574+
535575
return BfImportKind_Import_Static;
536576
}
537577

0 commit comments

Comments
 (0)