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