Each module carries its output directory
This commit is contained in:
+19
-1
@@ -29,6 +29,9 @@ public interface ModuleDescription {
|
||||
@NotNull
|
||||
String getModuleName();
|
||||
|
||||
@NotNull
|
||||
String getOutputDir();
|
||||
|
||||
@NotNull
|
||||
List<String> getSourceFiles();
|
||||
|
||||
@@ -41,6 +44,7 @@ public interface ModuleDescription {
|
||||
class Impl implements ModuleDescription {
|
||||
|
||||
private String name;
|
||||
private String outputDir;
|
||||
private final List<String> sources = new SmartList<String>();
|
||||
private final List<String> classpath = new SmartList<String>();
|
||||
private final List<String> annotations = new SmartList<String>();
|
||||
@@ -49,6 +53,10 @@ public interface ModuleDescription {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setOutputDir(String outputDir) {
|
||||
this.outputDir = outputDir;
|
||||
}
|
||||
|
||||
public void addSourcePath(String path) {
|
||||
sources.add(path);
|
||||
}
|
||||
@@ -67,6 +75,12 @@ public interface ModuleDescription {
|
||||
return name;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getOutputDir() {
|
||||
return outputDir;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<String> getSourceFiles() {
|
||||
@@ -87,7 +101,11 @@ public interface ModuleDescription {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + "\n\tsources=" + sources + "\n\tclasspath=" + classpath + "\n\tannotations=" + annotations;
|
||||
return name +
|
||||
"\n\toutputDir=" + outputDir +
|
||||
"\n\tsources=" + sources +
|
||||
"\n\tclasspath=" + classpath +
|
||||
"\n\tannotations=" + annotations;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-2
@@ -39,6 +39,7 @@ public class ModuleXmlParser {
|
||||
public static final String MODULES = "modules";
|
||||
public static final String MODULE = "module";
|
||||
public static final String NAME = "name";
|
||||
public static final String OUTPUT_DIR = "outputDir";
|
||||
public static final String SOURCES = "sources";
|
||||
public static final String PATH = "path";
|
||||
public static final String CLASSPATH = "classpath";
|
||||
@@ -116,7 +117,7 @@ public class ModuleXmlParser {
|
||||
throw createError(qName);
|
||||
}
|
||||
|
||||
setCurrentState(new InsideModule(getAttribute(attributes, NAME, qName)));
|
||||
setCurrentState(new InsideModule(getAttribute(attributes, NAME, qName), getAttribute(attributes, OUTPUT_DIR, qName)));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,9 +131,10 @@ public class ModuleXmlParser {
|
||||
private class InsideModule extends DefaultHandler {
|
||||
|
||||
private final ModuleDescription.Impl moduleDescription;
|
||||
private InsideModule(String name) {
|
||||
private InsideModule(String name, String outputDir) {
|
||||
this.moduleDescription = new ModuleDescription.Impl();
|
||||
this.moduleDescription.setName(name);
|
||||
this.moduleDescription.setOutputDir(outputDir);
|
||||
result.add(moduleDescription);
|
||||
}
|
||||
|
||||
|
||||
@@ -267,6 +267,11 @@ public class CompileEnvironmentUtil {
|
||||
return description.getModuleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getOutputDirectory() {
|
||||
return description.getOutputDir();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSourceFiles() {
|
||||
return description.getSourceFiles();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import kotlin.modules.*
|
||||
|
||||
fun project() {
|
||||
module("smoke") {
|
||||
module("smoke", ".") {
|
||||
sources += "Smoke.kt"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
name
|
||||
outputDir=out
|
||||
sources=[foo]
|
||||
classpath=[bar]
|
||||
annotations=[baz]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<modules>
|
||||
<module name="name">
|
||||
<module name="name" outputDir="out">
|
||||
<sources path="foo"/>
|
||||
<classpath path="bar"/>
|
||||
<externalAnnotations path="baz"/>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
name
|
||||
outputDir=out
|
||||
sources=[foo, foo1, foo2]
|
||||
classpath=[bar1, bar2]
|
||||
annotations=[baz, baz1, baz2]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<modules>
|
||||
<module name="name">
|
||||
<module name="name" outputDir="out">
|
||||
<sources path="foo"/>
|
||||
<sources path="foo1"/>
|
||||
<sources path="foo2"/>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
name
|
||||
outputDir=out
|
||||
sources=[]
|
||||
classpath=[]
|
||||
annotations=[]
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
<modules>
|
||||
<module name="name"/>
|
||||
<module name="name" outputDir="out"/>
|
||||
</modules>
|
||||
@@ -1,4 +1,5 @@
|
||||
name
|
||||
outputDir=out
|
||||
sources=[foo, foo1, foo2]
|
||||
classpath=[bar, bar1, bar2]
|
||||
annotations=[baz, baz1, baz2]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<modules>
|
||||
<module name="name">
|
||||
<module name="name" outputDir="out">
|
||||
<sources path="foo"/>
|
||||
<sources path="foo1"/>
|
||||
<sources path="foo2"/>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
name
|
||||
outputDir=out
|
||||
sources=[foo]
|
||||
classpath=[]
|
||||
annotations=[]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<modules>
|
||||
<module name="name">
|
||||
<module name="name" outputDir="out">
|
||||
<sources path="foo"/>
|
||||
</module>
|
||||
</modules>
|
||||
@@ -1,8 +1,10 @@
|
||||
name
|
||||
outputDir=out
|
||||
sources=[foo, foo1, foo2]
|
||||
classpath=[bar, bar1, bar2]
|
||||
annotations=[baz, baz1, baz2]
|
||||
name2
|
||||
outputDir=out2
|
||||
sources=[2foo, 2foo1, 2foo2]
|
||||
classpath=[2bar, 2bar1, 2bar2]
|
||||
annotations=[2baz, 2baz1, 2baz2]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<modules>
|
||||
<module name="name">
|
||||
<module name="name" outputDir="out">
|
||||
<sources path="foo"/>
|
||||
<sources path="foo1"/>
|
||||
<sources path="foo2"/>
|
||||
@@ -10,7 +10,7 @@
|
||||
<externalAnnotations path="baz1"/>
|
||||
<externalAnnotations path="baz2"/>
|
||||
</module>
|
||||
<module name="name2">
|
||||
<module name="name2" outputDir="out2">
|
||||
<sources path="2foo"/>
|
||||
<sources path="2foo1"/>
|
||||
<sources path="2foo2"/>
|
||||
|
||||
+1
@@ -26,6 +26,7 @@ import java.util.Set;
|
||||
public interface KotlinModuleDescriptionGenerator {
|
||||
CharSequence generateModuleScript(
|
||||
String moduleName,
|
||||
String outputDir,
|
||||
DependencyProvider dependencyProvider,
|
||||
List<File> sourceFiles,
|
||||
boolean tests,
|
||||
|
||||
+2
-2
@@ -34,7 +34,7 @@ public class KotlinModuleScriptGenerator implements KotlinModuleDescriptionGener
|
||||
@Override
|
||||
public CharSequence generateModuleScript(
|
||||
String moduleName,
|
||||
DependencyProvider dependencyProvider,
|
||||
String outputDir, DependencyProvider dependencyProvider,
|
||||
List<File> sourceFiles,
|
||||
boolean tests,
|
||||
final Set<File> directoriesToFilterOut
|
||||
@@ -50,7 +50,7 @@ public class KotlinModuleScriptGenerator implements KotlinModuleDescriptionGener
|
||||
|
||||
script.append("import kotlin.modules.*\n");
|
||||
script.append("fun project() {\n");
|
||||
script.append(" module(\"" + moduleName + "\") {\n");
|
||||
script.append(" module(\"" + moduleName + "\", outputDir = \"" + toSystemIndependentName(outputDir) + "\") {\n");
|
||||
|
||||
for (File sourceFile : sourceFiles) {
|
||||
script.append(" sources += \"" + toSystemIndependentName(sourceFile.getPath()) + "\"\n");
|
||||
|
||||
+4
-2
@@ -37,7 +37,7 @@ public class KotlinModuleXmlGenerator implements KotlinModuleDescriptionGenerato
|
||||
@Override
|
||||
public CharSequence generateModuleScript(
|
||||
String moduleName,
|
||||
DependencyProvider dependencyProvider,
|
||||
String outputDir, DependencyProvider dependencyProvider,
|
||||
List<File> sourceFiles,
|
||||
boolean tests,
|
||||
final Set<File> directoriesToFilterOut
|
||||
@@ -54,7 +54,9 @@ public class KotlinModuleXmlGenerator implements KotlinModuleDescriptionGenerato
|
||||
p.println("<!-- Module script for production -->");
|
||||
}
|
||||
|
||||
p.println("<", MODULE, " ", NAME, "=\"", escapeXml(moduleName), "\">");
|
||||
p.println("<", MODULE, " ",
|
||||
NAME, "=\"", escapeXml(moduleName), "\" ",
|
||||
OUTPUT_DIR, "=\"", getEscapedPath(new File(outputDir)), "\">");
|
||||
p.pushIndent();
|
||||
|
||||
for (File sourceFile : sourceFiles) {
|
||||
|
||||
@@ -159,6 +159,7 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
}
|
||||
CharSequence script = KotlinModuleScriptGenerator.INSTANCE.generateModuleScript(
|
||||
moduleName,
|
||||
moduleOutputDirectory.getAbsolutePath(),
|
||||
getDependencyProvider(chunk, tests, mainOutput),
|
||||
sourceFiles,
|
||||
tests,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<modules>
|
||||
<!-- Module script for production -->
|
||||
<module name="name">
|
||||
<module name="name" outputDir="output">
|
||||
<sources path="s1"/>
|
||||
<sources path="s2"/>
|
||||
<!-- External annotations -->
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<modules>
|
||||
<!-- Module script for production -->
|
||||
<module name="name">
|
||||
<module name="name" outputDir="output">
|
||||
<sources path="s1"/>
|
||||
<sources path="s2"/>
|
||||
<!-- External annotations -->
|
||||
|
||||
@@ -31,6 +31,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
public void testBasic() throws Exception {
|
||||
String actual = KotlinModuleXmlGenerator.INSTANCE.generateModuleScript(
|
||||
"name",
|
||||
"output",
|
||||
new KotlinModuleDescriptionGenerator.DependencyProvider() {
|
||||
@Override
|
||||
public void processClassPath(@NotNull KotlinModuleDescriptionGenerator.DependencyProcessor processor) {
|
||||
@@ -40,8 +41,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
},
|
||||
Arrays.asList(new File("s1"), new File("s2")),
|
||||
false,
|
||||
Collections.<File>emptySet()
|
||||
).toString();
|
||||
Collections.<File>emptySet()).toString();
|
||||
String expected = FileUtil.loadFile(new File("idea/testData/modules.xml/basic.xml"));
|
||||
UsefulTestCase.assertSameLines(expected, actual);
|
||||
}
|
||||
@@ -49,6 +49,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
public void testFiltered() throws Exception {
|
||||
String actual = KotlinModuleXmlGenerator.INSTANCE.generateModuleScript(
|
||||
"name",
|
||||
"output",
|
||||
new KotlinModuleDescriptionGenerator.DependencyProvider() {
|
||||
@Override
|
||||
public void processClassPath(@NotNull KotlinModuleDescriptionGenerator.DependencyProcessor processor) {
|
||||
@@ -58,8 +59,7 @@ public class KotlinModuleXmlGeneratorTest extends TestCase {
|
||||
},
|
||||
Arrays.asList(new File("s1"), new File("s2")),
|
||||
false,
|
||||
Collections.singleton(new File("cp1"))
|
||||
).toString();
|
||||
Collections.singleton(new File("cp1"))).toString();
|
||||
String expected = FileUtil.loadFile(new File("idea/testData/modules.xml/filtered.xml"));
|
||||
UsefulTestCase.assertSameLines(expected, actual);
|
||||
}
|
||||
|
||||
@@ -52,16 +52,22 @@ public class KotlinBuilderModuleScriptGenerator {
|
||||
public static File generateModuleDescription(CompileContext context, ModuleBuildTarget target, List<File> sourceFiles)
|
||||
throws IOException
|
||||
{
|
||||
File outputDir = target.getOutputDir();
|
||||
if (outputDir == null) {
|
||||
throw new IllegalStateException("No output directory found for " + target);
|
||||
|
||||
}
|
||||
CharSequence moduleScriptText = GENERATOR.generateModuleScript(
|
||||
target.getId(),
|
||||
outputDir.getAbsolutePath(),
|
||||
getKotlinModuleDependencies(context, target),
|
||||
sourceFiles,
|
||||
target.isTests(),
|
||||
// this excludes the output directory from the class path, to be removed for true incremental compilation
|
||||
Collections.singleton(target.getOutputDir())
|
||||
Collections.singleton(outputDir)
|
||||
);
|
||||
|
||||
File scriptFile = new File(target.getOutputDir(), "script." + GENERATOR.getFileExtension());
|
||||
File scriptFile = new File(outputDir, "script." + GENERATOR.getFileExtension());
|
||||
|
||||
writeScriptToFile(context, moduleScriptText, scriptFile);
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@ package kotlin.modules
|
||||
import java.util.*
|
||||
import jet.modules.*
|
||||
|
||||
public fun module(name: String, callback: ModuleBuilder.() -> Unit) {
|
||||
val builder = ModuleBuilder(name)
|
||||
public fun module(name: String, outputDir: String, callback: ModuleBuilder.() -> Unit) {
|
||||
val builder = ModuleBuilder(name, outputDir)
|
||||
builder.callback()
|
||||
AllModules.modules.get()?.add(builder)
|
||||
}
|
||||
@@ -27,7 +27,7 @@ class AnnotationsPathBuilder(val parent: ModuleBuilder) {
|
||||
}
|
||||
}
|
||||
|
||||
open class ModuleBuilder(val name: String): Module {
|
||||
open class ModuleBuilder(val name: String, val outputDir: String): Module {
|
||||
// http://youtrack.jetbrains.net/issue/KT-904
|
||||
private val sourceFiles0 = ArrayList<String>()
|
||||
private val classpathRoots0 = ArrayList<String>()
|
||||
@@ -54,6 +54,7 @@ open class ModuleBuilder(val name: String): Module {
|
||||
annotationsRoots0.add(name)
|
||||
}
|
||||
|
||||
public override fun getOutputDirectory(): String = outputDir
|
||||
public override fun getSourceFiles(): List<String> = sourceFiles0
|
||||
public override fun getClasspathRoots(): List<String> = classpathRoots0
|
||||
public override fun getAnnotationsRoots(): List<String> = annotationsRoots0
|
||||
|
||||
@@ -24,6 +24,9 @@ public interface Module {
|
||||
@KotlinSignature("fun getModuleName(): String")
|
||||
String getModuleName();
|
||||
|
||||
@KotlinSignature("fun getOutputDirectory(): String")
|
||||
String getOutputDirectory();
|
||||
|
||||
@KotlinSignature("fun getSourceFiles(): List<String>")
|
||||
List<String> getSourceFiles();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user