1 /*
2  * Copyright 2023 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.clang
18 
19 import androidx.build.KonanPrebuiltsSetup
20 import androidx.testutils.gradle.ProjectSetupRule
21 import org.gradle.api.Project
22 import org.gradle.api.plugins.ExtraPropertiesExtension
23 import org.gradle.testfixtures.ProjectBuilder
24 import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper
25 import org.junit.Before
26 import org.junit.Rule
27 import org.junit.rules.TemporaryFolder
28 
29 /**
30  * Base class for Clang tests that sets up necessary project properties to initialize
31  * [KonanBuildService] in tests.
32  */
33 abstract class BaseClangTest {
34     @get:Rule val projectSetup = ProjectSetupRule()
35 
36     @get:Rule val tmpFolder = TemporaryFolder()
37 
38     protected lateinit var project: Project
39     protected lateinit var clangExtension: AndroidXClang
40 
41     @Before
initnull42     fun init() {
43         project = ProjectBuilder.builder().withProjectDir(projectSetup.rootDir).build()
44         val extension = project.rootProject.property("ext") as ExtraPropertiesExtension
45         // build service needs prebuilts location to "download" clang and targets.
46         projectSetup.props.prebuiltsPath?.let { extension.set("prebuiltsRoot", it) }
47         // ensure that kotlin doesn't try to download prebuilts
48         extension.set("kotlin.native.distribution.downloadFromMaven", "false")
49         project.pluginManager.apply(KotlinMultiplatformPluginWrapper::class.java)
50         clangExtension = AndroidXClang(project)
51         KonanPrebuiltsSetup.configureKonanDirectory(project)
52     }
53 }
54