From 3dbd0b4069e26e5502cd1efea73ea84779220c07 Mon Sep 17 00:00:00 2001 From: Niclas Finne Date: Tue, 9 Jan 2024 17:50:47 +0100 Subject: [PATCH] build.gradle: only use clang-format when specified --- build.gradle | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index d68916d3a..6fad5643b 100644 --- a/build.gradle +++ b/build.gradle @@ -26,15 +26,25 @@ spotless { // formatAnnotations() // Use a different clang-format binary with -PclangFormat=clang-format-15. - def clangFormatBinary = (String) project.findProperty('clangFormat') ?: 'clang-format' - def clangOutput = new ByteArrayOutputStream() - exec { - commandLine clangFormatBinary, '--version' - standardOutput = clangOutput + // FIXME: make clang-format default in the future + // def clangFormatBinary = (String) project.findProperty('clangFormat') ?: 'clang-format' + def clangFormatBinary = (String) project.findProperty('clangFormat') + if (clangFormatBinary) { + try { + // Try to read clang-format version if not specified + def clangOutput = new ByteArrayOutputStream() + exec { + commandLine clangFormatBinary, '--version' + standardOutput = clangOutput + } + def clangVersion = (String) (clangOutput.toString() =~ /\d+\.\d+\.\d+/)[0] + clangFormat(clangVersion).pathToExe(clangFormatBinary).style('file') + } catch (IndexOutOfBoundsException ignored) { + logger.warn("Failed to parse version when running '{} --version'", clangFormatBinary) + } catch (Exception e) { + logger.warn("Failed to run '{} --version': {}", clangFormatBinary, e.getMessage()) + } } - def clangVersion = (String) (clangOutput.toString() =~ /\d+\.\d+\.\d+/)[0] - // FIXME: enable clangFormat in the future. -// clangFormat(clangVersion).pathToExe(clangFormatBinary).style('file') } }