Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions super_native_extensions/cargokit/gradle/plugin.gradle
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -12,6 +14,9 @@ class CargoKitExtension {

abstract class CargoKitBuildTask extends DefaultTask {

@Inject
abstract ExecOperations getExecOperations()

@Input
String buildMode

Expand All @@ -36,34 +41,28 @@ abstract class CargoKitBuildTask extends DefaultTask {
@Input
String pluginFile

@Input
String manifestDir

@Input
String rootProjectDir

@Input
List<String> 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"
Expand Down Expand Up @@ -140,6 +139,14 @@ class CargoKitPlugin implements Plugin<Project> {
// 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)) {
Expand All @@ -160,6 +167,8 @@ class CargoKitPlugin implements Plugin<Project> {
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") {
Expand Down