Skip to content

Commit

Permalink
build.gradle: only use clang-format when specified
Browse files Browse the repository at this point in the history
  • Loading branch information
nfi committed Jan 10, 2024
1 parent 2d59a89 commit 3dbd0b4
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
}

Expand Down

0 comments on commit 3dbd0b4

Please sign in to comment.