| 675 | len -= 4; |
| 676 | } |
| 677 | size_t start = 0; |
| 678 | if (len >= 3 && fileName[0] == 'S' && fileName[1] == 'C' && fileName[2] == '-') { |
| 679 | start = 3; |
| 680 | len -= 3; |
| 681 | } |
| 682 | if (len == 0) { |
| 683 | return String_duplicate("tool"); |
| 684 | } |
| 685 | char* result = (char*)malloc(len + 1); |
| 686 | if (!result) return NULL; |
| 687 | memcpy(result, fileName + start, len); |
| 688 | result[len] = 0; |
| 689 | return result; |
| 690 | } |
| 691 | |
| 692 | int isSCBuildDefinitionSource(const char* toolPath) { |
| 693 | const char* fileName = Path_fileName(toolPath); |
| 694 | return strcmp(fileName, "SC-build.cpp") == 0; |
| 695 | } |
| 696 | |
| 697 | char* buildBuiltInToolSourcePath(const BootloaderArgs* args) { |
| 698 | char* toolCpp = Path_join(args->toolSourceDir, "SC-"); |
| 699 | toolCpp = (char*)realloc(toolCpp, strlen(toolCpp) + strlen(args->toolName) + strlen(".cpp") + 1); |
| 700 | if (toolCpp) { |
| 701 | strcat(toolCpp, args->toolName); |
| 702 | strcat(toolCpp, ".cpp"); |
| 703 | } |
| 704 | return toolCpp; |
| 705 | } |
| 706 | |
| 707 | char* resolveToolSource(BootloaderArgs* args, int* builtInTool) { |
| 708 | *builtInTool = 1; |
| 709 | |
| 710 | char* toolCpp = buildBuiltInToolSourcePath(args); |
| 711 | if (FileSystem_exists(toolCpp)) { |
| 712 | return toolCpp; |
| 713 | } |
| 714 | |
| 715 | char* potentialCpp = String_duplicate(args->toolName); |
| 716 | if (FileSystem_exists(potentialCpp)) { |
| 717 | free(toolCpp); |
| 718 | *builtInTool = 0; |
| 719 | |
| 720 | char* toolIdentity = deriveToolIdentity(potentialCpp); |
| 721 | if (!toolIdentity) { |
no test coverage detected