audio_kernel_headers.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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, unifdef, 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. env = os.environ.copy()
  27. env["LOC_UNIFDEF"] = unifdef
  28. cmd = ["sh", headers_install, h, out_h]
  29. if verbose:
  30. print('run_headers_install: cmd is %s' % cmd)
  31. result = subprocess.call(cmd, env=env)
  32. if result != 0:
  33. print('error: run_headers_install: cmd %s failed %d' % (cmd, result))
  34. return False
  35. return True
  36. def gen_audio_headers(verbose, gen_dir, headers_install, unifdef, audio_include_uapi):
  37. error_count = 0
  38. for h in audio_include_uapi:
  39. audio_uapi_include_prefix = os.path.join(h.split('/include/uapi/')[0],
  40. 'include',
  41. 'uapi',
  42. 'audio') + os.sep
  43. if not run_headers_install(
  44. verbose, gen_dir, headers_install, unifdef,
  45. audio_uapi_include_prefix, h): error_count += 1
  46. return error_count
  47. def main():
  48. """Parse command line arguments and perform top level control."""
  49. parser = argparse.ArgumentParser(
  50. description=__doc__,
  51. formatter_class=argparse.RawDescriptionHelpFormatter)
  52. # Arguments that apply to every invocation of this script.
  53. parser.add_argument(
  54. '--verbose', action='store_true',
  55. help='Print output that describes the workings of this script.')
  56. parser.add_argument(
  57. '--header_arch', required=True,
  58. help='The arch for which to generate headers.')
  59. parser.add_argument(
  60. '--gen_dir', required=True,
  61. help='Where to place the generated files.')
  62. parser.add_argument(
  63. '--audio_include_uapi', required=True, nargs='*',
  64. help='The list of techpack/*/include/uapi header files.')
  65. parser.add_argument(
  66. '--headers_install', required=True,
  67. help='The headers_install tool to process input headers.')
  68. parser.add_argument(
  69. '--unifdef',
  70. required=True,
  71. help='The unifdef tool used by headers_install.')
  72. args = parser.parse_args()
  73. if args.verbose:
  74. print('header_arch [%s]' % args.header_arch)
  75. print('gen_dir [%s]' % args.gen_dir)
  76. print('audio_include_uapi [%s]' % args.audio_include_uapi)
  77. print('headers_install [%s]' % args.headers_install)
  78. print('unifdef [%s]' % args.unifdef)
  79. return gen_audio_headers(args.verbose, args.gen_dir,
  80. args.headers_install, args.unifdef, args.audio_include_uapi)
  81. if __name__ == '__main__':
  82. sys.exit(main())