Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 1 | apply plugin: 'maven-publish' |
| 2 | |
| 3 | def baseArtifactId = 'Glass' |
| 4 | def artifactGroupId = 'edu.wpi.first.tools' |
| 5 | def zipBaseName = '_GROUP_edu_wpi_first_tools_ID_Glass_CLS' |
| 6 | |
| 7 | def libBaseArtifactId = 'libglass' |
| 8 | def libArtifactGroupId = 'edu.wpi.first.glass' |
| 9 | def libZipBaseName = '_GROUP_edu_wpi_first_glass_ID_libglass_CLS' |
| 10 | |
| 11 | def libntBaseArtifactId = 'libglassnt' |
| 12 | def libntArtifactGroupId = 'edu.wpi.first.glass' |
| 13 | def libntZipBaseName = '_GROUP_edu_wpi_first_glass_ID_libglassnt_CLS' |
| 14 | |
| 15 | def outputsFolder = file("$project.buildDir/outputs") |
| 16 | |
| 17 | task libCppSourcesZip(type: Zip) { |
| 18 | destinationDirectory = outputsFolder |
| 19 | archiveBaseName = libZipBaseName |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 20 | archiveClassifier = "sources" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 21 | |
| 22 | from(licenseFile) { into '/' } |
| 23 | from('src/lib/native/cpp') { into '/' } |
| 24 | } |
| 25 | |
| 26 | task libCppHeadersZip(type: Zip) { |
| 27 | destinationDirectory = outputsFolder |
| 28 | archiveBaseName = libZipBaseName |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 29 | archiveClassifier = "headers" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 30 | |
| 31 | from(licenseFile) { into '/' } |
| 32 | from('src/lib/native/include') { into '/' } |
| 33 | } |
| 34 | |
| 35 | task libntCppSourcesZip(type: Zip) { |
| 36 | destinationDirectory = outputsFolder |
| 37 | archiveBaseName = libntZipBaseName |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 38 | archiveClassifier = "sources" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 39 | |
| 40 | from(licenseFile) { into '/' } |
| 41 | from('src/libnt/native/cpp') { into '/' } |
| 42 | } |
| 43 | |
| 44 | task libntCppHeadersZip(type: Zip) { |
| 45 | destinationDirectory = outputsFolder |
| 46 | archiveBaseName = libntZipBaseName |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 47 | archiveClassifier = "headers" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 48 | |
| 49 | from(licenseFile) { into '/' } |
| 50 | from('src/libnt/native/include') { into '/' } |
| 51 | } |
| 52 | |
| 53 | build.dependsOn libCppHeadersZip |
| 54 | build.dependsOn libCppSourcesZip |
| 55 | build.dependsOn libntCppHeadersZip |
| 56 | build.dependsOn libntCppSourcesZip |
| 57 | |
| 58 | addTaskToCopyAllOutputs(libCppHeadersZip) |
| 59 | addTaskToCopyAllOutputs(libCppSourcesZip) |
| 60 | addTaskToCopyAllOutputs(libntCppHeadersZip) |
| 61 | addTaskToCopyAllOutputs(libntCppSourcesZip) |
| 62 | |
| 63 | model { |
| 64 | tasks { |
| 65 | // Create the run task. |
| 66 | $.components.glassApp.binaries.each { bin -> |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 67 | if (bin.buildable && bin.name.toLowerCase().contains("debug") && nativeUtils.isNativeDesktopPlatform(bin.targetPlatform)) { |
| 68 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 69 | Task run = project.tasks.create("run", Exec) { |
| 70 | commandLine bin.tasks.install.runScriptFile.get().asFile.toString() |
| 71 | } |
| 72 | run.dependsOn bin.tasks.install |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | publishing { |
| 77 | def glassAppTaskList = [] |
| 78 | $.components.each { component -> |
| 79 | component.binaries.each { binary -> |
| 80 | if (binary in NativeExecutableBinarySpec && binary.component.name.contains("glassApp")) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame] | 81 | if (binary.buildable && (binary.name.contains('Release') || binary.name.contains('release'))) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 82 | // We are now in the binary that we want. |
| 83 | // This is the default application path for the ZIP task. |
| 84 | def applicationPath = binary.executable.file |
| 85 | def icon = file("$project.projectDir/src/app/native/mac/glass.icns") |
| 86 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 87 | // Create the ZIP. |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 88 | def task = project.tasks.create("copyGlassExecutable" + binary.targetPlatform.operatingSystem.name + binary.targetPlatform.architecture.name, Zip) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 89 | description("Copies the Glass executable to the outputs directory.") |
| 90 | destinationDirectory = outputsFolder |
| 91 | |
| 92 | archiveBaseName = '_M_' + zipBaseName |
| 93 | duplicatesStrategy = 'exclude' |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 94 | archiveClassifier = nativeUtils.getPublishClassifier(binary) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 95 | |
| 96 | from(licenseFile) { |
| 97 | into '/' |
| 98 | } |
| 99 | |
| 100 | from(applicationPath) |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 101 | |
| 102 | if (binary.targetPlatform.operatingSystem.isWindows()) { |
| 103 | def exePath = binary.executable.file.absolutePath |
| 104 | exePath = exePath.substring(0, exePath.length() - 4) |
| 105 | def pdbPath = new File(exePath + '.pdb') |
| 106 | from(pdbPath) |
| 107 | } |
| 108 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 109 | into(nativeUtils.getPlatformPath(binary)) |
| 110 | } |
| 111 | |
| 112 | if (binary.targetPlatform.operatingSystem.isMacOsX()) { |
James Kuszmaul | b13e13f | 2023-11-22 20:44:04 -0800 | [diff] [blame] | 113 | // Create the macOS bundle. |
| 114 | def bundleTask = project.tasks.create("bundleGlassOsxApp" + binary.targetPlatform.architecture.name, Copy) { |
| 115 | description("Creates a macOS application bundle for Glass") |
| 116 | from(file("$project.projectDir/Info.plist")) |
| 117 | into(file("$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name/Glass.app/Contents")) |
| 118 | into("MacOS") { |
| 119 | with copySpec { |
| 120 | from binary.executable.file |
| 121 | } |
| 122 | } |
| 123 | into("Resources") { |
| 124 | with copySpec { |
| 125 | from icon |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | inputs.property "HasDeveloperId", project.hasProperty("developerID") |
| 130 | |
| 131 | doLast { |
| 132 | if (project.hasProperty("developerID")) { |
| 133 | // Get path to binary. |
| 134 | exec { |
| 135 | workingDir rootDir |
| 136 | def args = [ |
| 137 | "sh", |
| 138 | "-c", |
| 139 | "codesign --force --strict --deep " + |
| 140 | "--timestamp --options=runtime " + |
| 141 | "--verbose -s ${project.findProperty("developerID")} " + |
| 142 | "$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name/Glass.app/" |
| 143 | ] |
| 144 | commandLine args |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | // Reset the application path if we are creating a bundle. |
| 151 | applicationPath = file("$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name") |
| 152 | project.build.dependsOn bundleTask |
| 153 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 154 | bundleTask.dependsOn binary.tasks.link |
| 155 | task.dependsOn(bundleTask) |
| 156 | } |
| 157 | |
| 158 | task.dependsOn binary.tasks.link |
| 159 | glassAppTaskList.add(task) |
| 160 | project.build.dependsOn task |
| 161 | project.artifacts { task } |
| 162 | addTaskToCopyAllOutputs(task) |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | def libGlassTaskList = createComponentZipTasks($.components, ['glass'], libZipBaseName, Zip, project, includeStandardZipFormat) |
| 169 | def libGlassntTaskList = createComponentZipTasks($.components, ['glassnt'], libntZipBaseName, Zip, project, includeStandardZipFormat) |
| 170 | |
| 171 | publications { |
| 172 | glassApp(MavenPublication) { |
| 173 | glassAppTaskList.each { artifact it } |
| 174 | |
| 175 | artifactId = baseArtifactId |
| 176 | groupId = artifactGroupId |
| 177 | version wpilibVersioning.version.get() |
| 178 | } |
| 179 | libglass(MavenPublication) { |
| 180 | libGlassTaskList.each { artifact it } |
| 181 | |
| 182 | artifact libCppHeadersZip |
| 183 | artifact libCppSourcesZip |
| 184 | |
| 185 | artifactId = libBaseArtifactId |
| 186 | groupId = libArtifactGroupId |
| 187 | version wpilibVersioning.version.get() |
| 188 | } |
| 189 | libglassnt(MavenPublication) { |
| 190 | libGlassntTaskList.each { artifact it } |
| 191 | |
| 192 | artifact libntCppHeadersZip |
| 193 | artifact libntCppSourcesZip |
| 194 | |
| 195 | artifactId = libntBaseArtifactId |
| 196 | groupId = libntArtifactGroupId |
| 197 | version wpilibVersioning.version.get() |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |