forked from Juniper/open-register-design-tool
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.gradle
129 lines (112 loc) · 3.79 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
// 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 {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:2.0.1'
}
}
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'java'
apply plugin: 'antlr'
repositories {
// Use jcenter for resolving my dependencies.
jcenter()
}
dependencies {
compile 'org.abego.treelayout:org.abego.treelayout.core:1.0.3'
antlr 'org.antlr:antlr4:4.5.3'
runtime 'org.antlr:antlr4-runtime:4.5.3'
}
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 {
baseName = 'Ordt'
classifier = null
manifest {
attributes 'Main-Class': 'ordt.extract.Ordt'
}
dependencies {
// The antlr plugin adds the entire library to the jar file,
// not just the runtime, so remove this dependency. The runtime
// library is named antlr4-runtime, so it won't be affected by
// this exclude rule.
exclude(dependency('org.antlr:antlr4:.*'))
}
}
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
}