forked from ibcn-cloudlet/dianne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
165 lines (144 loc) · 5.14 KB
/
build.gradle
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
/*
* Master Gradle build script
*
* Depends on bndPlugin property set by settings.gradle.
* and bnd_* values from gradle.properties.
*/
import aQute.bnd.build.Workspace
import aQute.bnd.osgi.Constants
/* Add bnd gradle plugin as a script dependency */
buildscript {
dependencies {
classpath bndPlugin
}
}
def runCommand(String[] args) {
new ByteArrayOutputStream().withStream { os ->
def result = exec {
commandLine = args
standardOutput = os
}
return os.toString().trim()
}
}
/* Initialize the bnd workspace */
Workspace.setDriver(Constants.BNDDRIVER_GRADLE)
Workspace.addGestalt(Constants.GESTALT_BATCH, null)
ext.bndWorkspace = new Workspace(rootDir, bnd_cnf)
if (bndWorkspace == null) {
throw new GradleException("Unable to load workspace ${rootDir}/${bnd_cnf}")
}
ext {
cnf = rootProject.project(bnd_cnf)
os = System.env.OS ?: runCommand('uname', '-s')
arch = System.env.ARCH ?: runCommand('uname', '-m')
osgi_os = os.replaceFirst(/^Darwin/, "MacOSX")
osgi_arch = arch.replaceFirst(/(?i)arm(.*)/,"ARM")
extension = (os == "Darwin") ? 'dylib' : 'so'
lib = System.env.NATIVE ?: "torch"
jenkins_build = System.env.BUILD ?: "false"
download_url = "http://dianne.intec.ugent.be/"
println("Configuring workspace with configuration parameters 'OS': '$os', 'ARCH': '$arch', 'osgi_os': '$osgi_os', 'osgi_arch': '$osgi_arch', extension: '$extension' and 'NATIVE' lib: '$lib'")
}
// create placeholder of template files so they exist before configuration phase of subprojects
runCommand('find', '.', '-name', '*.template', '-execdir', 'bash', '-c', 'touch ${0%%\\.template}', '{}', ';')
/* Configure the subprojects */
subprojects {
def bndProject = bndWorkspace.getProject(name)
if (bndProject != null) {
plugins.apply 'biz.aQute.bnd'
fileTree(projectDir) {
include '*.bndrun'
}.each {
def bndrun = it.name - '.bndrun'
task("run.${bndrun}") {
description "Run the exported ${bndrun}.jar file."
dependsOn "export.${bndrun}"
group 'run'
def executableJar = file("${distsDir}/executable/${bndrun}.jar")
inputs.file executableJar
doLast {
logger.info "Running {} from directory {}", executableJar.absolutePath, projectDir.absolutePath
javaexec {
main '-jar'
args executableJar
standardInput System.in
ignoreExitValue true
workingDir projectDir
}
}
}
}
task("cleanAll", description: "Clean all code including all (sub)native libraries.", group: 'build') {}
cleanAll.dependsOn(clean)
fileTree(projectDir) {
include 'jni/Makefile'
}.each { File file ->
logger.info "Found Makefile in jni folder: {}", file.absolutePath
task("buildNative", type: Exec, description: "Build native code", group: "build") {
def outputExtentions = ["*.o","*.dylib","*.so","*.a", "*_*.h"]
inputs.files compileJava
inputs.files fileTree(dir: file.parent, excludes: outputExtentions)
outputs.dir "$projectDir/native/$lib/$os/$arch"
outputs.dir "$projectDir/native/$os/$arch"
outputs.files fileTree(dir: file.parent, includes: outputExtentions)
workingDir file.parent
commandLine "make"
}
jar.dependsOn("buildNative")
task("cleanNative", type: Exec, description: "Clean dynamic libraries.", group: 'build') {
workingDir file.parent
commandLine "make", "clean"
standardOutput = new ByteArrayOutputStream()
}
clean.dependsOn("cleanNative")
task("cleanAllNative", type: Exec, description: "Clean all native code including sub projects.", group: 'build') {
workingDir file.parent
commandLine "make", "cleanall"
standardOutput = new ByteArrayOutputStream()
}
cleanAll.dependsOn("cleanAllNative")
}
/* fix native tests */
tasks.withType(Test) {
systemProperty "java.library.path", "${bnd.workspace}/be.iminds.iot.dianne.tensor.native/native/${lib}/${os}/${arch}/"
}
}
}
getTasksByName('test', true).each{ task -> task.dependsOn(getTasksByName('buildNative', true)) }
getAllTasks(true).each{ project -> project.value.each{ task -> if(task.name.startsWith('export.')) { task.dependsOn('clean' + task.name.substring(0,1).toUpperCase() + task.name.substring(1)) } } }
task("datasets") {
description "Download pre-configured datasets (all available by default)."
group 'util'
doLast {
def ds = project.hasProperty('which') ? project.properties['which'] + "/" : ""
def dir = project.properties['directory'] ?: "./tools/datasets/"
logger.info "Downloading dataset(s) {} to directory {}", ds , dir
directory(dir)
download(download_url + "datasets/" + ds, dir)
}
}
task("models") {
description "Download neural network models (all available by default)."
group 'util'
doLast {
def mod = project.hasProperty('which') ? project.properties['which'] + "/" : ""
def dir = project.properties['directory'] ?: "./tools/models/"
logger.info "Downloading model(s) {} to directory {}", mod , dir
directory(dir)
download(download_url + "models/" + mod, dir)
}
}
def download(String[] args) {
def url = args[0]
def dir = args[1]
exec {
/* Could be better, but works for now */
commandLine "wget", "-nv", "-r", "-np", "-nH", "--cut-dirs=1", "--reject=index.html*", "-P", dir, url
}
}
def directory(String arg) {
exec {
commandLine "mkdir", "-p", arg
}
}