blob: 55070775474bbee9f1204e2016496cca1ca4afbc [file] [log] [blame]
Paul Duffinbb7f1ac2021-03-29 22:18:45 +01001// Copyright 2021 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 java
16
17import (
18 "android/soong/android"
19 "android/soong/dexpreopt"
20)
21
22func init() {
23 registerPlatformBootclasspathBuildComponents(android.InitRegistrationContext)
24}
25
26func registerPlatformBootclasspathBuildComponents(ctx android.RegistrationContext) {
27 ctx.RegisterModuleType("platform_bootclasspath", platformBootclasspathFactory)
28}
29
30type platformBootclasspathModule struct {
31 android.ModuleBase
32}
33
34func platformBootclasspathFactory() android.Module {
35 m := &platformBootclasspathModule{}
36 android.InitAndroidArchModule(m, android.DeviceSupported, android.MultilibCommon)
37 return m
38}
39
40func (b *platformBootclasspathModule) DepsMutator(ctx android.BottomUpMutatorContext) {
41 if SkipDexpreoptBootJars(ctx) {
42 return
43 }
44
45 // Add a dependency onto the dex2oat tool which is needed for creating the boot image. The
46 // path is retrieved from the dependency by GetGlobalSoongConfig(ctx).
47 dexpreopt.RegisterToolDeps(ctx)
48}
49
50func (b *platformBootclasspathModule) GenerateAndroidBuildActions(ctx android.ModuleContext) {
51 // Nothing to do if skipping the dexpreopt of boot image jars.
52 if SkipDexpreoptBootJars(ctx) {
53 return
54 }
55
56 // Force the GlobalSoongConfig to be created and cached for use by the dex_bootjars
57 // GenerateSingletonBuildActions method as it cannot create it for itself.
58 dexpreopt.GetGlobalSoongConfig(ctx)
59
60 imageConfig := b.getImageConfig(ctx)
61 if imageConfig == nil {
62 return
63 }
64
65 // Construct the boot image info from the config.
66 info := BootImageInfo{imageConfig: imageConfig}
67
68 // Make it available for other modules.
69 ctx.SetProvider(BootImageInfoProvider, info)
70}
71
72func (b *platformBootclasspathModule) getImageConfig(ctx android.EarlyModuleContext) *bootImageConfig {
73 return defaultBootImageConfig(ctx)
74}