blob: 5e7cbaf7d5c373839fc942c27b8b2f64b97027e5 [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
20 classifier = "sources"
21
22 from(licenseFile) { into '/' }
23 from('src/lib/native/cpp') { into '/' }
24}
25
26task 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
35task 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
44task 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
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
87 // Create the macOS bundle.
James Kuszmaulcf324122023-01-14 14:07:17 -080088 def bundleTask = project.tasks.create("bundleGlassOsxApp" + binary.targetPlatform.architecture.name, Copy) {
Austin Schuh812d0d12021-11-04 20:16:48 -070089 description("Creates a macOS application bundle for Glass")
90 from(file("$project.projectDir/Info.plist"))
James Kuszmaulcf324122023-01-14 14:07:17 -080091 into(file("$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name/Glass.app/Contents"))
Austin Schuh812d0d12021-11-04 20:16:48 -070092 into("MacOS") { with copySpec { from binary.executable.file } }
93 into("Resources") { with copySpec { from icon } }
94
James Kuszmaulcf324122023-01-14 14:07:17 -080095 inputs.property "HasDeveloperId", project.hasProperty("developerID")
96
Austin Schuh812d0d12021-11-04 20:16:48 -070097 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 Kuszmaulcf324122023-01-14 14:07:17 -0800108 "$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name/Glass.app/"
Austin Schuh812d0d12021-11-04 20:16:48 -0700109 ]
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 Kuszmaulcf324122023-01-14 14:07:17 -0800118 applicationPath = file("$project.buildDir/outputs/bundles/$binary.targetPlatform.architecture.name")
Austin Schuh812d0d12021-11-04 20:16:48 -0700119 project.build.dependsOn bundleTask
120 }
121
122 // Create the ZIP.
James Kuszmaulcf324122023-01-14 14:07:17 -0800123 def task = project.tasks.create("copyGlassExecutable" + binary.targetPlatform.architecture.name, Zip) {
Austin Schuh812d0d12021-11-04 20:16:48 -0700124 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 Schuh75263e32022-02-22 18:05:32 -0800136
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 Schuh812d0d12021-11-04 20:16:48 -0700144 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}