spu_drivers_kernel_headers.py 3.5 KB

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