From 492ec7d5a1856672800b51c898099678bb95ac62 Mon Sep 17 00:00:00 2001 From: Mark Perry Date: Wed, 16 Sep 2015 01:08:45 +1000 Subject: Added help and Frege package dir for compile task --- build.gradle | 1 + src/main/groovy/frege/gradle/CompileTask.groovy | 151 +++++++++++++++++++++ src/main/groovy/frege/gradle/DocTask.groovy | 58 ++++++++ src/main/groovy/frege/gradle/FregeDocTask.groovy | 57 -------- src/main/groovy/frege/gradle/FregePlugin.groovy | 21 ++- .../groovy/frege/gradle/FregeQuickCheckTask.groovy | 62 --------- src/main/groovy/frege/gradle/FregeReplTask.groovy | 39 ------ src/main/groovy/frege/gradle/FregeTask.groovy | 109 --------------- src/main/groovy/frege/gradle/QuickCheckTask.groovy | 94 +++++++++++++ src/main/groovy/frege/gradle/ReplTask.groovy | 39 ++++++ 10 files changed, 360 insertions(+), 271 deletions(-) create mode 100644 src/main/groovy/frege/gradle/CompileTask.groovy create mode 100644 src/main/groovy/frege/gradle/DocTask.groovy delete mode 100644 src/main/groovy/frege/gradle/FregeDocTask.groovy delete mode 100644 src/main/groovy/frege/gradle/FregeQuickCheckTask.groovy delete mode 100644 src/main/groovy/frege/gradle/FregeReplTask.groovy delete mode 100644 src/main/groovy/frege/gradle/FregeTask.groovy create mode 100644 src/main/groovy/frege/gradle/QuickCheckTask.groovy create mode 100644 src/main/groovy/frege/gradle/ReplTask.groovy diff --git a/build.gradle b/build.gradle index 5991631..9986268 100644 --- a/build.gradle +++ b/build.gradle @@ -54,6 +54,7 @@ dependencies { compile "$projectGroup:frege:$fregeVersion" compile "$projectGroup:frege-repl-core:1.2" compile "$projectGroup:frege-native-gen:1.3" + compile "org.functionaljava:functionaljava:4.4" compile gradleApi() compile localGroovy() } diff --git a/src/main/groovy/frege/gradle/CompileTask.groovy b/src/main/groovy/frege/gradle/CompileTask.groovy new file mode 100644 index 0000000..d0a5e21 --- /dev/null +++ b/src/main/groovy/frege/gradle/CompileTask.groovy @@ -0,0 +1,151 @@ +package frege.gradle + +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" + + 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 + File sourceDir = deduceSourceDir(project) + + @Optional @OutputDirectory + File outputDir = deduceClassesDir(project) + + @Optional + List fregePackageDirs = [] + + static File deduceSourceDir(File projectDir, String subdir) { + new File(projectDir, subdir).exists() ? new File(projectDir, subdir) : null + } + + static File deduceSourceDir(Project project) { + deduceSourceDir(project.projectDir, DEFAULT_SRC_DIR) + } + + 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") + 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) + action.execute() + } + + 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 (sourceDir != null) { + args << "-sp" + args << sourceDir.absolutePath + } + + args << "-d" + args << outputDir + + if (!fregePackageDirs.isEmpty()) { + args << "-fp" + args << fregePackageDirs.join(";") + } + + if (!module && !extraArgs) { + logger.info "no module and no extra args given: compiling all of the sourceDir" + if (sourceDir != null) { + args << sourceDir.absolutePath + } + + } else if (module) { + logger.info "compiling module '$module'" + args << module + } else { + args = args + extraArgs.split().toList() + } + args + } +} \ No newline at end of file diff --git a/src/main/groovy/frege/gradle/DocTask.groovy b/src/main/groovy/frege/gradle/DocTask.groovy new file mode 100644 index 0000000..c020cf6 --- /dev/null +++ b/src/main/groovy/frege/gradle/DocTask.groovy @@ -0,0 +1,58 @@ +package frege.gradle + +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 DocTask extends DefaultTask { + + 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? + + @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 (verbose) args << '-v' + args << '-d' << targetDir.absolutePath + if (exclude) args << '-x' << exclude + args << module + + action.args args + action.execute() + } + +} + diff --git a/src/main/groovy/frege/gradle/FregeDocTask.groovy b/src/main/groovy/frege/gradle/FregeDocTask.groovy deleted file mode 100644 index 077c4e5..0000000 --- a/src/main/groovy/frege/gradle/FregeDocTask.groovy +++ /dev/null @@ -1,57 +0,0 @@ -package frege.gradle - -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 FregeDocTask extends DefaultTask { - - 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? - - @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 (verbose) args << '-v' - args << '-d' << targetDir.absolutePath - if (exclude) args << '-x' << exclude - args << module - action.args args - action.execute() - } - -} - diff --git a/src/main/groovy/frege/gradle/FregePlugin.groovy b/src/main/groovy/frege/gradle/FregePlugin.groovy index 21958b0..3b4d60b 100644 --- a/src/main/groovy/frege/gradle/FregePlugin.groovy +++ b/src/main/groovy/frege/gradle/FregePlugin.groovy @@ -2,6 +2,7 @@ package frege.gradle import org.gradle.api.Plugin import org.gradle.api.Project +import fj.data.Option class FregePlugin implements Plugin { @@ -12,18 +13,30 @@ class FregePlugin implements Plugin { project.apply(plugin: 'base') def e = (FregePluginExtension) project.extensions.create("frege", FregePluginExtension) - project.task('compileFrege', type: FregeTask, group: 'Build') << { + project.task('compileFrege', type: CompileTask, group: 'Build') << { } project.tasks.classes.dependsOn("compileFrege") - def replTask = project.task('fregeRepl', type: FregeReplTask, group: 'Tools', dependsOn: 'compileFrege') + project.task('compileTestFrege', type: CompileTask, group: 'Build') { + sourceDir = CompileTask.deduceTestSrcDir(project) + outputDir = CompileTask.deduceTestClassesDir(project) +// logger.info("compileTestFrege debug") +// logger.info("projectDir ${project.projectDir}") +// logger.info("defaultSrc ${CompileTask.DEFAULT_SRC_DIR}") + fregePackageDirs = Option.fromNull( + CompileTask.deduceClassesDir(project) + ).map { d -> [d.absolutePath] }.orSome([]) + } + project.tasks.testClasses.dependsOn("compileTestFrege") + + def replTask = project.task('fregeRepl', type: ReplTask, group: 'Tools', dependsOn: 'compileFrege') replTask.outputs.upToDateWhen { false } // always run, regardless of up to date checks - def checkTask = project.task('quickCheck', type: FregeQuickCheckTask, group: 'Tools', dependsOn: 'compileFrege') + def checkTask = project.task('fregeQuickCheck', type: QuickCheckTask, group: 'Tools', dependsOn: 'compileFrege') checkTask.outputs.upToDateWhen { false } // always run, regardless of up to date checks - project.task('fregeDoc', type: FregeDocTask, group: 'Tools', dependsOn: 'compileFrege') + project.task('fregeDoc', type: DocTask, group: 'Tools', dependsOn: 'compileFrege') project.task('fregeNativeGen', type: NativeGenTask, group: 'Tools') diff --git a/src/main/groovy/frege/gradle/FregeQuickCheckTask.groovy b/src/main/groovy/frege/gradle/FregeQuickCheckTask.groovy deleted file mode 100644 index 31f7d27..0000000 --- a/src/main/groovy/frege/gradle/FregeQuickCheckTask.groovy +++ /dev/null @@ -1,62 +0,0 @@ -package frege.gradle - -import org.gradle.api.DefaultTask -import org.gradle.api.internal.file.FileResolver -import org.gradle.api.tasks.InputDirectory -import org.gradle.api.tasks.Optional -import org.gradle.api.tasks.TaskAction -import org.gradle.process.internal.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction - -class FregeQuickCheckTask 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. - - */ - @TaskAction - void runQuickCheck() { - - FileResolver fileResolver = getServices().get(FileResolver.class) - JavaExecAction action = new DefaultJavaExecAction(fileResolver) - action.setMain("frege.tools.Quick") - action.setClasspath(project.files(project.configurations.testRuntime)) - - project.configurations.testRuntime.each { println it } - - action.args("$project.buildDir/classes/main/") // test all in build dir and below build/classes/test/ - action.execute() - } - -} \ No newline at end of file diff --git a/src/main/groovy/frege/gradle/FregeReplTask.groovy b/src/main/groovy/frege/gradle/FregeReplTask.groovy deleted file mode 100644 index d79a73f..0000000 --- a/src/main/groovy/frege/gradle/FregeReplTask.groovy +++ /dev/null @@ -1,39 +0,0 @@ -package frege.gradle - -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 FregeReplTask 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 diff --git a/src/main/groovy/frege/gradle/FregeTask.groovy b/src/main/groovy/frege/gradle/FregeTask.groovy deleted file mode 100644 index a85b4cc..0000000 --- a/src/main/groovy/frege/gradle/FregeTask.groovy +++ /dev/null @@ -1,109 +0,0 @@ -package frege.gradle - -import org.gradle.api.DefaultTask -import org.gradle.api.tasks.* -import org.gradle.process.internal.DefaultJavaExecAction -import org.gradle.process.internal.JavaExecAction -import org.gradle.api.internal.file.FileResolver -import org.gradle.tooling.BuildException - -class FregeTask 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? - - @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 - File sourceDir = new File(project.projectDir, DEFAULT_SRC_DIR).exists() ? new File(project.projectDir, DEFAULT_SRC_DIR) : null - - @Optional @OutputDirectory - File outputDir = new File(project.buildDir, DEFAULT_CLASSES_SUBDIR) - - @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") - action.setClasspath(project.files(project.configurations.compile)) - - List jvmargs = [] - if (xss) - jvmargs << "-Xss$xss" - action.setJvmArgs(jvmargs) - - def args = allArgs ? allArgs.split().toList() : assembleArguments() - - logger.info("Calling Frege compiler with args: '$args'") - action.args(args) - action.execute() - } - - 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 (sourceDir != null) { - args << "-sp" - args << sourceDir.absolutePath - } - - args << "-d" - args << outputDir - - if (!module && !extraArgs) { - logger.info "no module and no extra args given: compiling all of the sourceDir" - if (sourceDir != null) { - args << sourceDir.absolutePath - } - - } else if (module) { - logger.info "compiling module '$module'" - args << module - } else { - args = args + extraArgs.split().toList() - } - args - } -} \ No newline at end of file diff --git a/src/main/groovy/frege/gradle/QuickCheckTask.groovy b/src/main/groovy/frege/gradle/QuickCheckTask.groovy new file mode 100644 index 0000000..7da7924 --- /dev/null +++ b/src/main/groovy/frege/gradle/QuickCheckTask.groovy @@ -0,0 +1,94 @@ +package frege.gradle + +import org.gradle.api.DefaultTask +import org.gradle.api.internal.file.FileResolver +import org.gradle.api.tasks.InputDirectory +import org.gradle.api.tasks.Optional +import org.gradle.api.tasks.TaskAction +import org.gradle.process.internal.DefaultJavaExecAction +import org.gradle.process.internal.JavaExecAction + +class QuickCheckTask 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 includePredicates + List excludePredicates + String moduleName + String moduleDirectory + String moduleJar + List classpathDirectories = + ["$project.buildDir/classes/main/"] +// ["$project.buildDir/classes/main/", "$project.buildDir/classes/test/"] + + + @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 + + action.setClasspath(project.files(project.configurations.testRuntime)) + + project.configurations.testRuntime.each { println it } + + def args = [] + if (help) { + + } else { + if (verbose) args << "-v" + + args = args + classpathDirectories +// args.action.args(classpathDirectories) // test all in build dir and below build/classes/test/ + + + } + + action.args args + action.execute() + } + +} \ No newline at end of file diff --git a/src/main/groovy/frege/gradle/ReplTask.groovy b/src/main/groovy/frege/gradle/ReplTask.groovy new file mode 100644 index 0000000..1f570eb --- /dev/null +++ b/src/main/groovy/frege/gradle/ReplTask.groovy @@ -0,0 +1,39 @@ +package frege.gradle + +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 ReplTask 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 -- cgit