83 lines
2.6 KiB
Python
83 lines
2.6 KiB
Python
|
# Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||
|
# reserved. Use of this source code is governed by a BSD-style license that
|
||
|
# can be found in the LICENSE file.
|
||
|
|
||
|
from cef_parser import *
|
||
|
import datetime
|
||
|
from optparse import OptionParser
|
||
|
import os
|
||
|
import shutil
|
||
|
import sys
|
||
|
|
||
|
# cannot be loaded as a module
|
||
|
if __name__ != "__main__":
|
||
|
sys.stderr.write('This file cannot be loaded as a module!')
|
||
|
sys.exit()
|
||
|
|
||
|
|
||
|
# parse command-line options
|
||
|
disc = """
|
||
|
This utility creates the version header file.
|
||
|
"""
|
||
|
|
||
|
parser = OptionParser(description=disc)
|
||
|
parser.add_option('--header', dest='header', metavar='FILE',
|
||
|
help='output version header file [required]')
|
||
|
parser.add_option('-q', '--quiet',
|
||
|
action='store_true', dest='quiet', default=False,
|
||
|
help='do not output detailed status information')
|
||
|
(options, args) = parser.parse_args()
|
||
|
|
||
|
# the header option is required
|
||
|
if options.header is None:
|
||
|
parser.print_help(sys.stdout)
|
||
|
sys.exit()
|
||
|
|
||
|
def get_revision():
|
||
|
""" Retrieves the revision number from stdin. """
|
||
|
try:
|
||
|
# read the revision number
|
||
|
for line in sys.stdin:
|
||
|
if line[0:9] == "Revision:":
|
||
|
return line[10:-1];
|
||
|
raise IOError("Revision line not found.")
|
||
|
except IOError, (errno, strerror):
|
||
|
sys.stderr.write('Failed to read revision from stdin: ' + strerror)
|
||
|
raise
|
||
|
|
||
|
def get_year():
|
||
|
""" Returns the current year. """
|
||
|
return str(datetime.datetime.now().year)
|
||
|
|
||
|
def write_svn_header(file):
|
||
|
""" Creates the header file for the current revision if the revision has
|
||
|
changed or if the file doesn't already exist. """
|
||
|
if file_exists(file):
|
||
|
oldcontents = read_file(file)
|
||
|
else:
|
||
|
oldcontents = ''
|
||
|
|
||
|
newcontents = '// This file is generated by the make_version_header.py tool.\n'+\
|
||
|
'#ifndef _VERSION_H\n'+\
|
||
|
'#define _VERSION_H\n'+\
|
||
|
'\n'+\
|
||
|
'#define SVN_REVISION ' + get_revision() + '\n'+\
|
||
|
'#define COPYRIGHT_YEAR ' + get_year() + '\n'+\
|
||
|
'\n'+\
|
||
|
'#define DO_MAKE_STRING(p) #p\n'+\
|
||
|
'#define MAKE_STRING(p) DO_MAKE_STRING(p)\n'+\
|
||
|
'\n'+\
|
||
|
'#endif\n'
|
||
|
if newcontents != oldcontents:
|
||
|
write_file(file, newcontents)
|
||
|
return True
|
||
|
|
||
|
return False
|
||
|
|
||
|
written = write_svn_header(options.header)
|
||
|
if not options.quiet:
|
||
|
if written:
|
||
|
sys.stdout.write('File '+options.header+' updated.\n')
|
||
|
else:
|
||
|
sys.stdout.write('File '+options.header+' is already up to date.\n')
|