Make sure we write output for the files even if they're in std.* package
This commit is contained in:
@@ -22,7 +22,6 @@ import java.io.*;
|
|||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.jar.*;
|
import java.util.jar.*;
|
||||||
|
|
||||||
@@ -189,7 +188,7 @@ public class CompileEnvironment {
|
|||||||
public IModuleSetBuilder loadModuleScript(String moduleFile) {
|
public IModuleSetBuilder loadModuleScript(String moduleFile) {
|
||||||
CompileSession scriptCompileSession = new CompileSession(myEnvironment);
|
CompileSession scriptCompileSession = new CompileSession(myEnvironment);
|
||||||
scriptCompileSession.addSources(moduleFile);
|
scriptCompileSession.addSources(moduleFile);
|
||||||
scriptCompileSession.addStdLibSources();
|
scriptCompileSession.addStdLibSources(true);
|
||||||
|
|
||||||
if (!scriptCompileSession.analyze(myErrorStream)) {
|
if (!scriptCompileSession.analyze(myErrorStream)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -228,7 +227,7 @@ public class CompileEnvironment {
|
|||||||
|
|
||||||
public ClassFileFactory compileModule(IModuleBuilder moduleBuilder, String directory) {
|
public ClassFileFactory compileModule(IModuleBuilder moduleBuilder, String directory) {
|
||||||
CompileSession moduleCompileSession = new CompileSession(myEnvironment);
|
CompileSession moduleCompileSession = new CompileSession(myEnvironment);
|
||||||
moduleCompileSession.addStdLibSources();
|
moduleCompileSession.addStdLibSources(false);
|
||||||
for (String sourceFile : moduleBuilder.getSourceFiles()) {
|
for (String sourceFile : moduleBuilder.getSourceFiles()) {
|
||||||
File source = new File(sourceFile);
|
File source = new File(sourceFile);
|
||||||
if (!source.isAbsolute()) {
|
if (!source.isAbsolute()) {
|
||||||
@@ -250,17 +249,6 @@ public class CompileEnvironment {
|
|||||||
return new File(PathManager.getResourceRoot(CompileEnvironment.class, "/org/jetbrains/jet/compiler/CompileEnvironment.class")).getParentFile().getParentFile().getParent();
|
return new File(PathManager.getResourceRoot(CompileEnvironment.class, "/org/jetbrains/jet/compiler/CompileEnvironment.class")).getParentFile().getParentFile().getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<String> sanitized = Arrays.asList("kotlin/", "std/");
|
|
||||||
public static boolean skipFile(String name) {
|
|
||||||
boolean skip = false;
|
|
||||||
for (String prefix : sanitized) {
|
|
||||||
if(name.startsWith(prefix)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void writeToJar(ClassFileFactory factory, final OutputStream fos, @Nullable String mainClass, boolean includeRuntime) {
|
public static void writeToJar(ClassFileFactory factory, final OutputStream fos, @Nullable String mainClass, boolean includeRuntime) {
|
||||||
try {
|
try {
|
||||||
Manifest manifest = new Manifest();
|
Manifest manifest = new Manifest();
|
||||||
@@ -273,10 +261,8 @@ public class CompileEnvironment {
|
|||||||
JarOutputStream stream = new JarOutputStream(fos, manifest);
|
JarOutputStream stream = new JarOutputStream(fos, manifest);
|
||||||
try {
|
try {
|
||||||
for (String file : factory.files()) {
|
for (String file : factory.files()) {
|
||||||
if(!skipFile(file)) {
|
stream.putNextEntry(new JarEntry(file));
|
||||||
stream.putNextEntry(new JarEntry(file));
|
stream.write(factory.asBytes(file));
|
||||||
stream.write(factory.asBytes(file));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (includeRuntime) {
|
if (includeRuntime) {
|
||||||
writeRuntimeToJar(stream);
|
writeRuntimeToJar(stream);
|
||||||
@@ -343,7 +329,7 @@ public class CompileEnvironment {
|
|||||||
public void compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
|
public void compileBunchOfSources(String sourceFileOrDir, String jar, String outputDir, boolean includeRuntime) {
|
||||||
CompileSession session = new CompileSession(myEnvironment);
|
CompileSession session = new CompileSession(myEnvironment);
|
||||||
session.addSources(sourceFileOrDir);
|
session.addSources(sourceFileOrDir);
|
||||||
session.addStdLibSources();
|
session.addStdLibSources(false);
|
||||||
|
|
||||||
String mainClass = null;
|
String mainClass = null;
|
||||||
for (JetFile file : session.getSourceFileNamespaces()) {
|
for (JetFile file : session.getSourceFileNamespaces()) {
|
||||||
@@ -375,13 +361,11 @@ public class CompileEnvironment {
|
|||||||
public static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) {
|
public static void writeToOutputDirectory(ClassFileFactory factory, final String outputDir) {
|
||||||
List<String> files = factory.files();
|
List<String> files = factory.files();
|
||||||
for (String file : files) {
|
for (String file : files) {
|
||||||
if(!skipFile(file)) {
|
File target = new File(outputDir, file);
|
||||||
File target = new File(outputDir, file);
|
try {
|
||||||
try {
|
FileUtil.writeToFile(target, factory.asBytes(file));
|
||||||
FileUtil.writeToFile(target, factory.asBytes(file));
|
} catch (IOException e) {
|
||||||
} catch (IOException e) {
|
throw new CompileEnvironmentException(e);
|
||||||
throw new CompileEnvironmentException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,35 +49,39 @@ public class CompileSession {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
addSources(new File(path));
|
addSources(new File(path), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addSources(File file) {
|
private void addSources(File file, boolean library) {
|
||||||
if(file.isDirectory()) {
|
if(file.isDirectory()) {
|
||||||
for (File child : file.listFiles()) {
|
for (File child : file.listFiles()) {
|
||||||
addSources(child);
|
addSources(child, library);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
VirtualFile fileByPath = myEnvironment.getLocalFileSystem().findFileByPath(file.getAbsolutePath());
|
VirtualFile fileByPath = myEnvironment.getLocalFileSystem().findFileByPath(file.getAbsolutePath());
|
||||||
PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(fileByPath);
|
PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(fileByPath);
|
||||||
if(psiFile instanceof JetFile) {
|
if(psiFile instanceof JetFile) {
|
||||||
mySourceFiles.add((JetFile) psiFile);
|
(library ? myLibrarySourceFiles : mySourceFiles).add((JetFile) psiFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSources(VirtualFile vFile) {
|
public void addSources(VirtualFile vFile) {
|
||||||
|
addSources(vFile, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addSources(VirtualFile vFile, boolean library) {
|
||||||
if (vFile.isDirectory()) {
|
if (vFile.isDirectory()) {
|
||||||
for (VirtualFile virtualFile : vFile.getChildren()) {
|
for (VirtualFile virtualFile : vFile.getChildren()) {
|
||||||
addSources(virtualFile);
|
addSources(virtualFile, library);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (vFile.getFileType() == JetFileType.INSTANCE) {
|
if (vFile.getFileType() == JetFileType.INSTANCE) {
|
||||||
PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(vFile);
|
PsiFile psiFile = PsiManager.getInstance(myEnvironment.getProject()).findFile(vFile);
|
||||||
if (psiFile instanceof JetFile) {
|
if (psiFile instanceof JetFile) {
|
||||||
mySourceFiles.add((JetFile) psiFile);
|
(library ? myLibrarySourceFiles : mySourceFiles).add((JetFile) psiFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -115,17 +119,17 @@ public class CompileSession {
|
|||||||
return generationState.createText();
|
return generationState.createText();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean addStdLibSources() {
|
public boolean addStdLibSources(boolean toModuleSources) {
|
||||||
final File unpackedRuntimePath = CompileEnvironment.getUnpackedRuntimePath();
|
final File unpackedRuntimePath = CompileEnvironment.getUnpackedRuntimePath();
|
||||||
if (unpackedRuntimePath != null) {
|
if (unpackedRuntimePath != null) {
|
||||||
addSources(new File(unpackedRuntimePath, "../../../stdlib/ktSrc").getAbsoluteFile());
|
addSources(new File(unpackedRuntimePath, "../../../stdlib/ktSrc").getAbsoluteFile(), !toModuleSources);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
final File runtimeJarPath = CompileEnvironment.getRuntimeJarPath();
|
final File runtimeJarPath = CompileEnvironment.getRuntimeJarPath();
|
||||||
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
if (runtimeJarPath != null && runtimeJarPath.exists()) {
|
||||||
VirtualFile runtimeJar = myEnvironment.getLocalFileSystem().findFileByPath(runtimeJarPath.getAbsolutePath());
|
VirtualFile runtimeJar = myEnvironment.getLocalFileSystem().findFileByPath(runtimeJarPath.getAbsolutePath());
|
||||||
VirtualFile jarRoot = myEnvironment.getJarFileSystem().findFileByPath(runtimeJar.getPath() + "!/stdlib/ktSrc");
|
VirtualFile jarRoot = myEnvironment.getJarFileSystem().findFileByPath(runtimeJar.getPath() + "!/stdlib/ktSrc");
|
||||||
addSources(jarRoot);
|
addSources(jarRoot, !toModuleSources);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
|
|
||||||
session.addSources(myFile.getVirtualFile());
|
session.addSources(myFile.getVirtualFile());
|
||||||
try {
|
try {
|
||||||
session.addStdLibSources();
|
session.addStdLibSources(true);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,7 @@ public class StdlibTest extends CodegenTestCase {
|
|||||||
CompileSession session = new CompileSession(myEnvironment);
|
CompileSession session = new CompileSession(myEnvironment);
|
||||||
CompileEnvironment.initializeKotlinRuntime(myEnvironment);
|
CompileEnvironment.initializeKotlinRuntime(myEnvironment);
|
||||||
session.addSources(myFile.getVirtualFile());
|
session.addSources(myFile.getVirtualFile());
|
||||||
session.addStdLibSources();
|
session.addStdLibSources(true);
|
||||||
|
|
||||||
if (!session.analyze(System.out)) {
|
if (!session.analyze(System.out)) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user