-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.gradle
85 lines (70 loc) · 2.47 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
plugins {
id 'java'
id 'application' // note: this plugin automatically adds everything under src/dist to generated ZIP
id 'antlr'
}
group 'net.inet_lab'
version appVersion
repositories {
mavenCentral()
}
application {
// ./gradlew installDist will create script
// -> build/install/c4wa-compile/bin/c4wa-compile <-
// (appName is defined in gradle.properties, which is also included in Java resources)
applicationName = appName
}
/* some hacks we don't need, preserving here for reference */
/* This is how we could redirect to create JAR in /lib, not /libs
tasks.withType(Jar) {
libsDirName = "${project.buildDir}/lib" as File
}
*/
/* This is how we can copy all dependencies to /lib (basically content of distribution files)
task copyToLib(type: Copy) {
into "${project.buildDir}/lib" from configurations.runtimeClasspath
}
build.dependsOn(copyToLib)
*/
dependencies {
antlr 'org.antlr:antlr4:4.9.3'
compileOnly 'org.jetbrains:annotations:23.0.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.1'
}
generateGrammarSource {
// Approach borrowed from:
// https://stackoverflow.com/questions/50568405/antlr4-generate-grammar-source-for-more-language-in-gradle
def target = project.hasProperty('target') ? project.property('target') : 'Java'
switch(target) {
case "Java" :
// must match @header param in grammar definition file
outputDirectory = "${project.buildDir}/generated-src/antlr/main/net/inet_lab/c4wa/autogen/cparser" as File
break
case "JavaScript" :
// https://github.com/antlr/antlr4/blob/master/doc/javascript-target.md
// To generate JS parser:
// ./gradlew generateGrammarSource -Ptarget=JavaScript
// To run, will need antlr4 runtime: https://www.npmjs.com/package/antlr4
outputDirectory = "${project.buildDir}/generated-js" as File
arguments = ['-Dlanguage=' + target]
break
}
arguments += ['-visitor', '-long-messages']
}
task preprocess_library(type: Exec) {
doLast {
println 'Compiling built-in library'
}
executable "bash"
args "-c", 'for f in etc/lib/*.c; do gcc -E -C -DC4WA $f > src/main/resources/lib/$(basename $f); done'
}
processResources {
dependsOn preprocess_library
}
application {
mainClass = 'net.inet_lab.c4wa.app.Main'
}
test {
useJUnitPlatform()
}