clang-format detection cleanup.

This commit is contained in:
Ben Vanik 2015-08-01 00:41:46 -07:00
parent 741685d7e8
commit 73d48e188b
3 changed files with 31 additions and 20 deletions

View File

@ -10,6 +10,12 @@ os:
- linux - linux
# - osx # - osx
addons:
apt:
packages:
- clang-3.7
- clang-format-3.7
git: git:
# We handle submodules ourselves in xenia-build setup. # We handle submodules ourselves in xenia-build setup.
submodules: false submodules: false

View File

@ -215,6 +215,27 @@ def git_submodule_update():
]) ])
def get_clang_format_binary():
"""Finds a clang-format binary. Aborts if none is found.
Returns:
A path to the clang-format executable.
"""
attempts = [
'C:\\Program Files (x86)\\LLVM\\bin\\clang-format.exe',
'clang-format-3.7',
'clang-format',
]
for binary in attempts:
if os.path.exists(binary):
return binary
print 'ERROR: clang-format is not on PATH'
print 'LLVM is available from http://llvm.org/releases/download.html'
print 'At least version 3.7 is required.'
print 'See docs/style_guide.md for instructions on how to get it.'
sys.exit(1)
def run_premake(target_os, action): def run_premake(target_os, action):
"""Runs premake on the main project with the given format. """Runs premake on the main project with the given format.
@ -744,15 +765,7 @@ class LintCommand(Command):
help='Lints all files changed relative to origin/master.') help='Lints all files changed relative to origin/master.')
def execute(self, args, pass_args, cwd): def execute(self, args, pass_args, cwd):
clang_format_binary = 'clang-format' clang_format_binary = get_clang_format_binary()
win32_binary = 'C:\\Program Files (x86)\\LLVM\\bin\\clang-format.exe'
if os.path.exists(win32_binary):
clang_format_binary = win32_binary
if not has_bin(clang_format_binary):
print 'ERROR: clang-format is not on PATH'
print 'LLVM is available from http://llvm.org/releases/download.html'
print 'See docs/style_guide.md for instructions on how to get it'
return 1
difftemp = '.difftemp.txt' difftemp = '.difftemp.txt'
@ -791,7 +804,7 @@ class LintCommand(Command):
difftemp, difftemp,
]) ])
shell_call([ shell_call([
'type', 'type' if sys.platform=='win32' else 'cat',
difftemp, difftemp,
]) ])
if os.path.exists(difftemp): os.remove(difftemp) if os.path.exists(difftemp): os.remove(difftemp)
@ -851,15 +864,7 @@ class FormatCommand(Command):
help='Formats all files changed relative to origin/master.') help='Formats all files changed relative to origin/master.')
def execute(self, args, pass_args, cwd): def execute(self, args, pass_args, cwd):
clang_format_binary = 'clang-format' clang_format_binary = get_clang_format_binary()
win32_binary = 'C:\\Program Files (x86)\\LLVM\\bin\\clang-format.exe'
if os.path.exists(win32_binary):
clang_format_binary = win32_binary
if not has_bin(clang_format_binary):
print 'ERROR: clang-format is not on PATH'
print 'LLVM is available from http://llvm.org/releases/download.html'
print 'See docs/style_guide.md for instructions on how to get it'
return 1
if args['all']: if args['all']:
all_files = [os.path.join(root, name) all_files = [os.path.join(root, name)

View File

@ -2,4 +2,4 @@
# #
# Useful bash aliases and completions. # Useful bash aliases and completions.
alias xb='python xenia-build.py' alias xb='python xenia-build'