File: build.gradle

package info (click to toggle)
android-platform-tools-base 2.2.2-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 113,928 kB
  • sloc: java: 696,396; xml: 45,920; cpp: 2,526; ansic: 1,432; sh: 508; lisp: 110; javascript: 108; makefile: 17
file content (120 lines) | stat: -rw-r--r-- 4,870 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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 name;
    String projectDir;
    String[] flags = []

    def abis(String[] value) { abis = 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")

    if (data.abis.size() == 0) {
        // Building for the host
        createTasks(data, "Host", "host", cl.owner, host);
    } else {
        // Building multiple abis for android
        def configure = cl.owner.tasks.create(name: "configure" + data.name.capitalize(), group: "Native build", type: DefaultTask) {}
        def precompile = cl.owner.tasks.create(name: "precompile" + data.name.capitalize(), group: "Native build", type: DefaultTask) {}
        def compile = cl.owner.tasks.create(name: "compile" + data.name.capitalize(), group: "Native build", type: DefaultTask) {}
        def check = cl.owner.tasks.create(name: "check" + data.name.capitalize(), 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, cl.owner, host);
            configure.dependsOn cl.owner.tasks.("configure" + name)
            compile.dependsOn cl.owner.tasks.("compile" + name)
            check.dependsOn cl.owner.tasks.("check" + name)

            cl.owner.tasks.("compile" + name).dependsOn precompile
        }
    }
}

def createTasks(data, name, abi, project, host) {
  def cmakeBuildDir = "$rootDir/../../../out/studio/${project.name}"
  def gen = "$cmakeBuildDir/gen/$abi";
  def out = "$cmakeBuildDir/out/$abi";

  // TODO: Define different tasks for debug and release and specify
  // -DCMAKE_BUILD_TYPE=[Debug|Release|MinSizeRel]
  def configureAbi = createTask(project, host, "configure" + name) {
      doFirst {
          file(gen).deleteDir();
          file(gen).mkdirs();
      }
      workingDir gen
      executable "$rootDir/../../../prebuilts/cmake/$host-x86/bin/cmake"
      args = ["-G", "Ninja", data.projectDir,
          "-DCMAKE_TOOLCHAIN_FILE=$rootDir/native/cmake/${host}-${abi}.cmake",
          "-DCMAKE_MAKE_PROGRAM=$rootDir/../../../prebuilts/ninja/$host-x86/ninja",
          "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=$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"
      outputs.file "$gen/CMakeCache.txt"
  }

  def compileAbi = createTask(project, host, "compile" + name) {
      workingDir gen
      args = ["--build", "$gen"]
      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; }
  }
  compileAbi.dependsOn configureAbi

  def checkAbi = createTask(project, host, "check" + name) {
      workingDir gen
      args = ["--build", "$gen", "--target", "check"]
      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; }
  }
  checkAbi.dependsOn configureAbi
}

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.")
}