bt_kernel.bzl 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. load("//msm-kernel:target_variants.bzl", "get_all_variants")
  2. load("//build/kernel/kleaf:kernel.bzl", "ddk_module")
  3. load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
  4. load(":bt_modules.bzl", "bt_modules")
  5. def _get_config_choices(config_srcs, options):
  6. choices = []
  7. for option in config_srcs:
  8. choices.extend(config_srcs[option].get(option in options, []))
  9. return choices
  10. def _get_module_srcs(module, options):
  11. """
  12. Gets all the module sources, formats them with the path for that module
  13. and then groups them together
  14. It also includes all the headers within the `include` directory
  15. `native.glob()` returns a new list with every file need for the current package
  16. """
  17. srcs = module.srcs + _get_config_choices(module.config_srcs, options)
  18. return native.glob(
  19. ["{}/{}".format(module.path, src) for src in srcs] + ["include/*.h"]
  20. )
  21. def _get_module_deps(module, options, formatter):
  22. """
  23. Formats the dependent targets with the necessary prefix
  24. Args:
  25. module: kernel module
  26. options: dependencies that rely on a config option
  27. formatter: function that will replace the format string within `deps`
  28. Example:
  29. kernel build = "pineapple_gki"
  30. dep = "%b_btpower"
  31. The formatted string will look as follow
  32. formatted_dep = formatter(dep) = "pineapple_gki_btpower"
  33. """
  34. deps = module.deps + _get_config_choices(module.config_deps, options)
  35. return [formatter(dep) for dep in deps]
  36. def _get_build_options(modules, config_options):
  37. all_options = {option: True for option in config_options}
  38. all_options = all_options | {module.config_opt: True for module in modules if module.config_opt}
  39. return all_options
  40. def define_target_variant_modules(target, variant, modules, config_options = []):
  41. """
  42. Generates the ddk_module for each of our kernel modules
  43. Args:
  44. target: either `pineapple` or `kalama`
  45. variant: either `gki` or `consolidate`
  46. modules: bt_modules dictionary defined in `bt_modules.bzl`
  47. config_options: decides which kernel modules to build
  48. """
  49. kernel_build = "{}_{}".format(target, variant)
  50. kernel_build_label = "//msm-kernel:{}".format(kernel_build)
  51. modules = [bt_modules.get(module_name) for module_name in modules]
  52. options = _get_build_options(modules, config_options)
  53. formatter = lambda s : s.replace("%b", kernel_build)
  54. all_modules = []
  55. for module in modules:
  56. rule_name = "{}_{}".format(kernel_build, module.name)
  57. module_srcs = _get_module_srcs(module, options)
  58. ddk_module(
  59. name = rule_name,
  60. kernel_build = kernel_build_label,
  61. srcs = module_srcs,
  62. out = "{}.ko".format(module.name),
  63. deps = ["//msm-kernel:all_headers"] + _get_module_deps(module, options, formatter),
  64. includes = ["include"],
  65. local_defines = options.keys(),
  66. visibility = ["//visibility:public"],
  67. )
  68. all_modules.append(rule_name)
  69. copy_to_dist_dir(
  70. name = "{}_bt-kernel_dist".format(kernel_build),
  71. data = all_modules,
  72. dist_dir = "out/target/product/{}/dlkm/lib/modules".format(target),
  73. flat = True,
  74. wipe_dist_dir = False,
  75. allow_duplicate_filenames = False,
  76. mode_overrides = {"**/*": "644"},
  77. log = "info",
  78. )
  79. def define_bt_modules(target, modules, config_options = []):
  80. for (t, v) in get_all_variants():
  81. if t == target:
  82. define_target_variant_modules(t, v, modules, config_options)