| 62 | return processLimiter.close(); |
| 63 | } |
| 64 | Result runFormatTool(Tool::Arguments& arguments) |
| 65 | { |
| 66 | SmallString<256> clangFormat; |
| 67 | static constexpr StringView wantedVersion = "20.1.8"; |
| 68 | if (not Tools::findSystemClangFormat(arguments.console, wantedVersion, clangFormat)) |
| 69 | { |
| 70 | StringView additionalArgs[1]; |
| 71 | Tool::Arguments args = arguments; |
| 72 | args.tool = "packages"; |
| 73 | args.action = "install"; |
| 74 | additionalArgs[0] = "clang"; |
| 75 | args.arguments = {additionalArgs}; |
| 76 | // If no system installed clang-format (matching version 20.1.8) has been found, we install a local copy. |
| 77 | Tools::Package clangPackage; |
| 78 | SC_TRY(runPackageTool(args, &clangPackage)); |
| 79 | SC_TRY(StringBuilder::format(clangFormat, "{}/bin/clang-format", clangPackage.installDirectoryLink)); |
| 80 | } |
| 81 | arguments.console.print("Using: {}\n", clangFormat); |
| 82 | |
| 83 | if (arguments.action == "execute") |
| 84 | { |
| 85 | return Tools::formatSourceFiles(Tools::FormatSources::Execute, clangFormat.view(), |
| 86 | arguments.libraryDirectory.view()); |
| 87 | } |
| 88 | else if (arguments.action == "check") |
| 89 | { |
| 90 | return Tools::formatSourceFiles(Tools::FormatSources::Check, clangFormat.view(), |
| 91 | arguments.libraryDirectory.view()); |
| 92 | } |
| 93 | else |
| 94 | { |
| 95 | return Result::Error("SC-format unknown action (supported \"execute\" or \"check\")"); |
| 96 | } |
| 97 | } |
| 98 | #if !defined(SC_TOOLS_COMPILED_SEPARATELY) && !defined(SC_TOOLS_IMPORT) |
| 99 | StringView Tool::getToolName() { return "SC-format"; } |
| 100 | StringView Tool::getDefaultAction() { return "execute"; } |