1 /*
2  * 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 
17 package androidx.build.kythe
18 
19 import androidx.build.AndroidXExtension
20 import androidx.build.ProjectLayoutType
21 import androidx.build.checkapi.ApiTaskConfig
22 import androidx.build.checkapi.configureCompilationInputsAndManifest
23 import androidx.build.checkapi.createReleaseApiConfiguration
24 import androidx.build.getDefaultTargetJavaVersion
25 import androidx.build.getSupportRootFolder
26 import java.io.File
27 import org.gradle.api.Project
28 
29 /** Sets up tasks for generating kzip files that are used for generating xref support on website. */
Projectnull30 fun Project.configureProjectForKzipTasks(config: ApiTaskConfig, extension: AndroidXExtension) {
31     // We use the output of kzip tasks for the Kythe pipeline to generate xrefs in cs.android.com
32     // This is not supported, nor needed in GitHub
33     if (ProjectLayoutType.isPlayground(this)) {
34         return
35     }
36 
37     // TODO(b/379936315): Make these compatible with koltinc/javac that indexer is using
38     if (
39         project.path in
40             listOf(
41                 // Uses Java 9+ APIs, which are not part of any dependency in the classpath
42                 ":room:room-compiler-processing",
43                 ":room:room-compiler-processing-testing",
44                 // KSP generated folders not visible to AGP variant api (b/380363756)
45                 ":privacysandbox:tools:integration-tests:testsdk",
46                 ":room:room-runtime",
47                 // Depends on the generated output of the proto project
48                 // :wear:protolayout:protolayout-proto
49                 // which we haven't captured for Java Kzip generation.
50                 ":wear:tiles:tiles-proto"
51             )
52     ) {
53         return
54     }
55 
56     // afterEvaluate required to read extension properties
57     afterEvaluate {
58         val (compilationInputs, _) =
59             configureCompilationInputsAndManifest(config) ?: return@afterEvaluate
60         val compiledSources = createReleaseApiConfiguration()
61 
62         GenerateKotlinKzipTask.setupProject(
63             project,
64             compilationInputs,
65             compiledSources,
66             extension.kotlinTarget,
67             getDefaultTargetJavaVersion(extension.type, project.name)
68         )
69 
70         GenerateJavaKzipTask.setupProject(project, compilationInputs, compiledSources)
71     }
72 }
73 
74 internal const val ANDROIDX_CORPUS =
75     "android.googlesource.com/platform/frameworks/support//androidx-main"
76 
getVnamesJsonnull77 internal fun Project.getVnamesJson(): File =
78     File(project.getSupportRootFolder(), "buildSrc/vnames.json")
79