diff options
Diffstat (limited to 'src/main/groovy/frege/gradle/tasks')
5 files changed, 473 insertions, 0 deletions
diff --git a/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy new file mode 100644 index 0000000..13b617c --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeCompile.groovy @@ -0,0 +1,198 @@ +package frege.gradle.tasks +import groovy.transform.TypeChecked +import groovy.transform.TypeCheckingMode +import org.gradle.api.Action +import org.gradle.api.artifacts.Configuration +import org.gradle.api.file.FileCollection +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.TaskAction +import org.gradle.api.tasks.compile.AbstractCompile +import org.gradle.process.JavaExecSpec + +@TypeChecked +class FregeCompile extends AbstractCompile { + + FileCollection fregeClasspath + FileCollection classpath + + @Input + String stackSize = "4m" + + @Optional + @Input + boolean hints = false + + @Optional + @Input + boolean optimize = false + + @Optional + @Input + boolean verbose = false + + @Optional + @Input + boolean inline = true + + @Optional + @Input + boolean make = true + + @Optional + @Input + boolean compileGeneratedJava = true + + @Optional + @Input + String target = "" + + @Optional + @Input + boolean comments = false + + @Optional + @Input + boolean suppressWarnings = false + + @Optional + @Input + String explain = "" + + @Optional + @Input + String extraArgs = "" + + @Optional + @Input + String allArgs = "" // this is an option to overrule all other settings + + @Optional + @Input + String module = "" + + @Optional + @Input + List<File> fregePaths = [] + + @Input + String mainClass = "frege.compiler.Main" + + @Optional + @Input + List<String> allJvmArgs = [] + + @Optional + @Input + String encoding = "" + + @Optional + @Input + String prefix = "" + + List<File> sourcePaths = [] + + @Override + @TaskAction + protected void compile() { + logConfigurationInfo() + + def jvmArgs = allJvmArgs + if (jvmArgs.isEmpty()) { + jvmArgs << "-Xss$stackSize".toString() + } + def compilerArgs = allArgs ? allArgs.split().toList() : assembleArguments() + + logger.info("Calling Frege compiler with compilerArgs: '$compilerArgs'") + + //TODO integrate with gradle compiler daemon infrastructure and skip internal execution + project.javaexec(new Action<JavaExecSpec>() { + @Override + void execute(JavaExecSpec javaExecSpec) { + javaExecSpec.args = compilerArgs + javaExecSpec.classpath = FregeCompile.this.classpath + FregeCompile.this.fregeClasspath + javaExecSpec.main = mainClass + } + }); + } + + public FregeCompile source(Object... sources) { + super.source(sources); + // track directory roots + for (Object source : sources) { + sourcePaths.add(project.file(source)) + } + return this; + } + + void logConfigurationInfo() { + def path = project.files(compileConfig()).getAsPath() + logger.info("Compile configuation as path: $path") + } + + @TypeChecked(TypeCheckingMode.SKIP) + Configuration compileConfig() { + project.configurations.compile + } + + protected List<String> assembleArguments() { + List args = [] + if (hints) + args << "-hints" + if (optimize) { + args << "-O" + args << "-inline" + } + if (inline & !optimize) + args << "-inline" + if (make) + args << "-make" + if (!compileGeneratedJava) args << "-j" + if (target != "") { + args << "-target" + args << target + } + if (comments) args << "-comments" + if (suppressWarnings) args << "-nowarn" + if (explain != "") { + args << "-explain" + args << explain + } + if (verbose) + args << "-v" + + def fp = fregePaths + if (!fp.isEmpty()) { + args << "-fp" + args << fp.collect { f -> f.absolutePath }.join(File.pathSeparator) + } + + if (sourcePaths != null && !sourcePaths.isEmpty()) { + args << "-sp" + args << sourcePaths.collect { d -> d.absolutePath }.join(File.pathSeparator) + } + + if (encoding != "") { + args << "-enc" + args << encoding + } + + if (prefix != "") { + args << "-prefix" + args << prefix + } + + args << "-d" + args << getDestinationDir() + + if (!module.isEmpty()) { + logger.info "compiling module '$module'" + args << module + } else { + args = (args + extraArgs.split().toList()).toList() + } + + args + } + +} diff --git a/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy b/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy new file mode 100644 index 0000000..7ac49a7 --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeDoc.groovy @@ -0,0 +1,83 @@ +package frege.gradle.tasks + +import org.gradle.api.DefaultTask +import org.gradle.api.internal.file.FileResolver +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputDirectory +import org.gradle.api.tasks.TaskAction +import org.gradle.process.internal.DefaultJavaExecAction +import org.gradle.process.internal.JavaExecAction + +class FregeDoc extends DefaultTask { + + /* Usage: java -jar fregec.jar frege.tools.Doc [-v] [-d opt] [-x mod,...] modules ... + * -v print a message for each processed module + * -d docdir specify root directory for documentation + * Documentation for module x.y.Z will be writen to + * $docdir/x/y/Z.html + * -cp classpath class path for doc tool + * -x mod1[,mod2] exclude modules whose name starts with 'mod1' or 'mod2' + * + * Modules can be specified in three ways: + * my.nice.Modul by name, the Java class for this module must be on the class path + * directory/ all modules that could be loaded if the given directory was on the class path, except exxcluded ones + * path.jar all modules in the specified JAR file, except excluded ones + * + * Example: document base frege distribution without compiler modules + * java -cp fregec.jar frege.tools.Doc -d doc -x frege.compiler fregec.jar + * + */ + + static String DEFAULT_SRC_DIR = "src/main/frege" // TODO: should this come from a source set? + static String DEFAULT_DOCS_SUBDIR = "docs/frege" // TODO: should this come from a convention? + + Boolean help = false + + @Optional + @InputDirectory + File sourceDir = new File(project.projectDir, DEFAULT_SRC_DIR).exists() ? new File(project.projectDir, DEFAULT_SRC_DIR) : null + + @Optional + @OutputDirectory + File targetDir = new File(project.buildDir, DEFAULT_DOCS_SUBDIR) + + @Input + String module = "$project.buildDir/classes/main" // module name or directory or class path. Default is all production modules + + @Input @Optional + String exclude = null + + @Input @Optional + Boolean verbose = null + + @TaskAction + void fregedoc() { + + FileResolver fileResolver = getServices().get(FileResolver.class) + JavaExecAction action = new DefaultJavaExecAction(fileResolver) + action.setMain("frege.tools.Doc") + action.workingDir = sourceDir ?: project.projectDir + action.standardInput = System.in + action.standardOutput = System.out + action.errorOutput = System.err + action.setClasspath(project.files(project.configurations.compile) + project.files("$project.buildDir/classes/main")) + + def args = [] + if (help) { + args << "-h" + } else { + if (verbose) args << '-v' + args << '-d' << targetDir.absolutePath + if (exclude) args << '-x' << exclude + args << module + } + + logger.info("Calling Frege Doc with args: '$args'") + action.args args + action.execute() + } + +} + diff --git a/src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy b/src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy new file mode 100644 index 0000000..6f51218 --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeNativeGen.groovy @@ -0,0 +1,61 @@ +package frege.gradle.tasks + +import org.gradle.api.DefaultTask +import org.gradle.api.internal.file.FileResolver +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.InputFile +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction + +import org.gradle.process.internal.DefaultJavaExecAction +import org.gradle.process.internal.JavaExecAction + +class FregeNativeGen extends DefaultTask { + + /* + * Example from https://github.com/Frege/frege-native-gen: + * java -cp /path/to/guava-15.0.jar:lib/frege-YY.jar:frege-native-gen-XX.jar frege.nativegen.Main com.google.common.collect.ImmutableCollection + */ + + // help not currently supported by native gen tool + Boolean help = false + + @Optional + @InputFile + File typesFile = new File(project.projectDir, "types.properties") + + @Input + String className = null + + @Optional + @OutputFile + File outputFile = new File(project.buildDir, "generated/frege/NativeGenOutput.fr") + + + @TaskAction + void gen() { + + FileResolver fileResolver = getServices().get(FileResolver.class) + JavaExecAction action = new DefaultJavaExecAction(fileResolver) + action.setMain("frege.nativegen.Main") + action.workingDir = project.projectDir + action.standardInput = System.in + action.standardOutput = outputFile.newOutputStream() + action.errorOutput = System.err + action.setClasspath(project.files(project.configurations.compile) + project.files("$project.buildDir/classes/main")) + + def args = [] + if (help) { + args << "-h" + } else { + args << className + args << typesFile.absolutePath + } + logger.info("Calling Frege NativeGen with args: '$args'") + action.args args + action.execute() + } + + +} diff --git a/src/main/groovy/frege/gradle/tasks/FregeQuickCheck.groovy b/src/main/groovy/frege/gradle/tasks/FregeQuickCheck.groovy new file mode 100644 index 0000000..e06236f --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeQuickCheck.groovy @@ -0,0 +1,92 @@ +package frege.gradle.tasks +import org.gradle.api.DefaultTask +import org.gradle.api.internal.file.FileResolver +import org.gradle.api.tasks.TaskAction +import org.gradle.process.internal.DefaultJavaExecAction +import org.gradle.process.internal.JavaExecAction + +class FregeQuickCheck extends DefaultTask { + + // more options to consider: +/* + Looks up quick check predicates in the given modules and tests them. + + [Usage:] java -cp fregec.jar frege.tools.Quick [ option ... ] modulespec ... + + Options: + + - -v print a line for each pedicate that passed + - -n num run _num_ tests per predicate, default is 100 + - -p pred1,pred2,... only test the given predicates + - -x pred1,pred2,... do not test the given predicates + - -l just print the names of the predicates available. + + Ways to specify modules: + + - module the module name (e.g. my.great.Module), will be lookup up in + the current class path. + - dir/ A directory path. The directory is searched for class files, + and for each class files an attempt is made to load it as if + the given directory was in the class path. The directory must + be the root of the classes contained therein, otherwise the + classes won't get loaded. + - path-to.jar A jar or zip file is searched for class files, and for each + class file found an attempt is made to load it as if the + jar was in the class path. + + The number of passed/failed tests is reported. If any test failed or other + errors occured, the exit code will be non zero. + + The code will try to heat up your CPU by running tests on all available cores. + This should be faster on multi-core computers than running the tests + sequentially. It makes it feasable to run more tests per predicate. + + */ + + Boolean verbose = true + Boolean listAvailable = false + Boolean help = false + Integer num = 100 + List<String> includePredicates + List<String> excludePredicates + String moduleName + String moduleDirectory + String moduleJar + List<String> classpathDirectories = ["$project.buildDir/classes/main", "$project.buildDir/classes/test"] + String moduleDir = "$project.buildDir/classes/test" + List<String> allJvmArgs = [] + + @TaskAction + void runQuickCheck() { + + FileResolver fileResolver = getServices().get(FileResolver.class) + JavaExecAction action = new DefaultJavaExecAction(fileResolver) + action.setMain("frege.tools.Quick") + + action.standardInput = System.in + action.standardOutput = System.out + action.errorOutput = System.err + + def f = project.files(classpathDirectories.collect { s -> new File(s) }) + action.setClasspath(project.files(project.configurations.compile).plus(project.files(project.configurations.testRuntime)).plus(f)) + + + project.configurations.testRuntime.each { println it } + + def args = [] + if (help) { + + } else { + if (verbose) args << "-v" + if (listAvailable) args << "-l" + if (!allJvmArgs.isEmpty()) { + action.setJvmArgs(allJvmArgs) + } + args = args + [moduleDir] + } + logger.info("Calling Frege QuickCheck with args: '$args'") + action.args args + action.execute() + } + +}
\ No newline at end of file diff --git a/src/main/groovy/frege/gradle/tasks/FregeRepl.groovy b/src/main/groovy/frege/gradle/tasks/FregeRepl.groovy new file mode 100644 index 0000000..64e0186 --- /dev/null +++ b/src/main/groovy/frege/gradle/tasks/FregeRepl.groovy @@ -0,0 +1,39 @@ +package frege.gradle.tasks + +import org.gradle.api.DefaultTask +import org.gradle.api.internal.file.FileResolver +import org.gradle.api.tasks.* +import org.gradle.process.internal.DefaultJavaExecAction +import org.gradle.process.internal.JavaExecAction + +class FregeRepl extends DefaultTask { + + static String DEFAULT_SRC_DIR = "src/main/frege" // TODO: should this come from a source set? + static String DEFAULT_CLASSES_SUBDIR = "classes/main" // TODO: should this come from a convention? + + @Optional @InputDirectory + File sourceDir = new File(project.projectDir, DEFAULT_SRC_DIR).exists() ? new File(project.projectDir, DEFAULT_SRC_DIR) : null + + @Optional @OutputDirectory + File targetDir = new File(project.buildDir, DEFAULT_CLASSES_SUBDIR) + + @TaskAction + void openFregeRepl() { + + if (sourceDir != null && !sourceDir.exists() ) { + def currentDir = new File('.') + logger.info "Intended source dir '${sourceDir.absolutePath}' doesn't exist. Using current dir '${currentDir.absolutePath}' ." + sourceDir = currentDir + } + + FileResolver fileResolver = getServices().get(FileResolver.class) + JavaExecAction action = new DefaultJavaExecAction(fileResolver) + action.setMain("frege.repl.FregeRepl") + action.workingDir = sourceDir ?: project.projectDir + action.standardInput = System.in + action.setClasspath(project.files(project.configurations.runtime ) + project.files(targetDir.absolutePath)) + + action.execute() + } + +}
\ No newline at end of file |