File: brltty-build.gradle

package info (click to toggle)
brltty 6.9-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 44,828 kB
  • sloc: ansic: 154,246; java: 13,514; sh: 9,934; xml: 5,672; tcl: 2,679; makefile: 2,346; awk: 713; lisp: 366; python: 321; ml: 301
file content (232 lines) | stat: -rw-r--r-- 7,001 bytes parent folder | download | duplicates (4)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
String getJarsPath (Map properties) {
  return brltty.getJarsPath(properties.project)
}

String getLibrariesPath (Map properties) {
  return brltty.getLibrariesPath(properties.project)
}

String getABIPath (Map properties) {
  return brltty.getABIPath(properties.project, properties.ABI)
}

Map getABI (String abi) {
  if (!brltty.containsKey("ABI")) {
    brltty.ABI = [:]
  }

  def ABI = brltty.ABI
  if (!ABI.containsKey(abi)) ABI[abi] = [:]
  return ABI[abi]
}

Map getABI (Map properties) {
  return getABI(properties.ABI)
}

brltty.addConsumerTask = { Task producerTask, String consumerName ->
  gradle.projectsEvaluated {
    def consumerTask = producerTask.project.tasks.findByName(consumerName)

    if (consumerTask != null) {
      consumerTask.mustRunAfter producerTask
    }
  }
}

Task newTask (Project project, String name, Class<DefaultTask> type=DefaultTask, Closure closure) {
  def task = project.tasks.register(name, type, closure).get()

  task.configure {
    group "build"
  }

  return task
}

Task newTask (Map properties, String name, Class<DefaultTask> type=DefaultTask, Closure closure) {
  name += properties.taskNameSuffix
  return newTask(properties.project, name, type, closure)
}

Task newAssembleTask (Map properties) {
  return newTask(properties.project, "brlttyAssembleAllComponents") {
    description "Assemble all of the native jars, libraries, assets, etc."
  }
}

void addAssembleDependency (Map properties, Task task) {
  properties.assembleTask.dependsOn task
}

Task newCleanTask (Map properties) {
  return newTask(properties.project, "brlttyCleanAllComponents") {
    description "Clean all of the native jars, libraries, assets, etc."
  }
}

void addCleanDependency (Map properties, Task task) {
  properties.cleanTask.dependsOn task
}

Task newConfigureTask (Map properties) {
  return newTask(properties, "brlttyConfigureABI", Exec) {
    description "Configure the ${properties.componentName} for the ${properties.ABI} ABI."

    workingDir properties.abiDirectory
    ignoreExitValue false
    commandLine "${brltty.native.rootDirectory}/cfg-android-abi", properties.ABI
  }
}

Task getConfigureTask (Map properties) {
  def abi = getABI(properties)

  if (!abi.containsKey("configureTask")) {
    abi.configureTask = newConfigureTask(properties)
  }

  return abi.configureTask
}

Task newMakeComponentsTask (Map properties) {
  return newTask(properties, "brlttyMakeABI", Exec) {
    description "Make the ${properties.ABI} components of the ${properties.componentName}."
    dependsOn properties.configureTask

    workingDir properties.makeDirectory
    ignoreExitValue false

    commandLine "make"
    args properties.makeTargets
  }
}

Task newAddJarsTask (Map properties) {
  def task = newTask(properties, "brlttyAddJars", Copy) {
    description "Add the ${properties.componentName}'s ${properties.ABI} jars to the build."
    dependsOn properties.makeComponentsTask
    into getJarsPath(properties)

    properties.jarSubdirectories.each { subdirectory ->
      from properties.abiDirectory + File.separator + subdirectory
    }

    properties.jars.each { jar ->
      include "${jar}.jar"
    }
  }

  brltty.addConsumerTask(task, "mergeDebugJavaResource")
  brltty.addConsumerTask(task, "copyDebugJniLibsProjectAndLocalJars")

  return task
}

Task newAddLibrariesTask (Map properties) {
  def task = newTask(properties, "brlttyAddLibraries", Copy) {
    description "Add the ${properties.componentName}'s ${properties.ABI} libraries to the build."
    dependsOn properties.makeComponentsTask
    into getABIPath(properties)

    properties.librarySubdirectories.each { subdirectory ->
      from properties.abiDirectory + File.separator + subdirectory
    }

    properties.libraries.each { library ->
      include "lib${library}.so"
    }
  }

  brltty.addConsumerTask(task, "mergeDebugJniLibFolders")
  brltty.addConsumerTask(task, "mergeReleaseJniLibFolders")

  return task
}

Task newMakeCleanTask (Map properties) {
  return newTask(properties, "brlttyCleanABI", Exec) {
    description "Remove (make clean) the ${properties.ABI} components of the ${properties.componentName}."
    dependsOn properties.configureTask

    workingDir properties.makeDirectory
    ignoreExitValue true
    commandLine "make", "clean"
  }
}

Task newRemoveTask (Map properties) {
  return newTask(properties, "brlttyRemoveAllComponents", Delete) {
    description "Remove the ${properties.componentName}'s jars and libraries from the build."
    delete getJarsPath(properties)
    delete getLibrariesPath(properties)
  }
}

void addTasks (Map properties, String abi) {
  properties.ABI = abi
  def isPrimaryABI = abi.equals(brltty.native.abiList[0])

  properties.abiDirectory = brltty.native.abiDirectory + File.separator + properties.ABI
  properties.configureTask = getConfigureTask(properties)

  properties.makeDirectory = properties.abiDirectory + File.separator + properties.makeSubdirectory
  properties.makeComponentsTask = newMakeComponentsTask(properties)

  if (isPrimaryABI) {
    def jars = properties.jars

    if ((jars != null) && !jars.isEmpty()) {
      def addJarsTask = newAddJarsTask(properties)
      addAssembleDependency(properties, addJarsTask)
    }
  }

  def libraries = properties.libraries
  if ((libraries != null) && !libraries.isEmpty()) {
    def addLibrariesTask = newAddLibrariesTask(properties)
    addAssembleDependency(properties, addLibrariesTask)
  }

  def makeCleanTask = newMakeCleanTask(properties)
  addCleanDependency(properties, makeCleanTask)
}

void addTasks (Map properties) {
  def taskNameSuffix = ""
  properties.taskNameSuffix = taskNameSuffix

  properties.assembleTask = newAssembleTask(properties)
  properties.cleanTask = newCleanTask(properties)

  if (properties.makeTargets == null) properties.makeTargets = "all"
  if (properties.makeTargets instanceof String) properties.makeTargets = [properties.makeTargets]

  if (properties.jarSubdirectories == null) properties.jarSubdirectories = properties.makeSubdirectory
  if (properties.jarSubdirectories instanceof String) properties.jarSubdirectories = [properties.jarSubdirectories]

  if (properties.librarySubdirectories == null) properties.librarySubdirectories = properties.makeSubdirectory
  if (properties.librarySubdirectories instanceof String) properties.librarySubdirectories = [properties.librarySubdirectories]

  def removeTask = newRemoveTask(properties)
  addCleanDependency(properties, removeTask)

  brltty.native.abiList.each { abi ->
    properties.taskNameSuffix = "${taskNameSuffix}_${abi}"
    addTasks(properties, abi)
  }
}

brltty.addAssembleTask = { Project project, Task assembleTask ->
  project.afterEvaluate {
    project.tasks.withType(JavaCompile).each { compileTask ->
      compileTask.dependsOn assembleTask
    }
  }
}

brltty.buildComponent = { Map properties ->
  addTasks(properties)
  brltty.addAssembleTask(properties.project, properties.assembleTask)
  clean.dependsOn properties.cleanTask
}