blob: f2e3da7161208b19603fb7c3daece5d89d1b82d7 [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 ->
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 Schuh75263e32022-02-22 18:05:32 -0800133
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 Schuh812d0d12021-11-04 20:16:48 -0700141 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}