mm_module_build.bzl 3.9 KB

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