display_kernel_headers.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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_display_headers(verbose, gen_dir, headers_install, unifdef, display_include_uapi):
  37. error_count = 0
  38. for h in display_include_uapi:
  39. display_uapi_include_prefix = os.path.join(h.split('/include/uapi')[0], 'include', 'uapi') + os.sep
  40. if not run_headers_install(
  41. verbose, gen_dir, headers_install, unifdef,
  42. display_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. '--display_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. parser.add_argument(
  66. '--unifdef',
  67. required=True,
  68. help='The unifdef tool used by headers_install.')
  69. args = parser.parse_args()
  70. if args.verbose:
  71. print('header_arch [%s]' % args.header_arch)
  72. print('gen_dir [%s]' % args.gen_dir)
  73. print('display_include_uapi [%s]' % args.display_include_uapi)
  74. print('headers_install [%s]' % args.headers_install)
  75. print('unifdef [%s]' % args.unifdef)
  76. return gen_display_headers(args.verbose, args.gen_dir,
  77. args.headers_install, args.unifdef, args.display_include_uapi)
  78. if __name__ == '__main__':
  79. sys.exit(main())