Improved output dir checking in KotlinBuilder.

Output dir for representative target is necessary only for JS part: moved there.
This commit is contained in:
Evgeny Gerashchenko
2014-10-30 16:01:28 +03:00
parent 155775f925
commit 97b516a600
3 changed files with 10 additions and 28 deletions
@@ -24,8 +24,6 @@ import org.jetbrains.jet.preloading.ClassCondition;
import org.jetbrains.jet.utils.KotlinPaths;
import org.jetbrains.jet.utils.PathUtil;
import java.io.File;
import static org.jetbrains.jet.cli.common.messages.CompilerMessageLocation.NO_LOCATION;
import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.ERROR;
@@ -34,19 +32,16 @@ public final class CompilerEnvironment {
@NotNull
public static CompilerEnvironment getEnvironmentFor(
@NotNull KotlinPaths kotlinPaths,
@Nullable File outputDir,
@Nullable ClassLoader parentClassLoader,
@NotNull ClassCondition classesToLoadByParent,
@NotNull Services compilerServices
) {
return new CompilerEnvironment(kotlinPaths, outputDir, parentClassLoader, classesToLoadByParent, compilerServices);
return new CompilerEnvironment(kotlinPaths, parentClassLoader, classesToLoadByParent, compilerServices);
}
@NotNull
private final KotlinPaths kotlinPaths;
@Nullable
private final File output;
@Nullable
private final ClassLoader parentClassLoader;
@NotNull
private final ClassCondition classesToLoadByParent;
@@ -55,20 +50,18 @@ public final class CompilerEnvironment {
private CompilerEnvironment(
@NotNull KotlinPaths kotlinPaths,
@Nullable File output,
@Nullable ClassLoader parentClassLoader,
@NotNull ClassCondition classesToLoadByParent,
@NotNull Services services
) {
this.kotlinPaths = kotlinPaths;
this.output = output;
this.parentClassLoader = parentClassLoader;
this.classesToLoadByParent = classesToLoadByParent;
this.services = services;
}
public boolean success() {
return kotlinPaths.getHomePath().exists() && output != null;
return kotlinPaths.getHomePath().exists();
}
@NotNull
@@ -76,12 +69,6 @@ public final class CompilerEnvironment {
return kotlinPaths;
}
@NotNull
public File getOutput() {
assert output != null;
return output;
}
@Nullable
public ClassLoader getParentClassLoader() {
return parentClassLoader;
@@ -93,9 +80,6 @@ public final class CompilerEnvironment {
}
public void reportErrorsTo(@NotNull MessageCollector messageCollector) {
if (output == null) {
messageCollector.report(ERROR, "[Internal Error] No output directory", NO_LOCATION);
}
if (!kotlinPaths.getHomePath().exists()) {
messageCollector.report(ERROR, "Cannot find kotlinc home: " + kotlinPaths.getHomePath() + ". Make sure plugin is properly installed, " +
"or specify " + PathUtil.JPS_KOTLIN_HOME_PROPERTY + " system property", NO_LOCATION);
@@ -87,8 +87,6 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
val representativeTarget = chunk.representativeTarget()
val outputDir = representativeTarget.getOutputDir()
val dataManager = context.getProjectDescriptor().dataManager
val incrementalCaches = chunk.getTargets().keysToMap { dataManager.getStorage(it, IncrementalCacheStorageProvider) }
@@ -114,7 +112,6 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
val environment = CompilerEnvironment.getEnvironmentFor(
PathUtil.getKotlinPathsForJpsPluginOrJpsTests(),
outputDir,
javaClass.getClassLoader(),
{ className ->
className!!.startsWith("org.jetbrains.jet.lang.resolve.kotlin.incremental.cache.")
@@ -128,8 +125,6 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
return ABORT
}
assert(outputDir != null, "CompilerEnvironment must have checked for outputDir to be not null, but it didn't")
val outputItemCollector = OutputItemsCollectorImpl()
val project = representativeTarget.getModule().getProject()!!
@@ -162,6 +157,8 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR
return NOTHING_DONE
}
val outputDir = KotlinBuilderModuleScriptGenerator.getOutputDirSafe(representativeTarget)
val outputFile = File(outputDir, representativeTarget.getModule().getName() + ".js")
val libraryFiles = JpsJsModuleUtils.getLibraryFilesAndDependencies(representativeTarget)
val k2JsArguments = JpsKotlinCompilerSettings.getK2JsCompilerArguments(project)
@@ -31,6 +31,7 @@ import org.jetbrains.jps.builders.java.JavaSourceRootDescriptor;
import org.jetbrains.jps.builders.logging.ProjectBuilderLogger;
import org.jetbrains.jps.incremental.CompileContext;
import org.jetbrains.jps.incremental.ModuleBuildTarget;
import org.jetbrains.jps.incremental.ProjectBuildException;
import org.jetbrains.jps.model.java.JpsAnnotationRootType;
import org.jetbrains.jps.model.java.JpsJavaSdkType;
import org.jetbrains.jps.model.library.JpsLibrary;
@@ -60,7 +61,7 @@ public class KotlinBuilderModuleScriptGenerator {
MultiMap<ModuleBuildTarget, File> sourceFiles, // ignored for non-incremental compilation
boolean hasRemovedFiles
)
throws IOException
throws IOException, ProjectBuildException
{
KotlinModuleDescriptionBuilder builder = FACTORY.create();
@@ -68,11 +69,11 @@ public class KotlinBuilderModuleScriptGenerator {
Set<File> outputDirs = new HashSet<File>();
for (ModuleBuildTarget target : chunk.getTargets()) {
outputDirs.add(getOutputDir(target));
outputDirs.add(getOutputDirSafe(target));
}
ProjectBuilderLogger logger = context.getLoggingManager().getProjectBuilderLogger();
for (ModuleBuildTarget target : chunk.getTargets()) {
File outputDir = getOutputDir(target);
File outputDir = getOutputDirSafe(target);
List<File> moduleSources = new ArrayList<File>(
IncrementalCompilation.ENABLED
@@ -108,10 +109,10 @@ public class KotlinBuilderModuleScriptGenerator {
}
@NotNull
private static File getOutputDir(@NotNull ModuleBuildTarget target) {
public static File getOutputDirSafe(@NotNull ModuleBuildTarget target) throws ProjectBuildException {
File outputDir = target.getOutputDir();
if (outputDir == null) {
throw new IllegalStateException("No output directory found for " + target);
throw new ProjectBuildException("No output directory found for " + target);
}
return outputDir;
}