| Vinh Tran | 0ccc232 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 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 |  | 
|  | 15 | package cc | 
|  | 16 |  | 
|  | 17 | import ( | 
|  | 18 | "android/soong/android" | 
|  | 19 |  | 
|  | 20 | "github.com/google/blueprint" | 
|  | 21 | ) | 
|  | 22 |  | 
|  | 23 | func init() { | 
|  | 24 | RegisterFdoProfileBuildComponents(android.InitRegistrationContext) | 
|  | 25 | } | 
|  | 26 |  | 
|  | 27 | func RegisterFdoProfileBuildComponents(ctx android.RegistrationContext) { | 
|  | 28 | ctx.RegisterModuleType("fdo_profile", fdoProfileFactory) | 
|  | 29 | } | 
|  | 30 |  | 
|  | 31 | type fdoProfile struct { | 
|  | 32 | android.ModuleBase | 
|  | 33 |  | 
|  | 34 | properties fdoProfileProperties | 
|  | 35 | } | 
|  | 36 |  | 
|  | 37 | type fdoProfileProperties struct { | 
|  | 38 | Profile *string `android:"arch_variant"` | 
|  | 39 | } | 
|  | 40 |  | 
|  | 41 | // FdoProfileInfo is provided by FdoProfileProvider | 
|  | 42 | type FdoProfileInfo struct { | 
|  | 43 | Path android.Path | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | // FdoProfileProvider is used to provide path to an fdo profile | 
|  | 47 | var FdoProfileProvider = blueprint.NewMutatorProvider(FdoProfileInfo{}, "fdo_profile") | 
|  | 48 |  | 
|  | 49 | // FdoProfileMutatorInterface is the interface implemented by fdo_profile module type | 
|  | 50 | // module types that can depend on an fdo_profile module | 
|  | 51 | type FdoProfileMutatorInterface interface { | 
|  | 52 | // FdoProfileMutator eithers set or get FdoProfileProvider | 
| Vinh Tran | 611f036 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 53 | fdoProfileMutator(ctx android.BottomUpMutatorContext) | 
| Vinh Tran | 0ccc232 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 54 | } | 
|  | 55 |  | 
|  | 56 | var _ FdoProfileMutatorInterface = (*fdoProfile)(nil) | 
|  | 57 |  | 
|  | 58 | // GenerateAndroidBuildActions of fdo_profile does not have any build actions | 
|  | 59 | func (fp *fdoProfile) GenerateAndroidBuildActions(ctx android.ModuleContext) {} | 
|  | 60 |  | 
|  | 61 | // FdoProfileMutator sets FdoProfileProvider to fdo_profile module | 
|  | 62 | // or sets afdo.Properties.FdoProfilePath to path in FdoProfileProvider of the depended fdo_profile | 
| Vinh Tran | 611f036 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 63 | func (fp *fdoProfile) fdoProfileMutator(ctx android.BottomUpMutatorContext) { | 
| Vinh Tran | 0ccc232 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 64 | if fp.properties.Profile != nil { | 
|  | 65 | path := android.PathForModuleSrc(ctx, *fp.properties.Profile) | 
|  | 66 | ctx.SetProvider(FdoProfileProvider, FdoProfileInfo{ | 
|  | 67 | Path: path, | 
|  | 68 | }) | 
|  | 69 | } | 
|  | 70 | } | 
|  | 71 |  | 
| Vinh Tran | 611f036 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 72 | // fdoProfileMutator calls the generic fdoProfileMutator function of fdoProfileMutator | 
| Vinh Tran | 0ccc232 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 73 | // which is implemented by cc and cc.FdoProfile | 
|  | 74 | func fdoProfileMutator(ctx android.BottomUpMutatorContext) { | 
|  | 75 | if f, ok := ctx.Module().(FdoProfileMutatorInterface); ok { | 
| Vinh Tran | 611f036 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 76 | f.fdoProfileMutator(ctx) | 
| Vinh Tran | 0ccc232 | 2023-03-09 22:07:19 -0500 | [diff] [blame] | 77 | } | 
|  | 78 | } | 
|  | 79 |  | 
|  | 80 | func fdoProfileFactory() android.Module { | 
|  | 81 | m := &fdoProfile{} | 
|  | 82 | m.AddProperties(&m.properties) | 
|  | 83 | android.InitAndroidMultiTargetsArchModule(m, android.DeviceSupported, android.MultilibBoth) | 
|  | 84 | return m | 
|  | 85 | } |