From fa7545ab2de9f81fed1a156a39778b138fb80bd5 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 10 Nov 2015 09:26:52 -0500 Subject: buildversion: Add debugging messages Add ability to output debug messages from the buildversion.py build script. Signed-off-by: Kevin O'Connor --- scripts/buildversion.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'scripts') diff --git a/scripts/buildversion.py b/scripts/buildversion.py index 1045049..ad47b90 100755 --- a/scripts/buildversion.py +++ b/scripts/buildversion.py @@ -4,7 +4,7 @@ # Copyright (C) 2015 Kevin O'Connor # # This file may be distributed under the terms of the GNU GPLv3 license. -import sys, os, subprocess, shlex, time, socket, optparse +import sys, os, subprocess, shlex, time, socket, optparse, logging, traceback VERSION_FORMAT = """ /* DO NOT EDIT! This is an autogenerated file. See scripts/buildversion.py. */ @@ -14,40 +14,51 @@ VERSION_FORMAT = """ # Run program and return the specified output def check_output(prog): + logging.debug("Running %s" % (repr(prog),)) try: process = subprocess.Popen(shlex.split(prog), stdout=subprocess.PIPE) output = process.communicate()[0] retcode = process.poll() except OSError: + logging.debug("Exception on run: %s" % (traceback.format_exc(),)) return "" + logging.debug("Got (code=%s): %s" % (retcode, repr(output))) if retcode: return "" try: return output.decode() except UnicodeError: + logging.debug("Exception on decode: %s" % (traceback.format_exc(),)) return "" # Obtain version info from "git" program def git_version(): if not os.path.exists('.git'): + logging.debug("No '.git' file/directory found") return "" - return check_output("git describe --tags --long --dirty").strip() + ver = check_output("git describe --tags --long --dirty").strip() + logging.debug("Got git version: %s" % (repr(ver),)) + return ver # Look for version in a ".version" file. Official release tarballs # have this file (see scripts/tarball.sh). def file_version(): if not os.path.isfile('.version'): + logging.debug("No '.version' file found") return "" try: f = open('.version', 'r') ver = f.readline().strip() f.close() except OSError: + logging.debug("Exception on read: %s" % (traceback.format_exc(),)) return "" + logging.debug("Got .version: %s" % (repr(ver),)) return ver # Generate an output file with the version information def write_version(outfile, version, toolstr): + logging.debug("Write file %s and %s" % (repr(version), repr(toolstr))) sys.stdout.write("Version: %s\n" % (version,)) f = open(outfile, 'w') f.write(VERSION_FORMAT % (version, toolstr)) @@ -74,6 +85,8 @@ def tool_versions(tools): continue # Check for any version conflicts if versions[isbinutils] and versions[isbinutils] != ver: + logging.debug("Mixed version %s vs %s" % ( + repr(versions[isbinutils]), repr(ver))) vers[isbinutils] = "mixed" continue versions[isbinutils] = ver @@ -88,11 +101,15 @@ def main(): help="extra version string to append to version") opts.add_option("-t", "--tools", dest="tools", default="", help="list of build programs to extract version from") + opts.add_option("-v", action="store_true", dest="verbose", + help="enable debug messages") options, args = opts.parse_args() if len(args) != 1: opts.error("Incorrect arguments") outfile = args[0] + if options.verbose: + logging.basicConfig(level=logging.DEBUG) cleanbuild, toolstr = tool_versions(options.tools) -- cgit v1.1