JPS plugin: add support external compilation for JS modules.
Original commit: 2b9b563efb
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.jps.build;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jps.incremental.ModuleBuildTarget;
|
||||||
|
import org.jetbrains.jps.model.java.JpsJavaClasspathKind;
|
||||||
|
import org.jetbrains.jps.model.java.JpsJavaDependenciesEnumerator;
|
||||||
|
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
|
||||||
|
|
||||||
|
public class JpsUtil {
|
||||||
|
@NotNull
|
||||||
|
public static JpsJavaDependenciesEnumerator getAllDependencies(@NotNull ModuleBuildTarget target) {
|
||||||
|
return JpsJavaExtensionService.dependencies(target.getModule()).recursively().exportedOnly()
|
||||||
|
.includedIn(JpsJavaClasspathKind.compile(target.isTests()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.jet.jps.build;
|
package org.jetbrains.jet.jps.build;
|
||||||
|
|
||||||
import com.intellij.openapi.util.text.StringUtil;
|
import com.intellij.openapi.util.text.StringUtil;
|
||||||
|
import com.intellij.util.Consumer;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
import com.intellij.util.containers.ContainerUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -25,6 +26,7 @@ import org.jetbrains.jet.cli.common.messages.CompilerMessageLocation;
|
|||||||
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
import org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity;
|
||||||
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
import org.jetbrains.jet.cli.common.messages.MessageCollector;
|
||||||
import org.jetbrains.jet.compiler.runner.*;
|
import org.jetbrains.jet.compiler.runner.*;
|
||||||
|
import org.jetbrains.jet.utils.LibraryUtils;
|
||||||
import org.jetbrains.jet.utils.PathUtil;
|
import org.jetbrains.jet.utils.PathUtil;
|
||||||
import org.jetbrains.jps.ModuleChunk;
|
import org.jetbrains.jps.ModuleChunk;
|
||||||
import org.jetbrains.jps.builders.DirtyFilesHolder;
|
import org.jetbrains.jps.builders.DirtyFilesHolder;
|
||||||
@@ -33,19 +35,22 @@ import org.jetbrains.jps.incremental.*;
|
|||||||
import org.jetbrains.jps.incremental.java.JavaBuilder;
|
import org.jetbrains.jps.incremental.java.JavaBuilder;
|
||||||
import org.jetbrains.jps.incremental.messages.BuildMessage;
|
import org.jetbrains.jps.incremental.messages.BuildMessage;
|
||||||
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
||||||
|
import org.jetbrains.jps.model.java.JavaSourceRootType;
|
||||||
|
import org.jetbrains.jps.model.java.JpsJavaModuleType;
|
||||||
|
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||||
|
import org.jetbrains.jps.model.library.JpsLibraryRoot;
|
||||||
|
import org.jetbrains.jps.model.library.JpsOrderRootType;
|
||||||
import org.jetbrains.jps.model.module.JpsModule;
|
import org.jetbrains.jps.model.module.JpsModule;
|
||||||
|
import org.jetbrains.jps.model.module.JpsModuleSourceRoot;
|
||||||
|
import org.jetbrains.jps.util.JpsPathUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.EXCEPTION;
|
import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.*;
|
||||||
import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.INFO;
|
|
||||||
import static org.jetbrains.jet.cli.common.messages.CompilerMessageSeverity.WARNING;
|
|
||||||
|
|
||||||
public class KotlinBuilder extends ModuleLevelBuilder {
|
public class KotlinBuilder extends ModuleLevelBuilder {
|
||||||
|
|
||||||
@@ -109,8 +114,6 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
|||||||
return ExitCode.NOTHING_DONE;
|
return ExitCode.NOTHING_DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
File moduleFile = KotlinBuilderModuleScriptGenerator.generateModuleDescription(context, representativeTarget, sourceFiles);
|
|
||||||
|
|
||||||
File outputDir = representativeTarget.getOutputDir();
|
File outputDir = representativeTarget.getOutputDir();
|
||||||
|
|
||||||
CompilerEnvironment environment = CompilerEnvironment.getEnvironmentFor(PathUtil.getKotlinPathsForJpsPluginOrJpsTests(), outputDir);
|
CompilerEnvironment environment = CompilerEnvironment.getEnvironmentFor(PathUtil.getKotlinPathsForJpsPluginOrJpsTests(), outputDir);
|
||||||
@@ -123,12 +126,27 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
|||||||
|
|
||||||
OutputItemsCollectorImpl outputItemCollector = new OutputItemsCollectorImpl(outputDir);
|
OutputItemsCollectorImpl outputItemCollector = new OutputItemsCollectorImpl(outputDir);
|
||||||
|
|
||||||
KotlinCompilerRunner.runCompiler(
|
if (isJsKotlinModule(representativeTarget)) {
|
||||||
messageCollector,
|
File outputFile = new File(outputDir, representativeTarget.getModule().getName() + ".js");
|
||||||
environment,
|
|
||||||
moduleFile,
|
KotlinCompilerRunner.runK2JsCompiler(
|
||||||
outputItemCollector,
|
messageCollector,
|
||||||
/*runOutOfProcess = */false);
|
environment,
|
||||||
|
outputItemCollector,
|
||||||
|
sourceFiles,
|
||||||
|
getLibraryFilesAndDependencies(representativeTarget),
|
||||||
|
outputFile);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
File moduleFile = KotlinBuilderModuleScriptGenerator.generateModuleDescription(context, representativeTarget, sourceFiles);
|
||||||
|
|
||||||
|
KotlinCompilerRunner.runK2JvmCompiler(
|
||||||
|
messageCollector,
|
||||||
|
environment,
|
||||||
|
moduleFile,
|
||||||
|
outputItemCollector,
|
||||||
|
/*runOutOfProcess = */false);
|
||||||
|
}
|
||||||
|
|
||||||
for (SimpleOutputItem outputItem : outputItemCollector.getOutputs()) {
|
for (SimpleOutputItem outputItem : outputItemCollector.getOutputs()) {
|
||||||
outputConsumer.registerOutputFile(
|
outputConsumer.registerOutputFile(
|
||||||
@@ -211,4 +229,50 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
|||||||
public List<String> getCompilableFileExtensions() {
|
public List<String> getCompilableFileExtensions() {
|
||||||
return COMPILABLE_FILE_EXTENSIONS;
|
return COMPILABLE_FILE_EXTENSIONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isJsKotlinModule(@NotNull ModuleBuildTarget target) {
|
||||||
|
Set<JpsLibrary> libraries = JpsUtil.getAllDependencies(target).getLibraries();
|
||||||
|
for (JpsLibrary library : libraries) {
|
||||||
|
for (JpsLibraryRoot root : library.getRoots(JpsOrderRootType.COMPILED)) {
|
||||||
|
if (LibraryUtils.isJsRuntimeLibrary(JpsPathUtil.urlToFile(root.getUrl())))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private static Set<String> getLibraryFilesAndDependencies(@NotNull ModuleBuildTarget target) {
|
||||||
|
Set<String> result = new HashSet<String>();
|
||||||
|
getLibraryPaths(target, result);
|
||||||
|
getDependencyModulesAndSources(target, result);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getLibraryPaths(@NotNull ModuleBuildTarget target, Set<String> result) {
|
||||||
|
Set<JpsLibrary> libraries = JpsUtil.getAllDependencies(target).getLibraries();
|
||||||
|
for (JpsLibrary library : libraries) {
|
||||||
|
for (JpsLibraryRoot root : library.getRoots(JpsOrderRootType.COMPILED)) {
|
||||||
|
String path = JpsPathUtil.urlToOsPath(root.getUrl());
|
||||||
|
if (path.endsWith(PathUtil.JS_LIB_JAR_NAME)) {
|
||||||
|
result.add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void getDependencyModulesAndSources(@NotNull final ModuleBuildTarget target, final Set<String> result) {
|
||||||
|
JpsUtil.getAllDependencies(target).processModules(new Consumer<JpsModule>() {
|
||||||
|
@Override
|
||||||
|
public void consume(JpsModule module) {
|
||||||
|
if (module == target.getModule() || module.getModuleType() != JpsJavaModuleType.INSTANCE) return;
|
||||||
|
|
||||||
|
result.add("@" + module.getName());
|
||||||
|
|
||||||
|
for (JpsModuleSourceRoot root : module.getSourceRoots(JavaSourceRootType.SOURCE)) {
|
||||||
|
result.add(JpsPathUtil.urlToOsPath(root.getUrl()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-7
@@ -27,7 +27,6 @@ import org.jetbrains.jps.incremental.CompileContext;
|
|||||||
import org.jetbrains.jps.incremental.ModuleBuildTarget;
|
import org.jetbrains.jps.incremental.ModuleBuildTarget;
|
||||||
import org.jetbrains.jps.incremental.messages.BuildMessage;
|
import org.jetbrains.jps.incremental.messages.BuildMessage;
|
||||||
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
import org.jetbrains.jps.incremental.messages.CompilerMessage;
|
||||||
import org.jetbrains.jps.model.JpsDummyElement;
|
|
||||||
import org.jetbrains.jps.model.java.*;
|
import org.jetbrains.jps.model.java.*;
|
||||||
import org.jetbrains.jps.model.library.JpsLibrary;
|
import org.jetbrains.jps.model.library.JpsLibrary;
|
||||||
import org.jetbrains.jps.model.library.sdk.JpsSdk;
|
import org.jetbrains.jps.model.library.sdk.JpsSdk;
|
||||||
@@ -44,6 +43,7 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.compiler.runner.KotlinModuleDescriptionGenerator.DependencyProvider;
|
import static org.jetbrains.jet.compiler.runner.KotlinModuleDescriptionGenerator.DependencyProvider;
|
||||||
|
import static org.jetbrains.jet.jps.build.JpsUtil.getAllDependencies;
|
||||||
|
|
||||||
public class KotlinBuilderModuleScriptGenerator {
|
public class KotlinBuilderModuleScriptGenerator {
|
||||||
|
|
||||||
@@ -144,12 +144,6 @@ public class KotlinBuilderModuleScriptGenerator {
|
|||||||
return JpsJavaSdkType.INSTANCE;
|
return JpsJavaSdkType.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
private static JpsJavaDependenciesEnumerator getAllDependencies(@NotNull ModuleBuildTarget target) {
|
|
||||||
return JpsJavaExtensionService.dependencies(target.getModule()).recursively().exportedOnly()
|
|
||||||
.includedIn(JpsJavaClasspathKind.compile(target.isTests()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private static JpsLibrary getLibrary(@NotNull JpsDependencyElement dependencyElement) {
|
private static JpsLibrary getLibrary(@NotNull JpsDependencyElement dependencyElement) {
|
||||||
if (dependencyElement instanceof JpsSdkDependency) {
|
if (dependencyElement instanceof JpsSdkDependency) {
|
||||||
|
|||||||
Reference in New Issue
Block a user