| subprojects { |
| buildscript { |
| repositories { |
| maven { |
| url = '../../../../prebuilts/tools/common/m2/repository/' |
| } |
| } |
| } |
| |
| buildDir = "$rootDir/../../../out/studio/$project.name" |
| repositories { |
| maven { url = "$rootDir/../../../prebuilts/tools/common/m2/repository" } |
| } |
| } |
| |
| class CMakeClosureDelegate { |
| String[] abis = []; |
| String[] buildTypes = []; |
| String name; |
| String projectDir; |
| String[] flags = [] |
| |
| def abis(String[] value) { abis = value; } |
| def buildTypes(String[] value) { buildTypes = value; } |
| def name(String value) { name = value; } |
| def projectDir(String value) { projectDir = value; } |
| def flags(String[] value) { flags = value} |
| } |
| |
| |
| def cmake(cl) { |
| CMakeClosureDelegate data = new CMakeClosureDelegate(); |
| cl.delegate = data; |
| cl.call(); |
| def os = System.getProperty("os.name").toLowerCase(); |
| def host = os.startsWith("linux") ? "linux" : (os.startsWith("win") ? "windows" : "darwin") |
| |
| data.buildTypes.each { buildType -> |
| if (data.abis.size() == 0) { |
| // Building for the host |
| createTasks(data, "Host", "host", buildType, cl.owner, host); |
| } else { |
| // Building multiple abis for android |
| def configure = cl.owner.tasks.create(name: "configure" + data.name.capitalize() + buildType, group: "Native build", type: DefaultTask) {} |
| def precompile = cl.owner.tasks.create(name: "precompile" + data.name.capitalize() + buildType, group: "Native build", type: DefaultTask) {} |
| def compile = cl.owner.tasks.create(name: "compile" + data.name.capitalize() + buildType, group: "Native build", type: DefaultTask) {} |
| def check = cl.owner.tasks.create(name: "check" + data.name.capitalize() + buildType, group: "Native build", type: DefaultTask) {} |
| |
| data.abis.each { abi -> |
| // ABI names contain "-" which do not work well as task names. |
| // Remove them and capitalize instead. |
| def normAbi = abi.split("-").collect { it.capitalize() }.join() |
| def name = data.name.capitalize() + normAbi; |
| createTasks(data, name, abi, buildType, cl.owner, host); |
| configure.dependsOn cl.owner.tasks.("configure" + name + buildType) |
| compile.dependsOn cl.owner.tasks.("compile" + name + buildType) |
| check.dependsOn cl.owner.tasks.("check" + name + buildType) |
| |
| cl.owner.tasks.("compile" + name + buildType).dependsOn precompile |
| } |
| } |
| } |
| } |
| |
| def createTasks(data, name, abi, buildType, project, host) { |
| def buildTypeDir = buildType.toLowerCase() |
| def cmakeBuildDir = "$rootDir/../../../out/studio/${project.name}" |
| def gen = "$cmakeBuildDir/gen/$buildTypeDir/$abi"; |
| def out = "$cmakeBuildDir/out/$buildTypeDir/$abi"; |
| |
| def configureAbi = createTask(project, host, "configure" + name + buildType) { |
| doFirst { |
| file(gen).deleteDir(); |
| file(gen).mkdirs(); |
| } |
| workingDir gen |
| executable "$rootDir/../../../prebuilts/cmake/$host-x86/bin/cmake" |
| args = ["-G", "Ninja", data.projectDir, |
| "-DCMAKE_BUILD_TYPE=$buildType", |
| "-DCMAKE_TOOLCHAIN_FILE=$rootDir/native/cmake/toolchains/${host}-${abi}.cmake", |
| "-DCMAKE_MAKE_PROGRAM=$rootDir/../../../prebuilts/ninja/$host-x86/ninja", |
| "-DCMAKE_INSTALL_PREFIX=$out", |
| "-DGO_EXECUTABLE=$rootDir/../../../prebuilts/go/$host-x86/bin/go", |
| "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"] + Arrays.asList(data.flags) |
| environment GOROOT: "$rootDir/../../../prebuilts/go/$host-x86" |
| inputs.dir "$rootDir/native/cmake/toolchains" |
| outputs.file "$gen/CMakeCache.txt" |
| } |
| |
| createBuildTask(configureAbi, gen, project, host, "compile" + name + buildType, ["install/strip"]) |
| createBuildTask(configureAbi, gen, project, host, "compileTools" + name + buildType, ["protoc", "grpc_cpp_plugin"]) |
| createBuildTask(configureAbi, gen, project, host, "check" + name + buildType, ["check"]) |
| createBuildTask(configureAbi, gen, project, host, "lint" + name + buildType, ["lint"]) |
| } |
| |
| def createBuildTask(configAbi, gen, project, host, name, targets) { |
| def task = createTask(project, host, name) { |
| workingDir gen |
| args = ["--build", "$gen", "--"] + targets |
| executable "$rootDir/../../../prebuilts/cmake/$host-x86/bin/cmake" |
| environment GOROOT: "$rootDir/../../../prebuilts/go/$host-x86" |
| // Always run this task as ninja's super fast dependency check takes care of it |
| outputs.upToDateWhen { return false; } |
| } |
| task.dependsOn configAbi |
| } |
| |
| def createTask(project, host, name, cl) { |
| if (host == "windows") { |
| // Do not build anything on windows yet, but create the tasks to keep the correct dependencies. |
| return project.tasks.create(name: name, group: "Native build", type: DefaultTask) {}; |
| } else { |
| return project.tasks.create(name: name, group: "Native build", type: Exec, cl); |
| } |
| } |
| |
| def requiredVersion = JavaVersion.VERSION_1_8 |
| def jvmVersion = JavaVersion.current() |
| if (requiredVersion != jvmVersion) { |
| throw new RuntimeException("Profiler tools need to be compiled with Java $requiredVersion you are using Java $jvmVersion.") |
| } |