Artur Satayev | eabf2c1 | 2021-04-07 15:45:02 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2021 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package java |
| 18 | |
| 19 | import ( |
| 20 | "android/soong/android" |
| 21 | ) |
| 22 | |
| 23 | // Build rules and utilities to generate individual packages/modules/SdkExtensions/proto/classpaths.proto |
| 24 | // config files based on build configuration to embed into /system and /apex on a device. |
| 25 | // |
| 26 | // See `derive_classpath` service that reads the configs at runtime and defines *CLASSPATH variables |
| 27 | // on the device. |
| 28 | |
| 29 | type classpathType int |
| 30 | |
| 31 | const ( |
| 32 | // Matches definition in packages/modules/SdkExtensions/proto/classpaths.proto |
| 33 | BOOTCLASSPATH classpathType = iota |
| 34 | DEX2OATBOOTCLASSPATH |
| 35 | SYSTEMSERVERCLASSPATH |
| 36 | ) |
| 37 | |
| 38 | func (c classpathType) String() string { |
| 39 | return [...]string{"BOOTCLASSPATH", "DEX2OATBOOTCLASSPATH", "SYSTEMSERVERCLASSPATH"}[c] |
| 40 | } |
| 41 | |
| 42 | type classpathFragmentProperties struct { |
| 43 | } |
| 44 | |
| 45 | // classpathFragment interface is implemented by a module that contributes jars to a *CLASSPATH |
| 46 | // variables at runtime. |
| 47 | type classpathFragment interface { |
| 48 | android.Module |
| 49 | |
| 50 | classpathFragmentBase() *classpathFragmentBase |
| 51 | } |
| 52 | |
| 53 | // classpathFragmentBase is meant to be embedded in any module types that implement classpathFragment; |
| 54 | // such modules are expected to call initClasspathFragment(). |
| 55 | type classpathFragmentBase struct { |
| 56 | properties classpathFragmentProperties |
| 57 | |
| 58 | classpathType classpathType |
| 59 | |
| 60 | outputFilepath android.OutputPath |
| 61 | } |
| 62 | |
| 63 | // Initializes classpathFragmentBase struct. Must be called by all modules that include classpathFragmentBase. |
| 64 | func initClasspathFragment(c classpathFragment) { |
| 65 | base := c.classpathFragmentBase() |
| 66 | c.AddProperties(&base.properties) |
| 67 | } |