Split apart compiler and api.

This commit is contained in:
JesseBrault0709 2024-05-20 12:16:03 +02:00
parent 269963563f
commit 9bb76f819d
212 changed files with 461 additions and 349 deletions

View File

@ -6,7 +6,8 @@ pluginManagement {
rootProject.name = 'groowt'
include 'cli', 'groowt-all', 'groowt-gradle', 'groowt-gradle-model', 'views', 'view-components', 'web-view-components'
include 'cli', 'groowt-all', 'groowt-gradle', 'groowt-gradle-model', 'views', 'view-components',
'web-view-components', 'web-view-components-compiler'
file('util').eachDir {
include it.name

View File

@ -0,0 +1,2 @@
bin
groovyc-out

View File

@ -0,0 +1,206 @@
import groovy.transform.NullCheck
import groowt.gradle.antlr.GroowtAntlrExecTask
plugins {
id 'groowt-conventions'
id 'groowt-antlr-plugin'
id 'groowt-testing'
id 'groowt-publish'
id 'java-library'
id 'groovy'
id 'org.jetbrains.kotlin.jvm'
id 'java-test-fixtures'
}
repositories {
mavenCentral()
}
configurations {
groovyConsole
sketchingImplementation {
extendsFrom(apiElements, runtimeElements)
}
testFixturesApi {
extendsFrom configurations.testing
}
toolsImplementation {
extendsFrom(apiElements, runtimeElements)
}
}
sourceSets {
sketching {
java {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
srcDirs = [file('sketching/java')]
}
groovy {
srcDirs = [file('sketching/groovy')]
}
resources {
srcDirs = [file('sketching/resources')]
}
}
tools {
java {
compileClasspath += sourceSets.main.output
runtimeClasspath += sourceSets.main.output
}
}
}
dependencies {
api project(':web-view-components')
api libs.antlr.runtime
api project(':fp')
compileOnlyApi libs.jetbrains.anotations
implementation libs.slf4j.api
implementation libs.kotlin.stdlib
implementation libs.jansi
implementation libs.asm
implementation project(':di')
implementation project(':extensible')
groowtAntlr libs.antlr
testing libs.mockito.core, libs.mockito.junit
groovyConsole libs.groovy.console
toolsImplementation libs.picocli
toolsImplementation libs.groovy.console
toolsImplementation libs.log4j.core
toolsRuntimeOnly libs.log4j.slf4jBinding
}
ext {
antlrPackageName = 'groowt.view.component.web.antlr'
toolsPackageName = 'groowt.view.component.web.tools'
}
groowtAntlr {
packageName = project.ext.get('antlrPackageName')
visitor = true
}
tasks.named('generateWebViewComponentsLexerBase', GroowtAntlrExecTask) { task ->
doLast {
def pattern = ~/public class WebViewComponentsLexerBase(.*)/
def lexerSource = task.resolveOutputFile 'WebViewComponentsLexerBase.java'
def outLines = lexerSource.readLines().collect {
def matcher = pattern.matcher(it)
if (matcher.matches()) {
return 'public abstract class WebViewComponentsLexerBase' + matcher.group(1)
} else {
return it
}
}
lexerSource.write(outLines.join('\n'))
}
}
tasks.register('groovyConsole', JavaExec) {
group = 'groovy'
classpath += sourceSets.main.runtimeClasspath + configurations.groovyConsole
mainClass = 'groovy.console.ui.Console'
}
tasks.register('toolsJar', Jar) {
group 'tools'
archiveBaseName = 'web-tools'
exclude { FileTreeElement element ->
element.file in sourceSets.main.output
}
from sourceSets.tools.output
from sourceSets.tools.runtimeClasspath.filter(File.&exists).collect { it.isDirectory() ? it : zipTree(it) }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
dependsOn tasks.named('jar')
}
@NullCheck
class ToolSpec {
final String name
final String mainClass
final String mainClassPackage
ToolSpec(String name, String mainClass, String mainClassPackage) {
this.name = name
this.mainClass = mainClass
this.mainClassPackage = mainClassPackage
}
String getFullMainClass() {
this.mainClassPackage + '.' + this.mainClass
}
}
def toolSpec = { String name, String mainClass ->
new ToolSpec(name, mainClass, project.ext.get('toolsPackageName') as String)
}
final List<ToolSpec> toolSpecs = [
toolSpec('astFileMaker', 'AstFileMakerCli'),
toolSpec('convertToGroovy', 'ConvertToGroovy'),
toolSpec('lexer', 'LexerTool'),
toolSpec('parser', 'ParserTool'),
toolSpec('parseTreeFileMaker', 'ParseTreeFileMakerCli')
]
toolSpecs.each { spec ->
tasks.register("create${spec.name.capitalize()}StartScripts", CreateStartScripts) {
group = 'tools'
outputDir = file('bin')
applicationName = spec.name
mainClass = spec.fullMainClass
unixStartScriptGenerator.template = resources.text.fromFile('src/tools/binTemplate.gst')
dependsOn tasks.named('toolsJar')
}
}
tasks.register('createToolsStartScripts') {
group 'tools'
dependsOn tasks.matching { Task task ->
task != it
&& task.name.startsWith('create')
&& task.name.endsWith('StartScripts')
&& task.group == 'tools'
}
}
tasks.register('cleanBin', Delete) {
group = 'tools'
delete file('bin')
}
tasks.register('uberJar', Jar) {
group 'groovyc'
archiveBaseName = 'web-view-components-uber'
from sourceSets.main.output
from sourceSets.main.runtimeClasspath.filter(File.&exists).collect { it.isDirectory() ? it : zipTree(it) }
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
}
test {
jvmArgs '-XX:+EnableDynamicAgentLoading' // for mockito/bytebuddy
}
java {
withSourcesJar()
}
publishing {
publications {
create('webViewComponentsCompiler', MavenPublication) {
artifactId = 'web-view-components-compiler'
from components.java
}
}
}

View File

@ -0,0 +1,18 @@
#!/usr/bin/env bash
if [ "$1" == "--debug" ]; then
shift
gradle -q uberJar && \
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=*:8192 \
-cp build/libs/web-view-components-uber-0.1.0.jar \
org.codehaus.groovy.tools.FileSystemCompiler \
--configscript src/main/resources/groowt/view/component/web/groovyc/groovycConfigurationScript.groovy \
-d groovyc-out \
"$@"
else
gradle -q uberJar && \
groovyc -cp build/libs/web-view-components-uber-0.1.0.jar \
--configscript src/main/resources/groowt/view/component/web/groovyc/groovycConfigurationScript.groovy \
-d groovyc-out \
"$@"
fi

View File

@ -1,4 +1,4 @@
---
package groowt.view.web.sketching
package sketching
---
<Greeters.Simple target='World' />

View File

@ -3,13 +3,13 @@ package sketching
import groowt.view.component.web.BaseWebViewComponent
class Greeter extends BaseWebViewComponent {
class SimpleHello extends BaseWebViewComponent {
String target
Greeter(Map attr) {
SimpleHello(Map attr) {
super('Hello, $target!')
this.target = attr.target
}
}
---
<Greeter target='World' />
<SimpleHello target='World' />

View File

@ -1,5 +1,5 @@
---
package groowt.view.web.sketching
package sketching
---
<>
<Greeters.Simple greeting='Hello, one!' />&nbsp;<Greeters.Simple greeting='Hello, two!' />

View File

@ -0,0 +1,12 @@
package groowt.view.component.web.compiler;
import groowt.view.component.compiler.ComponentTemplateCompilerConfiguration;
public class DefaultWebViewComponentTemplateCompilerFactory implements WebViewComponentTemplateCompilerFactory {
@Override
public WebViewComponentTemplateCompiler create(ComponentTemplateCompilerConfiguration configuration) {
return new DefaultWebViewComponentTemplateCompiler(configuration);
}
}

View File

@ -10,10 +10,7 @@ import groowt.view.component.web.antlr.*;
import groowt.view.component.web.ast.DefaultAstBuilder;
import groowt.view.component.web.ast.DefaultNodeFactory;
import groowt.view.component.web.ast.node.CompilationUnitNode;
import groowt.view.component.web.compiler.AnonymousWebViewComponent;
import groowt.view.component.web.compiler.MultipleWebViewComponentCompileErrorsException;
import groowt.view.component.web.compiler.WebViewComponentTemplateCompileException;
import groowt.view.component.web.compiler.WebViewComponentTemplateCompileUnit;
import groowt.view.component.web.compiler.*;
import groowt.view.component.web.transpile.DefaultGroovyTranspiler;
import groowt.view.component.web.util.SourcePosition;
import org.antlr.v4.runtime.ParserRuleContext;
@ -135,7 +132,7 @@ public class DelegatingWvcParserPlugin implements ParserPlugin {
final int lastSlashIndex = sourceUnitFullName.lastIndexOf(File.separator);
final String sourceUnitFileName = sourceUnitFullName.substring(lastSlashIndex + 1);
if (sourceUnitFileName.endsWith(".wvc")) {
final var compileUnit = new WebViewComponentTemplateCompileUnit(
final var compileUnit = new DefaultWebViewComponentTemplateCompileUnit(
AnonymousWebViewComponent.class,
ComponentTemplateSource.of(sourceUnit.getSource().getURI()),
"" // default package

Some files were not shown because too many files have changed in this diff Show More