glibc_shared_code.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/python
  2. # Copyright (C) 2021-2026 Free Software Foundation, Inc.
  3. # This file is part of the GNU C Library.
  4. #
  5. # The GNU C Library is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 2.1 of the License, or (at your option) any later version.
  9. #
  10. # The GNU C Library is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public
  16. # License along with the GNU C Library; if not, see
  17. # <https://www.gnu.org/licenses/>.
  18. def get_glibc_shared_code(path):
  19. """ Get glibc shared code information from a file
  20. The input file must have project names in their own line ending with a colon
  21. and all shared files in the project on their own lines following the project
  22. name. Whitespaces are ignored. Lines with # as the first non-whitespace
  23. character are ignored.
  24. Args:
  25. path: The path to file containing shared code information.
  26. Returns:
  27. A dictionary with project names as key and lists of files as values.
  28. """
  29. projects = {}
  30. with open(path, 'r') as f:
  31. for line in f.readlines():
  32. line = line.strip()
  33. if len(line) == 0 or line[0] == '#':
  34. continue
  35. if line[-1] == ':':
  36. cur = line[:-1]
  37. projects[cur] = []
  38. else:
  39. projects[cur].append(line)
  40. return projects
  41. # Function testing.
  42. import sys
  43. from os import EX_NOINPUT
  44. from os.path import exists
  45. from pprint import *
  46. if __name__ == '__main__':
  47. if len(sys.argv) != 2:
  48. print('Usage: %s <file name>' % sys.argv[0])
  49. print('Run this script from the base glibc source directory')
  50. sys.exit(EX_NOINPUT)
  51. print('Testing get_glibc_shared_code with %s:\n' % sys.argv[1])
  52. r = get_glibc_shared_code(sys.argv[1])
  53. errors = False
  54. for k in r.keys():
  55. for f in r[k]:
  56. if not exists(f):
  57. print('%s does not exist' % f)
  58. errors = True
  59. if not errors:
  60. pprint(r)