-
-
Notifications
You must be signed in to change notification settings - Fork 979
Expand file tree
/
Copy pathrails.gradle
More file actions
382 lines (306 loc) · 11.6 KB
/
rails.gradle
File metadata and controls
382 lines (306 loc) · 11.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/*
* Copyright 2022 Thoughtworks, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import com.thoughtworks.go.build.ExecuteUnderRailsTask
import com.thoughtworks.go.build.InstallerType
import com.thoughtworks.go.build.YarnInstallTask
import com.thoughtworks.go.build.YarnRunTask
import groovy.text.SimpleTemplateEngine
import groovy.text.Template
import org.apache.tools.ant.types.Commandline
import org.gradle.internal.jvm.Jvm
task pathingJar(type: Jar) {
archiveClassifier = 'pathing'
dependsOn(project.railsTasksDefaultDependsOn)
doFirst {
manifest {
attributes 'Class-Path': (project.railsClasspath.files - [project.configurations.compileClasspath.files { it.name == 'jruby-complete' }.first()]).collect { it.toURI() }.join(' ')
}
}
}
task generateJSRoutes(type: ExecuteUnderRailsTask) {
outputs.cacheIf { true }
onlyIf { !project.hasProperty('fastBuild') }
def outputDir = file("${project.railsRoot}/webpack/gen")
inputs.dir(file("${project.railsRoot}/vendor"))
inputs.files(fileTree(dir: "${project.railsRoot}/config", includes: ['**/*.rb']))
outputs.dir(outputDir)
environment(
'RAILS_ENV': 'production',
'RAILS_GROUPS': 'assets',
'OUTPUT_DIR': outputDir,
)
args = ['-S', 'rake', '--trace', 'generated_js']
doFirst {
delete outputDir
}
}
task createJRubyBinstubs {
outputs.cacheIf { true }
def outputDir = file("scripts")
inputs.dir("script-templates")
inputs.properties([
bundledGemDir: project.bundledGemDir,
railsRoot: project.railsRoot
])
def jrubyJar = project.configurations.compileClasspath.files { it.name == 'jruby-complete' }.first()
def templateProperties = [
mainClassName : 'org.jruby.Main',
jvmArgs : project.jrubyOptimizationJvmArgs,
systemProperties : (project.jrubyOptimizationSystemProperties + project.jrubyDefaultSystemProperties + project.railsSystemProperties),
classpath : [pathingJar.archiveFile.get().asFile],
jrubyJar : jrubyJar,
environment : project.defaultJRubyEnvironment,
additionalJRubyPaths: project.additionalJRubyPaths,
javaExecutable : Jvm.current().getExecutable("java")
]
inputs.properties(templateProperties)
outputs.dir(outputDir)
doFirst {
project.delete(outputDir)
project.mkdir(outputDir)
['jgem', 'rspec', 'ruby', 'gem'].each { file ->
copy {
from "script-templates/${file}"
into outputDir
eachFile { FileCopyDetails fcp ->
fcp.mode = 0755
}
}
}
['jruby', 'jruby.bat'].each { eachFile ->
def inputTemplate = file("script-templates/${eachFile}")
def engine = new SimpleTemplateEngine()
Template template = engine.createTemplate(inputTemplate)
String output = template.make(templateProperties).toString()
file("${outputDir}/${inputTemplate.name}").write(output)
file("${outputDir}/${inputTemplate.name}").setExecutable(true)
}
}
}
task initializeRailsGems {
outputs.cacheIf { true }
dependsOn createJRubyBinstubs
inputs.file("${project.railsRoot}/Gemfile")
inputs.file("${project.railsRoot}/Gemfile.lock")
inputs.file("${project.railsRoot}/.bundle/config")
inputs.properties([
jrubyVersion: project.deps.jruby,
bundledGemDir: project.bundledGemDir,
railsRoot: project.railsRoot
])
outputs.dir(project.bundledGemDir)
doFirst {
project.jrubyexec {
workingDir = project.railsRoot
args = ['-S', 'bundle', 'install']
maxHeapSize = '1g'
}
}
}
task yarnInstall(type: YarnInstallTask) {
// delete this in the compile phase, because otherwise the yarnInstall detects a new folder and reinstalls.
project.delete(project.file("${project.railsRoot}/node_modules/.cache"))
workingDir = project.railsRoot
}
prepare.dependsOn(initializeRailsGems, createJRubyBinstubs, yarnInstall)
task cleanRails(type: Delete) {
delete "${buildDir}/railsTests"
delete "${project.railsRoot}/config/cipher"
delete "${project.railsRoot}/config/cipher.aes"
delete "${project.railsRoot}/db/config.git"
delete "${project.railsRoot}/db/h2db"
delete "${project.railsRoot}/logs"
delete "${project.railsRoot}/node_modules"
delete "${project.railsRoot}/public/assets"
delete "${project.railsRoot}/tmp"
delete "${project.railsRoot}/webpack/gen"
delete "${project.railsRoot}/yarn-error.log"
doFirst {
// these are purposely added as `doFirst` to avoid intellij from excluding these from the modules
project.delete project.jrubyScriptsDir
project.delete project.bundledGemDir
}
}
clean.dependsOn cleanRails
task compileAssetsWebpackDev(type: YarnRunTask) {
dependsOn yarnInstall
dependsOn generateJSRoutes
onlyIf { !project.hasProperty('fastBuild') }
ext.licenseReportFile = project.file("${project.buildDir}/reports/yarn-license/license-report.json")
outputs.dir(ext.licenseReportFile.parentFile)
source(project.file("${project.railsRoot}/webpack"))
source(project.file("${project.railsRoot}/vendor/assets"))
source(project.file("${project.railsRoot}/config"))
workingDir = project.railsRoot
destinationDir = project.file("${project.railsRoot}/public/assets/webpack")
yarnCommand = ['webpack-dev', '--env', "outputDir=${destinationDir.toPath().toString()}", '--env', "licenseReportFile=${ext.licenseReportFile}"]
}
task compileAssetsWebpackProd(type: YarnRunTask) {
dependsOn yarnInstall
dependsOn generateJSRoutes
onlyIf { !project.hasProperty('fastBuild') }
ext.licenseReportFile = project.file("${project.buildDir}/reports/yarn-license/license-report.json")
outputs.dir(ext.licenseReportFile.parentFile)
source(project.file("${project.railsRoot}/webpack"))
source(project.file("${project.railsRoot}/vendor/assets"))
source(project.file("${project.railsRoot}/config"))
workingDir = project.railsRoot
destinationDir = project.file("${project.buildDir}/webpack-assets")
yarnCommand = ['webpack-prod', '--env', "outputDir=${destinationDir.toPath().toString()}", '--env', "licenseReportFile=${ext.licenseReportFile}"]
}
task compileAssetsRailsTest(type: ExecuteUnderRailsTask) {
dependsOn yarnInstall
outputs.cacheIf { true }
onlyIf { !project.hasProperty('fastBuild') }
def publicAssetsDir = file("${project.railsRoot}/public/assets")
inputs.dir(file("${project.railsRoot}/config"))
inputs.dir(file("${project.railsRoot}/app/assets/config"))
inputs.dir(file("${project.railsRoot}/app/assets/javascripts"))
inputs.dir(file("${project.railsRoot}/vendor/assets/javascripts"))
outputs.dir(publicAssetsDir)
environment += [
'RAILS_ENV' : 'test',
'RAILS_GROUPS': 'assets',
]
// Native-subprocess control is needed for usage of Dart Sass via sass-embedded
jvmArgs += [
'--add-opens=java.base/sun.nio.ch=ALL-UNNAMED',
'--add-opens=java.base/java.io=ALL-UNNAMED'
]
args = ['-S', 'rake', '--trace', 'assets:clobber', 'assets:precompile']
doFirst {
delete "${project.railsRoot}/tmp"
delete publicAssetsDir
publicAssetsDir.parentFile.mkdirs()
}
}
task compileAssetsRailsProd(type: ExecuteUnderRailsTask) {
dependsOn yarnInstall
outputs.cacheIf { true }
onlyIf { !project.hasProperty('fastBuild') }
def outputAssetsDir = file("${project.buildDir}/rails-assets")
def publicAssetsDir = file("${project.railsRoot}/public/assets")
inputs.dir(file("${project.railsRoot}/config"))
inputs.dir(file("${project.railsRoot}/app/assets"))
inputs.dir(file("${project.railsRoot}/vendor/assets"))
outputs.dir(outputAssetsDir)
disableJRubyOptimization = true
environment(
'RAILS_ENV': 'production',
'RAILS_GROUPS': 'assets',
)
// Native-subprocess control is needed for usage of Dart Sass via sass-embedded
jvmArgs += [
'--add-opens=java.base/sun.nio.ch=ALL-UNNAMED',
'--add-opens=java.base/java.io=ALL-UNNAMED'
]
args = ['-S', 'rake', '--trace', 'assets:clobber', 'assets:precompile']
doFirst {
delete "${project.railsRoot}/tmp"
delete outputAssetsDir
outputAssetsDir.parentFile.mkdirs()
}
doLast {
copy {
from publicAssetsDir
into outputAssetsDir
}
delete publicAssetsDir
}
}
task compileAssets {
dependsOn compileAssetsWebpackProd
dependsOn licenseReportAggregate
dependsOn compileAssetsRailsProd
inputs.files licenseReportAggregate.outputs.files
inputs.files compileAssetsRailsProd.outputs.files
inputs.files compileAssetsWebpackProd.outputs.files
def outputDir = project.file("${project.buildDir}/assets")
outputs.dir(outputDir)
onlyIf { !project.hasProperty('fastBuild') }
doFirst {
delete outputDir
copy {
from licenseReportAggregate
// assets are cached with a long lived cache header
// we purposefully add a version string in the path so every new build will basically use a different url
into "${outputDir}/dependency-license-report-${project.version}"
}
copy {
from compileAssetsRailsProd
into outputDir
}
copy {
from compileAssetsWebpackProd
into "${outputDir}/webpack"
}
}
}
task rspec(type: ExecuteUnderRailsTask) {
dependsOn yarnInstall
outputs.cacheIf { true }
inputs.files project.railsRoot
inputs.files project.railsClasspath
description = "Run specs (pass '-Popts=...' to pass options)"
disableJRubyOptimization = true
environment += [
'REPORTS_DIR': "${project.buildDir}/rspec-results"
]
jvmArgs += InstallerType.server.jvmModuleOpensArgs + ['-XX:+HeapDumpOnOutOfMemoryError', "-XX:HeapDumpPath=${project.buildDir}/heap-dumps"]
args = ['-S', 'rspec', '--backtrace']
maxHeapSize = '2g'
if (project.hasProperty('opts')) {
args += Commandline.translateCommandline(project.property('opts')) as List<String>
}
doFirst {
project.mkdir("${project.buildDir}/heap-dumps")
project.file("${project.buildDir}/heap-dumps/foo.txt").setText("")
}
}
task parallelRspec(type: ExecuteUnderRailsTask) {
dependsOn yarnInstall
outputs.cacheIf { true }
inputs.files project.railsRoot
inputs.files project.railsClasspath
description = "Run specs (pass '-Popts=...' to pass options)"
disableJRubyOptimization = true
environment += [
'REPORTS_DIR': "${project.buildDir}/rspec-results"
]
jvmArgs += InstallerType.server.jvmModuleOpensArgs + ['-XX:+HeapDumpOnOutOfMemoryError', "-XX:HeapDumpPath=${project.buildDir}/heap-dumps"]
args = ['-S', 'rspec', '--backtrace']
maxHeapSize = '2g'
if (project.hasProperty('opts')) {
args += Commandline.translateCommandline(project.property('opts')) as List<String>
}
doFirst {
project.mkdir("${project.buildDir}/heap-dumps")
project.file("${project.buildDir}/heap-dumps/foo.txt").setText("")
}
doFirst {
FileTree tree = fileTree(dir: "${project.railsRoot}/spec", includes: ['**/*_spec.rb'])
def files = partitionFiles(tree.files)
args += files.collect { project.railsRoot.toURI().relativize(it.toURI()).getPath() }
if (project.hasProperty('opts')) {
args += Commandline.translateCommandline(project.property('opts')) as List<String>
}
}
}
task railsExec(type: ExecuteUnderRailsTask) {
outputs.upToDateWhen { false }
description = "rails exec (pass '-Pcmd=...' to pass options)"
args = Commandline.translateCommandline(project.properties.get('cmd')) as List<String>
}