Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GROOVY-11194 (Groovy 2.5) #1977

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 58 additions & 3 deletions src/main/java/org/codehaus/groovy/tools/FileSystemCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.codehaus.groovy.control.CompilationUnit;
import org.codehaus.groovy.control.CompilerConfiguration;
import org.codehaus.groovy.control.ConfigurationException;
import org.codehaus.groovy.control.messages.WarningMessage;
import org.codehaus.groovy.runtime.DefaultGroovyStaticMethods;
import org.codehaus.groovy.runtime.StringGroovyMethods;
import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
Expand Down Expand Up @@ -387,18 +388,33 @@ public static class CompilationOptions {
@Option(names = "-d", paramLabel = "<dir>", description = "Specify where to place generated class files")
private File targetDir;

@Option(names = {"-de", "--debug"}, description = "If set, outputs a little more information during compilation when errors occur.")
private boolean debug;

@Option(names = {"-e", "--exception"}, description = "Print stack trace on error")
private boolean printStack;

@Option(names = {"-w", "--warningLevel"}, description = "The amount of warnings to print. Set to 0 for none, 1 for likely errors, 2 for possible errors, and 3 for as many warnings as possible.", defaultValue = "1")
private String warningLevel;

@Option(names = {"-pa", "--parameters"}, description = "Generate metadata for reflection on method parameter names (jdk8+ only)")
private boolean parameterMetadata;

@Option(names = {"-pr", "--enable-preview"}, description = "Enable preview Java features (JEP 12) (jdk12+ only) - must be after classpath but before other arguments")
@Option(names = {"-pl", "--parallel-parsing"}, description = "Enable parallel parsing")
private boolean parallelParsing;

@Option(names = {"-pr", "--enable-preview"}, description = "Enable preview Java features (jdk12+ only) - must be after classpath but before other arguments")
private boolean previewFeatures;

@Option(names = {"-j", "--jointCompilation"}, description = "Attach javac compiler to compile .java files")
private boolean jointCompilation;

@Option(names = {"-s", "--stubDirectory"}, description = "The directory into which the Java source stub files should be generated")
private String stubDirectory;

@Option(names = {"-ks", "--keepStubs"}, description = "Whether to keep the generated stubs rather than deleting them")
private boolean keepStubs;

@Option(names = {"-b", "--basescript"}, paramLabel = "<class>", description = "Base class name for scripts (must derive from Script)")
private String scriptBaseClass;

Expand All @@ -411,9 +427,12 @@ public static class CompilationOptions {
@Option(names = {"--indy"}, description = "Enables compilation using invokedynamic")
private boolean indy;

@Option(names = {"--configscript"}, paramLabel = "<script>", description = "A script for tweaking the configuration options")
@Option(names = {"-cf", "--configscript"}, paramLabel = "<script>", description = "A script for tweaking the configuration options")
private String configScript;

@Option(names = {"-t", "--tolerance"}, description = "The number of non-fatal errors to allow before bailing")
private int tolerance;

@Option(names = {"-h", "--help"}, usageHelp = true, description = "Show this help message and exit")
private boolean helpRequested;

Expand All @@ -423,6 +442,12 @@ public static class CompilationOptions {
@Parameters(description = "The groovy source files to compile, or @-files containing a list of source files to compile", paramLabel = "<source-files>")
private List<String> files;

@Option(names = {"--compile-static"}, description = "Use CompileStatic")
private boolean compileStatic;

@Option(names = {"--type-checked"}, description = "Use TypeChecked")
private boolean typeChecked;

public CompilerConfiguration toCompilerConfiguration() throws IOException {
CompilerConfiguration configuration = new CompilerConfiguration();

Expand All @@ -436,14 +461,32 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {

configuration.setParameters(parameterMetadata);
configuration.setPreviewFeatures(previewFeatures);
configuration.setScriptBaseClass(scriptBaseClass);
configuration.setSourceEncoding(encoding);
configuration.setScriptBaseClass(scriptBaseClass);
if (tolerance > 0) {
configuration.setTolerance(tolerance);
}

if (Integer.parseInt(warningLevel) == WarningMessage.NONE
|| Integer.parseInt(warningLevel) == WarningMessage.LIKELY_ERRORS
|| Integer.parseInt(warningLevel) == WarningMessage.POSSIBLE_ERRORS
|| Integer.parseInt(warningLevel) == WarningMessage.PARANOIA) {
configuration.setWarningLevel(Integer.parseInt(warningLevel));
} else {
System.err.println("error: warning level not recognized: " + warningLevel);
}

// joint compilation parameters
if (jointCompilation) {
Map<String, Object> compilerOptions = new HashMap<>();
compilerOptions.put("flags", javacFlags());
compilerOptions.put("namedValues", javacNamedValues());
if (stubDirectory != null) {
compilerOptions.put("stubDir", stubDirectory);
}
if (keepStubs) {
compilerOptions.put("keepStubs", true);
}
configuration.setJointCompilationOptions(compilerOptions);
}

Expand All @@ -452,6 +495,18 @@ public CompilerConfiguration toCompilerConfiguration() throws IOException {
configuration.getOptimizationOptions().put("indy", Boolean.TRUE);
}

if (parallelParsing) {
configuration.getOptimizationOptions().put("parallelParse", true);
}

final List<String> transformations = new ArrayList<>();
if (compileStatic) {
transformations.add("ast(groovy.transform.CompileStatic)");
}
if (typeChecked) {
transformations.add("ast(groovy.transform.TypeChecked)");
}

String configScripts = System.getProperty("groovy.starter.configscripts", null);
if (configScript != null || (configScripts != null && !configScripts.isEmpty())) {
List<String> scripts = new ArrayList<>();
Expand Down
Loading