1# Copyright (c) 2019 The Chromium Embedded Framework Authors. All rights 2# reserved. Use of this source code is governed by a BSD-style license that 3# can be found in the LICENSE file. 4 5from __future__ import absolute_import 6from date_util import * 7from file_util import * 8from optparse import OptionParser 9import sys 10 11# cannot be loaded as a module 12if __name__ != "__main__": 13 sys.stderr.write('This file cannot be loaded as a module!') 14 sys.exit() 15 16# parse command-line options 17disc = """ 18This utility creates the config header file. 19""" 20parser = OptionParser(description=disc) 21parser.add_option( 22 '--header', 23 dest='header', 24 metavar='FILE', 25 help='output config header file [required]') 26parser.add_option( 27 '--cef_gn_config', 28 dest='cef_gn_config', 29 metavar='FILE', 30 help='input CEF gn config file [required]') 31parser.add_option( 32 '-q', 33 '--quiet', 34 action='store_true', 35 dest='quiet', 36 default=False, 37 help='do not output detailed status information') 38(options, args) = parser.parse_args() 39 40# the header option is required 41if options.header is None or options.cef_gn_config is None: 42 parser.print_help(sys.stdout) 43 sys.exit() 44 45 46def check_x11_build(gn_config): 47 """ Scan gn configuration file and decide whether it's x11 build or not """ 48 lines = read_file(gn_config).split("\n") 49 for line in lines: 50 parts = line.split('=', 1) 51 if (parts[0] == "use_x11" and 52 parts[1] == "false") or (parts[0] == "use_ozone" and 53 parts[1] == "true"): 54 return False 55 56 return True 57 58 59def write_config_header(header, cef_gn_config): 60 """ Creates the header file for the cef build configuration 61 if the information has changed or if the file doesn't already exist. """ 62 63 if not path_exists(cef_gn_config): 64 raise Exception('file ' + cef_gn_config + ' does not exist.') 65 66 if path_exists(header): 67 oldcontents = read_file(header) 68 else: 69 oldcontents = '' 70 71 year = get_year() 72 73 cef_x11_defines = "#define CEF_X11 1" if check_x11_build( 74 cef_gn_config) else "" 75 76 newcontents = '// Copyright (c) '+year+' Marshall A. Greenblatt. All rights reserved.\n'+\ 77 '//\n'+\ 78 '// Redistribution and use in source and binary forms, with or without\n'+\ 79 '// modification, are permitted provided that the following conditions are\n'+\ 80 '// met:\n'+\ 81 '//\n'+\ 82 '// * Redistributions of source code must retain the above copyright\n'+\ 83 '// notice, this list of conditions and the following disclaimer.\n'+\ 84 '// * Redistributions in binary form must reproduce the above\n'+\ 85 '// copyright notice, this list of conditions and the following disclaimer\n'+\ 86 '// in the documentation and/or other materials provided with the\n'+\ 87 '// distribution.\n'+\ 88 '// * Neither the name of Google Inc. nor the name Chromium Embedded\n'+\ 89 '// Framework nor the names of its contributors may be used to endorse\n'+\ 90 '// or promote products derived from this software without specific prior\n'+\ 91 '// written permission.\n'+\ 92 '//\n'+\ 93 '// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n'+\ 94 '// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n'+\ 95 '// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n'+\ 96 '// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n'+\ 97 '// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n'+\ 98 '// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n'+\ 99 '// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n'+\ 100 '// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n'+\ 101 '// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n'+\ 102 '// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n'+\ 103 '// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n'+\ 104 '//\n'+\ 105 '// ---------------------------------------------------------------------------\n'+\ 106 '//\n'+\ 107 '// This file is generated by the make_config_header.py tool.\n'+\ 108 '//\n\n'+\ 109 '#ifndef CEF_INCLUDE_CEF_CONFIG_H_\n'+\ 110 '#define CEF_INCLUDE_CEF_CONFIG_H_\n\n'+\ 111 '' + cef_x11_defines + '\n'+\ 112 '#endif // CEF_INCLUDE_CEF_CONFIG_H_\n' 113 if newcontents != oldcontents: 114 write_file(header, newcontents) 115 return True 116 return False 117 118 119written = write_config_header(options.header, options.cef_gn_config) 120if not options.quiet: 121 if written: 122 sys.stdout.write('File ' + options.header + ' updated.\n') 123 else: 124 sys.stdout.write('File ' + options.header + ' is already up to date.\n') 125