• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2# Copyright 2022 The PDFium Authors
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5"""Verifies libcxx_revision entries are in sync.
6
7DEPS and buildtools/deps_revisions.gni both have libcxx_revision entries.
8Check that they are in sync.
9"""
10
11import re
12import sys
13
14
15def _ExtractRevisionFromFile(path, regex):
16  """Gets the revision by reading path and searching the lines using regex."""
17  data = open(path, 'rb').read().splitlines()
18  revision = None
19  for line in data:
20    match = regex.match(line)
21    if not match:
22      continue
23    if revision:
24      return None
25    revision = match.group(1)
26  return revision
27
28
29def _GetDepsLibcxxRevision(deps_path):
30  """Gets the libcxx_revision from DEPS."""
31  regex = re.compile(b"^  'libcxx_revision': '(.*)',$")
32  return _ExtractRevisionFromFile(deps_path, regex)
33
34
35def _GetBuildtoolsLibcxxRevision(buildtools_deps_path):
36  """Gets the libcxx_revision from buildtools/deps_revisions.gni."""
37  regex = re.compile(b'^  libcxx_revision = "(.*)"$')
38  return _ExtractRevisionFromFile(buildtools_deps_path, regex)
39
40
41def main():
42  if len(sys.argv) != 3:
43    print('Wrong number of arguments')
44    return 0
45
46  deps_path = sys.argv[1]
47  deps_revision = _GetDepsLibcxxRevision(deps_path)
48  if not deps_revision:
49    print('Cannot parse', deps_path)
50    return 0
51
52  buildtools_deps_path = sys.argv[2]
53  buildtools_revision = _GetBuildtoolsLibcxxRevision(buildtools_deps_path)
54  if not buildtools_revision:
55    print('Cannot parse', buildtools_deps_path)
56    return 0
57
58  if deps_revision != buildtools_revision:
59    print('libcxx_revision mismatch between %s and %s: %s vs. %s' %
60          (deps_path, buildtools_deps_path, deps_revision, buildtools_revision))
61  return 0
62
63
64if __name__ == '__main__':
65  sys.exit(main())
66