Wei Li | 5c6d83b | 2024-10-03 05:35:03 +0000 | [diff] [blame] | 1 | // Copyright 2024 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 etc |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | func init() { |
| 22 | android.RegisterModuleType("adb_keys", AdbKeysModuleFactory) |
| 23 | } |
| 24 | |
| 25 | type AdbKeysModule struct { |
| 26 | android.ModuleBase |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 27 | outputPath android.Path |
Wei Li | 5c6d83b | 2024-10-03 05:35:03 +0000 | [diff] [blame] | 28 | installPath android.InstallPath |
| 29 | } |
| 30 | |
| 31 | func AdbKeysModuleFactory() android.Module { |
| 32 | module := &AdbKeysModule{} |
| 33 | android.InitAndroidArchModule(module, android.DeviceSupported, android.MultilibFirst) |
| 34 | return module |
| 35 | } |
| 36 | |
| 37 | func (m *AdbKeysModule) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 38 | productVariables := ctx.Config().ProductVariables() |
Jihoon Kang | 06689b1 | 2024-11-06 00:25:45 +0000 | [diff] [blame] | 39 | |
| 40 | if !m.ProductSpecific() { |
| 41 | ctx.ModuleErrorf("adb_keys module type must set product_specific to true") |
| 42 | } |
| 43 | |
Wei Li | 5c6d83b | 2024-10-03 05:35:03 +0000 | [diff] [blame] | 44 | if !(android.Bool(productVariables.Debuggable) && len(android.String(productVariables.AdbKeys)) > 0) { |
Wei Li | 5c6d83b | 2024-10-03 05:35:03 +0000 | [diff] [blame] | 45 | m.SkipInstall() |
| 46 | return |
| 47 | } |
| 48 | |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 49 | outputPath := android.PathForModuleOut(ctx, "adb_keys") |
Wei Li | 5c6d83b | 2024-10-03 05:35:03 +0000 | [diff] [blame] | 50 | input := android.ExistentPathForSource(ctx, android.String(productVariables.AdbKeys)) |
| 51 | ctx.Build(pctx, android.BuildParams{ |
| 52 | Rule: android.Cp, |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 53 | Output: outputPath, |
Wei Li | 5c6d83b | 2024-10-03 05:35:03 +0000 | [diff] [blame] | 54 | Input: input.Path(), |
| 55 | }) |
Jihoon Kang | 06689b1 | 2024-11-06 00:25:45 +0000 | [diff] [blame] | 56 | m.installPath = android.PathForModuleInstall(ctx, "etc/security") |
Cole Faust | 4e9f592 | 2024-11-13 16:09:23 -0800 | [diff] [blame] | 57 | ctx.InstallFile(m.installPath, "adb_keys", outputPath) |
| 58 | m.outputPath = outputPath |
Wei Li | 5c6d83b | 2024-10-03 05:35:03 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | func (m *AdbKeysModule) AndroidMkEntries() []android.AndroidMkEntries { |
| 62 | if m.IsSkipInstall() { |
| 63 | return []android.AndroidMkEntries{} |
| 64 | } |
| 65 | |
| 66 | return []android.AndroidMkEntries{ |
| 67 | { |
| 68 | Class: "ETC", |
| 69 | OutputFile: android.OptionalPathForPath(m.outputPath), |
| 70 | }} |
| 71 | } |