-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild.gradle
447 lines (360 loc) · 16.3 KB
/
build.gradle
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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
buildscript {
// This configuration is needed to find the JastAdd plugin.
repositories.mavenCentral()
dependencies {
classpath 'org.jastadd:jastaddgradle:1.13.3'
}
}
apply plugin: 'java'
apply plugin: 'jastadd'
apply plugin: 'idea'
apply plugin: 'eclipse'
defaultTasks 'test'
// Specify where to look for dependencies like Beaver, JFlex:
repositories.mavenCentral()
repositories.mavenLocal()
// Dependency configurations (https://docs.gradle.org/current/userguide/dependency_management.html#sub:configurations):
configurations {
jflex
beaver
jastaddparser
}
// Dependencies are Jar files needed to compile and generate the compiler.
dependencies {
// compile 'net.sf.beaver:beaver-rt:0.9.11' - this is included by ExtendJ
// and duplicating it confuses the runtime when calling beaver.Symbol.clone(), for example.
compile 'com.opencsv:opencsv:4.3.2'
compile 'org.junit.jupiter:junit-jupiter-api:5.3.1'
compile 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
compile 'org.apache.commons:commons-lang3:3.8'
compile 'org.apache.commons:commons-collections4:4.4'
compile 'org.json:json:20200518'
compile group: 'commons-io', name: 'commons-io', version: '2.6'
compile group: 'commons-cli', name: 'commons-cli', version: '1.4'
compile group: 'org.jgrapht', name: 'jgrapht-core', version: '1.4.0'
compile group: 'org.jgrapht', name: 'jgrapht-io', version: '1.4.0'
// https://mvnrepository.com/artifact/org.xerial/sqlite-jdbc
compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.20.1'
// use a fictive version of extendj
compile 'org.extendj:java8:100.100.100'
jflex 'de.jflex:jflex:1.6.1'
beaver 'net.sf.beaver:beaver-cc:0.9.11'
compile 'se.lth:sep:100.100.100'
// fictive versions for jastadd and jastaddparser - they
// are substituted in settings.gradle
jastaddparser 'org.jastadd:jastaddparser:100.100.100'
jastadd2 'org.jastadd:jastadd:100.100.100'
testCompile('org.junit.jupiter:junit-jupiter-api:5.3.1')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.3.1')
testCompile('org.junit.jupiter:junit-jupiter-params:5.3.1')
}
// This specifies where the source code is located:
sourceSets {
main.java.srcDirs = [ 'src/java', 'src/gen']
test.java.srcDirs = [ 'src/test' ]
}
// Configuration for the test running.
test {
maxParallelForks = Runtime.runtime.availableProcessors()
maxHeapSize = "2048m"
useJUnitPlatform()
// {
// excludeTags 'slow'
// includeEngines 'junit-jupiter'
// }
failFast = false
dependsOn 'cleanTest' // This causes tests to always be re-run.
// Summary of tests
afterSuite { desc, result ->
if (!desc.parent) {
println "\nTest result: ${result.resultType}"
println "Test summary: ${result.testCount} tests, " +
"${result.successfulTestCount} succeeded, " +
"${result.failedTestCount} failed, " +
"${result.skippedTestCount} skipped"
}
}
testLogging {
outputs.upToDateWhen {false}
// Enable stdout
showStandardStreams true
// Log passed/failed tests in the console (see also build/reports/tests):
events "passed", "skipped", "failed"
}
doFirst {
// Ensure src/gen exists before running JFlex:
file('tests/output').mkdirs()
file('tests/evaluation/bottomupout/souffle').mkdirs()
}
reports {
junitXml.enabled = true
}
file('./tests/output/souffle').mkdirs()
}
jar {
// The Main-Class attribute specifies which class should be run when by java -jar compiler.jar.
manifest.attributes 'Main-Class': 'lang.Compiler'
destinationDir = projectDir // Gradle by default puts the Jar in build/libs/.
archiveName = 'compiler.jar'
// The following from-specification includes all dependencies in compiler.jar
// so that it can be run as a separate program easily.
// This is needed because the Beaver runtime classes are otherwise not included.
// Source: https://www.mkyong.com/gradle/gradle-create-a-jar-file-with-dependencies/
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}
// Before compiling, we should generate some Java code:
compileJava.dependsOn 'generateJava', 'generateScanner', 'generateParser',
'genMetadlLang',
'genJava8Lang'
void makeGenerateJavaTask(String name, String outDir, String srcDir, String pkg,
boolean patternGrammar = false,
FileTree commonSources = null) {
// A custom implementation of the behaviour of JastAddTask that does not
// remove any generated files from the output directory. The removal of generated
// files interacts badly with other file-generation task (e.g. makeGenerateParserTask)
// that use the same directory
tasks.create(name, JavaExec) {
description 'Generates the compiler AST classes from JastAdd specifications.'
main = 'org.jastadd.JastAdd'
def sources = fileTree(dir: srcDir, includes: [ '**/*.jrag', '**/*.jadd', '**/*.ast' ])
if (commonSources != null)
sources = sources + commonSources
outputs.dir(outDir)
inputs.files(sources)
args = [ "--o=" + file(outDir).path, '--package=' + pkg, '--beaver', '--rewrite=cnta'] +
(patternGrammar ? "--pattern_grammar" : []) + sources.files
classpath = project.configurations.jastadd2
}
}
makeGenerateJavaTask('generateJava', 'src/gen', 'src/jastadd', 'lang.ast')
// makeGenerateJavaTask('generateConfig', 'src/gen', 'src/config/', 'lang.ast.config')
void makeConcatenateTask(String name, String outFile, FileCollection sources) {
tasks.create(name) {
doFirst {
file(file(outFile).getParent()).mkdirs()
}
doLast {
file(outFile).text = sources.collect{it.getText()}.join('\n')
}
}
}
void makeGenerateScannerTask(String name, String outDir, String srcFile) {
tasks.create(name, JavaExec) {
description 'Generates the scanner with JFlex.'
classpath = configurations.jflex
main = 'jflex.Main'
inputs.file(srcFile)
outputs.dir(outDir)
// Options to JFlex (http://jflex.de/manual.html#running-jflex):
args '-d', file(outDir).path, file(srcFile).path
}
}
makeGenerateScannerTask('generateScanner', 'src/gen/lang/ast', 'src/scanner/scanner.flex')
// makeGenerateScannerTask('generateScannerConfig', 'src/gen/lang/ast/config', 'src/config/scanner/scanner.flex')
void makeGenerateParserTask(String name, String outDir, String srcFile) {
tasks.create(name, JavaExec) {
description 'Generates the parser with Beaver.'
classpath = configurations.beaver
main = 'beaver.comp.run.Make'
outputs.dir(outDir)
inputs.file(srcFile)
// Options to Beaver (http://beaver.sourceforge.net/):
args '-d', file(outDir).path,
'-t', '-c', '-w', '-a',
file(srcFile).path
}
}
// makeGenerateParserTask('generateParserConfig', 'src/gen', 'src/config/parser/parser.beaver')
void makeGenerateBeaverTask(String name, String outFile, String srcFile, boolean patternGrammar = false) {
tasks.create(name, JavaExec) {
doFirst {
file('src/gen').mkdirs()
}
description 'Generates the parser with Beaver.'
classpath = configurations.jastaddparser
main = 'org.jastadd.jastaddparser.Main'
inputs.file(srcFile)
outputs.file(outFile)
if (patternGrammar)
args '--pattern_grammar', file(srcFile).path, file(outFile).path
else
args file(srcFile).path, file(outFile).path
}
}
void makeGenerateSEPTask(String name, String outFile, String srcFile) {
tasks.create(name, JavaExec) {
doFirst {
file('src/gen').mkdirs()
}
description 'Generates the parser with Beaver.'
classpath = configurations.jastaddparser
main = 'org.jastadd.jastaddparser.Main'
inputs.file(srcFile)
outputs.file(outFile)
args '--sep', file(srcFile).path, file(outFile).path
}
}
void makeGeneratePatLangTask(String taskName, String outDir, String srcLang, ArrayList<String> lexOrder,
List<String> parseOrder = []) {
tasks.create('MkDirs' + taskName) {
doFirst {
file(outDir + '/lang/' + srcLang + '/pat/ast').mkdirs()
}
}
makeConcatenateTask('catPatScanner' + taskName,
outDir + '/lang/' + srcLang + '/pat/scanner/scanner.flex',
files(lexOrder.collect({'src/lang/' + srcLang + '/pat/scanner/' + it})))
def parserFiles = fileTree(dir : 'src/lang/' + srcLang + '/pat/parser', includes : ['**/*.parser'])
if (parseOrder) {
// Explicit parse order
parserFiles = files(parseOrder.collect({'src/lang/' + srcLang + '/pat/parser/' + it}))
}
makeConcatenateTask('catPatlangParser' + taskName,
outDir + '/lang/' + srcLang + '/pat/parser/lang.parser',
parserFiles)
// .parser -> .java file describing a SEP grammar
makeGenerateSEPTask('generateSEP' + taskName, outDir + '/lang/' + srcLang + '/pat/ast/PatLangParserSEP.java',
outDir + '/lang/' + srcLang + '/pat/parser/lang.parser')
// .flex -> .java
makeGenerateScannerTask('generateScannerPatlang' + taskName, outDir + '/lang/' + srcLang + '/pat/ast',
outDir + '/lang/' + srcLang + '/pat/scanner/scanner.flex')
// .ast, .jrag -> .java
def commonPatAspectFiles = fileTree(dir : 'src/lang/common/pat/jastadd', includes : ['**/*.jrag'])
makeGenerateJavaTask('generateJavaPatlang' + taskName, outDir,
'src/lang/' + srcLang + '/pat/jastadd', 'lang.' + srcLang + '.pat.ast', true, commonPatAspectFiles)
// an empty task to depend on everything here
tasks.create(taskName)
tasks.getByName(taskName).dependsOn tasks.getByName('generateScannerPatlang' + taskName)
tasks.getByName(taskName).dependsOn tasks.getByName('generateJavaPatlang' + taskName)
tasks.getByName(taskName).dependsOn tasks.getByName('generateSEP' + taskName)
tasks.getByName('generateSEP' + taskName).dependsOn tasks.getByName('MkDirs' + taskName),
tasks.getByName('catPatlangParser' + taskName)
tasks.getByName('generateScannerPatlang' + taskName).dependsOn tasks.getByName('MkDirs' + taskName),
tasks.getByName('catPatScanner' + taskName)
tasks.getByName('generateJavaPatlang' + taskName).dependsOn tasks.getByName('MkDirs' + taskName)
}
void makeGenerateLangTask(String taskName, String outDir, String srcLang, ArrayList<String> lexOrder, boolean patlang = true) {
tasks.create('MkDirs' + taskName) {
doFirst {
file(outDir + '/lang/' + srcLang + '/obj/ast').mkdirs()
file(outDir + '/lang/' + srcLang + '/pat/ast').mkdirs()
}
}
makeConcatenateTask('catObjScanner' + taskName,
outDir + '/lang/' + srcLang + '/obj/scanner/scanner.flex',
files(lexOrder.collect({'src/lang/' + srcLang + '/obj/scanner/' + it})))
makeConcatenateTask('catPatScanner' + taskName,
outDir + '/lang/' + srcLang + '/pat/scanner/scanner.flex',
files(lexOrder.collect({'src/lang/' + srcLang + '/pat/scanner/' + it})))
makeConcatenateTask('catObjlangParser' + taskName,
outDir + '/lang/' + srcLang + '/obj/parser/lang.parser',
fileTree(dir : 'src/lang/' + srcLang + '/obj/parser', includes : ['**/*.parser']))
makeConcatenateTask('catPatlangParser' + taskName,
outDir + '/lang/' + srcLang + '/pat/parser/lang.parser',
fileTree(dir : 'src/lang/' + srcLang + '/pat/parser', includes : ['**/*.parser']))
// .parser -> .beaver
makeGenerateBeaverTask('generateBeaverObjlang' + taskName, outDir + '/lang/' + srcLang + '/ObjLangParser.beaver',
outDir + '/lang/' + srcLang + '/obj/parser/lang.parser',
false)
// .parser -> .java file describing a SEP grammar
makeGenerateSEPTask('generateSEP' + taskName, outDir + '/lang/' + srcLang + '/pat/ast/PatLangParserSEP.java',
outDir + '/lang/' + srcLang + '/pat/parser/lang.parser')
// .beaver -> .java
makeGenerateParserTask('generateParserObjlang' + taskName, outDir + '/lang/' + srcLang + '/obj/ast',
outDir + '/lang/' + srcLang + '/ObjLangParser.beaver')
// .flex -> .java
makeGenerateScannerTask('generateScannerPatlang' + taskName, outDir + '/lang/' + srcLang + '/pat/ast',
outDir + '/lang/' + srcLang + '/pat/scanner/scanner.flex')
makeGenerateScannerTask('generateScannerObjlang' + taskName, outDir + '/lang/' + srcLang + '/obj/ast',
outDir + '/lang/' + srcLang + '/obj/scanner/scanner.flex')
// .ast, .jrag -> .java
def commonPatAspectFiles = fileTree(dir : 'src/lang/common/pat/jastadd', includes : ['**/*.jrag'])
makeGenerateJavaTask('generateJavaPatlang' + taskName, outDir,
'src/lang/' + srcLang + '/pat/jastadd', 'lang.' + srcLang + '.pat.ast', true, commonPatAspectFiles)
def commonObjAspectFiles = fileTree(dir : 'src/lang/common/obj/jastadd', includes : ['**/*.jrag'])
makeGenerateJavaTask('generateJavaObjlang' + taskName, outDir,
'src/lang/' + srcLang + '/obj/jastadd', 'lang.' + srcLang + '.obj.ast', false, commonObjAspectFiles)
// an empty task to depend on everything here
tasks.create(taskName)
if (patlang) {
// Disable the pattern lang while bringing up a new language
tasks.getByName(taskName).dependsOn tasks.getByName('generateScannerPatlang' + taskName)
tasks.getByName(taskName).dependsOn tasks.getByName('generateJavaPatlang' + taskName)
tasks.getByName(taskName).dependsOn tasks.getByName('generateSEP' + taskName)
}
tasks.getByName(taskName).dependsOn tasks.getByName('generateBeaverObjlang' + taskName)
tasks.getByName(taskName).dependsOn tasks.getByName('generateParserObjlang' + taskName)
tasks.getByName(taskName).dependsOn tasks.getByName('generateScannerObjlang' + taskName)
tasks.getByName(taskName).dependsOn tasks.getByName('generateJavaObjlang' + taskName)
tasks.getByName('generateParserObjlang' + taskName).dependsOn tasks.getByName('generateBeaverObjlang' + taskName)
tasks.getByName('generateBeaverObjlang' + taskName).dependsOn tasks.getByName('MkDirs' + taskName), tasks.getByName('catObjlangParser' + taskName)
tasks.getByName('generateSEP' + taskName).dependsOn tasks.getByName('MkDirs' + taskName), tasks.getByName('catPatlangParser' + taskName)
tasks.getByName('generateScannerObjlang' + taskName).dependsOn tasks.getByName('MkDirs' + taskName), tasks.getByName('catObjScanner' + taskName)
tasks.getByName('generateScannerPatlang' + taskName).dependsOn tasks.getByName('MkDirs' + taskName), tasks.getByName('catPatScanner' + taskName)
tasks.getByName('generateJavaObjlang' + taskName).dependsOn tasks.getByName('MkDirs' + taskName)
tasks.getByName('generateJavaPatlang' + taskName).dependsOn tasks.getByName('MkDirs' + taskName)
}
// The order in which the lex files are concatenated
def java8LexOrder = [
"Header.flex",
"Preamble.flex",
"Macros.flex",
"RulesPreamble.flex",
"WhiteSpace.flex",
"Comments.flex",
"Keywords.flex",
"Literals.flex",
"Operators.flex",
"Separators.flex",
"Identifiers.flex",
"Postamble.flex"
]
def metadlLexOrder = ['scanner.flex']
// The order in which the parser files are concatenated
def java8ParseOrder = [
"Java1.4.parser",
"java14fix.parser",
"Literals.parser",
"Generics.parser",
"Annotations.parser",
"ConstructorReference.parser",
"Diamond.parser",
"EnhancedFor.parser",
"Enums.parser",
"ErrorRecovery.parser",
"GenericMethods.parser",
"Goal.parser",
"Header.parser",
"InterfaceMethods.parser",
"IntersectionCasts.parser",
"Lambda.parser",
"MethodReference.parser",
"MultiCatch.parser",
"NonGenericTypes.parser",
"PackageModifier.parser",
"Preamble.parser",
"Precedence.parser",
"StaticImports.parser",
"TryWithResources.parser",
"VariableArityParameters.parser"
]
makeGenerateLangTask('genMetadlLang', 'src/gen/', 'metadl', metadlLexOrder)
makeGeneratePatLangTask('genJava8Lang', 'src/gen/', 'java8', java8LexOrder, java8ParseOrder)
makeGenerateBeaverTask('generateBeaver', 'src/gen/LangParser.beaver', 'src/parser/metadl.parser')
makeGenerateParserTask('generateParser', 'src/gen/lang/ast', 'src/gen/LangParser.beaver')
generateParser.dependsOn 'generateBeaver'
// The following makes the clean task also remove generated code:
clean.dependsOn 'cleanGeneratedJava'
task cleanGeneratedJava(type: Delete) {
description 'Remove generated Java code.'
delete file('src/gen')
delete file('compiler.jar')
delete file('tests/output')
delete file('tests/evaluation/bottomupout')
delete file('./out')
delete file('./tmp')
}
// Additional flags to the java compilter
compileJava {
options.compilerArgs << "-Xlint:deprecation"
}