blob: 0797fa15ef656d2d43c29289fbada696e483be1e [file] [log] [blame]
Austin Schuh812d0d12021-11-04 20:16:48 -07001apply plugin: 'maven-publish'
2
3def baseArtifactId = 'Glass'
4def artifactGroupId = 'edu.wpi.first.tools'
5def zipBaseName = '_GROUP_edu_wpi_first_tools_ID_Glass_CLS'
6
7def libBaseArtifactId = 'libglass'
8def libArtifactGroupId = 'edu.wpi.first.glass'
9def libZipBaseName = '_GROUP_edu_wpi_first_glass_ID_libglass_CLS'
10
11def libntBaseArtifactId = 'libglassnt'
12def libntArtifactGroupId = 'edu.wpi.first.glass'
13def libntZipBaseName = '_GROUP_edu_wpi_first_glass_ID_libglassnt_CLS'
14
15def outputsFolder = file("$project.buildDir/outputs")
16
17task libCppSourcesZip(type: Zip) {
18 destinationDirectory = outputsFolder
19 archiveBaseName = libZipBaseName
James Kuszmaulb13e13f2023-11-22 20:44:04 -080020 archiveClassifier = "sources"
Austin Schuh812d0d12021-11-04 20:16:48 -070021
22 from(licenseFile) { into '/' }
23 from('src/lib/native/cpp') { into '/' }
24}
25
26task libCppHeadersZip(type: Zip) {
27 destinationDirectory = outputsFolder
28 archiveBaseName = libZipBaseName
James Kuszmaulb13e13f2023-11-22 20:44:04 -080029 archiveClassifier = "headers"
Austin Schuh812d0d12021-11-04 20:16:48 -070030
31 from(licenseFile) { into '/' }
32 from('src/lib/native/include') { into '/' }
33}
34
35task libntCppSourcesZip(type: Zip) {
36 destinationDirectory = outputsFolder
37 archiveBaseName = libntZipBaseName
James Kuszmaulb13e13f2023-11-22 20:44:04 -080038 archiveClassifier = "sources"
Austin Schuh812d0d12021-11-04 20:16:48 -070039
40 from(licenseFile) { into '/' }
41 from('src/libnt/native/cpp') { into '/' }
42}
43
44task libntCppHeadersZip(type: Zip) {
45 destinationDirectory = outputsFolder
46 archiveBaseName = libntZipBaseName
James Kuszmaulb13e13f2023-11-22 20:44:04 -080047 archiveClassifier = "headers"
Austin Schuh812d0d12021-11-04 20:16:48 -070048
49 from(licenseFile) { into '/' }
50 from('src/libnt/native/include') { into '/' }
51}
52
53build.dependsOn libCppHeadersZip
54build.dependsOn libCppSourcesZip
55build.dependsOn libntCppHeadersZip
56build.dependsOn libntCppSourcesZip
57
58addTaskToCopyAllOutputs(libCppHeadersZip)
59addTaskToCopyAllOutputs(libCppSourcesZip)
60addTaskToCopyAllOutputs(libntCppHeadersZip)
61addTaskToCopyAllOutputs(libntCppSourcesZip)
62
63model {
64 tasks {
65 // Create the run task.
66 $.components.glassApp.binaries.each { bin ->
James Kuszmaulcf324122023-01-14 14:07:17 -080067 if (bin.buildable && bin.name.toLowerCase().contains("debug") && nativeUtils.isNativeDesktopPlatform(bin.targetPlatform)) {
68
Austin Schuh812d0d12021-11-04 20:16:48 -070069 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 Kuszmaulcf324122023-01-14 14:07:17 -080081 if (binary.buildable && (binary.name.contains('Release') || binary.name.contains('release'))) {
Austin Schuh812d0d12021-11-04 20:16:48 -070082 // 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 Schuh812d0d12021-11-04 20:16:48 -070087 // Create the ZIP.
James Kuszmaulb13e13f2023-11-22 20:44:04 -080088 def task = project.tasks.create("copyGlassExecutable" + binary.targetPlatform.operatingSystem.name + binary.targetPlatform.architecture.name, Zip) {
Austin Schuh812d0d12021-11-04 20:16:48 -070089 description("Copies the Glass executable to the outputs directory.")
90 destinationDirectory = outputsFolder
91
92 archiveBaseName = '_M_' + zipBaseName
93 duplicatesStrategy = 'exclude'
James Kuszmaulb13e13f2023-11-22 20:44:04 -080094 archiveClassifier = nativeUtils.getPublishClassifier(binary)
Austin Schuh812d0d12021-11-04 20:16:48 -070095
96 from(licenseFile) {
97 into '/'
98 }
99
100 from(applicationPath)
Austin Schuh75263e32022-02-22 18:05:32 -0800101
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 Schuh812d0d12021-11-04 20:16:48 -0700109 into(nativeUtils.getPlatformPath(binary))
110 }
111
112 if (binary.targetPlatform.operatingSystem.isMacOsX()) {
James Kuszmaulb13e13f2023-11-22 20:44:04 -0800113 // 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 Schuh812d0d12021-11-04 20:16:48 -0700154 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}