Skip to content

Commit def251a

Browse files
committed
Merge branch 'master' into more-generics
2 parents b38a607 + c5e8764 commit def251a

8 files changed

Lines changed: 238 additions & 172 deletions

File tree

de.peeeq.wurstscript/build.gradle

Lines changed: 86 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ buildscript {
33
dependencies {
44
// used at configuration-time for version info
55
classpath 'org.eclipse.jgit:org.eclipse.jgit:5.7.+'
6+
classpath "javax.inject:javax.inject:1"
67
}
78
}
89

@@ -20,9 +21,6 @@ plugins {
2021

2122

2223
import de.undercouch.gradle.tasks.download.Download
23-
import org.eclipse.jgit.api.Git
24-
import org.eclipse.jgit.lib.Constants
25-
import org.eclipse.jgit.lib.ObjectId
2624

2725
import java.util.regex.Pattern
2826

@@ -36,22 +34,31 @@ java {
3634
}
3735
}
3836

37+
def toolchainSvc = extensions.getByType(JavaToolchainService)
38+
def j25Launcher = toolchainSvc.launcherFor(java.toolchain)
39+
40+
tasks.withType(JavaExec).configureEach {
41+
javaLauncher.set(j25Launcher)
42+
}
43+
3944
tasks.withType(JavaCompile).configureEach { options.release = 25 }
4045

4146
jacoco {
4247
toolVersion = "0.8.13"
4348
}
4449

