Merge remote branch 'origin/master'
This commit is contained in:
@@ -43,7 +43,20 @@ public class KotlinCompiler {
|
||||
target.println("Usage: KotlinCompiler [-output <outputDir>|-jar <jarFileName>] [-stdlib <path to runtime.jar>] [-src <filename or dirname>|-module <module file>] [-includeRuntime]");
|
||||
}
|
||||
|
||||
public static void main(String ... args) {
|
||||
public static void main(String... args) {
|
||||
try {
|
||||
int rc = exec(args);
|
||||
if (rc != 0) {
|
||||
System.err.println("exec() finished with " + rc + " return code");
|
||||
System.exit(rc);
|
||||
}
|
||||
} catch (CompileEnvironmentException e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static int exec(String... args) {
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
Arguments arguments = new Arguments();
|
||||
try {
|
||||
@@ -51,18 +64,16 @@ public class KotlinCompiler {
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
usage(System.err);
|
||||
System.exit(1);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
System.exit(1);
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (arguments.help) {
|
||||
usage(System.out);
|
||||
System.exit(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
CompileEnvironment environment = new CompileEnvironment();
|
||||
@@ -71,22 +82,16 @@ public class KotlinCompiler {
|
||||
environment.setStdlib(arguments.stdlib);
|
||||
}
|
||||
|
||||
try {
|
||||
if (arguments.module != null) {
|
||||
environment.compileModuleScript(arguments.module, arguments.jar, arguments.includeRuntime);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if (!environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime)) {
|
||||
System.exit(1);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (CompileEnvironmentException e) {
|
||||
System.err.println(e.getMessage());
|
||||
System.exit(1);
|
||||
return;
|
||||
if (arguments.module != null) {
|
||||
environment.compileModuleScript(arguments.module, arguments.jar, arguments.includeRuntime);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
if (!environment.compileBunchOfSources(arguments.src, arguments.jar, arguments.outputDir, arguments.includeRuntime)) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import java.lang.reflect.Method;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.jar.*;
|
||||
|
||||
@@ -124,6 +125,10 @@ public class CompileEnvironment {
|
||||
throw new CompileEnvironmentException("Module script " + moduleFile + " compilation failed");
|
||||
}
|
||||
|
||||
if (modules.isEmpty()) {
|
||||
throw new CompileEnvironmentException("No modules where defined by " + moduleFile);
|
||||
}
|
||||
|
||||
final String directory = new File(moduleFile).getParent();
|
||||
for (Module moduleBuilder : modules) {
|
||||
ClassFileFactory moduleFactory = compileModule(moduleBuilder, directory);
|
||||
@@ -150,7 +155,7 @@ public class CompileEnvironment {
|
||||
}
|
||||
|
||||
private List<Module> runDefineModules(String moduleFile, ClassFileFactory factory) {
|
||||
ClassLoader loader = myStdlib != null ? new GeneratedClassLoader(factory, new URLClassLoader(new URL[] {myStdlib})) : new GeneratedClassLoader(factory);
|
||||
ClassLoader loader = myStdlib != null ? new GeneratedClassLoader(factory, new URLClassLoader(new URL[] {myStdlib}, AllModules.class.getClassLoader())) : new GeneratedClassLoader(factory);
|
||||
try {
|
||||
Class namespaceClass = loader.loadClass(JvmAbi.PACKAGE_CLASS);
|
||||
final Method method = namespaceClass.getDeclaredMethod("project");
|
||||
@@ -161,7 +166,9 @@ public class CompileEnvironment {
|
||||
method.setAccessible(true);
|
||||
method.invoke(null);
|
||||
|
||||
return AllModules.modules;
|
||||
ArrayList<Module> answer = new ArrayList<Module>(AllModules.modules);
|
||||
AllModules.modules.clear();
|
||||
return answer;
|
||||
} catch (Exception e) {
|
||||
throw new ModuleExecutionException(e);
|
||||
}
|
||||
@@ -169,12 +176,21 @@ public class CompileEnvironment {
|
||||
|
||||
public ClassFileFactory compileModule(Module moduleBuilder, String directory) {
|
||||
CompileSession moduleCompileSession = new CompileSession(myEnvironment);
|
||||
|
||||
if (moduleBuilder.getSourceFiles().isEmpty()) {
|
||||
throw new CompileEnvironmentException("No source files where defined");
|
||||
}
|
||||
|
||||
for (String sourceFile : moduleBuilder.getSourceFiles()) {
|
||||
File source = new File(sourceFile);
|
||||
if (!source.isAbsolute()) {
|
||||
source = new File(directory, sourceFile);
|
||||
}
|
||||
|
||||
if (!source.exists()) {
|
||||
throw new CompileEnvironmentException("'" + source + "' does not exist");
|
||||
}
|
||||
|
||||
moduleCompileSession.addSources(source.getPath());
|
||||
}
|
||||
for (String classpathRoot : moduleBuilder.getClasspathRoots()) {
|
||||
|
||||
@@ -20,6 +20,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
private static final TokenSet WHEN_CONDITION_RECOVERY_SET = TokenSet.create(RBRACE, IN_KEYWORD, NOT_IN, IS_KEYWORD, NOT_IS, ELSE_KEYWORD);
|
||||
private static final TokenSet WHEN_CONDITION_RECOVERY_SET_WITH_ARROW = TokenSet.create(RBRACE, IN_KEYWORD, NOT_IN, IS_KEYWORD, NOT_IS, ELSE_KEYWORD, ARROW, DOT);
|
||||
|
||||
|
||||
private static final ImmutableMap<String, JetToken> KEYWORD_TEXTS = tokenSetToMap(KEYWORDS);
|
||||
|
||||
private static ImmutableMap<String, JetToken> tokenSetToMap(TokenSet tokens) {
|
||||
@@ -1406,9 +1407,9 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
parseControlStructureBody();
|
||||
}
|
||||
|
||||
expect(WHILE_KEYWORD, "Expecting 'while' followed by a post-condition");
|
||||
|
||||
parseCondition();
|
||||
if (expect(WHILE_KEYWORD, "Expecting 'while' followed by a post-condition")) {
|
||||
parseCondition();
|
||||
}
|
||||
|
||||
loop.done(DO_WHILE);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ public class ForTestCompileStdlib {
|
||||
|
||||
private static void compileKotlinPartOfStdlib(File destdir) throws IOException {
|
||||
// lame
|
||||
KotlinCompiler.main("-output", destdir.getPath(), "-src", "./stdlib/ktSrc");
|
||||
KotlinCompiler.exec("-output", destdir.getPath(), "-src", "./stdlib/ktSrc");
|
||||
}
|
||||
|
||||
private static List<File> javaFilesInDir(File dir) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
try {
|
||||
File stdlib = ForTestCompileStdlib.stdlibJarForTests();
|
||||
File resultJar = new File(tempDir, "result.jar");
|
||||
KotlinCompiler.main("-module", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts",
|
||||
KotlinCompiler.exec("-module", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kts",
|
||||
"-jar", resultJar.getAbsolutePath(),
|
||||
"-stdlib", stdlib.getAbsolutePath());
|
||||
FileInputStream fileInputStream = new FileInputStream(resultJar);
|
||||
@@ -68,7 +68,7 @@ public class CompileEnvironmentTest extends TestCase {
|
||||
File out = new File(tempDir, "out");
|
||||
File stdlib = new File(tempDir, "stdlib.jar");
|
||||
FileUtil.copy(ForTestCompileStdlib.stdlibJarForTests(), stdlib);
|
||||
KotlinCompiler.main("-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt",
|
||||
KotlinCompiler.exec("-src", JetParsingTest.getTestDataDir() + "/compiler/smoke/Smoke.kt",
|
||||
"-output", out.getAbsolutePath(),
|
||||
"-stdlib", stdlib.getAbsolutePath());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user