From 283abdf3b2de08c9e5be764a02e89120fe7b67da Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Thu, 26 Jun 2014 16:03:52 +0600 Subject: Fix compilation error with scons and older pythons --- build_files/scons/tools/Blender.py | 22 +++++++++++----------- build_files/scons/tools/btools.py | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 12 deletions(-) (limited to 'build_files') diff --git a/build_files/scons/tools/Blender.py b/build_files/scons/tools/Blender.py index 72eafcdd681..e0f18480c74 100644 --- a/build_files/scons/tools/Blender.py +++ b/build_files/scons/tools/Blender.py @@ -413,7 +413,7 @@ def buildinfo(lenv, build_type): if os.path.isdir(os.path.abspath('.git')): try: - build_commit_timestamp = subprocess.check_output(args=['git', 'log', '-1', '--format=%ct']).strip() + build_commit_timestamp = btools.get_command_output(args=['git', 'log', '-1', '--format=%ct']).strip() except OSError: build_commit_timestamp = None if not build_commit_timestamp: @@ -425,42 +425,42 @@ def buildinfo(lenv, build_type): no_upstream = False try : - build_hash = subprocess.check_output(['git', 'rev-parse', '--short', '@{u}']).strip() + build_hash = btools.get_command_output(['git', 'rev-parse', '--short', '@{u}']).strip() except subprocess.CalledProcessError: # assume branch has no upstream configured build_hash = '' - build_branch = subprocess.check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip() + build_branch = btools.get_command_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD']).strip() if build_branch == 'HEAD': - master_check = subprocess.check_output(['git', 'branch', '--list', 'master', '--contains', build_hash]).strip() + master_check = btools.get_command_output(['git', 'branch', '--list', 'master', '--contains', build_hash]).strip() if master_check == 'master': build_branch = 'master' else: - head_hash = subprocess.check_output(['git', 'rev-parse', 'HEAD']).strip() - tag_hashes = subprocess.check_output(['git', 'show-ref', '--tags', '-d']) + head_hash = btools.get_command_output(['git', 'rev-parse', 'HEAD']).strip() + tag_hashes = btools.get_command_output(['git', 'show-ref', '--tags', '-d']) if tag_hashes.find(head_hash) != -1: build_branch = 'master' if build_hash == '': - build_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip() + build_hash = btools.get_command_output(['git', 'rev-parse', '--short', 'HEAD']).strip() no_upstream = True else: - older_commits = subprocess.check_output(['git', 'log', '--oneline', 'HEAD..@{u}']).strip() + older_commits = btools.get_command_output(['git', 'log', '--oneline', 'HEAD..@{u}']).strip() if older_commits: - build_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip() + build_hash = btools.get_command_output(['git', 'rev-parse', '--short', 'HEAD']).strip() # ## Check for local modifications has_local_changes = False # Update GIT index before getting dirty files os.system('git update-index -q --refresh') - changed_files = subprocess.check_output(['git', 'diff-index', '--name-only', 'HEAD', '--']).strip() + changed_files = btools.get_command_output(['git', 'diff-index', '--name-only', 'HEAD', '--']).strip() if changed_files: has_local_changes = True elif no_upstream == False: - unpushed_log = subprocess.check_output(['git', 'log', '--oneline', '@{u}..']).strip() + unpushed_log = btools.get_command_output(['git', 'log', '--oneline', '@{u}..']).strip() has_local_changes = unpushed_log != '' if build_branch.startswith('blender-v'): diff --git a/build_files/scons/tools/btools.py b/build_files/scons/tools/btools.py index d22adfda5f6..83daef7c00b 100644 --- a/build_files/scons/tools/btools.py +++ b/build_files/scons/tools/btools.py @@ -14,6 +14,21 @@ import sys Variables = SCons.Variables BoolVariable = SCons.Variables.BoolVariable +def get_command_output(*popenargs, **kwargs): + if hasattr(subprocess, "check_output"): + return subprocess.check_output(*popenargs, **kwargs) + if 'stdout' in kwargs: + raise ValueError('stdout argument not allowed, it will be overridden.') + process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs) + output, unused_err = process.communicate() + retcode = process.poll() + if retcode: + cmd = kwargs.get("args") + if cmd is None: + cmd = popenargs[0] + raise + return output + def get_version(): import re @@ -57,7 +72,7 @@ def get_version(): def get_hash(): try: - build_hash = subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD']).strip() + build_hash = get_command_output(['git', 'rev-parse', '--short', 'HEAD']).strip() except OSError: build_hash = None print("WARNING: could not use git to retrieve current Blender repository hash...") -- cgit v1.2.3