John Park | 7eb9042 | 2018-01-27 12:04:57 -0800 | [diff] [blame] | 1 | import edu.wpi.first.nativeutils.NativeUtils |
| 2 | import edu.wpi.first.nativeutils.tasks.JNIHeaders |
| 3 | |
| 4 | buildscript { |
| 5 | repositories { |
| 6 | mavenLocal() |
| 7 | maven { |
| 8 | url "https://plugins.gradle.org/m2/" |
| 9 | } |
| 10 | } |
| 11 | dependencies { |
| 12 | classpath 'gradle.plugin.edu.wpi.first:native-utils:1.5.1' |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | plugins { |
| 17 | id 'net.ltgt.errorprone' version '0.0.10' |
| 18 | id 'edu.wpi.first.wpilib.versioning.WPILibVersioningPlugin' version '2.0' |
| 19 | id 'idea' |
| 20 | } |
| 21 | |
| 22 | ext.licenseFile = file("$rootDir/LICENSE.txt") |
| 23 | |
| 24 | ext.getJNIHeadersClass = { |
| 25 | return JNIHeaders |
| 26 | } |
| 27 | |
| 28 | ext.getClassifier = { binary-> |
| 29 | return NativeUtils.getClassifier(binary) |
| 30 | } |
| 31 | |
| 32 | ext.getPlatformPath = { binary-> |
| 33 | return NativeUtils.getPlatformPath(binary) |
| 34 | } |
| 35 | |
| 36 | ext.createComponentZipTasks = { components, name, base, type, project, func -> |
| 37 | def configMap = [:] |
| 38 | components.each { |
| 39 | if (it in NativeLibrarySpec && it.name == name) { |
| 40 | it.binaries.each { |
| 41 | def target = getClassifier(it) |
| 42 | if (configMap.containsKey(target)) { |
| 43 | configMap.get(target).add(it) |
| 44 | } else { |
| 45 | configMap.put(target, []) |
| 46 | configMap.get(target).add(it) |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | def taskList = [] |
| 52 | def outputsFolder = file("$project.buildDir/outputs") |
| 53 | def baseN = base + name |
| 54 | configMap.each { key, value -> |
| 55 | def task = project.tasks.create(baseN + "-${key}", type) { |
| 56 | description = 'Creates component archive for platform ' + key |
| 57 | destinationDir = outputsFolder |
| 58 | classifier = key |
| 59 | baseName = baseN + '-classifier' |
| 60 | duplicatesStrategy = 'exclude' |
| 61 | |
| 62 | from(licenseFile) { |
| 63 | into '/' |
| 64 | } |
| 65 | |
| 66 | func(it, value) |
| 67 | } |
| 68 | taskList.add(task) |
| 69 | |
| 70 | project.build.dependsOn task |
| 71 | |
| 72 | project.artifacts { |
| 73 | task |
| 74 | } |
| 75 | } |
| 76 | return taskList |
| 77 | } |
| 78 | |
| 79 | ext.createAllCombined = { list, name, base, type, project -> |
| 80 | def outputsFolder = file("$project.buildDir/outputs") |
| 81 | def baseN = base + name |
| 82 | def task = project.tasks.create(baseN + '-all', type) { |
| 83 | description = 'Creates component archive for all classifiers' |
| 84 | destinationDir = outputsFolder |
| 85 | classifier = 'all' |
| 86 | baseName = baseN + '-classifier' |
| 87 | duplicatesStrategy = 'exclude' |
| 88 | |
| 89 | list.each { |
| 90 | it.outputs.files.each { |
| 91 | from project.zipTree(it) |
| 92 | } |
| 93 | dependsOn it |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | project.build.dependsOn task |
| 98 | |
| 99 | project.artifacts { |
| 100 | task |
| 101 | } |
| 102 | |
| 103 | return task |
| 104 | |
| 105 | } |
| 106 | |
| 107 | ext.includeStandardZipFormat = { task, value -> |
| 108 | value.each { binary-> |
| 109 | if (binary.buildable) { |
| 110 | if (binary instanceof SharedLibraryBinarySpec) { |
| 111 | task.dependsOn binary.buildTask |
| 112 | task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) { |
| 113 | into getPlatformPath(binary) + '/shared' |
| 114 | } |
| 115 | task.from (binary.sharedLibraryFile) { |
| 116 | into getPlatformPath(binary) + '/shared' |
| 117 | } |
| 118 | task.from (binary.sharedLibraryLinkFile) { |
| 119 | into getPlatformPath(binary) + '/shared' |
| 120 | } |
| 121 | } else if (binary instanceof StaticLibraryBinarySpec) { |
| 122 | task.dependsOn binary.buildTask |
| 123 | task.from (binary.staticLibraryFile) { |
| 124 | into getPlatformPath(binary) + '/static' |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // Ensure that the WPILibVersioningPlugin is setup by setting the release type, if releaseType wasn't |
| 132 | // already specified on the command line |
| 133 | if (!hasProperty('releaseType')) { |
| 134 | WPILibVersion { |
| 135 | releaseType = 'dev' |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | def pubVersion |
| 140 | if (project.hasProperty("publishVersion")) { |
| 141 | pubVersion = project.publishVersion |
| 142 | } else { |
| 143 | pubVersion = WPILibVersion.version |
| 144 | } |
| 145 | |
| 146 | def outputsFolder = file("$buildDir/outputs") |
| 147 | |
| 148 | def versionFile = file("$outputsFolder/version.txt") |
| 149 | |
| 150 | task outputVersions() { |
| 151 | description = 'Prints the versions of wpilib to a file for use by the downstream packaging project' |
| 152 | group = 'Build' |
| 153 | outputs.files(versionFile) |
| 154 | |
| 155 | doFirst { |
| 156 | buildDir.mkdir() |
| 157 | outputsFolder.mkdir() |
| 158 | } |
| 159 | |
| 160 | doLast { |
| 161 | versionFile.write pubVersion |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | task build() {} |
| 166 | |
| 167 | build.dependsOn outputVersions |
| 168 | |
| 169 | task clean(type: Delete) { |
| 170 | delete buildDir |
| 171 | } |
| 172 | |
| 173 | subprojects { |
| 174 | apply plugin: 'eclipse' |
| 175 | apply plugin: 'idea' |
| 176 | apply plugin: 'checkstyle' |
| 177 | |
| 178 | repositories { |
| 179 | mavenCentral() |
| 180 | } |
| 181 | |
| 182 | checkstyle { |
| 183 | toolVersion = "8.1" |
| 184 | configFile = new File(rootDir, "styleguide/checkstyle.xml") |
| 185 | } |
| 186 | |
| 187 | // Disables doclint in java 8. |
| 188 | if (JavaVersion.current().isJava8Compatible()) { |
| 189 | tasks.withType(Javadoc) { |
| 190 | options.addStringOption('Xdoclint:none', '-quiet') |
| 191 | } |
| 192 | } |
| 193 | ext.setupWpilibRepo = { publishing -> |
| 194 | publishing.repositories.maven { |
| 195 | url = WPILibVersion.mavenLocalUrl |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | task wrapper(type: Wrapper) { |
| 201 | gradleVersion = '4.1' |
| 202 | } |