From a3e072bb89b2ef34d49458c78c1c67ee65e5d2a3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=89ric=20Araujo?= Date: Sat, 30 Jul 2011 21:34:04 +0200 Subject: [PATCH] =?utf8?q?Let=20=E2=80=9Cmake=20patchcheck=E2=80=9D=20work?= =?utf8?q?=20for=20out-of-dir=20builds=20(#9860)?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Tools/scripts/patchcheck.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Tools/scripts/patchcheck.py b/Tools/scripts/patchcheck.py index 13b8ba44b6..9eb367defe 100755 --- a/Tools/scripts/patchcheck.py +++ b/Tools/scripts/patchcheck.py @@ -4,11 +4,15 @@ import sys import shutil import os.path import subprocess +import sysconfig import reindent import untabify +SRCDIR = sysconfig.get_config_var('srcdir') + + def n_files_str(count): """Return 'N file(s)' with the proper plurality on 'file'.""" return "{} file{}".format(count, "s" if count != 1 else "") @@ -36,7 +40,7 @@ def status(message, modal=False, info=None): info=lambda x: n_files_str(len(x))) def changed_files(): """Get the list of changed or added files from the VCS.""" - if os.path.isdir('.hg'): + if os.path.isdir(os.path.join(SRCDIR, '.hg')): vcs = 'hg' cmd = 'hg status --added --modified --no-status' elif os.path.isdir('.svn'): @@ -75,7 +79,7 @@ def normalize_whitespace(file_paths): reindent.makebackup = False # No need to create backups. fixed = [] for path in (x for x in file_paths if x.endswith('.py')): - if reindent.check(path): + if reindent.check(os.path.join(SRCDIR, path)): fixed.append(path) return fixed @@ -85,10 +89,11 @@ def normalize_c_whitespace(file_paths): """Report if any C files """ fixed = [] for path in file_paths: - with open(path, 'r') as f: + abspath = os.path.join(SRCDIR, path) + with open(abspath, 'r') as f: if '\t' not in f.read(): continue - untabify.process(path, 8, verbose=False) + untabify.process(abspath, 8, verbose=False) fixed.append(path) return fixed @@ -99,13 +104,14 @@ ws_re = re.compile(br'\s+(\r?\n)$') def normalize_docs_whitespace(file_paths): fixed = [] for path in file_paths: + abspath = os.path.join(SRCDIR, path) try: - with open(path, 'rb') as f: + with open(abspath, 'rb') as f: lines = f.readlines() new_lines = [ws_re.sub(br'\1', line) for line in lines] if new_lines != lines: - shutil.copyfile(path, path + '.bak') - with open(path, 'wb') as f: + shutil.copyfile(abspath, abspath + '.bak') + with open(abspath, 'wb') as f: f.writelines(new_lines) fixed.append(path) except Exception as err: -- 2.40.0