Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Spotless use of clang-format optional and disabled by default for now #1393

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 19 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,32 @@ java {
spotless {
java {
toggleOffOn()
removeUnusedImports()
// FIXME: gives unclosed string literal in ScriptRunner.java with spotless 6.23.3.
// removeUnusedImports()
importOrder()
// trimTrailingWhitespace()
// cleanthat()
// 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 {
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