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 |
| 20 | classifier = "sources" |
| 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 |
| 29 | classifier = "headers" |
| 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 |
| 38 | classifier = "sources" |
| 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 |
| 47 | classifier = "headers" |
| 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 | |
| 87 | // Create the macOS bundle. |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 88 | def bundleTask = project.tasks.create("bundleGlassOsxApp" + binary.targetPlatform.architecture.name, Copy) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 89 | description("Creates a macOS application bundle for Glass") |
| 90 | from(file("$project.projectDir/Info.plist")) |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 91 | into(file("$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name/Glass.app/Contents")) |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 92 | into("MacOS") { with copySpec { from binary.executable.file } } |
| 93 | into("Resources") { with copySpec { from icon } } |
| 94 | |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 95 | inputs.property "HasDeveloperId", project.hasProperty("developerID") |
| 96 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 97 | doLast { |
| 98 | if (project.hasProperty("developerID")) { |
| 99 | // Get path to binary. |
| 100 | exec { |
| 101 | workingDir rootDir |
| 102 | def args = [ |
| 103 | "sh", |
| 104 | "-c", |
| 105 | "codesign --force --strict --deep " + |
| 106 | "--timestamp --options=runtime " + |
| 107 | "--verbose -s ${project.findProperty("developerID")} " + |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 108 | "$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name/Glass.app/" |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 109 | ] |
| 110 | commandLine args |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | // Reset the application path if we are creating a bundle. |
| 117 | if (binary.targetPlatform.operatingSystem.isMacOsX()) { |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 118 | applicationPath = file("$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name") |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 119 | project.build.dependsOn bundleTask |
| 120 | } |
| 121 | |
| 122 | // Create the ZIP. |
James Kuszmaul | cf32412 | 2023-01-14 14:07:17 -0800 | [diff] [blame^] | 123 | def task = project.tasks.create("copyGlassExecutable" + binary.targetPlatform.architecture.name, Zip) { |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 124 | description("Copies the Glass executable to the outputs directory.") |
| 125 | destinationDirectory = outputsFolder |
| 126 | |
| 127 | archiveBaseName = '_M_' + zipBaseName |
| 128 | duplicatesStrategy = 'exclude' |
| 129 | classifier = nativeUtils.getPublishClassifier(binary) |
| 130 | |
| 131 | from(licenseFile) { |
| 132 | into '/' |
| 133 | } |
| 134 | |
| 135 | from(applicationPath) |
Austin Schuh | 75263e3 | 2022-02-22 18:05:32 -0800 | [diff] [blame] | 136 | |
| 137 | if (binary.targetPlatform.operatingSystem.isWindows()) { |
| 138 | def exePath = binary.executable.file.absolutePath |
| 139 | exePath = exePath.substring(0, exePath.length() - 4) |
| 140 | def pdbPath = new File(exePath + '.pdb') |
| 141 | from(pdbPath) |
| 142 | } |
| 143 | |
Austin Schuh | 812d0d1 | 2021-11-04 20:16:48 -0700 | [diff] [blame] | 144 | into(nativeUtils.getPlatformPath(binary)) |
| 145 | } |
| 146 | |
| 147 | if (binary.targetPlatform.operatingSystem.isMacOsX()) { |
| 148 | bundleTask.dependsOn binary.tasks.link |
| 149 | task.dependsOn(bundleTask) |
| 150 | } |
| 151 | |
| 152 | task.dependsOn binary.tasks.link |
| 153 | glassAppTaskList.add(task) |
| 154 | project.build.dependsOn task |
| 155 | project.artifacts { task } |
| 156 | addTaskToCopyAllOutputs(task) |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | def libGlassTaskList = createComponentZipTasks($.components, ['glass'], libZipBaseName, Zip, project, includeStandardZipFormat) |
| 163 | def libGlassntTaskList = createComponentZipTasks($.components, ['glassnt'], libntZipBaseName, Zip, project, includeStandardZipFormat) |
| 164 | |
| 165 | publications { |
| 166 | glassApp(MavenPublication) { |
| 167 | glassAppTaskList.each { artifact it } |
| 168 | |
| 169 | artifactId = baseArtifactId |
| 170 | groupId = artifactGroupId |
| 171 | version wpilibVersioning.version.get() |
| 172 | } |
| 173 | libglass(MavenPublication) { |
| 174 | libGlassTaskList.each { artifact it } |
| 175 | |
| 176 | artifact libCppHeadersZip |
| 177 | artifact libCppSourcesZip |
| 178 | |
| 179 | artifactId = libBaseArtifactId |
| 180 | groupId = libArtifactGroupId |
| 181 | version wpilibVersioning.version.get() |
| 182 | } |
| 183 | libglassnt(MavenPublication) { |
| 184 | libGlassntTaskList.each { artifact it } |
| 185 | |
| 186 | artifact libntCppHeadersZip |
| 187 | artifact libntCppSourcesZip |
| 188 | |
| 189 | artifactId = libntBaseArtifactId |
| 190 | groupId = libntArtifactGroupId |
| 191 | version wpilibVersioning.version.get() |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | } |