blob: c0f898e04f09877b4e865372e0d6acf3ab022a55 (
plain)
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
|
package org.gradle.frege
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.InvalidUserDataException
import org.gradle.api.tasks.*
import org.gradle.process.internal.DefaultJavaExecAction
import org.gradle.process.internal.JavaExecAction
import org.gradle.api.internal.file.FileResolver
class FregeTask extends DefaultTask {
private static final FREGE_FILE_EXTENSION_PATTERN = ~/.*\.fr?$/
static String DEFAULT_CLASSES_DIR = "build/classes/main"
static String DEFAULT_SRC_DIR = "src/main/frege"
@Input
boolean hints = false
@Input
boolean verbose = false
@Input
boolean inline = false
@Input
boolean make = true
@Input
boolean skipCompile = false
@Input
boolean includeStale
@Input
String extraArgs = ""
@Input
String allArgs = ""
// TODO: Find default
@OutputDirectory
File outputDir = new File(DEFAULT_CLASSES_DIR)
@TaskAction
void executeCompile() {
println "Compiling Frege to " + outputDir
// access extension configuration values as ${project.frege.key1}
FileResolver fileResolver = getServices().get(FileResolver.class)
JavaExecAction action = new DefaultJavaExecAction(fileResolver)
action.setMain("frege.compiler.Main")
action.setClasspath(project.files(project.configurations.compile))
List args = []
if (allArgs != "") {
args = allArgs.split().toList()
} else {
if (hints)
args << "-hints"
if (inline)
args << "-inline"
if (make)
args << "-make"
if (verbose)
args << "-v"
if (skipCompile)
args << "-j"
args << "-d"
args << outputDir
args = args + extraArgs.split().toList()
}
eachFileRecurse(new File(DEFAULT_SRC_DIR)) { File file ->
if (file.name =~ FREGE_FILE_EXTENSION_PATTERN) {
args << file
}
}
println("FregeTask args: $args")
action.args(args)
action.execute()
}
private static void eachFileRecurse(File dir, Closure fileProcessor) {
dir.eachFile { File file ->
if (file.directory) {
eachFileRecurse(file, fileProcessor)
} else {
fileProcessor(file)
}
}
}
}
|