blob: 07011b68ffb89749c31b05784288f5d7ddcd7a02 [file] [log] [blame]
import com.google.androidgamesdk.BuildFolders
import com.google.androidgamesdk.BuildOptions
import com.google.androidgamesdk.ExternalAndroidProject
import com.google.androidgamesdk.ExternalAndroidProjectBuilder
import com.google.androidgamesdk.SpecificToolchain
import com.google.androidgamesdk.LocalToolchain
import com.google.androidgamesdk.OboeDownloader
import com.google.androidgamesdk.Toolchain
import com.google.androidgamesdk.NativeLibrary
import com.google.androidgamesdk.NativeLibrary.SampleFolder
import com.google.androidgamesdk.ToolchainEnumerator
import java.nio.file.Paths
import org.gradle.internal.logging.text.StyledTextOutputFactory;
import static org.gradle.internal.logging.text.StyledTextOutput.Style;
import org.gradle.internal.os.OperatingSystem;
import static groovy.lang.Closure.IDENTITY;
import org.apache.tools.ant.filters.ReplaceTokens;
import com.google.androidgamesdk.ExternalToolName;
import static com.google.androidgamesdk.OsSpecificTools.osFolderName;
import static com.google.androidgamesdk.OsSpecificTools.joinPath;
import static com.google.androidgamesdk.CMakeWrapper.runAndroidCMake;
import static com.google.androidgamesdk.CMakeWrapper.runHostCMake;
import static com.google.androidgamesdk.CMakeWrapper.runNinja;
import static com.google.androidgamesdk.ToolchainEnumerator.filterBuiltLibraries;
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.2'
}
}
def swappyNativeLibrary = new NativeLibrary('swappy', 'GAMESDK_BUILD_SWAPPY')
.setAarLibrary("games-frame-pacing", "1.7.0-beta01")
.addSampleAndroidProject(
new ExternalAndroidProject(joinPath('samples', "bouncyball"))
.copySourcesTo("samples/bouncyball")
.buildDebugApkTo("apks/samples", "bouncyball.apk"))
.addSampleAndroidProject(
new ExternalAndroidProject(joinPath('samples', "cube"))
.copySourcesTo("samples/cube")
.buildDebugApkTo("apks/samples", "cube.apk")
.setDebugApkLocation("third_party/cube/app/build/outputs/apk/debug/app-debug.apk"))
.addSampleAndroidProject(
new ExternalAndroidProject(joinPath('third_party', "cube"))
.copySourcesTo("third_party/cube"))
.addSampleAndroidProject(
new ExternalAndroidProject("test/swappy/testapp")
.buildDebugApkTo("apks/test", "swappytest.apk")
)
def tuningForkNativeLibrary = new NativeLibrary('tuningfork', 'GAMESDK_BUILD_TUNINGFORK')
.setAarLibrary("games-performance-tuner", "1.1.0-beta01")
.setUsesProtobuf()
.addSampleAndroidProject(
new ExternalAndroidProject(joinPath('samples', 'tuningfork', 'insightsdemo'))
.copySourcesTo("samples/tuningfork/insightsdemo")
.buildDebugApkTo("apks/samples", "insightsdemo.apk"))
.addSampleAndroidProject(
new ExternalAndroidProject(joinPath('samples', 'tuningfork', 'experimentsdemo'))
.copySourcesTo("samples/tuningfork/experimentsdemo")
.buildDebugApkTo("apks/samples", "experimentsdemo.apk"))
.addSampleAndroidProject(
new ExternalAndroidProject(joinPath('src', 'tuningfork', 'tools', 'validation'))
.copySourcesTo("src/tuningfork/tools/validation"))
.addSampleAndroidProject(
new ExternalAndroidProject("src/tuningfork/tools/TuningForkMonitor")
.buildDebugApkTo("apks/tools", "TuningForkMonitor.apk"))
.addSampleAndroidProject(
new ExternalAndroidProject("test/tuningfork/testapp")
.buildDebugApkTo("apks/test", "tuningforktest.apk"))
.addSampleExtraFolder(
new SampleFolder(joinPath('samples', 'tuningfork', "common")))
.addSampleExtraFolder(
new SampleFolder(joinPath('src', 'protobuf')))
.addSampleExtraFolder(
new SampleFolder(joinPath('third_party', 'protobuf-3.0.0')))
.addSampleExtraFolder(
new SampleFolder(joinPath('..', 'external', 'nanopb-c'), joinPath('external', 'nanopb-c')))
.addSampleExtraFolder(
new SampleFolder(joinPath('src', 'tuningfork', 'proto')).include('tuningfork.proto'))
def memoryAdviceNativeLibrary = new NativeLibrary('memory_advice', 'GAMESDK_BUILD_MEMORY_ADVICE')
.setAarLibrary("games-memory-advice", "1.0.0-beta01")
def oboeNativeLibrary = new NativeLibrary('oboe', 'GAMESDK_BUILD_OBOE')
.setAarLibrary("games-oboe", "1.0.0-beta01")
.setThirdParty()
.setMinimumAndroidApiLevel(16)
.setMinimumNdkVersion(17)
.setSupportedStlVersions(["c++_shared", "c++_static"])
def protobufInstallDir() {
return new File("$projectDir/third_party/protobuf-3.0.0/install/"
+ osFolderName(ExternalToolName.PROTOBUF)).getPath()
}
def getEnvironment() {
def env = [:]
def trans = IDENTITY
if (OperatingSystem.current().isWindows()) {
trans = { it.toUpperCase() }
}
System.getenv().each{entry -> env[trans(entry.key)] = entry.value}
return env
}
task prepare_proto_before {
def protocBinDir = protobufInstallDir() + "/bin"
def env = getEnvironment()
env['PATH'] = protocBinDir + System.getProperty("path.separator") + env['PATH']
doLast {
// Install python-protobuf
exec {
workingDir "./third_party/protobuf-3.0.0/python"
setEnvironment env
commandLine "python", "setup.py", "install", "--user"
}
// Generate nano-pb requirements
exec {
workingDir '../external/nanopb-c/generator/proto'
setEnvironment env
commandLine 'make'
}
}
}
task prepare_proto(dependsOn: prepare_proto_before) {
doLast {
exec {
commandLine "python"
args = ["ab_info.py"]
}
}
}
// Download third party libraries that are distributed in the Game SDK
// but not part of the Game SDK sources.
task prepare_third_party_libraries {
outputs.dir("src/oboe")
outputs.dir("include/oboe")
doLast {
def oboeDownloader = new OboeDownloader(project)
oboeDownloader.fetchAndInstall();
}
}
allprojects {
buildDir = getOutPath()
repositories {
google()
jcenter()
}
}
def allLibraries = [swappyNativeLibrary, tuningForkNativeLibrary, memoryAdviceNativeLibrary, oboeNativeLibrary]
def getBuildPath() {
return new File("$projectDir/build").getPath()
}
def getOutPath() {
return new File("$projectDir/../out").getPath()
}
def getPackagePath() {
return new File("$projectDir/../package").getPath();
}
def getDistPath() {
if (project.hasProperty("distPath")) {
return new File(project.distPath.trim()).getPath()
}
return getPackagePath()
}
def getTempPath() {
return new File("$projectDir/../.temp").getPath()//.getAbsolutePath()
}
def buildHostModule(subdir, buildType) {
def toolchain = getLocalToolchain()
def buildKey = "host"
def workingFolder = joinPath(getTempPath(), buildKey, '.cmake')
def outputFolder = joinPath(getOutPath(), buildKey)
def cmakeProjectFolder = joinPath("$projectDir", subdir)
def buildFolders = new BuildFolders(cmakeProjectFolder, workingFolder, outputFolder)
runHostCMake(project, buildFolders, toolchain, buildType)
runNinja(project, toolchain, workingFolder)
return [buildKey: buildKey, outputFolder: outputFolder]
}
def buildNativeModules(BuildOptions buildOptions, Toolchain toolchain, Collection<NativeLibrary> libraries, subdir) {
def buildKey = toolchain.getBuildKey(buildOptions)
def workingFolder = joinPath(getTempPath(), buildKey, '.cmake')
def outputFolder = joinPath(getOutPath(), buildKey)
def cmakeProjectFolder = joinPath("$projectDir", subdir)
def buildFolders = new BuildFolders(cmakeProjectFolder, workingFolder, outputFolder)
def builtLibraries = filterBuiltLibraries(libraries, buildOptions, toolchain)
runAndroidCMake(project, buildFolders, toolchain, buildOptions, builtLibraries)
runNinja(project, toolchain, workingFolder)
def jsonDescription = new File(joinPath(outputFolder, "abi.json"))
jsonDescription.text = '{"abi":"'+buildOptions.arch+'","api":'+toolchain.getAndroidVersion()+
',"ndk":'+toolchain.getNdkVersionNumber()+',"stl":"'+buildOptions.stl+'"}'
return [arch: buildOptions.arch, buildKey: buildKey]
}
task cleanPath(type: Delete) {
delete getOutPath()
delete getPackagePath()
delete getTempPath()
delete getBuildPath()
}
def executeCmd(cmd, dir) {
def out = new StringBuilder()
def err = new StringBuilder()
def process = cmd.execute(null, new File(dir))
process.consumeProcessOutput(out, err)
process.waitFor()
logger.info("Running $cmd")
if(out.length()>0)
logger.info(out.toString())
if(err.length()>0)
logger.error(err.toString())
}
def copyLibraryToPrefabAar(buildInfo, outFolder, library) {
def libraryName = library.nativeLibraryName
def prefabName = library.aarLibraryName
def arch = buildInfo.arch
def buildKey = buildInfo.buildKey
def cmakeFolder = joinPath(getTempPath(), buildKey, '.cmake', libraryName)
def buildFolder = joinPath(getPackagePath(), outFolder)
def sharedLibBuildFolder = joinPath(buildFolder, 'prefab','modules', libraryName, 'libs',
'android.'+buildKey)
def staticLibBuildFolder = joinPath(buildFolder, 'prefab','modules', libraryName + '_static', 'libs',
'android.'+buildKey)
def staticsFolder = joinPath(getOutPath(), buildKey)
def sharedIncludeBuildFolder = joinPath(buildFolder, 'prefab','modules', libraryName, 'include', libraryName)
def staticIncludeBuildFolder = joinPath(buildFolder, 'prefab','modules', libraryName + '_static', 'include', libraryName)
def sharedCommonIncludeBuildFolder = joinPath(buildFolder, 'prefab','modules', libraryName, 'include', 'common')
def staticCommonIncludeBuildFolder = joinPath(buildFolder, 'prefab','modules', libraryName + '_static', 'include', 'common')
def headerFolder = './include/' + libraryName
def commonHeaderFolder = './include/common'
// TODO: including the dynamic library (uncommenting these next lines)
// errors because no proper library can be found for module swappy (the shared version),
// probably because we're using c++_static in samples?
def buildSharedLibrary = false
def buildStaticLibrary = true
// 1. Copy dynamic library
if (buildSharedLibrary) {
copy {
from file(cmakeFolder)
include "*.so"
into file(sharedLibBuildFolder)
includeEmptyDirs = false
}
copy {
from file(staticsFolder)
include "*.json"
into file(sharedLibBuildFolder)
}
}
// 2. Copy the static libary
if (buildStaticLibrary) {
copy {
from file(staticsFolder)
include("lib" + libraryName + "_static.a", "*.json")
rename("lib" + libraryName + "_static.a", "lib" + libraryName + ".a")
into file(staticLibBuildFolder)
}
}
// 3.1 Copy headers (shared library)
if (buildSharedLibrary) {
copy {
from file(headerFolder)
include "*.h"
into file(sharedIncludeBuildFolder)
includeEmptyDirs = false
}
copy {
from file(commonHeaderFolder)
include "*.h"
into file(sharedCommonIncludeBuildFolder)
includeEmptyDirs = false
}
}
// 3.2 Copy headers (static library)
if (buildStaticLibrary) {
copy {
from file(headerFolder)
include "*.h"
into file(staticIncludeBuildFolder)
includeEmptyDirs = false
}
copy {
from file(commonHeaderFolder)
include "*.h"
into file(staticCommonIncludeBuildFolder)
includeEmptyDirs = false
}
}
// 4. Copy the manifest
copy {
from file("./src")
include "AndroidManifest.xml"
into file(buildFolder)
includeEmptyDirs = false
}
// 5. Create the json files
def jsonPrefabDescription = new File(joinPath(buildFolder, 'prefab', 'prefab.json'))
jsonPrefabDescription.text = '{"name":"' + prefabName + '","schema_version":1,"dependencies":[],"version":"1.3.0"}'
if (buildSharedLibrary) {
def jsonModuleDescription = new File(joinPath(buildFolder, 'prefab', 'modules', libraryName, 'module.json'))
jsonModuleDescription.text = '{"library_name": "lib' + libraryName + '", "export_libraries": []}'
}
if (buildStaticLibrary) {
def jsonStaticModuleDescription = new File(joinPath(buildFolder, 'prefab', 'modules', libraryName + '_static', 'module.json'))
jsonStaticModuleDescription.text = '{"library_name": "lib' + libraryName + '", "export_libraries": []}'
}
}
def copyLibs(buildInfo, outFolder, Collection<NativeLibrary> libraries, staticToo = false,
useFullBuildKey = false, flattenLibDirs = false, shared = true) {
def arch = buildInfo.arch
def buildKey = buildInfo.buildKey
def cmakeFolder = joinPath(getTempPath(), buildKey, '.cmake')
def buildFolder = joinPath(getPackagePath(), outFolder)
def libBuildFolder = joinPath(buildFolder, 'libs',
useFullBuildKey ? buildKey : arch, 'lib')
if (shared) {
libraries.forEach({ nativeLibrary ->
copy {
from file(cmakeFolder)
include nativeLibrary.nativeLibraryName + "*/lib*.so"
into file(libBuildFolder)
includeEmptyDirs = false
if (flattenLibDirs) {
eachFile {
path = name
}
}
}
})
}
if (staticToo) {
def staticsFolder = joinPath(getOutPath(), buildKey)
def staticLibsBuildFolder = joinPath(buildFolder, 'libs', buildKey)
libraries.forEach({nativeLibrary ->
copy {
from file(staticsFolder)
include "lib" + nativeLibrary.nativeLibraryName + "_static.a"
into file(staticLibsBuildFolder)
}
})
}
}
def copyIncludes(outFolder, Collection<NativeLibrary> libraries) {
def buildFolder = getPackagePath() + '/' + outFolder
def headerFolder = './include'
def includeBuildFolder = joinPath(buildFolder, 'include')
libraries.forEach({ nativeLibrary ->
copy {
from file(headerFolder)
include nativeLibrary.nativeLibraryName + "*/*.h"
into file(includeBuildFolder)
includeEmptyDirs = false
}
})
// Copy common headers
copy {
from file(headerFolder)
include "common/*.h"
into file(includeBuildFolder)
includeEmptyDirs = false
}
}
def copyDocs(outFolder) {
copy {
from "LICENSE", "THIRD_PARTY_NOTICES", "RELEASE_NOTES"
into getPackagePath() + '/' + outFolder
}
}
// Copy samples for packaging. Also rename CMakeLists.txt files so that the
// one distributed are using the packaged game sdk.
def copySampleSources(outFolder, Collection<NativeLibrary> libraries) {
def buildFolder = getPackagePath() + '/' + outFolder
// CMake utility for the Game SDK
copy {
from file(joinPath('samples', "gamesdk.cmake"))
into file(joinPath(buildFolder, 'samples'))
}
// All sample common files
copy {
from file(joinPath('samples', "common"))
into file(joinPath(buildFolder, 'samples', 'common'))
}
// Library specific files
libraries.forEach({ nativeLibrary ->
nativeLibrary.sampleAndroidProjects.forEach({externalAndroidProject ->
if (externalAndroidProject.projectDestinationPath) {
copy {
from file(externalAndroidProject.projectRootPath)
into file(joinPath(buildFolder, externalAndroidProject.projectDestinationPath))
exclude '**/build', '**/out', "local.properties", "**/.externalNativeBuild",
"**/.gradle", "**/OWNERS", "**/.idea", "**/.cxx", '**/CMakeLists.txt'
rename 'CMakeLists.for-samples-in-archive.txt', 'CMakeLists.txt'
includeEmptyDirs = false
}
}
})
nativeLibrary.sampleExtraFolderPaths.forEach({sampleFolder ->
copy {
from file(sampleFolder.sourcePath)
into file(joinPath(buildFolder, sampleFolder.destinationPath))
if (sampleFolder.includePattern != null) {
include sampleFolder.includePattern
}
includeEmptyDirs = false
}
})
})
}
def unityNativeBuild(libraries, buildType="Release") {
def threadChecks = false
def allAbis = new ToolchainEnumerator().allAbis
return allAbis.collect {
buildNativeModules(
new BuildOptions(buildType, threadChecks, "c++_static", it),
new SpecificToolchain(project, "21", "r19"),
libraries,
"src")
}
}
def sdkNativeBuild(libraries, buildType="Release") {
def threadChecks = false
def toolchainEnumerator = new ToolchainEnumerator()
def allToolchains = toolchainEnumerator.enumerateAllToolchains(project)
return toolchainEnumerator.parallelMap(allToolchains, { enumeratedToolchain ->
buildNativeModules(
new BuildOptions(
buildType,
threadChecks,
enumeratedToolchain.stl,
enumeratedToolchain.abi),
enumeratedToolchain.toolchain,
libraries,
"src")
})
}
def sdkAarNativeBuild(libraries, buildType) {
def threadChecks = false
def toolchainEnumerator = new ToolchainEnumerator()
def allAarToolchains = toolchainEnumerator.enumerateAllAarToolchains(project)
return toolchainEnumerator.parallelMap(allAarToolchains, { enumeratedToolchain ->
buildNativeModules(
new BuildOptions(
buildType,
threadChecks,
enumeratedToolchain.stl,
enumeratedToolchain.abi),
enumeratedToolchain.toolchain,
libraries,
"src")
})
}
def specificNativeBuild(specificToolchainConfiguration, libraries,
buildType="Release") {
def threadChecks = false
def allAbis = new ToolchainEnumerator().allAbis
def toolchain = new SpecificToolchain(project,
specificToolchainConfiguration.sdk,
specificToolchainConfiguration.ndk)
return allAbis.collect {
buildNativeModules(
new BuildOptions(buildType, threadChecks, specificToolchainConfiguration.stl, it),
toolchain,
libraries,
"src")
}
}
def getLocalToolchain() {
def kApiLevel = project.hasProperty("androidApiLevel") ?
project.androidApiLevel : "24"
def ndkVersion = project.hasProperty("ndk") ? project.ndk : null;
return new LocalToolchain(project, kApiLevel, ndkVersion)
}
def localNativeBuild(libraries, subdir = "src", buildType="Release") {
def allAbis = new ToolchainEnumerator().allAbis
def toolchain = getLocalToolchain();
def threadChecks = true
return allAbis.collect {
def buildOptions = new BuildOptions(buildType, threadChecks, "c++_static", it)
buildNativeModules(buildOptions, toolchain, libraries, subdir)
}
}
def getBuildType() {
return project.hasProperty("buildType") ?
project.buildType : "Release"
}
def getPackageName() {
return project.hasProperty("packageName") ?
project.packageName : "gamesdk"
}
def shouldIncludeSampleSources() {
return project.hasProperty("includeSampleSources")
}
def shouldIncludeSampleArtifacts() {
return project.hasProperty("includeSampleArtifacts")
}
def shouldSkipSamplesBuild() {
return project.hasProperty("skipSamplesBuild")
}
def getSpecificToolchainConfiguration() {
if (!project.hasProperty("sdk") || !project.hasProperty("ndk") || !project.hasProperty("stl")) {
throw new GradleException("""
Must set SDK, NDK and STL for a specific build,
e.g. ./gradlew packageSpecificZip -Plibraries=swappy -Psdk=14 -Pndk=r16 -Pstl='c++_static'"""
)
}
return [sdk: project.sdk, ndk: project.ndk, stl: project.stl]
}
def filterLibraries(allLibraries) {
if (!project.hasProperty("libraries")) {
return []
}
def requestedLibraryNames = project.libraries.split(',');
return requestedLibraryNames.collect { requestedLibraryName ->
def library = allLibraries.find {
library -> library.nativeLibraryName == requestedLibraryName
}
if (library == null) {
throw new GradleException("Library ${requestedLibraryName} does not exist.")
}
return library
}
}
class BuildTask extends DefaultTask {
}
task build(type: BuildTask) {
ext.flattenLibs = false
ext.withSharedLibs = true
ext.withStaticLibs = true
ext.withFullBuildKey = true
ext.nativeBuild = { -> sdkNativeBuild(filterLibraries(allLibraries), getBuildType()) }
}
task buildUnity(type: BuildTask) {
ext.flattenLibs = true
ext.withSharedLibs = true
ext.withStaticLibs = true
ext.withFullBuildKey = true
ext.nativeBuild = { -> unityNativeBuild(filterLibraries(allLibraries), getBuildType()) }
}
task buildLocal(type: BuildTask) {
ext.flattenLibs = false
ext.withSharedLibs = true
ext.withStaticLibs = true
ext.withFullBuildKey = false
ext.nativeBuild = { -> localNativeBuild(filterLibraries(allLibraries), "src", getBuildType()) }
}
task buildSpecific(type: BuildTask) {
ext.flattenLibs = false
ext.withSharedLibs = true
ext.withStaticLibs = true
ext.withFullBuildKey = false
ext.nativeBuild = { ->
specificNativeBuild(getSpecificToolchainConfiguration(), filterLibraries(allLibraries), getBuildType())
}
}
tasks.withType(BuildTask) {
def libraries = filterLibraries(allLibraries)
dependsOn ':extras:assembleRelease'
libraries.each { nativeLibrary ->
if (nativeLibrary.isThirdParty()) dependsOn prepare_third_party_libraries
if (nativeLibrary.getUsesProtobuf()) dependsOn prepare_proto
}
doFirst {
// Ensure some libraries to build were set
if (libraries.isEmpty()) {
throw new GradleException("""
Must specify which libraries to build,
e.g. ./gradlew build -Plibraries=swappy,tuningfork""")
}
}
doLast {
def packageName = getPackageName()
// Clear the package path to ensure the task zip is not polluted
// by previous build tasks.
delete joinPath(getPackagePath(), packageName)
nativeBuild().each {
copyLibs(it, packageName, libraries, withStaticLibs,
withFullBuildKey, flattenLibs, withSharedLibs)
}
copyIncludes(packageName, libraries)
copyDocs(packageName)
if (shouldIncludeSampleSources()) {
copySampleSources(packageName, libraries)
}
}
}
// Build task for making an AAR that can be used with Prefab
task buildAar {
def libraries = filterLibraries(allLibraries)
dependsOn ':extras:assembleRelease'
libraries.each { nativeLibrary ->
if (nativeLibrary.isThirdParty()) dependsOn prepare_third_party_libraries
if (nativeLibrary.getUsesProtobuf()) dependsOn prepare_proto
}
doFirst {
// Clear the package path to ensure AAR generation is not polluted
// by previous build tasks.
delete joinPath(getPackagePath(), getPackageName())
}
ext.flattenLibs = false
ext.withSharedLibs = true
ext.withStaticLibs = true
ext.withFullBuildKey = true
ext.nativeBuild = { -> sdkAarNativeBuild(libraries, getBuildType()) }
doLast {
def packageName = getPackageName()
nativeBuild().each { buildInfo ->
libraries.forEach {
library -> copyLibraryToPrefabAar(buildInfo, packageName, library)
}
}
}
}
task localUnitTests {
// These unit tests require a single connected device with target architecture set by the
// project property 'arch'.
// Set the property 'component' to 'tuningfork' or 'swappy' to run the required test suite.
// e.g. ./gradlew localUnitTests -Parch=x86 -Pcomponent=tuningfork
// arch defaults to 'arm64-v8a' and component to 'tuningfork' if they are not set.
doLast {
def pcomponent = 'tuningfork'
if (project.hasProperty('component'))
pcomponent = component
def parch = 'arm64-v8a'
if (project.hasProperty('arch'))
parch = arch
def buildInfo = localNativeBuild([swappyNativeLibrary, tuningForkNativeLibrary, memoryAdviceNativeLibrary], "test/$pcomponent")
def buildKey = buildInfo.buildKey.findAll{it.contains(parch)}[0]
def cmakeFolder = getTempPath() + "/$buildKey/.cmake"
def toolchain = getLocalToolchain();
def adb = toolchain.getAdbPath();
exec {
workingDir cmakeFolder
commandLine adb, "push", "${pcomponent}_test", "/data/local/tmp"
}
exec {
workingDir cmakeFolder
commandLine adb, "shell", "/data/local/tmp/${pcomponent}_test"
}
}
}
task localDeviceInfoUnitTests {
doLast {
def buildInfo = buildHostModule("test/device_info", "Release")
exec {
workingDir buildInfo.outputFolder
commandLine "./device_info_test"
}
}
}
task format {
doLast {
def formattedFiles =
fileTree(dir: 'src', include: ['**/*.cpp', '**/*.c', '**/*.h'], excludes: ["protobuf"]) +
fileTree(dir: 'include', include: ['**/*.h'], excludes: ["third_party"]) +
fileTree(dir: 'test/swappy', include: ['**/*.cpp', '**/*.c', '**/*.h']) +
fileTree(dir: 'test/tuningfork', include: ['**/*.cpp', '**/*.c', '**/*.h'])
formattedFiles.files.each { file ->
exec {
commandLine "/bin/bash"
args "-c", "clang-format -i " + file
workingDir projectDir
}
}
}
}
task buildSampleArtifacts {
doFirst {
def buildFolder = joinPath(getPackagePath(), getPackageName())
def builder = new ExternalAndroidProjectBuilder(project, buildFolder)
builder.setSkipSamplesBuild(shouldSkipSamplesBuild())
filterLibraries(allLibraries).forEach { nativeLibrary ->
logger.info("Building samples of " + nativeLibrary.nativeLibraryName + "...")
builder.buildSampleArtifacts(nativeLibrary)
}
}
}
// Zipping things up
def addZipTask(name, buildTask, archName) {
tasks.register(name, Zip) {
dependsOn buildTask
if (shouldIncludeSampleArtifacts()) {
dependsOn buildSampleArtifacts
}
def buildFolder = joinPath(getPackagePath(), getPackageName())
from fileTree(buildFolder)
exclude archName
destinationDirectory = file(buildFolder)
archiveFileName = archName
doLast {
def outFolder = getBuildPath();
mkdir outFolder;
copy {
from file(archiveName)
into outFolder
}
if (getDistPath() != getPackagePath()) {
copy {
from getPackagePath()
into getDistPath()
}
}
def out = services.get(StyledTextOutputFactory).create("output")
out.style(Style.Identifier).text('\n' + archName +' is in ')
.style(Style.ProgressStatus)
.println(destinationDirectory.get());
}
}
}
task prepareMavenZipContent {
description "Build the AAR and prepare the versioned pom file for the specified library"
dependsOn "packageAar"
doLast {
def buildFolder = joinPath(getPackagePath(), getPackageName())
def mavenZipContentFolder = joinPath(buildFolder, "maven-zip");
delete mavenZipContentFolder
mkdir mavenZipContentFolder
filterLibraries(allLibraries).forEach { nativeLibrary ->
def libraryName = nativeLibrary.aarLibraryName
def aarVersion = nativeLibrary.aarVersion
copy {
from file(joinPath(buildFolder, "gamesdk.aar"))
into file(joinPath(mavenZipContentFolder))
rename "gamesdk.aar", libraryName + "-" + aarVersion + ".aar"
}
copy {
from file(joinPath("src", "maven", libraryName + ".pom"))
into file(joinPath(mavenZipContentFolder))
rename libraryName + ".pom", libraryName + "-" + aarVersion + ".pom"
filter(ReplaceTokens, tokens: [aarVersion: aarVersion])
}
}
}
}
// Generate a zip file with the library AAR and its pom file, all versioned,
// so that it's ready to be uploaded to Maven.
task packageMavenZip(type: Zip) {
dependsOn prepareMavenZipContent
def buildFolder = joinPath(getPackagePath(), getPackageName())
def mavenZipContentFolder = joinPath(buildFolder, "maven-zip")
from fileTree(mavenZipContentFolder)
destinationDirectory = file(buildFolder)
def aarName = filterLibraries(allLibraries).collect { it.aarLibraryName }.join('-')
archiveFileName = aarName + "-maven-zip.zip"
// Don't lose time compressing already compressed files
entryCompression = ZipEntryCompression.STORED
doLast {
if (getDistPath() != getPackagePath()) {
copy {
from getPackagePath()
into getDistPath()
}
}
}
}
addZipTask("packageUnityZip", buildUnity, "builds.zip")
addZipTask("packageZip", build, "gamesdk.zip")
addZipTask("packageLocalZip", buildLocal, "gamesdk.zip")
addZipTask("packageSpecificZip", buildSpecific, "gamesdk.zip")
addZipTask("packageAar", buildAar, "gamesdk.aar")