display_kernel_headers.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  2. #
  3. # This program is free software; you can redistribute it and/or modify it
  4. # under the terms of the GNU General Public License version 2 as published by
  5. # the Free Software Foundation.
  6. #
  7. # This program is distributed in the hope that it will be useful, but WITHOUT
  8. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. # more details.
  11. #
  12. # You should have received a copy of the GNU General Public License along with
  13. # this program. If not, see <http://www.gnu.org/licenses/>.
  14. import argparse
  15. import filecmp
  16. import os
  17. import re
  18. import subprocess
  19. import sys
  20. def run_headers_install(verbose, gen_dir, headers_install, prefix, h):
  21. if not h.startswith(prefix):
  22. print('error: expected prefix [%s] on header [%s]' % (prefix, h))
  23. return False
  24. out_h = os.path.join(gen_dir, h[len(prefix):])
  25. (out_h_dirname, out_h_basename) = os.path.split(out_h)
  26. cmd = ["bash", headers_install, h, out_h]
  27. if verbose:
  28. print('run_headers_install: cmd is %s' % cmd)
  29. result = subprocess.call(cmd)
  30. if result != 0:
  31. print('error: run_headers_install: cmd %s failed %d' % (cmd, result))
  32. return False
  33. return True
  34. def gen_display_headers(verbose, gen_dir, headers_install, display_include_uapi):
  35. error_count = 0
  36. for h in display_include_uapi:
  37. display_uapi_include_prefix = os.path.join(h.split('/include/uapi')[0], 'include', 'uapi') + os.sep
  38. if not run_headers_install(
  39. verbose, gen_dir, headers_install,
  40. display_uapi_include_prefix, h): error_count += 1
  41. return error_count
  42. def main():
  43. """Parse command line arguments and perform top level control."""
  44. parser = argparse.ArgumentParser(
  45. description=__doc__,
  46. formatter_class=argparse.RawDescriptionHelpFormatter)
  47. # Arguments that apply to every invocation of this script.
  48. parser.add_argument(
  49. '--verbose', action='store_true',
  50. help='Print output that describes the workings of this script.')
  51. parser.add_argument(
  52. '--header_arch', required=True,
  53. help='The arch for which to generate headers.')
  54. parser.add_argument(
  55. '--gen_dir', required=True,
  56. help='Where to place the generated files.')
  57. parser.add_argument(
  58. '--display_include_uapi', required=True, nargs='*',
  59. help='The list of techpack/*/include/uapi header files.')
  60. parser.add_argument(
  61. '--headers_install', required=True,
  62. help='The headers_install tool to process input headers.')
  63. args = parser.parse_args()
  64. if args.verbose:
  65. print('header_arch [%s]' % args.header_arch)
  66. print('gen_dir [%s]' % args.gen_dir)
  67. print('display_include_uapi [%s]' % args.display_include_uapi)
  68. print('headers_install [%s]' % args.headers_install)
  69. return gen_display_headers(args.verbose, args.gen_dir,
  70. args.headers_install, args.display_include_uapi)
  71. if __name__ == '__main__':
  72. sys.exit(main())