blob: 04722d7e224d7701b39d6be05489312b991826b3 (
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
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
package frege.gradle
import frege.compiler.Main
import frege.prelude.PreludeBase
import frege.runtime.Lambda
import org.gradle.api.DefaultTask
import org.gradle.api.Project
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 CompileTask extends DefaultTask {
static String DEFAULT_CLASSES_SUBDIR = "classes/main" // TODO: should this come from a convention?
static String DEFAULT_SRC_DIR = "src/main/frege" // TODO: should this come from a source set?
static String DEFAULT_TEST_CLASSES_DIR = "classes/test"
static String DEFAULT_TEST_SRC_DIR = "src/test/frege"
static Boolean USE_EXTERNAl = true
Boolean help = false
@Optional @Input
String xss = "4m"
@Optional @Input
boolean hints = false
@Optional @Input
boolean verbose = false
@Optional @Input
boolean inline = true
@Optional @Input
boolean make = true
@Optional @Input
boolean skipCompile = false
@Optional @Input
String extraArgs = ""
@Optional @Input
String allArgs = "" // this is an option to overrule all other settings
@Optional @Input
String module = ""
// @Optional @InputDirectory
List<File> sourcePaths = deduceSourceDir(project)
@Optional @OutputDirectory
File outputDir = deduceClassesDir(project)
@Optional
List<String> fregePackageDirs = []
static File deduceSourceDir(File projectDir, String subdir) {
new File(projectDir, subdir).exists() ? new File(projectDir, subdir) : null
}
static List<File> deduceSourceDir(Project project) {
def d = deduceSourceDir(project.projectDir, DEFAULT_SRC_DIR)
d == null ? [] : [d]
}
static File deduceClassesDir(File projectDir, String subdir) {
new File(projectDir, subdir)
}
static File deduceClassesDir(Project project) {
deduceClassesDir(project.buildDir, DEFAULT_CLASSES_SUBDIR)
}
static File deduceTestClassesDir(Project project) {
deduceClassesDir(project.buildDir, DEFAULT_TEST_CLASSES_DIR)
}
static File deduceTestSrcDir(Project project) {
deduceSourceDir(project.projectDir, DEFAULT_TEST_SRC_DIR)
}
@TaskAction
void executeCompile() {
if (! outputDir.exists() ) {
logger.info "Creating output directory '${outputDir.absolutePath}'."
outputDir.mkdirs()
}
// access extension configuration values as ${project.frege.key1}
FileResolver fileResolver = getServices().get(FileResolver.class)
JavaExecAction action = new DefaultJavaExecAction(fileResolver)
action.setMain("frege.compiler.Main")
def pf = project.files(project.configurations.compile)
def path = pf.getAsPath()
logger.info("Compile configuation as path: $path")
action.setClasspath(project.files(project.configurations.compile))
def args = []
if (help) {
args << "-help"
} else {
List jvmargs = []
if (xss)
jvmargs << "-Xss$xss"
action.setJvmArgs(jvmargs)
args = allArgs ? allArgs.split().toList() : assembleArguments()
}
logger.info("Calling Frege compiler with args: '$args'")
action.args(args)
if (USE_EXTERNAl) {
action.execute()
} else {
def args2 = args as String[]
// frege.compiler.Main.main(args2)
compile(args2)
// frege.compiler.Main.runCompiler(args2)
}
}
void compile(String[] paramArrayOfString) {
long l1 = System.nanoTime();
Integer localInteger = frege.runtime.Runtime.runMain(
PreludeBase.TST.performUnsafe(
(Lambda)Main.IJ._mainƒd0fa0028.inst.apply(PreludeBase._toList(paramArrayOfString)).forced()
)
);
long l2 = System.nanoTime();
((PrintWriter)frege.runtime.Runtime.stderr.get()).println("runtime " + (l2 - l1 + 500000L) / 1000000L / 1000.0D + " wallclock seconds.");
if (localInteger != null) {
// System.exit(localInteger.intValue());
}
}
List<String> totalFregeClasspath(Project p, List<String> fp) {
def result = []
result.addAll(project.files(project.configurations.compile).getFiles().toList().collect { File f -> f.absolutePath })
result.addAll(fp)
result
}
protected List assembleArguments() {
List args = []
if (hints)
args << "-hints"
if (inline)
args << "-inline"
if (make)
args << "-make"
if (verbose)
args << "-v"
if (skipCompile)
args << "-j"
if (sourcePaths != null && !sourcePaths.isEmpty()) {
logger.info("sourcePaths1: $sourcePaths")
args << "-sp"
args << sourcePaths.collect { d -> d.absolutePath }.join(":")
}
args << "-d"
args << outputDir
def fp = USE_EXTERNAl ? fregePackageDirs : totalFregeClasspath(project, fregePackageDirs)
if (!fp.isEmpty()) {
args << "-fp"
args << fp.join(";")
}
if (!module && !extraArgs) {
logger.info "no module and no extra args given: compiling all of the sourceDir"
logger.info("sourcePaths2: $sourcePaths")
if (sourcePaths != null && !sourcePaths.isEmpty()) {
args << sourcePaths.collect { d -> d.absolutePath }.join(":")
}
} else if (module) {
logger.info "compiling module '$module'"
args << module
} else {
args = args + extraArgs.split().toList()
}
args
}
}
|