From 73d48e188b849a718a7c11a79338a745e5a0d0fd Mon Sep 17 00:00:00 2001 From: Ben Vanik Date: Sat, 1 Aug 2015 00:41:46 -0700 Subject: [PATCH] clang-format detection cleanup. --- .travis.yml | 6 ++++++ xenia-build | 43 ++++++++++++++++++++++++------------------- xeniarc | 2 +- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1c36d54f9..ca48e25db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,12 @@ os: - linux # - osx +addons: + apt: + packages: + - clang-3.7 + - clang-format-3.7 + git: # We handle submodules ourselves in xenia-build setup. submodules: false diff --git a/xenia-build b/xenia-build index 00189e11f..158b36b77 100755 --- a/xenia-build +++ b/xenia-build @@ -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): """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.') def execute(self, args, pass_args, cwd): - clang_format_binary = 'clang-format' - 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 + clang_format_binary = get_clang_format_binary() difftemp = '.difftemp.txt' @@ -791,7 +804,7 @@ class LintCommand(Command): difftemp, ]) shell_call([ - 'type', + 'type' if sys.platform=='win32' else 'cat', 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.') def execute(self, args, pass_args, cwd): - clang_format_binary = 'clang-format' - 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 + clang_format_binary = get_clang_format_binary() if args['all']: all_files = [os.path.join(root, name) diff --git a/xeniarc b/xeniarc index d7cb3cdea..ed988280c 100644 --- a/xeniarc +++ b/xeniarc @@ -2,4 +2,4 @@ # # Useful bash aliases and completions. -alias xb='python xenia-build.py' +alias xb='python xenia-build'