diff --git a/super_native_extensions/cargokit/gradle/plugin.gradle b/super_native_extensions/cargokit/gradle/plugin.gradle index fdf94c43..b5101c30 100644 --- a/super_native_extensions/cargokit/gradle/plugin.gradle +++ b/super_native_extensions/cargokit/gradle/plugin.gradle @@ -1,5 +1,7 @@ import java.nio.file.Paths +import javax.inject.Inject import org.apache.tools.ant.taskdefs.condition.Os +import org.gradle.process.ExecOperations CargoKitPlugin.file = buildscript.sourceFile @@ -12,6 +14,9 @@ class CargoKitExtension { abstract class CargoKitBuildTask extends DefaultTask { + @Inject + abstract ExecOperations getExecOperations() + @Input String buildMode @@ -36,34 +41,28 @@ abstract class CargoKitBuildTask extends DefaultTask { @Input String pluginFile + @Input + String manifestDir + + @Input + String rootProjectDir + @Input List targetPlatforms @TaskAction def build() { - if (project.cargokit.manifestDir == null) { - throw new GradleException("Property 'manifestDir' must be set on cargokit extension"); - } - - if (project.cargokit.libname == null) { - throw new GradleException("Property 'libname' must be set on cargokit extension"); - } - def executableName = Os.isFamily(Os.FAMILY_WINDOWS) ? "run_build_tool.cmd" : "run_build_tool.sh" def path = Paths.get(new File(pluginFile).parent, "..", executableName); - def manifestDir = Paths.get(project.buildscript.sourceFile.parent, project.cargokit.manifestDir) - - def rootProjectDir = project.rootProject.projectDir - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { - project.exec { - commandLine 'chmod', '+x', path + execOperations.exec { + commandLine 'chmod', '+x', path.toString() } } - project.exec { - executable path + execOperations.exec { + executable path.toString() args "build-gradle" environment "CARGOKIT_ROOT_PROJECT_DIR", rootProjectDir environment "CARGOKIT_TOOL_TEMP_DIR", "${buildDir}/build_tool" @@ -140,6 +139,14 @@ class CargoKitPlugin implements Plugin { // The task name depends on plugin properties, which are not available // at this point project.getGradle().afterProject { + if (project.cargokit.manifestDir == null) { + throw new GradleException("Property 'manifestDir' must be set on cargokit extension"); + } + + if (project.cargokit.libname == null) { + throw new GradleException("Property 'libname' must be set on cargokit extension"); + } + def taskName = "cargokitCargoBuild${project.cargokit.libname.capitalize()}${buildType.capitalize()}"; if (project.tasks.findByName(taskName)) { @@ -160,6 +167,8 @@ class CargoKitPlugin implements Plugin { compileSdkVersion = plugin.project.android.compileSdkVersion.substring(8) as int targetPlatforms = platforms pluginFile = CargoKitPlugin.file + manifestDir = Paths.get(project.buildscript.sourceFile.parent, project.cargokit.manifestDir).toString() + rootProjectDir = project.rootProject.projectDir.toString() } def onTask = { newTask -> if (newTask.name == "merge${buildType.capitalize()}NativeLibs") {