Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 1 | // Copyright 2020 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 dexpreopt |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | ) |
| 20 | |
| 21 | type dummyToolBinary struct { |
| 22 | android.ModuleBase |
| 23 | } |
| 24 | |
| 25 | func (m *dummyToolBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {} |
| 26 | |
| 27 | func (m *dummyToolBinary) HostToolPath() android.OptionalPath { |
| 28 | return android.OptionalPathForPath(android.PathForTesting("dex2oat")) |
| 29 | } |
| 30 | |
| 31 | func dummyToolBinaryFactory() android.Module { |
| 32 | module := &dummyToolBinary{} |
| 33 | android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst) |
| 34 | return module |
| 35 | } |
| 36 | |
Paul Duffin | 635aa08 | 2021-01-25 19:11:24 +0000 | [diff] [blame] | 37 | func RegisterToolModulesForTest(ctx android.RegistrationContext) { |
Martin Stjernholm | d90676f | 2020-01-11 00:37:30 +0000 | [diff] [blame] | 38 | ctx.RegisterModuleType("dummy_tool_binary", dummyToolBinaryFactory) |
| 39 | } |
| 40 | |
| 41 | func BpToolModulesForTest() string { |
| 42 | return ` |
| 43 | dummy_tool_binary { |
| 44 | name: "dex2oatd", |
| 45 | } |
| 46 | ` |
| 47 | } |
Paul Duffin | 4fced55 | 2021-03-09 16:28:16 +0000 | [diff] [blame] | 48 | |
| 49 | // Prepares a test fixture by enabling dexpreopt. |
| 50 | var PrepareForTestWithDexpreopt = FixtureModifyGlobalConfig(func(*GlobalConfig) {}) |
| 51 | |
| 52 | // FixtureModifyGlobalConfig enables dexpreopt (unless modified by the mutator) and modifies the |
| 53 | // configuration. |
| 54 | func FixtureModifyGlobalConfig(configModifier func(dexpreoptConfig *GlobalConfig)) android.FixturePreparer { |
| 55 | return android.FixtureModifyConfig(func(config android.Config) { |
| 56 | // Initialize the dexpreopt GlobalConfig to an empty structure. This has no effect if it has |
| 57 | // already been set. |
| 58 | pathCtx := android.PathContextForTesting(config) |
| 59 | dexpreoptConfig := GlobalConfigForTests(pathCtx) |
| 60 | SetTestGlobalConfig(config, dexpreoptConfig) |
| 61 | |
| 62 | // Retrieve the existing configuration and modify it. |
| 63 | dexpreoptConfig = GetGlobalConfig(pathCtx) |
| 64 | configModifier(dexpreoptConfig) |
| 65 | }) |
| 66 | } |
| 67 | |
| 68 | // FixtureSetArtBootJars enables dexpreopt and sets the ArtApexJars property. |
| 69 | func FixtureSetArtBootJars(bootJars ...string) android.FixturePreparer { |
| 70 | return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { |
| 71 | dexpreoptConfig.ArtApexJars = android.CreateTestConfiguredJarList(bootJars) |
| 72 | }) |
| 73 | } |
| 74 | |
| 75 | // FixtureSetBootJars enables dexpreopt and sets the BootJars property. |
| 76 | func FixtureSetBootJars(bootJars ...string) android.FixturePreparer { |
| 77 | return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { |
| 78 | dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList(bootJars) |
| 79 | }) |
| 80 | } |
Ulya Trafimovich | 9023b02 | 2021-03-22 16:02:28 +0000 | [diff] [blame^] | 81 | |
| 82 | // FixtureSetUpdatableBootJars sets the UpdatableBootJars property in the global config. |
| 83 | func FixtureSetUpdatableBootJars(bootJars ...string) android.FixturePreparer { |
| 84 | return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { |
| 85 | dexpreoptConfig.UpdatableBootJars = android.CreateTestConfiguredJarList(bootJars) |
| 86 | }) |
| 87 | } |
| 88 | |
| 89 | // FixtureSetPreoptWithUpdatableBcp sets the PreoptWithUpdatableBcp property in the global config. |
| 90 | func FixtureSetPreoptWithUpdatableBcp(value bool) android.FixturePreparer { |
| 91 | return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) { |
| 92 | dexpreoptConfig.PreoptWithUpdatableBcp = value |
| 93 | }) |
| 94 | } |