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