Colin Cross | b2559a0 | 2018-04-19 15:26:10 -0700 | [diff] [blame] | 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 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "sort" |
| 19 | "strings" |
| 20 | |
| 21 | "android/soong/android" |
| 22 | ) |
| 23 | |
| 24 | func init() { |
| 25 | android.RegisterMakeVarsProvider(pctx, supportLibrariesMakeVarsProvider) |
| 26 | } |
| 27 | |
| 28 | func supportLibrariesMakeVarsProvider(ctx android.MakeVarsContext) { |
| 29 | var supportAars, supportJars []string |
| 30 | |
Yu Liu | 2a815b6 | 2025-02-21 20:46:25 +0000 | [diff] [blame^] | 31 | ctx.VisitAllModuleProxies(func(module android.ModuleProxy) { |
Colin Cross | 65494b9 | 2019-02-07 14:25:51 -0800 | [diff] [blame] | 32 | dir := ctx.ModuleDir(module) |
Colin Cross | b2559a0 | 2018-04-19 15:26:10 -0700 | [diff] [blame] | 33 | switch { |
| 34 | case strings.HasPrefix(dir, "prebuilts/sdk/current/extras"), |
Alan Viverette | ec26327 | 2023-10-23 13:16:52 -0400 | [diff] [blame] | 35 | strings.HasPrefix(dir, "prebuilts/sdk/current/androidx"), |
Colin Cross | b2559a0 | 2018-04-19 15:26:10 -0700 | [diff] [blame] | 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 | |
Colin Cross | 65494b9 | 2019-02-07 14:25:51 -0800 | [diff] [blame] | 45 | name := ctx.ModuleName(module) |
Colin Cross | b2559a0 | 2018-04-19 15:26:10 -0700 | [diff] [blame] | 46 | if strings.HasSuffix(name, "-nodeps") { |
| 47 | return |
| 48 | } |
| 49 | |
Yu Liu | 2a815b6 | 2025-02-21 20:46:25 +0000 | [diff] [blame^] | 50 | _, isAndroidLibrary := android.OtherModuleProvider(ctx, module, AndroidLibraryInfoProvider) |
| 51 | _, isAARImport := android.OtherModuleProvider(ctx, module, AARImportInfoProvider) |
| 52 | if isAndroidLibrary || isAARImport { |
Colin Cross | b2559a0 | 2018-04-19 15:26:10 -0700 | [diff] [blame] | 53 | supportAars = append(supportAars, name) |
Yu Liu | 2a815b6 | 2025-02-21 20:46:25 +0000 | [diff] [blame^] | 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 | } |
Colin Cross | b2559a0 | 2018-04-19 15:26:10 -0700 | [diff] [blame] | 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 | } |