• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// 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
31	ctx.VisitAllModuleProxies(func(module android.ModuleProxy) {
32		dir := ctx.ModuleDir(module)
33		switch {
34		case strings.HasPrefix(dir, "prebuilts/sdk/current/extras"),
35			strings.HasPrefix(dir, "prebuilts/sdk/current/androidx"),
36			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
45		name := ctx.ModuleName(module)
46		if strings.HasSuffix(name, "-nodeps") {
47			return
48		}
49
50		_, isAndroidLibrary := android.OtherModuleProvider(ctx, module, AndroidLibraryInfoProvider)
51		_, isAARImport := android.OtherModuleProvider(ctx, module, AARImportInfoProvider)
52		if isAndroidLibrary || isAARImport {
53			supportAars = append(supportAars, name)
54		} 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			}
60		}
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}
69