aboutsummaryrefslogtreecommitdiff
path: root/src/main/groovy/org/gradle/frege/FregeTask.groovy
blob: 26598b9e97023f90308c763cefb561a2a0266b7b (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
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?$/

  @Input boolean hints

  @Input boolean verbose

  @Input boolean inline = true

  @Input boolean make = true

  @Input boolean skipCompile

  @Input boolean includeStale

  // TODO: Find default
  @OutputDirectory File outputDir = new File("build/classes")

  @TaskAction
  void executeCompile() {
    println "Compiling Frege to " + outputDir

    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 (hints)
      args << "-hints"
    if (inline)
      args << "-inline"
    if (make)
      args << "-make"
    if (verbose)
      args << "-v"
    if (skipCompile)
      args << "-j"

    args << "-d"
    args << outputDir


    eachFileRecurse(new File("src/main/frege")) { File file ->
      if (file.name =~ FREGE_FILE_EXTENSION_PATTERN) {
        args << file
      }

    }

    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)
      }
    }
  }

}