-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
106 lines (89 loc) · 2.76 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
plugins {
id 'java'
id 'application'
id 'antlr'
}
version = project.project_version
group = ""
repositories {
mavenCentral()
}
dependencies {
antlr("org.antlr:antlr4:$project.antlr_version")
implementation("org.antlr:antlr4-runtime:$project.antlr_version")
}
def mainClass = "${project.src_root_name}.Compiler"
def lexanDir = "src/${project.src_root_name}/phase/lexan"
def lexerName = project.lexer_file_name
sourceSets {
main {
java {
srcDirs = ['src']
}
antlr {
srcDirs = [lexanDir]
}
}
}
generateGrammarSource {
include("${lexerName}.g4")
outputDirectory = file(lexanDir)
}
application {
mainClassName = mainClass
}
jar {
// Fat jar (include all dependencies)
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
// Specify the main class when launching the jar
manifest {
attributes(
'Main-Class': mainClass
)
}
}
clean {
delete file("$lexanDir/${lexerName}.java")
delete file("$lexanDir/${lexerName}.java-orig")
delete file("$lexanDir/${lexerName}.interp")
delete file("$lexanDir/${lexerName}.tokens")
// Remove generated program xml and html files
delete fileTree("prg", {
it.include("*.xml", "*.html")
})
}
// todo
tasks.register('testProgram', Test) {
dependsOn(compileJava, compileTestJava)
description = "Runs the compiler for specified test file."
testClassesDirs = sourceSets.main.output.classesDirs
classpath = sourceSets.main.runtimeClasspath
def fileExtension = project.source_file_extension
def loggedPhase = project.hasProperty('loggedPhase') ? project.loggedPhase : "all"
def targetPhase = project.hasProperty('targetPhase') ? project.targetPhase : "all"
if (!project.hasProperty('file')) {
throw new GradleException("No file specified. Use -Pfile=<file>")
}
def prgDir = file('prg/')
// Test the specified file
def testFile = file(project.file)
println("Testing file: $testFile.name")
doLast {
println("is file: ${testFile.isFile()}, ends with: ${testFile.name.endsWith(".$fileExtension")} ")
if (testFile.isFile() && testFile.name.endsWith(".$fileExtension")) {
println("Testing file: $testFile.name")
// Run the compiler with "--src-file-name=file.name"
exec {
workingDir prgDir
commandLine 'java',
"-cp", classpath.asPath, mainClass,
"--xsl=../lib/xsl/",
"--logged-phase=$loggedPhase",
"--target-phase=$targetPhase",
"--src-file-name=$testFile.name"
}
}
}
}