blob: 8e90295b1b735acc1821792793c67c7f61e7eb9b [file] [log] [blame]
Martin Stjernholmd90676f2020-01-11 00:37:30 +00001// 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
15package dexpreopt
16
17import (
18 "android/soong/android"
19)
20
21type dummyToolBinary struct {
22 android.ModuleBase
23}
24
25func (m *dummyToolBinary) GenerateAndroidBuildActions(ctx android.ModuleContext) {}
26
27func (m *dummyToolBinary) HostToolPath() android.OptionalPath {
28 return android.OptionalPathForPath(android.PathForTesting("dex2oat"))
29}
30
31func dummyToolBinaryFactory() android.Module {
32 module := &dummyToolBinary{}
33 android.InitAndroidArchModule(module, android.HostSupported, android.MultilibFirst)
34 return module
35}
36
Paul Duffin635aa082021-01-25 19:11:24 +000037func RegisterToolModulesForTest(ctx android.RegistrationContext) {
Martin Stjernholmd90676f2020-01-11 00:37:30 +000038 ctx.RegisterModuleType("dummy_tool_binary", dummyToolBinaryFactory)
39}
40
41func BpToolModulesForTest() string {
42 return `
43 dummy_tool_binary {
44 name: "dex2oatd",
45 }
46 `
47}
Paul Duffin4fced552021-03-09 16:28:16 +000048
49// Prepares a test fixture by enabling dexpreopt.
50var PrepareForTestWithDexpreopt = FixtureModifyGlobalConfig(func(*GlobalConfig) {})
51
52// FixtureModifyGlobalConfig enables dexpreopt (unless modified by the mutator) and modifies the
53// configuration.
54func 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.
69func 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.
76func FixtureSetBootJars(bootJars ...string) android.FixturePreparer {
77 return FixtureModifyGlobalConfig(func(dexpreoptConfig *GlobalConfig) {
78 dexpreoptConfig.BootJars = android.CreateTestConfiguredJarList(bootJars)
79 })
80}