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