display_driver_build.bzl 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. load("//build/kernel/kleaf:kernel.bzl", "ddk_module", "ddk_submodule")
  2. load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
  3. load("//msm-kernel:target_variants.bzl", "get_all_variants")
  4. def _register_module_to_map(module_map, name, path, config_option, srcs, config_srcs, deps, config_deps):
  5. processed_config_srcs = {}
  6. nested_config = {}
  7. for config_src_name in config_srcs:
  8. config_src = config_srcs[config_src_name]
  9. if type(config_src) == "list":
  10. processed_config_srcs[config_src_name] = {True: config_src}
  11. else:
  12. processed_config_srcs[config_src_name] = config_src
  13. if type(config_src) == "dict":
  14. nested_config = config_src
  15. for nested_src, nest_name in nested_config.items():
  16. if nested_src == "True":
  17. for nest_src in nest_name:
  18. final_srcs = nest_name[nest_src]
  19. processed_config_srcs[nest_src] = final_srcs
  20. module = struct(
  21. name = name,
  22. path = path,
  23. srcs = srcs,
  24. config_srcs = processed_config_srcs,
  25. config_option = config_option,
  26. deps = deps,
  27. )
  28. module_map[name] = module
  29. def _get_config_choices(map, options):
  30. choices = []
  31. for option in map:
  32. choices.extend(map[option].get(option in options,[]))
  33. return choices
  34. def _get_kernel_build_options(modules, config_options):
  35. all_options = {option: True for option in config_options}
  36. all_options = all_options | {module.config_option: True for module in modules if module.config_option}
  37. return all_options
  38. def _get_kernel_build_module_srcs(module, options, formatter):
  39. srcs = module.srcs + _get_config_choices(module.config_srcs, options)
  40. print("-",module.name,",",module.config_option,",srcs =",srcs)
  41. module_path = "{}/".format(module.path) if module.path else ""
  42. return ["{}{}".format(module_path, formatter(src)) for src in srcs]
  43. def _get_kernel_build_module_deps(module, options, formatter):
  44. return [formatter(dep) for dep in module.deps]
  45. def display_module_entry(hdrs = []):
  46. module_map = {}
  47. def register(name, path = None, config_option = None, srcs = [], config_srcs = {}, deps = [], config_deps = {}):
  48. _register_module_to_map(module_map, name, path, config_option, srcs, config_srcs, deps, config_deps)
  49. return struct(
  50. register = register,
  51. get = module_map.get,
  52. hdrs = hdrs,
  53. module_map = module_map
  54. )
  55. def define_target_variant_modules(target, variant, registry, modules, config_options = []):
  56. kernel_build = "{}_{}".format(target, variant)
  57. kernel_build_label = "//msm-kernel:{}".format(kernel_build)
  58. modules = [registry.get(module_name) for module_name in modules]
  59. options = _get_kernel_build_options(modules, config_options)
  60. build_print = lambda message : print("{}: {}".format(kernel_build, message))
  61. formatter = lambda s : s.replace("%b", kernel_build).replace("%t", target)
  62. headers = ["//msm-kernel:all_headers"] + registry.hdrs
  63. all_module_rules = []
  64. for module in modules:
  65. rule_name = "{}_{}".format(kernel_build, module.name)
  66. module_srcs = _get_kernel_build_module_srcs(module, options, formatter)
  67. if not module_srcs:
  68. continue
  69. ddk_submodule(
  70. name = rule_name,
  71. srcs = module_srcs,
  72. out = "{}.ko".format(module.name),
  73. deps = headers + _get_kernel_build_module_deps(module, options, formatter),
  74. local_defines = options.keys(),
  75. )
  76. all_module_rules.append(rule_name)
  77. ddk_module(
  78. name = "{}_display_drivers".format(kernel_build),
  79. kernel_build = kernel_build_label,
  80. deps = all_module_rules,
  81. )
  82. copy_to_dist_dir(
  83. name = "{}_display_drivers_dist".format(kernel_build),
  84. data = [":{}_display_drivers".format(kernel_build)],
  85. dist_dir = "out/target/product/{}/dlkm/lib/modules/".format(target),
  86. flat = True,
  87. wipe_dist_dir = False,
  88. allow_duplicate_filenames = False,
  89. mode_overrides = {"**/*": "644"},
  90. log = "info",
  91. )
  92. def define_consolidate_gki_modules(target, registry, modules, config_options = []):
  93. for (targets, variant) in get_all_variants():
  94. define_target_variant_modules(targets, variant, registry, modules, config_options)