• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 cef_api_hash import cef_api_hash
7from cef_parser import get_copyright
8from file_util import *
9import os
10import sys
11
12
13def make_api_hash_header(cpp_header_dir):
14  # calculate api hashes
15  api_hash_calculator = cef_api_hash(cpp_header_dir, verbose=False)
16  api_hash = api_hash_calculator.calculate()
17
18  result = get_copyright(full=True, translator=False) + \
19"""//
20// ---------------------------------------------------------------------------
21//
22// This file was generated by the make_api_hash_header.py tool.
23//
24
25#ifndef CEF_INCLUDE_API_HASH_H_
26#define CEF_INCLUDE_API_HASH_H_
27
28#include "include/internal/cef_export.h"
29
30// The API hash is created by analyzing CEF header files for C API type
31// definitions. The hash value will change when header files are modified in a
32// way that may cause binary incompatibility with other builds. The universal
33// hash value will change if any platform is affected whereas the platform hash
34// values will change only if that particular platform is affected.
35#define CEF_API_HASH_UNIVERSAL "$UNIVERSAL$"
36#if defined(OS_WIN)
37#define CEF_API_HASH_PLATFORM "$WINDOWS$"
38#elif defined(OS_MAC)
39#define CEF_API_HASH_PLATFORM "$MAC$"
40#elif defined(OS_LINUX)
41#define CEF_API_HASH_PLATFORM "$LINUX$"
42#endif
43
44#ifdef __cplusplus
45extern "C" {
46#endif
47
48///
49// Returns CEF API hashes for the libcef library. The returned string is owned
50// by the library and should not be freed. The |entry| parameter describes which
51// hash value will be returned:
52// 0 - CEF_API_HASH_PLATFORM
53// 1 - CEF_API_HASH_UNIVERSAL
54// 2 - CEF_COMMIT_HASH (from cef_version.h)
55///
56CEF_EXPORT const char* cef_api_hash(int entry);
57
58#ifdef __cplusplus
59}
60#endif
61#endif  // CEF_INCLUDE_API_HASH_H_
62"""
63
64  # Substitute hash values for placeholders.
65  for platform, value in api_hash.items():
66    result = result.replace('$%s$' % platform.upper(), value)
67
68  return result
69
70
71def write_api_hash_header(output, cpp_header_dir):
72  output = os.path.abspath(output)
73  result = make_api_hash_header(cpp_header_dir)
74  ret = write_file_if_changed(output, result)
75
76  # Also write to |cpp_header_dir| if a different path from |output|, since we
77  # need to commit the hash header for cef_version.py to correctly calculate the
78  # version number based on git history.
79  header_path = os.path.abspath(
80      os.path.join(cpp_header_dir, os.path.basename(output)))
81  if (output != header_path):
82    write_file_if_changed(header_path, result)
83
84  return ret
85
86
87def main(argv):
88  if len(argv) < 3:
89    print(("Usage:\n  %s <output_filename> <cpp_header_dir>" % argv[0]))
90    sys.exit(-1)
91  write_api_hash_header(argv[1], argv[2])
92
93
94if '__main__' == __name__:
95  main(sys.argv)
96