1 /* <lambda>null2 * Copyright 2024 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 package com.android.security.autorepro 17 18 import org.gradle.api.Project 19 import org.gradle.api.attributes.Attribute 20 21 class PluginBase { 22 class AbiAttributes(name: String, bitness: Int) { 23 val name = name 24 val bitness = bitness 25 } 26 27 // https://developer.android.com/ndk/guides/abis#sa 28 enum class Abi(val attr: AbiAttributes) { 29 ABI_ARMEABI_V7A(AbiAttributes("armeabi-v7a", 32)), 30 ABI_ARM64_V8A(AbiAttributes("arm64-v8a", 64)), 31 ABI_X86(AbiAttributes("x86", 32)), 32 ABI_X86_64(AbiAttributes("x86_64", 64)), 33 } 34 35 companion object { 36 val AUTOREPRO_TESTCASES_RESOURCE_CONFIGURATION_NAME = "testResource" 37 38 fun applyConfiguration( 39 project: Project, 40 sourceDirectoryArtifact: Any, 41 manifestArtifact: Any, 42 resourceArtifacts: List<Pair<Abi, Any>>, 43 ) { 44 // Export a configuration for users to add dependencies. 45 // "testResource" represents Soong modules for the Tradefed testcases/ directory. 46 // See "android_test_helper_app" and "cc_test" Soong modules. 47 // Dependencies should map 1:1 to tradefed Android.bp files for easy reconstruction. 48 project.configurations.create(AUTOREPRO_TESTCASES_RESOURCE_CONFIGURATION_NAME) { 49 configuration -> 50 configuration.isCanBeConsumed = true 51 configuration.isCanBeResolved = false 52 } 53 54 val testResourceConfiguration = 55 project.configurations.getByName(AUTOREPRO_TESTCASES_RESOURCE_CONFIGURATION_NAME) 56 val abiAttribute = Attribute.of("com.android.security.autorepro.abi", Abi::class.java) 57 testResourceConfiguration.outgoing { configurationPublications -> 58 configurationPublications.artifact(sourceDirectoryArtifact) { 59 configurePublishArtifact -> 60 configurePublishArtifact.setType("source") 61 } 62 configurationPublications.artifact(manifestArtifact) { configurePublishArtifact -> 63 configurePublishArtifact.setType("manifest") 64 } 65 configurationPublications.variants { namedDomainObjectContainer -> 66 resourceArtifacts.forEach { resourceArtifact -> 67 val (abi, artifact) = resourceArtifact 68 val abiName = abi.attr.name 69 namedDomainObjectContainer.create("abi-$abiName") { configurationVariant -> 70 configurationVariant.attributes { attributeContainer -> 71 attributeContainer.attribute(abiAttribute, abi) 72 } 73 configurationVariant.artifact(artifact) { configurablePublishArtifact -> 74 configurablePublishArtifact.setType("resource") 75 } 76 } 77 } 78 } 79 } 80 } 81 } 82 83 class ModuleManifest<T>(project: Project, type: String, resource: T) { 84 val name: String = project.name 85 val type: String = type 86 val resource: T = resource 87 } 88 } 89