mirror of
https://github.com/MetaCubeX/ClashMetaForAndroid.git
synced 2024-11-22 21:36:09 +03:00
Fix: force use cmake installed in system
This commit is contained in:
parent
7cfefbca19
commit
a2f3330455
@ -3,18 +3,13 @@ package com.github.kr328.clash.tools
|
|||||||
import com.android.build.gradle.LibraryExtension
|
import com.android.build.gradle.LibraryExtension
|
||||||
import golangBuild
|
import golangBuild
|
||||||
import golangSource
|
import golangSource
|
||||||
import org.gradle.api.GradleException
|
|
||||||
import org.gradle.api.Plugin
|
import org.gradle.api.Plugin
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.tasks.Delete
|
|
||||||
import java.io.File
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
class ClashBuildPlugin : Plugin<Project> {
|
class ClashBuildPlugin : Plugin<Project> {
|
||||||
override fun apply(target: Project) {
|
override fun apply(target: Project) {
|
||||||
target.afterEvaluate {
|
target.afterEvaluate {
|
||||||
val cmakeDirectory = resolveCmakeDir(target)
|
|
||||||
|
|
||||||
target.extensions.getByType(LibraryExtension::class.java).apply {
|
target.extensions.getByType(LibraryExtension::class.java).apply {
|
||||||
libraryVariants.forEach { variant ->
|
libraryVariants.forEach { variant ->
|
||||||
val config = BuildConfig.of(this, variant)
|
val config = BuildConfig.of(this, variant)
|
||||||
@ -27,7 +22,6 @@ class ClashBuildPlugin : Plugin<Project> {
|
|||||||
) {
|
) {
|
||||||
it.config.set(config)
|
it.config.set(config)
|
||||||
it.ndkDirectory.set(ndkDirectory)
|
it.ndkDirectory.set(ndkDirectory)
|
||||||
it.cmakeDirectory.set(cmakeDirectory)
|
|
||||||
it.inputDirectory.set(target.golangSource)
|
it.inputDirectory.set(target.golangSource)
|
||||||
it.outputDirectory.set(buildDir)
|
it.outputDirectory.set(buildDir)
|
||||||
}
|
}
|
||||||
@ -48,14 +42,4 @@ class ClashBuildPlugin : Plugin<Project> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resolveCmakeDir(project: Project): File {
|
|
||||||
val properties = Properties().apply {
|
|
||||||
project.rootProject.file("local.properties").inputStream().use(this::load)
|
|
||||||
}
|
|
||||||
|
|
||||||
return project.rootProject.file(
|
|
||||||
properties.getProperty("cmake.dir") ?: throw GradleException("cmake.dir not found")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -16,9 +16,6 @@ abstract class ClashBuildTask : DefaultTask() {
|
|||||||
abstract val ndkDirectory: DirectoryProperty
|
abstract val ndkDirectory: DirectoryProperty
|
||||||
@InputDirectory get
|
@InputDirectory get
|
||||||
|
|
||||||
abstract val cmakeDirectory: DirectoryProperty
|
|
||||||
@InputDirectory get
|
|
||||||
|
|
||||||
abstract val inputDirectory: DirectoryProperty
|
abstract val inputDirectory: DirectoryProperty
|
||||||
@InputDirectory get
|
@InputDirectory get
|
||||||
|
|
||||||
@ -31,7 +28,7 @@ abstract class ClashBuildTask : DefaultTask() {
|
|||||||
val output = outputDirectory.file
|
val output = outputDirectory.file
|
||||||
|
|
||||||
val config = config.get()
|
val config = config.get()
|
||||||
val environment = Environment(ndkDirectory.file, cmakeDirectory.file, config.minSdkVersion)
|
val environment = Environment(ndkDirectory.file, config.minSdkVersion)
|
||||||
|
|
||||||
val tags = listOf("without_gvisor", "without_system") +
|
val tags = listOf("without_gvisor", "without_system") +
|
||||||
(if (config.debug) listOf("debug") else emptyList()) +
|
(if (config.debug) listOf("debug") else emptyList()) +
|
||||||
|
@ -6,7 +6,6 @@ import java.io.File
|
|||||||
|
|
||||||
class Environment(
|
class Environment(
|
||||||
private val ndkDirectory: File,
|
private val ndkDirectory: File,
|
||||||
private val cmakeDirectory: File,
|
|
||||||
private val minSdkVersion: Int,
|
private val minSdkVersion: Int,
|
||||||
) {
|
) {
|
||||||
fun ofCoreBuild(abi: NativeAbi): Map<String, String> {
|
fun ofCoreBuild(abi: NativeAbi): Map<String, String> {
|
||||||
@ -35,10 +34,7 @@ class Environment(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun ofLwipBuild(abi: NativeAbi): Map<String, String> {
|
fun ofLwipBuild(abi: NativeAbi): Map<String, String> {
|
||||||
val path = "${cmakeDirectory.absolutePath}${File.pathSeparator}${System.getenv("PATH")}"
|
|
||||||
|
|
||||||
return mapOf(
|
return mapOf(
|
||||||
"PATH" to path,
|
|
||||||
"CMAKE_SYSTEM_NAME" to "Android",
|
"CMAKE_SYSTEM_NAME" to "Android",
|
||||||
"CMAKE_ANDROID_NDK" to ndkDirectory.absolutePath,
|
"CMAKE_ANDROID_NDK" to ndkDirectory.absolutePath,
|
||||||
"CMAKE_ANDROID_ARCH_ABI" to abi.value,
|
"CMAKE_ANDROID_ARCH_ABI" to abi.value,
|
||||||
|
Loading…
Reference in New Issue
Block a user