Update cef_api_hash.h at build time if necessary (fixes issue #2922)

The cef_api_hash.h file was previously only updated when the translator tool
was run manually. Forgetting to run the translator tool after changing
include/internal/cef_types*.h files would result in cef_parser.py
incorrectly computing the CEF minor version number for future builds. By
updating this file automatically at build time the number of errors should be
reduced.
This commit is contained in:
Marshall Greenblatt
2020-04-30 15:59:23 -04:00
parent 7c6e53ddfb
commit d65483ae16
15 changed files with 232 additions and 199 deletions

View File

@ -3,146 +3,107 @@
# can be found in the LICENSE file.
from __future__ import absolute_import
from cef_parser import get_copyright
from cef_version import VersionFormatter
from date_util import *
from file_util import *
from optparse import OptionParser
import git_util as git
import os
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 write_version_header(header):
""" Creates the header file for the current revision and Chrome version information
if the information has changed or if the file doesn't already exist. """
def make_version_header(header):
if not git.is_checkout('.'):
raise Exception('Not a valid checkout')
if path_exists(header):
oldcontents = read_file(header)
else:
oldcontents = ''
result = get_copyright(full=True, translator=False) + \
"""//
// ---------------------------------------------------------------------------
//
// This file was generated by the make_version_header.py tool.
//
#ifndef CEF_INCLUDE_CEF_VERSION_H_
#define CEF_INCLUDE_CEF_VERSION_H_
#define CEF_VERSION "$VERSION$"
#define CEF_VERSION_MAJOR $VERSION_MAJOR$
#define CEF_VERSION_MINOR $VERSION_MINOR$
#define CEF_VERSION_PATCH $VERSION_PATCH$
#define CEF_COMMIT_NUMBER $COMMIT_NUMBER$
#define CEF_COMMIT_HASH "$COMMIT_HASH$"
#define COPYRIGHT_YEAR $YEAR$
#define CHROME_VERSION_MAJOR $CHROME_MAJOR$
#define CHROME_VERSION_MINOR $CHROME_MINOR$
#define CHROME_VERSION_BUILD $CHROME_BUILD$
#define CHROME_VERSION_PATCH $CHROME_PATCH$
#define DO_MAKE_STRING(p) #p
#define MAKE_STRING(p) DO_MAKE_STRING(p)
#ifndef APSTUDIO_HIDDEN_SYMBOLS
#include "include/internal/cef_export.h"
#ifdef __cplusplus
extern "C" {
#endif
// Returns CEF version information for the libcef library. The |entry|
// parameter describes which version component will be returned:
// 0 - CEF_VERSION_MAJOR
// 1 - CEF_VERSION_MINOR
// 2 - CEF_VERSION_PATCH
// 3 - CEF_COMMIT_NUMBER
// 4 - CHROME_VERSION_MAJOR
// 5 - CHROME_VERSION_MINOR
// 6 - CHROME_VERSION_BUILD
// 7 - CHROME_VERSION_PATCH
///
CEF_EXPORT int cef_version_info(int entry);
#ifdef __cplusplus
}
#endif
#endif // APSTUDIO_HIDDEN_SYMBOLS
#endif // CEF_INCLUDE_CEF_VERSION_H_
"""
year = get_year()
formatter = VersionFormatter()
commit_hash = formatter.get_cef_commit_components()['HASH']
commit_number = formatter.get_cef_commit_components()['NUMBER']
version = formatter.get_version_string()
# Substitute hash values for placeholders.
result = result.replace('$YEAR$', get_year())
result = result.replace('$VERSION$', formatter.get_version_string())
commit_components = formatter.get_cef_commit_components()
for key in ('HASH', 'NUMBER'):
result = result.replace('$COMMIT_%s$' % key, str(commit_components[key]))
version_parts = formatter.get_version_parts()
chrome = formatter.get_chrome_version_components()
version_defines = '#define CEF_VERSION "%s"\n' % version
for key in ('MAJOR', 'MINOR', 'PATCH'):
version_defines += '#define CEF_VERSION_%s %d\n' % (key, version_parts[key])
result = result.replace('$VERSION_%s$' % key, str(version_parts[key]))
newcontents = '// Copyright (c) '+year+' Marshall A. Greenblatt. All rights reserved.\n'+\
'//\n'+\
'// Redistribution and use in source and binary forms, with or without\n'+\
'// modification, are permitted provided that the following conditions are\n'+\
'// met:\n'+\
'//\n'+\
'// * Redistributions of source code must retain the above copyright\n'+\
'// notice, this list of conditions and the following disclaimer.\n'+\
'// * Redistributions in binary form must reproduce the above\n'+\
'// copyright notice, this list of conditions and the following disclaimer\n'+\
'// in the documentation and/or other materials provided with the\n'+\
'// distribution.\n'+\
'// * Neither the name of Google Inc. nor the name Chromium Embedded\n'+\
'// Framework nor the names of its contributors may be used to endorse\n'+\
'// or promote products derived from this software without specific prior\n'+\
'// written permission.\n'+\
'//\n'+\
'// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n'+\
'// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n'+\
'// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n'+\
'// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n'+\
'// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n'+\
'// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n'+\
'// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n'+\
'// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n'+\
'// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n'+\
'// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n'+\
'// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n'+\
'//\n'+\
'// ---------------------------------------------------------------------------\n'+\
'//\n'+\
'// This file is generated by the make_version_header.py tool.\n'+\
'//\n\n'+\
'#ifndef CEF_INCLUDE_CEF_VERSION_H_\n'+\
'#define CEF_INCLUDE_CEF_VERSION_H_\n\n'+\
version_defines+\
'#define CEF_COMMIT_NUMBER ' + commit_number + '\n'+\
'#define CEF_COMMIT_HASH "' + commit_hash + '"\n'+\
'#define COPYRIGHT_YEAR ' + year + '\n\n'+\
'#define CHROME_VERSION_MAJOR ' + chrome['MAJOR'] + '\n'+\
'#define CHROME_VERSION_MINOR ' + chrome['MINOR'] + '\n'+\
'#define CHROME_VERSION_BUILD ' + chrome['BUILD'] + '\n'+\
'#define CHROME_VERSION_PATCH ' + chrome['PATCH'] + '\n\n'+\
'#define DO_MAKE_STRING(p) #p\n'+\
'#define MAKE_STRING(p) DO_MAKE_STRING(p)\n\n'+\
'#ifndef APSTUDIO_HIDDEN_SYMBOLS\n\n'\
'#include "include/internal/cef_export.h"\n\n'+\
'#ifdef __cplusplus\n'+\
'extern "C" {\n'+\
'#endif\n\n'+\
'// Returns CEF version information for the libcef library. The |entry|\n'+\
'// parameter describes which version component will be returned:\n'+\
'// 0 - CEF_VERSION_MAJOR\n'+\
'// 1 - CEF_VERSION_MINOR\n'+\
'// 2 - CEF_VERSION_PATCH\n'+\
'// 3 - CEF_COMMIT_NUMBER\n'+\
'// 4 - CHROME_VERSION_MAJOR\n'+\
'// 5 - CHROME_VERSION_MINOR\n'+\
'// 6 - CHROME_VERSION_BUILD\n'+\
'// 7 - CHROME_VERSION_PATCH\n'+\
'///\n'+\
'CEF_EXPORT int cef_version_info(int entry);\n\n'+\
'#ifdef __cplusplus\n'+\
'}\n'+\
'#endif\n\n'+\
'#endif // APSTUDIO_HIDDEN_SYMBOLS\n\n'+\
'#endif // CEF_INCLUDE_CEF_VERSION_H_\n'
if newcontents != oldcontents:
write_file(header, newcontents)
return True
chrome_version_components = formatter.get_chrome_version_components()
for key in ('MAJOR', 'MINOR', 'BUILD', 'PATCH'):
result = result.replace('$CHROME_%s$' % key,
str(chrome_version_components[key]))
return False
return result
written = write_version_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')
def write_version_header(output):
result = make_version_header(output)
return write_file_if_changed(output, result)
def main(argv):
if len(argv) < 2:
print(("Usage:\n %s <output_filename>" % argv[0]))
sys.exit(-1)
write_version_header(argv[1])
if '__main__' == __name__:
main(sys.argv)