video_kernel_headers.py 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. # Copyright (c) 2020, 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_video_headers(verbose, gen_dir, headers_install, video_include_uapi):
  35. error_count = 0
  36. for h in video_include_uapi:
  37. video_uapi_include_prefix = os.path.join(h.split('/include/uapi/')[0],
  38. 'include',
  39. 'uapi') + os.sep
  40. if not run_headers_install(
  41. verbose, gen_dir, headers_install,
  42. video_uapi_include_prefix, h): error_count += 1
  43. return error_count
  44. def main():
  45. """Parse command line arguments and perform top level control."""
  46. parser = argparse.ArgumentParser(
  47. description=__doc__,
  48. formatter_class=argparse.RawDescriptionHelpFormatter)
  49. # Arguments that apply to every invocation of this script.
  50. parser.add_argument(
  51. '--verbose', action='store_true',
  52. help='Print output that describes the workings of this script.')
  53. parser.add_argument(
  54. '--header_arch', required=True,
  55. help='The arch for which to generate headers.')
  56. parser.add_argument(
  57. '--gen_dir', required=True,
  58. help='Where to place the generated files.')
  59. parser.add_argument(
  60. '--video_include_uapi', required=True, nargs='*',
  61. help='The list of techpack/*/include/uapi header files.')
  62. parser.add_argument(
  63. '--headers_install', required=True,
  64. help='The headers_install tool to process input headers.')
  65. args = parser.parse_args()
  66. if args.verbose:
  67. print('header_arch [%s]' % args.header_arch)
  68. print('gen_dir [%s]' % args.gen_dir)
  69. print('video_include_uapi [%s]' % args.video_include_uapi)
  70. print('headers_install [%s]' % args.headers_install)
  71. return gen_video_headers(args.verbose, args.gen_dir,
  72. args.headers_install, args.video_include_uapi)
  73. if __name__ == '__main__':
  74. sys.exit(main())