Move compiler running utils to common module
Original commit: 6198d0abbc
This commit is contained in:
committed by
Zalim Bashorov
parent
2878d8d56d
commit
4c7dfda080
@@ -1,24 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 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.kotlin.compilerRunner;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public interface OutputItemsCollector {
|
|
||||||
void add(Collection<File> sourceFiles, File outputFile);
|
|
||||||
}
|
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 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.kotlin.compilerRunner;
|
|
||||||
|
|
||||||
import com.intellij.util.containers.ContainerUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class OutputItemsCollectorImpl implements OutputItemsCollector {
|
|
||||||
private final List<SimpleOutputItem> outputs = ContainerUtil.newArrayList();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void add(Collection<File> sourceFiles, File outputFile) {
|
|
||||||
outputs.add(new SimpleOutputItem(sourceFiles, outputFile));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public List<SimpleOutputItem> getOutputs() {
|
|
||||||
return outputs;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 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.kotlin.compilerRunner;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public class SimpleOutputItem {
|
|
||||||
private final Collection<File> sourceFiles;
|
|
||||||
private final File outputFile;
|
|
||||||
|
|
||||||
public SimpleOutputItem(@NotNull Collection<File> sourceFiles, @NotNull File outputFile) {
|
|
||||||
this.sourceFiles = sourceFiles;
|
|
||||||
this.outputFile = outputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public Collection<File> getSourceFiles() {
|
|
||||||
return sourceFiles;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public File getOutputFile() {
|
|
||||||
return outputFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return sourceFiles + " -> " + outputFile;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 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.kotlin.jps.build
|
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
data class JvmSourceRoot(val file: File, val packagePrefix: String? = null)
|
|
||||||
+3
-1
@@ -33,6 +33,7 @@ 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.incremental.ProjectBuildException;
|
||||||
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
|
import org.jetbrains.jps.model.java.JpsJavaExtensionService;
|
||||||
|
import org.jetbrains.kotlin.build.JvmSourceRoot;
|
||||||
import org.jetbrains.kotlin.config.IncrementalCompilation;
|
import org.jetbrains.kotlin.config.IncrementalCompilation;
|
||||||
import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder;
|
import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder;
|
||||||
|
|
||||||
@@ -89,7 +90,8 @@ public class KotlinBuilderModuleScriptGenerator {
|
|||||||
moduleSources,
|
moduleSources,
|
||||||
findSourceRoots(context, target),
|
findSourceRoots(context, target),
|
||||||
findClassPathRoots(target),
|
findClassPathRoots(target),
|
||||||
(JavaModuleBuildTargetType) targetType,
|
((JavaModuleBuildTargetType) targetType).getTypeId(),
|
||||||
|
((JavaModuleBuildTargetType) targetType).isTests(),
|
||||||
// this excludes the output directories from the class path, to be removed for true incremental compilation
|
// this excludes the output directories from the class path, to be removed for true incremental compilation
|
||||||
outputDirs,
|
outputDirs,
|
||||||
friendDirs
|
friendDirs
|
||||||
|
|||||||
@@ -1,136 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2015 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.kotlin.modules
|
|
||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil.toSystemIndependentName
|
|
||||||
import com.intellij.openapi.util.text.StringUtil.escapeXml
|
|
||||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
|
|
||||||
import org.jetbrains.kotlin.cli.common.modules.ModuleXmlParser.*
|
|
||||||
import org.jetbrains.kotlin.config.IncrementalCompilation
|
|
||||||
import org.jetbrains.kotlin.jps.build.JvmSourceRoot
|
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class KotlinModuleXmlBuilder {
|
|
||||||
private val xml = StringBuilder()
|
|
||||||
private val p = Printer(xml)
|
|
||||||
private var done = false
|
|
||||||
|
|
||||||
init {
|
|
||||||
openTag(p, MODULES)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addModule(
|
|
||||||
moduleName: String,
|
|
||||||
outputDir: String,
|
|
||||||
sourceFiles: List<File>,
|
|
||||||
javaSourceRoots: List<JvmSourceRoot>,
|
|
||||||
classpathRoots: Collection<File>,
|
|
||||||
targetType: JavaModuleBuildTargetType,
|
|
||||||
directoriesToFilterOut: Set<File>,
|
|
||||||
friendDirs: List<File>): KotlinModuleXmlBuilder {
|
|
||||||
assert(!done) { "Already done" }
|
|
||||||
|
|
||||||
if (targetType.isTests) {
|
|
||||||
p.println("<!-- Module script for tests -->")
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
p.println("<!-- Module script for production -->")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.println("<", MODULE, " ",
|
|
||||||
NAME, "=\"", escapeXml(moduleName), "\" ",
|
|
||||||
TYPE, "=\"", escapeXml(targetType.typeId), "\" ",
|
|
||||||
OUTPUT_DIR, "=\"", getEscapedPath(File(outputDir)), "\">")
|
|
||||||
p.pushIndent()
|
|
||||||
|
|
||||||
for (friendDir in friendDirs) {
|
|
||||||
p.println("<", FRIEND_DIR, " ", PATH, "=\"", getEscapedPath(friendDir), "\"/>")
|
|
||||||
}
|
|
||||||
|
|
||||||
for (sourceFile in sourceFiles) {
|
|
||||||
p.println("<", SOURCES, " ", PATH, "=\"", getEscapedPath(sourceFile), "\"/>")
|
|
||||||
}
|
|
||||||
|
|
||||||
processJavaSourceRoots(javaSourceRoots)
|
|
||||||
processClasspath(classpathRoots, directoriesToFilterOut)
|
|
||||||
|
|
||||||
closeTag(p, MODULE)
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun processClasspath(
|
|
||||||
files: Collection<File>,
|
|
||||||
directoriesToFilterOut: Set<File>) {
|
|
||||||
p.println("<!-- Classpath -->")
|
|
||||||
for (file in files) {
|
|
||||||
val isOutput = directoriesToFilterOut.contains(file) && !IncrementalCompilation.isEnabled()
|
|
||||||
if (isOutput) {
|
|
||||||
// For IDEA's make (incremental compilation) purposes, output directories of the current module and its dependencies
|
|
||||||
// appear on the class path, so we are at risk of seeing the results of the previous build, i.e. if some class was
|
|
||||||
// removed in the sources, it may still be there in binaries. Thus, we delete these entries from the classpath.
|
|
||||||
p.println("<!-- Output directory, commented out -->")
|
|
||||||
p.println("<!-- ")
|
|
||||||
p.pushIndent()
|
|
||||||
}
|
|
||||||
|
|
||||||
p.println("<", CLASSPATH, " ", PATH, "=\"", getEscapedPath(file), "\"/>")
|
|
||||||
|
|
||||||
if (isOutput) {
|
|
||||||
p.popIndent()
|
|
||||||
p.println("-->")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun processJavaSourceRoots(roots: List<JvmSourceRoot>) {
|
|
||||||
p.println("<!-- Java source roots -->")
|
|
||||||
for (root in roots) {
|
|
||||||
p.print("<")
|
|
||||||
p.printWithNoIndent(JAVA_SOURCE_ROOTS, " ", PATH, "=\"", getEscapedPath(root.file), "\"")
|
|
||||||
|
|
||||||
if (root.packagePrefix != null) {
|
|
||||||
p.printWithNoIndent(" ", JAVA_SOURCE_PACKAGE_PREFIX, "=\"", root.packagePrefix, "\"")
|
|
||||||
}
|
|
||||||
|
|
||||||
p.printWithNoIndent("/>")
|
|
||||||
p.println()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun asText(): CharSequence {
|
|
||||||
if (!done) {
|
|
||||||
closeTag(p, MODULES)
|
|
||||||
done = true
|
|
||||||
}
|
|
||||||
return xml
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun openTag(p: Printer, tag: String) {
|
|
||||||
p.println("<$tag>")
|
|
||||||
p.pushIndent()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun closeTag(p: Printer, tag: String) {
|
|
||||||
p.popIndent()
|
|
||||||
p.println("</$tag>")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun getEscapedPath(sourceFile: File): String {
|
|
||||||
return escapeXml(toSystemIndependentName(sourceFile.path))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.jvm.compiler
|
package org.jetbrains.kotlin.jvm.compiler
|
||||||
|
|
||||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
|
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType
|
||||||
import org.jetbrains.kotlin.jps.build.JvmSourceRoot
|
import org.jetbrains.kotlin.build.JvmSourceRoot
|
||||||
import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder
|
import org.jetbrains.kotlin.modules.KotlinModuleXmlBuilder
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||||
import org.jetbrains.kotlin.test.MockLibraryUtil
|
import org.jetbrains.kotlin.test.MockLibraryUtil
|
||||||
@@ -46,7 +46,8 @@ class ClasspathOrderTest : TestCaseWithTmpdir() {
|
|||||||
listOf(sourceDir),
|
listOf(sourceDir),
|
||||||
listOf(JvmSourceRoot(sourceDir)),
|
listOf(JvmSourceRoot(sourceDir)),
|
||||||
listOf(PathUtil.getKotlinPathsForDistDirectory().runtimePath),
|
listOf(PathUtil.getKotlinPathsForDistDirectory().runtimePath),
|
||||||
JavaModuleBuildTargetType.PRODUCTION,
|
JavaModuleBuildTargetType.PRODUCTION.typeId,
|
||||||
|
JavaModuleBuildTargetType.PRODUCTION.isTests,
|
||||||
setOf(),
|
setOf(),
|
||||||
emptyList()
|
emptyList()
|
||||||
).asText().toString()
|
).asText().toString()
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.modules;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType;
|
||||||
import org.jetbrains.kotlin.jps.build.JvmSourceRoot;
|
import org.jetbrains.kotlin.build.JvmSourceRoot;
|
||||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -33,7 +33,8 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
|||||||
Arrays.asList(new File("s1"), new File("s2")),
|
Arrays.asList(new File("s1"), new File("s2")),
|
||||||
Collections.singletonList(new JvmSourceRoot(new File("java"), null)),
|
Collections.singletonList(new JvmSourceRoot(new File("java"), null)),
|
||||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||||
JavaModuleBuildTargetType.PRODUCTION,
|
JavaModuleBuildTargetType.PRODUCTION.getTypeId(),
|
||||||
|
JavaModuleBuildTargetType.PRODUCTION.isTests(),
|
||||||
Collections.<File>emptySet(),
|
Collections.<File>emptySet(),
|
||||||
Collections.<File>emptyList()
|
Collections.<File>emptyList()
|
||||||
).asText().toString();
|
).asText().toString();
|
||||||
@@ -47,7 +48,8 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
|||||||
Arrays.asList(new File("s1"), new File("s2")),
|
Arrays.asList(new File("s1"), new File("s2")),
|
||||||
Collections.<JvmSourceRoot>emptyList(),
|
Collections.<JvmSourceRoot>emptyList(),
|
||||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||||
JavaModuleBuildTargetType.PRODUCTION,
|
JavaModuleBuildTargetType.PRODUCTION.getTypeId(),
|
||||||
|
JavaModuleBuildTargetType.PRODUCTION.isTests(),
|
||||||
Collections.singleton(new File("cp1")),
|
Collections.singleton(new File("cp1")),
|
||||||
Collections.<File>emptyList()
|
Collections.<File>emptyList()
|
||||||
).asText().toString();
|
).asText().toString();
|
||||||
@@ -62,7 +64,8 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
|||||||
Arrays.asList(new File("s1"), new File("s2")),
|
Arrays.asList(new File("s1"), new File("s2")),
|
||||||
Collections.<JvmSourceRoot>emptyList(),
|
Collections.<JvmSourceRoot>emptyList(),
|
||||||
Arrays.asList(new File("cp1"), new File("cp2")),
|
Arrays.asList(new File("cp1"), new File("cp2")),
|
||||||
JavaModuleBuildTargetType.PRODUCTION,
|
JavaModuleBuildTargetType.PRODUCTION.getTypeId(),
|
||||||
|
JavaModuleBuildTargetType.PRODUCTION.isTests(),
|
||||||
Collections.singleton(new File("cp1")),
|
Collections.singleton(new File("cp1")),
|
||||||
Collections.<File>emptyList()
|
Collections.<File>emptyList()
|
||||||
);
|
);
|
||||||
@@ -72,7 +75,8 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
|||||||
Arrays.asList(new File("s12"), new File("s22")),
|
Arrays.asList(new File("s12"), new File("s22")),
|
||||||
Collections.<JvmSourceRoot>emptyList(),
|
Collections.<JvmSourceRoot>emptyList(),
|
||||||
Arrays.asList(new File("cp12"), new File("cp22")),
|
Arrays.asList(new File("cp12"), new File("cp22")),
|
||||||
JavaModuleBuildTargetType.TEST,
|
JavaModuleBuildTargetType.TEST.getTypeId(),
|
||||||
|
JavaModuleBuildTargetType.TEST.isTests(),
|
||||||
Collections.singleton(new File("cp12")),
|
Collections.singleton(new File("cp12")),
|
||||||
Collections.<File>emptyList()
|
Collections.<File>emptyList()
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user