Support API versioning in platform-specific headers (see #3836)

- Exclude platform-specific includes (anything in < >) from the
  clang preprocessor by using `!defined(GENERATING_CEF_API_HASH)`
  in CEF header files.
- Define "target platforms" by passing platform- and architecture-
  specific ifdefs to the clang preprocessor. Grep for `defined(OS_`
  to identify headers that require target platform processing, and
  then process for each target as the platform-specific API hash
  contribution.
- Delete the univeral hash which is no longer a useful concept.
This commit is contained in:
Nik Pavlov
2025-02-25 11:43:44 -05:00
committed by Marshall Greenblatt
parent 8ddb1bffbb
commit fdd36e8461
22 changed files with 922 additions and 550 deletions

View File

@ -11,8 +11,8 @@ import sys
def make_api_versions_header(json):
result = get_copyright(full=True, translator=False) + \
"""//
result = get_copyright(
full=True, translator=False) + """//
// ---------------------------------------------------------------------------
//
// This file was generated by the make_api_versions_header.py tool. Versions
@ -27,42 +27,40 @@ def make_api_versions_header(json):
"""
for version, hashes in json['hashes'].items():
version_part = """
version_part = f"""
// $COMMENT$
#define CEF_API_VERSION_$VER$ $VER$
#define CEF_API_HASH_$VER$_UNIVERSAL "$UNIVERSAL$"
#define CEF_API_VERSION_{version} {version}
#if defined(OS_WIN)
#define CEF_API_HASH_$VER$_PLATFORM "$WINDOWS$"
#define CEF_API_HASH_{version} "$WINDOWS$"
#elif defined(OS_MAC)
#define CEF_API_HASH_$VER$_PLATFORM "$MAC$"
#define CEF_API_HASH_{version} "$MAC$"
#elif defined(OS_LINUX)
#define CEF_API_HASH_$VER$_PLATFORM "$LINUX$"
#define CEF_API_HASH_{version} "$LINUX$"
#endif
""".replace('$VER$', version)
"""
# Substitute hash values for placeholders.
for key, value in hashes.items():
version_part = version_part.replace('$%s$' % key.upper(), value)
version_part = version_part.replace(f"${key.upper()}$", value)
result += version_part
result += \
"""
result += f"""
// Oldest supported CEF version.
#define CEF_API_VERSION_MIN CEF_API_VERSION_$MIN$
#define CEF_API_VERSION_MIN CEF_API_VERSION_{json['min']}
// Newest supported CEF version.
#define CEF_API_VERSION_LAST CEF_API_VERSION_$LAST$
#define CEF_API_VERSION_LAST CEF_API_VERSION_{json['last']}
#endif // CEF_INCLUDE_CEF_API_VERSIONS_H_
""".replace('$LAST$', json['last']).replace('$MIN$', json['min'])
"""
return result
def make_api_versions_inc(json):
result = get_copyright(full=False, translator=False) + \
"""//
result = get_copyright(
full=False, translator=False) + """//
// ---------------------------------------------------------------------------
//
// This file was generated by the make_api_versions_header.py tool.
@ -72,56 +70,53 @@ namespace {
struct ApiVersionHash {
int version;
const char* const universal;
const char* const platform;
const char* const hash;
};
const ApiVersionHash kApiVersionHashes[] = {"""
for version, hashes in json['hashes'].items():
result += """
{$VER$, CEF_API_HASH_$VER$_UNIVERSAL, CEF_API_HASH_$VER$_PLATFORM},""".replace(
'$VER$', version)
for version in json['hashes'].keys():
result += f"\n{{{version}, CEF_API_HASH_{version}}},"
result += \
"""
result += """
};
const size_t kApiVersionHashesSize = std::size(kApiVersionHashes);
} // namespace
"""
return result
def write_api_versions(out_header_file, out_inc_file, json):
def write_api_versions(out_header_file, out_inc_file, json) -> bool:
"""
Return True if the files were written, False if no changes were made.
"""
out_file = os.path.abspath(out_header_file)
result = make_api_versions_header(json)
if not bool(result):
sys.stderr.write('Failed to create %s\n' % out_file)
if not result:
sys.stderr.write(f'Failed to create {out_file}\n')
sys.exit(1)
retval1 = write_file_if_changed(out_file, result)
header_write_result = write_file_if_changed(out_file, result)
out_file = os.path.abspath(out_inc_file)
result = make_api_versions_inc(json)
if not bool(result):
sys.stderr.write('Failed to create %s\n' % out_file)
if not result:
sys.stderr.write(f'Failed to create {out_file}\n')
sys.exit(1)
retval2 = write_file_if_changed(out_file, result)
inc_write_result = write_file_if_changed(out_file, result)
return retval1 or retval2
return header_write_result or inc_write_result
def main(argv):
if len(argv) < 5:
print(
"Usage:\n %s <output_header_file> <output_inc_file> <api_versions_file> <api_untracked_file>"
% argv[0])
f"Usage:\n {argv[0]} <output_header_file> <output_inc_file> <api_versions_file> <api_untracked_file>"
)
sys.exit(-1)
json, initialized = \
read_version_files(argv[3], argv[4], True, combine=True)
json = read_version_files(argv[3], argv[4], initialize=True, combine=True)[0]
if not write_api_versions(argv[1], argv[2], json):
print('Nothing done')