fdo_profile.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2023 Google Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package cc
  15. import (
  16. "android/soong/android"
  17. "github.com/google/blueprint"
  18. )
  19. func init() {
  20. RegisterFdoProfileBuildComponents(android.InitRegistrationContext)
  21. }
  22. func RegisterFdoProfileBuildComponents(ctx android.RegistrationContext) {
  23. ctx.RegisterModuleType("fdo_profile", fdoProfileFactory)
  24. }
  25. type fdoProfile struct {
  26. android.ModuleBase
  27. properties fdoProfileProperties
  28. }
  29. type fdoProfileProperties struct {
  30. Profile *string `android:"arch_variant"`
  31. }
  32. // FdoProfileInfo is provided by FdoProfileProvider
  33. type FdoProfileInfo struct {
  34. Path android.Path
  35. }
  36. // FdoProfileProvider is used to provide path to an fdo profile
  37. var FdoProfileProvider = blueprint.NewMutatorProvider(FdoProfileInfo{}, "fdo_profile")
  38. // FdoProfileMutatorInterface is the interface implemented by fdo_profile module type
  39. // module types that can depend on an fdo_profile module
  40. type FdoProfileMutatorInterface interface {
  41. // FdoProfileMutator eithers set or get FdoProfileProvider
  42. fdoProfileMutator(ctx android.BottomUpMutatorContext)
  43. }
  44. var _ FdoProfileMutatorInterface = (*fdoProfile)(nil)
  45. // GenerateAndroidBuildActions of fdo_profile does not have any build actions
  46. func (fp *fdoProfile) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
  47. // FdoProfileMutator sets FdoProfileProvider to fdo_profile module
  48. // or sets afdo.Properties.FdoProfilePath to path in FdoProfileProvider of the depended fdo_profile
  49. func (fp *fdoProfile) fdoProfileMutator(ctx android.BottomUpMutatorContext) {
  50. if fp.properties.Profile != nil {
  51. path := android.PathForModuleSrc(ctx, *fp.properties.Profile)
  52. ctx.SetProvider(FdoProfileProvider, FdoProfileInfo{
  53. Path: path,
  54. })
  55. }
  56. }
  57. // fdoProfileMutator calls the generic fdoProfileMutator function of fdoProfileMutator
  58. // which is implemented by cc and cc.FdoProfile
  59. func fdoProfileMutator(ctx android.BottomUpMutatorContext) {
  60. if f, ok := ctx.Module().(FdoProfileMutatorInterface); ok {
  61. f.fdoProfileMutator(ctx)
  62. }
  63. }
  64. func fdoProfileFactory() android.Module {
  65. m := &fdoProfile{}
  66. m.AddProperties(&m.properties)
  67. android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibBoth)
  68. return m
  69. }