45-
jacocoTestReport {
46-
dependsOn test
50+
tasks.named("jacocoTestReport", JacocoReport) {
51+
dependsOn(tasks.named("test"))
52+
4753
reports { xml.required.set(true) }
48-
afterEvaluate {
49-
classDirectories.setFrom(files(classDirectories.files.collect {
50-
fileTree(dir: it, exclude: [
51-
'**/ast/**', '**/jassAst/**', '**/jassIm/**', '**/luaAst/**', '**/antlr/**'
52-
])
53-
}))
54-
}
54+
55+
def excluded = ['**/ast/**', '**/jassAst/**', '**/jassIm/**', '**/luaAst/**', '**/antlr/**']
56+
57+
classDirectories.setFrom(
58+
files(classDirectories.files.collect { dir ->
59+
fileTree(dir: dir, exclude: excluded)
60+
})
61+
)
5562
}
5663

5764
def genDir = "$projectDir/src-gen"
@@ -120,68 +127,93 @@ def parseqFiles = fileTree(dir: 'parserspec', include: '*.parseq')
120127

121128
def pkgPattern = Pattern.compile(/package\s+(\S+)\s*;/)
122129

123-
tasks.register('genAst') {
124-
// make it incremental/cacheable
125-
inputs.files(parseqFiles)
126-
outputs.dir(genDir)
130+
// resolve once at configuration time
131+
def genDirFile = file(genDir)
132+
def astgenCp = configurations.astgen
133+
def pkgPatternLocal = pkgPattern
127134

128-
doLast {
129-
// fetch ExecOperations from Gradle services (no @Inject needed)
130-
ExecOperations execOps = project.services.get(ExecOperations)
135+
def perFileTasks = []
131136

132-
parseqFiles.files.each { File f ->
133-
String contents = f.getText('UTF-8')
134-
def m = pkgPattern.matcher(contents)
135-
String pkg = m.find() ? m.group(1) : ""
136-
File targetDir = file("$genDir/${pkg.replace('.', '/')}")
137+
parseqFiles.files.each { File f ->
138+
// determine package at configuration time (same logic you had)
139+
String contents = f.getText('UTF-8')
140+
def m = pkgPatternLocal.matcher(contents)
141+
String pkg = m.find() ? m.group(1) : ""
142+
File targetDir = new File(genDirFile, pkg.replace('.', '/'))
137143

138-
targetDir.mkdirs()
144+
def t = tasks.register("genAst_${f.name.replaceAll(/[^A-Za-z0-9_]/, '_')}", JavaExec) {
145+
// incremental + cache correctness for the generator
146+
inputs.file(f)
147+
inputs.files(astgenCp).withPropertyName("astgenClasspath")
148+
outputs.dir(targetDir)
139149

140-
// run: asg.Main <file> <targetDir> using isolated classpath
141-
execOps.javaexec {
142-
classpath = configurations.astgen
143-
mainClass.set('asg.Main')
144-
args(f.absolutePath, targetDir.absolutePath)
145-
}
146-
}
150+
classpath = astgenCp
151+
mainClass.set("asg.Main")
152+
args(f.absolutePath, targetDir.absolutePath)
153+
154+
// optional: ensure target dir exists
155+
doFirst { targetDir.mkdirs() }
147156
}
157+
158+
perFileTasks << t
148159
}
149160

161+
tasks.register("genAst") {
162+
inputs.files(parseqFiles)
163+
outputs.dir(genDirFile)
164+
dependsOn(perFileTasks)
165+
}
166+
167+
168+
150169
/** -------- Version info file generation -------- */
151170

152171
tasks.register('versionInfoFile') {
153172
description "Generates a file CompileTimeInfo.java with version number etc."
154173

155-
// resolve git info at configuration time
156-
Git git = Git.open(new File(rootProject.projectDir, '..'))
157-
ObjectId head = git.getRepository().resolve(Constants.HEAD)
158-
String gitRevision = head.abbreviate(8).name()
159-
String gitRevisionlong = head.getName()
160-
String tag = git.describe().setTarget(head).setAlways(true).setTags(true).call()
161-
String wurstVersion = "${version}-${tag}"
162-
163-
inputs.property("wurstVersion", wurstVersion)
174+
def repoDir = new File(rootProject.projectDir, '..')
164175

165176
def dir = new File("$genDir/de/peeeq/wurstscript/")
166177
def out = new File(dir, 'CompileTimeInfo.java')
167178
outputs.file(out)
168179

180+
// capture at configuration time (no Task.project usage later)
181+
def versionString = project.version.toString()
182+
183+
// Inputs so the task reruns when metadata changes:
184+
// - project version changes
185+
inputs.property("projectVersion", versionString)
186+
// - HEAD changes (branch updates)
187+
inputs.file(new File(repoDir, ".git/HEAD")).withPropertyName("gitHeadRef")
188+
// - branch ref changes (only for branch-based HEAD; harmless if missing)
189+
inputs.files(fileTree(new File(repoDir, ".git/refs"))).withPropertyName("gitRefs")
190+
// - tags move / new tags (for git describe --tags)
191+
inputs.files(fileTree(new File(repoDir, ".git/refs/tags"))).withPropertyName("gitTags")
192+
// - working tree dirtiness affects "--dirty"
193+
inputs.file(new File(repoDir, ".git/index")).optional().withPropertyName("gitIndex")
194+
169195
doLast {
196+
def rev8 = ["git", "rev-parse", "--short=8", "HEAD"].execute(null, repoDir).text.trim()
197+
def revLong = ["git", "rev-parse", "HEAD"].execute(null, repoDir).text.trim()
198+
def tag = ["git", "describe", "--tags", "--always", "--dirty"].execute(null, repoDir).text.trim()
199+
200+
def wurstVersion = "${versionString}-${tag}"
201+
170202
dir.mkdirs()
171-
String currentTime = new Date().format("yyyy/MM/dd KK:mm:ss")
172203
out.text = """
173-
package de.peeeq.wurstscript;
204+
package de.peeeq.wurstscript;
174205
175-
public class CompileTimeInfo {
176-
public static final String time="${currentTime}";
177-
public static final String revision="${gitRevision}";
178-
public static final String revisionLong="${gitRevisionlong}";
179-
public static final String version="${wurstVersion}";
180-
}
181-
"""
206+
public class CompileTimeInfo {
207+
public static final String revision="${rev8}";
208+
public static final String revisionLong="${revLong}";
209+
public static final String version="${wurstVersion}";
210+
}
211+
"""
182212
}
183213
}
184214

215+
216+
185217
/** -------- Aggregate generation + wiring into compile -------- */
186218

187219
tasks.register('gen') {
@@ -308,5 +340,9 @@ tasks.register('generate_hotdoc') {
308340
}
309341
}
310342

343+
tasks.named("coveralls") {
344+
notCompatibleWithConfigurationCache("coveralls plugin task uses Project at execution time")
345+
}
346+
311347
/** -------- Apply deployment settings -------- */
312348
apply from: 'deploy.gradle'

0 commit comments

Comments
 (0)