Brian Silverman | 8fce748 | 2020-01-05 13:18:21 -0800 | [diff] [blame] | 1 | import org.gradle.internal.os.OperatingSystem |
| 2 | |
| 3 | nativeUtils.addWpiNativeUtils() |
| 4 | nativeUtils.withRoboRIO() |
| 5 | nativeUtils.withRaspbian() |
| 6 | nativeUtils.withBionic() |
| 7 | nativeUtils { |
| 8 | wpi { |
| 9 | configureDependencies { |
| 10 | wpiVersion = "-1" |
| 11 | niLibVersion = "2020.10.1" |
| 12 | opencvVersion = "3.4.7-2" |
| 13 | googleTestVersion = "1.9.0-4-437e100-1" |
| 14 | imguiVersion = "1.72b-2" |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | nativeUtils.wpi.addWarnings() |
| 20 | nativeUtils.wpi.addWarningsAsErrors() |
| 21 | |
| 22 | nativeUtils.setSinglePrintPerPlatform() |
| 23 | |
| 24 | model { |
| 25 | components { |
| 26 | all { |
| 27 | nativeUtils.useAllPlatforms(it) |
| 28 | } |
| 29 | } |
| 30 | binaries { |
| 31 | withType(NativeBinarySpec).all { |
| 32 | nativeUtils.usePlatformArguments(it) |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | ext.appendDebugPathToBinaries = { binaries-> |
| 38 | binaries.withType(StaticLibraryBinarySpec) { |
| 39 | if (it.buildType.name.contains('debug')) { |
| 40 | def staticFileDir = it.staticLibraryFile.parentFile |
| 41 | def staticFileName = it.staticLibraryFile.name |
| 42 | def staticFileExtension = staticFileName.substring(staticFileName.lastIndexOf('.')) |
| 43 | staticFileName = staticFileName.substring(0, staticFileName.lastIndexOf('.')) |
| 44 | staticFileName = staticFileName + 'd' + staticFileExtension |
| 45 | def newStaticFile = new File(staticFileDir, staticFileName) |
| 46 | it.staticLibraryFile = newStaticFile |
| 47 | } |
| 48 | } |
| 49 | binaries.withType(SharedLibraryBinarySpec) { |
| 50 | if (it.buildType.name.contains('debug')) { |
| 51 | def sharedFileDir = it.sharedLibraryFile.parentFile |
| 52 | def sharedFileName = it.sharedLibraryFile.name |
| 53 | def sharedFileExtension = sharedFileName.substring(sharedFileName.lastIndexOf('.')) |
| 54 | sharedFileName = sharedFileName.substring(0, sharedFileName.lastIndexOf('.')) |
| 55 | sharedFileName = sharedFileName + 'd' + sharedFileExtension |
| 56 | def newSharedFile = new File(sharedFileDir, sharedFileName) |
| 57 | |
| 58 | def sharedLinkFileDir = it.sharedLibraryLinkFile.parentFile |
| 59 | def sharedLinkFileName = it.sharedLibraryLinkFile.name |
| 60 | def sharedLinkFileExtension = sharedLinkFileName.substring(sharedLinkFileName.lastIndexOf('.')) |
| 61 | sharedLinkFileName = sharedLinkFileName.substring(0, sharedLinkFileName.lastIndexOf('.')) |
| 62 | sharedLinkFileName = sharedLinkFileName + 'd' + sharedLinkFileExtension |
| 63 | def newLinkFile = new File(sharedLinkFileDir, sharedLinkFileName) |
| 64 | |
| 65 | it.sharedLibraryLinkFile = newLinkFile |
| 66 | it.sharedLibraryFile = newSharedFile |
| 67 | } |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | ext.createComponentZipTasks = { components, names, base, type, project, func -> |
| 72 | def stringNames = names.collect {it.toString()} |
| 73 | def configMap = [:] |
| 74 | components.each { |
| 75 | if (it in NativeLibrarySpec && stringNames.contains(it.name)) { |
| 76 | it.binaries.each { |
| 77 | if (!it.buildable) return |
| 78 | def target = nativeUtils.getPublishClassifier(it) |
| 79 | if (configMap.containsKey(target)) { |
| 80 | configMap.get(target).add(it) |
| 81 | } else { |
| 82 | configMap.put(target, []) |
| 83 | configMap.get(target).add(it) |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | } |
| 88 | def taskList = [] |
| 89 | def outputsFolder = file("$project.buildDir/outputs") |
| 90 | configMap.each { key, value -> |
| 91 | def task = project.tasks.create(base + "-${key}", type) { |
| 92 | description = 'Creates component archive for platform ' + key |
| 93 | destinationDirectory = outputsFolder |
| 94 | classifier = key |
| 95 | archiveBaseName = '_M_' + base |
| 96 | duplicatesStrategy = 'exclude' |
| 97 | |
| 98 | from(licenseFile) { |
| 99 | into '/' |
| 100 | } |
| 101 | |
| 102 | func(it, value) |
| 103 | } |
| 104 | taskList.add(task) |
| 105 | |
| 106 | project.build.dependsOn task |
| 107 | |
| 108 | project.artifacts { |
| 109 | task |
| 110 | } |
| 111 | addTaskToCopyAllOutputs(task) |
| 112 | } |
| 113 | return taskList |
| 114 | } |
| 115 | |
| 116 | ext.includeStandardZipFormat = { task, value -> |
| 117 | value.each { binary -> |
| 118 | if (binary.buildable) { |
| 119 | if (binary instanceof SharedLibraryBinarySpec) { |
| 120 | task.dependsOn binary.tasks.link |
| 121 | task.from(new File(binary.sharedLibraryFile.absolutePath + ".debug")) { |
| 122 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 123 | } |
| 124 | def sharedPath = binary.sharedLibraryFile.absolutePath |
| 125 | sharedPath = sharedPath.substring(0, sharedPath.length() - 4) |
| 126 | |
| 127 | task.from(new File(sharedPath + '.pdb')) { |
| 128 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 129 | } |
| 130 | task.from(binary.sharedLibraryFile) { |
| 131 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 132 | } |
| 133 | task.from(binary.sharedLibraryLinkFile) { |
| 134 | into nativeUtils.getPlatformPath(binary) + '/shared' |
| 135 | } |
| 136 | } else if (binary instanceof StaticLibraryBinarySpec) { |
| 137 | task.dependsOn binary.tasks.createStaticLib |
| 138 | task.from(binary.staticLibraryFile) { |
| 139 | into nativeUtils.getPlatformPath(binary) + '/static' |
| 140 | } |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |