blob: 9f40a6c0d4d1c6e68b558a8464b6c5038764994e [file] [log] [blame]
Colin Cross3d7c9822019-03-01 13:46:24 -08001// Copyright 2019 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
20 "github.com/google/blueprint"
21)
22
23type DeviceHostConverter struct {
24 android.ModuleBase
25 android.DefaultableModuleBase
26
27 properties DeviceHostConverterProperties
28
29 headerJars android.Paths
30 implementationJars android.Paths
31 implementationAndResourceJars android.Paths
32 resourceJars android.Paths
33}
34
35type DeviceHostConverterProperties struct {
36 // List of modules whose contents will be visible to modules that depend on this module.
37 Libs []string
38}
39
40type DeviceForHost struct {
41 DeviceHostConverter
42}
43
44// java_device_for_host makes the classes.jar output of a device java_library module available to host
45// java_library modules.
46//
47// It is rarely necessary, and its used is restricted to a few whitelisted projects.
48func DeviceForHostFactory() android.Module {
49 module := &DeviceForHost{}
50
51 module.AddProperties(&module.properties)
52
53 InitJavaModule(module, android.HostSupported)
54 return module
55}
56
57type HostForDevice struct {
58 DeviceHostConverter
59}
60
61// java_host_for_device makes the classes.jar output of a host java_library module available to device
62// java_library modules.
63//
64// It is rarely necessary, and its used is restricted to a few whitelisted projects.
65func HostForDeviceFactory() android.Module {
66 module := &HostForDevice{}
67
68 module.AddProperties(&module.properties)
69
70 InitJavaModule(module, android.DeviceSupported)
71 return module
72}
73
74var deviceHostConverterDepTag = dependencyTag{name: "device_host_converter"}
75
76func (d *DeviceForHost) DepsMutator(ctx android.BottomUpMutatorContext) {
77 variation := []blueprint.Variation{{Mutator: "arch", Variation: "android_common"}}
78 ctx.AddFarVariationDependencies(variation, deviceHostConverterDepTag, d.properties.Libs...)
79}
80
81func (d *HostForDevice) DepsMutator(ctx android.BottomUpMutatorContext) {
82 variation := []blueprint.Variation{{Mutator: "arch", Variation: ctx.Config().BuildOsCommonVariant}}
83 ctx.AddFarVariationDependencies(variation, deviceHostConverterDepTag, d.properties.Libs...)
84}
85
86func (d *DeviceHostConverter) GenerateAndroidBuildActions(ctx android.ModuleContext) {
87 if len(d.properties.Libs) < 1 {
88 ctx.PropertyErrorf("libs", "at least one dependency is required")
89 }
90
91 ctx.VisitDirectDepsWithTag(deviceHostConverterDepTag, func(m android.Module) {
92 if dep, ok := m.(Dependency); ok {
93 d.headerJars = append(d.headerJars, dep.HeaderJars()...)
94 d.implementationJars = append(d.implementationJars, dep.ImplementationJars()...)
95 d.implementationAndResourceJars = append(d.implementationAndResourceJars, dep.ImplementationAndResourcesJars()...)
96 d.resourceJars = append(d.resourceJars, dep.ResourceJars()...)
97 } else {
98 ctx.PropertyErrorf("libs", "module %q cannot be used as a dependency", ctx.OtherModuleName(m))
99 }
100 })
101}
102
103var _ Dependency = (*DeviceHostConverter)(nil)
104
105func (d *DeviceHostConverter) HeaderJars() android.Paths {
106 return d.headerJars
107}
108
109func (d *DeviceHostConverter) ImplementationJars() android.Paths {
110 return d.implementationJars
111}
112
113func (d *DeviceHostConverter) ResourceJars() android.Paths {
114 return d.resourceJars
115}
116
117func (d *DeviceHostConverter) ImplementationAndResourcesJars() android.Paths {
118 return d.implementationAndResourceJars
119}
120
121func (d *DeviceHostConverter) DexJar() android.Path {
122 return nil
123}
124
125func (d *DeviceHostConverter) AidlIncludeDirs() android.Paths {
126 return nil
127}
128
129func (d *DeviceHostConverter) ExportedSdkLibs() []string {
130 return nil
131}