buildversion: Add debugging messages
Add ability to output debug messages from the buildversion.py build script. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
8c12694b8a
commit
fa7545ab2d
|
@ -4,7 +4,7 @@
|
||||||
# Copyright (C) 2015 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2015 Kevin O'Connor <kevin@koconnor.net>
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# 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 = """
|
VERSION_FORMAT = """
|
||||||
/* DO NOT EDIT! This is an autogenerated file. See scripts/buildversion.py. */
|
/* 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
|
# Run program and return the specified output
|
||||||
def check_output(prog):
|
def check_output(prog):
|
||||||
|
logging.debug("Running %s" % (repr(prog),))
|
||||||
try:
|
try:
|
||||||
process = subprocess.Popen(shlex.split(prog), stdout=subprocess.PIPE)
|
process = subprocess.Popen(shlex.split(prog), stdout=subprocess.PIPE)
|
||||||
output = process.communicate()[0]
|
output = process.communicate()[0]
|
||||||
retcode = process.poll()
|
retcode = process.poll()
|
||||||
except OSError:
|
except OSError:
|
||||||
|
logging.debug("Exception on run: %s" % (traceback.format_exc(),))
|
||||||
return ""
|
return ""
|
||||||
|
logging.debug("Got (code=%s): %s" % (retcode, repr(output)))
|
||||||
if retcode:
|
if retcode:
|
||||||
return ""
|
return ""
|
||||||
try:
|
try:
|
||||||
return output.decode()
|
return output.decode()
|
||||||
except UnicodeError:
|
except UnicodeError:
|
||||||
|
logging.debug("Exception on decode: %s" % (traceback.format_exc(),))
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
# Obtain version info from "git" program
|
# Obtain version info from "git" program
|
||||||
def git_version():
|
def git_version():
|
||||||
if not os.path.exists('.git'):
|
if not os.path.exists('.git'):
|
||||||
|
logging.debug("No '.git' file/directory found")
|
||||||
return ""
|
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
|
# Look for version in a ".version" file. Official release tarballs
|
||||||
# have this file (see scripts/tarball.sh).
|
# have this file (see scripts/tarball.sh).
|
||||||
def file_version():
|
def file_version():
|
||||||
if not os.path.isfile('.version'):
|
if not os.path.isfile('.version'):
|
||||||
|
logging.debug("No '.version' file found")
|
||||||
return ""
|
return ""
|
||||||
try:
|
try:
|
||||||
f = open('.version', 'r')
|
f = open('.version', 'r')
|
||||||
ver = f.readline().strip()
|
ver = f.readline().strip()
|
||||||
f.close()
|
f.close()
|
||||||
except OSError:
|
except OSError:
|
||||||
|
logging.debug("Exception on read: %s" % (traceback.format_exc(),))
|
||||||
return ""
|
return ""
|
||||||
|
logging.debug("Got .version: %s" % (repr(ver),))
|
||||||
return ver
|
return ver
|
||||||
|
|
||||||
# Generate an output file with the version information
|
# Generate an output file with the version information
|
||||||
def write_version(outfile, version, toolstr):
|
def write_version(outfile, version, toolstr):
|
||||||
|
logging.debug("Write file %s and %s" % (repr(version), repr(toolstr)))
|
||||||
sys.stdout.write("Version: %s\n" % (version,))
|
sys.stdout.write("Version: %s\n" % (version,))
|
||||||
f = open(outfile, 'w')
|
f = open(outfile, 'w')
|
||||||
f.write(VERSION_FORMAT % (version, toolstr))
|
f.write(VERSION_FORMAT % (version, toolstr))
|
||||||
|
@ -74,6 +85,8 @@ def tool_versions(tools):
|
||||||
continue
|
continue
|
||||||
# Check for any version conflicts
|
# Check for any version conflicts
|
||||||
if versions[isbinutils] and versions[isbinutils] != ver:
|
if versions[isbinutils] and versions[isbinutils] != ver:
|
||||||
|
logging.debug("Mixed version %s vs %s" % (
|
||||||
|
repr(versions[isbinutils]), repr(ver)))
|
||||||
vers[isbinutils] = "mixed"
|
vers[isbinutils] = "mixed"
|
||||||
continue
|
continue
|
||||||
versions[isbinutils] = ver
|
versions[isbinutils] = ver
|
||||||
|
@ -88,11 +101,15 @@ def main():
|
||||||
help="extra version string to append to version")
|
help="extra version string to append to version")
|
||||||
opts.add_option("-t", "--tools", dest="tools", default="",
|
opts.add_option("-t", "--tools", dest="tools", default="",
|
||||||
help="list of build programs to extract version from")
|
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()
|
options, args = opts.parse_args()
|
||||||
if len(args) != 1:
|
if len(args) != 1:
|
||||||
opts.error("Incorrect arguments")
|
opts.error("Incorrect arguments")
|
||||||
outfile = args[0]
|
outfile = args[0]
|
||||||
|
if options.verbose:
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
cleanbuild, toolstr = tool_versions(options.tools)
|
cleanbuild, toolstr = tool_versions(options.tools)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue