forked from Juniper/open-register-design-tool
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
133 lines (115 loc) · 3.8 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
// Gradle build file for ordt
description = 'Tool to generate register RTL, models, and docs using ' +
'SystemRDL or JSpec input'
// Get version from constant in Ordt.java
def versionMatcher = file('src/ordt/extract/Ordt.java').text =~ /String version = \"(.*)\";/
version = versionMatcher[0][1]
buildscript {
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
classpath 'com.gradleup.shadow:shadow-gradle-plugin:8.3.3'
}
}
apply plugin: 'com.gradleup.shadow'
apply plugin: 'java'
apply plugin: 'antlr'
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
configurations {
compile {
extendsFrom = extendsFrom.findAll { it != configurations.antlr }
}
}
dependencies {
antlr group: "org.antlr", name: "antlr4", version: "4.6"
compile group: "org.antlr", name: "antlr4-runtime", version: "4.6"
}
// make to resulting jar java 8 compatible for now
compileJava {
options.release = 8
}
final antlrSrc = 'src/ordt/parse/grammars'
final antlrGen = 'build/generated-src/antlr/main'
// Override default srcDirs for the main source set.
sourceSets {
main {
java {
srcDirs = ['src/ordt/annotate',
'src/ordt/extract',
'src/ordt/output',
'src/ordt/parameters',
'src/ordt/parse' ]
}
antlr {
srcDirs = [ antlrSrc ]
}
}
}
// If MyDebugController.java does not exist, then make a copy of
// MyDebugController.example. If it already exists, then we assume that
// it might have local edits.It won't be overwritten even if the example file
// is newer.
// Use the distclean target to remove the local copy of MyDebugController.java.
task copyMyDebugController {
doLast {
if (!file('src/ordt/extract/MyDebugController.java').exists()) {
exec {
commandLine 'cp', 'src/ordt/extract/MyDebugController.example',
'src/ordt/extract/MyDebugController.java'
}
}
}
}
compileJava.dependsOn(copyMyDebugController)
generateGrammarSource {
outputs.upToDateWhen { false } // force compile of all grammar files so import dependencies are picked up
// copy all generated antlr files to their package locations - not optimum, but avoids ide issues due to package mismatch
doLast {
final destFolder = 'src'
copyAntlrGeneratedFilesToTheirPackages(antlrSrc, 'ExtParms', antlrGen, destFolder)
copyAntlrGeneratedFilesToTheirPackages(antlrSrc, 'JSpec', antlrGen, destFolder)
copyAntlrGeneratedFilesToTheirPackages(antlrSrc, 'SystemRDL', antlrGen, destFolder)
copyAntlrGeneratedFilesToTheirPackages(antlrSrc, 'SimpleSV', antlrGen, destFolder)
}
}
shadowJar {
archiveBaseName.set('Ordt')
archiveClassifier.set('')
archiveVersion.set(version)
manifest {
attributes 'Main-Class': 'ordt.extract.Ordt'
}
}
task distclean {
dependsOn clean
doLast {
exec {
commandLine 'rm', '-f', 'src/ordt/extract/MyDebugController.java'
}
}
}
def copyAntlrGeneratedFilesToTheirPackages(grammarFolder, grammarName, genFolder, destFolder) {
File grammarFile = file("${grammarFolder}/${grammarName}.g4")
final grammarPackage = extractPackageNameFromGrammerFile(grammarFile)
copy {
from genFolder
include "${grammarName}*.*"
into destFolder + "/" + grammarPackage.replaceAll("\\.", "/")
}
}
def extractPackageNameFromGrammerFile(File grammarFile) {
def grammarPackage = "unknown.package"
def packageRegex = ~/[ ]*package[ ]*([a-zA-Z]+[a-zA-Z0-9.-_]*)[ ]*;/
grammarFile.eachLine { line ->
def matcher = packageRegex.matcher(line)
if (matcher.find()){
grammarPackage = matcher.group(1)
}
}
return grammarPackage
}