From e0210a78b4f5b3bb1e592eb488ad15988011bc62 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Mon, 9 May 2011 15:01:41 +0000 Subject: [PATCH] Add make_version_header tool for populating libcef.dll version number and copyright year via version.h header file (issue #108). git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@224 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- cef.gyp | 11 +++++ libcef_dll/libcef_dll.rc | 12 ++--- tools/make_version_header.bat | 2 + tools/make_version_header.py | 82 +++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 tools/make_version_header.bat create mode 100644 tools/make_version_header.py diff --git a/cef.gyp b/cef.gyp index f63f76daa..c800bbdbe 100644 --- a/cef.gyp +++ b/cef.gyp @@ -223,6 +223,17 @@ 'tools/patch_source.bat.output', ], 'action': ['', '<@(_inputs)'], + }, + { + 'action_name': 'make_version_header', + 'msvs_cygwin_shell': 0, + 'inputs': [ + 'tools/make_version_header.bat', + ], + 'outputs': [ + 'tools/make_version_header.bat.output', + ], + 'action': ['', '<@(_inputs)'], }], }, { # OS!="win" 'actions': [{ diff --git a/libcef_dll/libcef_dll.rc b/libcef_dll/libcef_dll.rc index f690d8ad0..3925a96c1 100644 --- a/libcef_dll/libcef_dll.rc +++ b/libcef_dll/libcef_dll.rc @@ -10,6 +10,7 @@ #define APSTUDIO_HIDDEN_SYMBOLS #include "windows.h" #undef APSTUDIO_HIDDEN_SYMBOLS +#include "version.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS @@ -39,6 +40,7 @@ BEGIN "#define APSTUDIO_HIDDEN_SYMBOLS\r\n" "#include ""windows.h""\r\n" "#undef APSTUDIO_HIDDEN_SYMBOLS\r\n" + "#include ""version.h""\r\n" "\0" END @@ -57,8 +59,8 @@ END // VS_VERSION_INFO VERSIONINFO - FILEVERSION 1,0,0,1 - PRODUCTVERSION 1,0,0,1 + FILEVERSION 1,0,SVN_REVISION,0 + PRODUCTVERSION 1,0,SVN_REVISION,0 FILEFLAGSMASK 0x17L #ifdef _DEBUG FILEFLAGS 0x1L @@ -74,12 +76,12 @@ BEGIN BLOCK "040904b0" BEGIN VALUE "FileDescription", "Chromium Embedded Framework (CEF) Dynamic Link Library" - VALUE "FileVersion", "1, 0, 0, 1" + VALUE "FileVersion", "1.0." MAKE_STRING(SVN_REVISION) VALUE "InternalName", "libcef" - VALUE "LegalCopyright", "Copyright (C) 2009 The Chromium Embedded Framework Authors" + VALUE "LegalCopyright", "Copyright (C) " MAKE_STRING(COPYRIGHT_YEAR) " The Chromium Embedded Framework Authors" VALUE "OriginalFilename", "libcef.dll" VALUE "ProductName", "Chromium Embedded Framework (CEF) Dynamic Link Library" - VALUE "ProductVersion", "1, 0, 0, 1" + VALUE "ProductVersion", "1.0." MAKE_STRING(SVN_REVISION) END END BLOCK "VarFileInfo" diff --git a/tools/make_version_header.bat b/tools/make_version_header.bat new file mode 100644 index 000000000..520ba709d --- /dev/null +++ b/tools/make_version_header.bat @@ -0,0 +1,2 @@ +@echo off +svn info | ..\third_party\python_26\python.exe tools\make_version_header.py --header libcef_dll\version.h diff --git a/tools/make_version_header.py b/tools/make_version_header.py new file mode 100644 index 000000000..476368c33 --- /dev/null +++ b/tools/make_version_header.py @@ -0,0 +1,82 @@ +# 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')