We are able to call clang-format by shelling out to it on the system path, and we are able to cache its results by enforcing a version check on the binary. However, if it isn't on the path, or the version is wrong, we just show a helpful error message and let the user figure it out from there:
|
String howToInstall = "" + |
|
"You can download clang-format from https://releases.llvm.org and " + |
|
"then point Spotless to it with `pathToExe('/path/to/clang-format')` " + |
|
"or you can use your platform's package manager:" + |
|
"\n win: choco install llvm --version {version} (try dropping version if it fails)" + |
|
"\n mac: brew install clang-format (TODO: how to specify version?)" + |
|
"\n linux: apt install clang-format (try clang-format-{version} with dropped minor versions)"; |
|
String exeAbsPath = ForeignExe.nameAndVersion("clang-format", version) |
|
.pathToExe(pathToExe) |
|
.fixCantFind(howToInstall) |
|
.fixWrongVersion( |
|
"You can tell Spotless to use the version you already have with `clangFormat('{versionFound}')`" + |
|
"or you can download the currently specified version, {version}.\n" + howToInstall) |
|
.confirmVersionAndGetAbsolutePath(); |
It would be nice if we could handle this better, or at least have better instructions.
We are able to call
clang-formatby shelling out to it on the system path, and we are able to cache its results by enforcing a version check on the binary. However, if it isn't on the path, or the version is wrong, we just show a helpful error message and let the user figure it out from there:spotless/lib/src/main/java/com/diffplug/spotless/cpp/ClangFormatStep.java
Lines 70 to 83 in 608e128
It would be nice if we could handle this better, or at least have better instructions.