blob: f76eb116ee37bdd0d3b6c0168ef7d39bb5fb48f2 [file] [log] [blame]
Colin Crossb2559a02018-04-19 15:26:10 -07001// Copyright 2018 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 "sort"
19 "strings"
20
21 "android/soong/android"
22)
23
24func init() {
25 android.RegisterMakeVarsProvider(pctx, supportLibrariesMakeVarsProvider)
26}
27
28func supportLibrariesMakeVarsProvider(ctx android.MakeVarsContext) {
29 var supportAars, supportJars []string
30
Yu Liu2a815b62025-02-21 20:46:25 +000031 ctx.VisitAllModuleProxies(func(module android.ModuleProxy) {
Colin Cross65494b92019-02-07 14:25:51 -080032 dir := ctx.ModuleDir(module)
Colin Crossb2559a02018-04-19 15:26:10 -070033 switch {
34 case strings.HasPrefix(dir, "prebuilts/sdk/current/extras"),
Alan Viveretteec263272023-10-23 13:16:52 -040035 strings.HasPrefix(dir, "prebuilts/sdk/current/androidx"),
Colin Crossb2559a02018-04-19 15:26:10 -070036 dir == "prebuilts/sdk/current/car",
37 dir == "prebuilts/sdk/current/optional",
38 dir == "prebuilts/sdk/current/support":
39 // Support library
40 default:
41 // Not a support library
42 return
43 }
44
Colin Cross65494b92019-02-07 14:25:51 -080045 name := ctx.ModuleName(module)
Colin Crossb2559a02018-04-19 15:26:10 -070046 if strings.HasSuffix(name, "-nodeps") {
47 return
48 }
49
Yu Liu2a815b62025-02-21 20:46:25 +000050 _, isAndroidLibrary := android.OtherModuleProvider(ctx, module, AndroidLibraryInfoProvider)
51 _, isAARImport := android.OtherModuleProvider(ctx, module, AARImportInfoProvider)
52 if isAndroidLibrary || isAARImport {
Colin Crossb2559a02018-04-19 15:26:10 -070053 supportAars = append(supportAars, name)
Yu Liu2a815b62025-02-21 20:46:25 +000054 } else {
55 _, isJavaLibrary := android.OtherModuleProvider(ctx, module, JavaLibraryInfoProvider)
56 _, isJavaPlugin := android.OtherModuleProvider(ctx, module, JavaPluginInfoProvider)
57 if isJavaLibrary && !isJavaPlugin {
58 supportJars = append(supportJars, name)
59 }
Colin Crossb2559a02018-04-19 15:26:10 -070060 }
61 })
62
63 sort.Strings(supportAars)
64 sort.Strings(supportJars)
65
66 ctx.Strict("SUPPORT_LIBRARIES_AARS", strings.Join(supportAars, " "))
67 ctx.Strict("SUPPORT_LIBRARIES_JARS", strings.Join(supportJars, " "))
68}