JS: write and load pre-release flag on binaries

This commit is contained in:
Alexander Udalov
2017-02-07 12:04:52 +03:00
parent de8dd37e44
commit 25c1828288
13 changed files with 189 additions and 38 deletions
@@ -54,7 +54,6 @@ object JvmPlatformConfigurator : PlatformConfigurator(
ProtectedInSuperClassCompanionCallChecker(),
UnsupportedSyntheticCallableReferenceChecker(),
SuperCallWithDefaultArgumentsChecker(),
MissingDependencyClassChecker,
ProtectedSyntheticExtensionCallChecker,
ReifiedTypeParameterSubstitutionChecker()
),
@@ -67,7 +66,6 @@ object JvmPlatformConfigurator : PlatformConfigurator(
),
additionalClassifierUsageCheckers = listOf(
MissingDependencyClassChecker.ClassifierUsage
),
additionalAnnotationCheckers = listOf(
@@ -92,11 +92,13 @@ private val DEFAULT_CALL_CHECKERS = listOf(
CapturingInClosureChecker(), InlineCheckerWrapper(), SafeCallChecker(),
DeprecatedCallChecker, CallReturnsArrayOfNothingChecker(), InfixCallChecker(), OperatorCallChecker(),
ConstructorHeaderCallChecker, ProtectedConstructorCallChecker, ApiVersionCallChecker,
CoroutineSuspendCallChecker, BuilderFunctionsCallChecker, DslScopeViolationCallChecker,
CoroutineSuspendCallChecker, BuilderFunctionsCallChecker, DslScopeViolationCallChecker, MissingDependencyClassChecker,
CallableReferenceCompatibilityChecker()
)
private val DEFAULT_TYPE_CHECKERS = emptyList<AdditionalTypeChecker>()
private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf(DeprecatedClassifierUsageChecker(), ApiVersionClassifierUsageChecker)
private val DEFAULT_CLASSIFIER_USAGE_CHECKERS = listOf(
DeprecatedClassifierUsageChecker(), ApiVersionClassifierUsageChecker, MissingDependencyClassChecker.ClassifierUsage
)
abstract class PlatformConfigurator(
@@ -0,0 +1,9 @@
package a
open class A {
class Nested
}
fun foo() = ""
var bar = 42
typealias TA = String
@@ -0,0 +1,41 @@
error: incompatible classes were found in dependencies. Remove them from the classpath or use '-Xskip-metadata-version-check' to suppress errors
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:5:16: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
fun baz(param: A, nested: A.Nested) {
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:5:27: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
fun baz(param: A, nested: A.Nested) {
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:5:29: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
fun baz(param: A, nested: A.Nested) {
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:6:23: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val constructor = A()
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:7:18: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val nested = A.Nested()
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:7:20: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val nested = A.Nested()
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:8:22: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val methodCall = param.method()
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:8:28: error: unresolved reference: method
val methodCall = param.method()
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:9:30: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val supertype = object : A() {}
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:11:13: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val x = foo()
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:12:13: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val y = bar
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:13:5: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
bar = 239
^
compiler/testData/compileKotlinAgainstCustomBinaries/releaseCompilerAgainstPreReleaseLibraryJs/source.kt:14:12: error: package 'a' is compiled by a pre-release version of Kotlin and cannot be loaded by this version of the compiler
val z: TA = ""
^
COMPILATION_ERROR
@@ -0,0 +1,15 @@
package usage
import a.*
fun baz(param: A, nested: A.Nested) {
val constructor = A()
val nested = A.Nested()
val methodCall = param.method()
val supertype = object : A() {}
val x = foo()
val y = bar
bar = 239
val z: TA = ""
}
@@ -30,10 +30,12 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.analyzer.AnalysisResult;
import org.jetbrains.kotlin.cli.AbstractCliTest;
import org.jetbrains.kotlin.cli.WrongBytecodeVersionTest;
import org.jetbrains.kotlin.cli.common.CLICompiler;
import org.jetbrains.kotlin.cli.common.ExitCode;
import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport;
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer;
import org.jetbrains.kotlin.cli.common.messages.PrintingMessageCollector;
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
@@ -87,10 +89,16 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
@NotNull
private File compileLibrary(@NotNull String sourcePath, @NotNull File... extraClassPath) {
File result = new File(tmpdir, sourcePath + ".jar");
Pair<String, ExitCode> output = compileKotlin(sourcePath, result, extraClassPath);
File destination = new File(tmpdir, sourcePath + ".jar");
compileLibrary(new K2JVMCompiler(), sourcePath, destination, extraClassPath);
return destination;
}
private void compileLibrary(
@NotNull CLICompiler<?> compiler, @NotNull String sourcePath, @NotNull File destination, @NotNull File... extraClassPath
) {
Pair<String, ExitCode> output = compileKotlin(compiler, sourcePath, destination, Collections.<String>emptyList(), extraClassPath);
Assert.assertEquals(normalizeOutput(new Pair<String, ExitCode>("", ExitCode.OK)), normalizeOutput(output));
return result;
}
@NotNull
@@ -218,22 +226,49 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
private Pair<String, ExitCode> compileKotlin(
@NotNull String fileName,
@NotNull File output,
List<String> additionalOptions,
@NotNull List<String> additionalOptions,
@NotNull File... classpath
) {
return compileKotlin(new K2JVMCompiler(), fileName, output, additionalOptions, classpath);
}
@NotNull
private Pair<String, ExitCode> compileKotlin(
@NotNull CLICompiler<?> compiler,
@NotNull String fileName,
@NotNull File output,
@NotNull List<String> additionalOptions,
@NotNull File... classpath
) {
List<String> args = new ArrayList<String>();
File sourceFile = new File(getTestDataDirectory(), fileName);
assert sourceFile.exists() : "Source file does not exist: " + sourceFile.getAbsolutePath();
args.add(sourceFile.getPath());
if (classpath.length > 0) {
args.add("-classpath");
args.add(StringsKt.join(Arrays.asList(classpath), File.pathSeparator));
if (compiler instanceof K2JSCompiler) {
if (classpath.length > 0) {
args.add("-libraries");
args.add(StringsKt.join(Arrays.asList(classpath), File.pathSeparator));
}
args.add("-output");
args.add(output.getPath());
args.add("-meta-info");
}
args.add("-d");
args.add(output.getPath());
else if (compiler instanceof K2JVMCompiler) {
if (classpath.length > 0) {
args.add("-classpath");
args.add(StringsKt.join(Arrays.asList(classpath), File.pathSeparator));
}
args.add("-d");
args.add(output.getPath());
}
else {
throw new UnsupportedOperationException(compiler.toString());
}
args.addAll(additionalOptions);
return AbstractCliTest.executeCompilerGrabOutput(new K2JVMCompiler(), args);
return AbstractCliTest.executeCompilerGrabOutput(compiler, args);
}
private void doTestBrokenJavaLibrary(@NotNull String libraryName, @NotNull String... pathsToDelete) throws Exception {
@@ -278,13 +313,18 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
}
@SuppressWarnings("deprecation")
private void doTestPreReleaseKotlinLibrary(@NotNull String libraryName, @NotNull String... additionalOptions) throws Exception {
private void doTestPreReleaseKotlinLibrary(
@NotNull CLICompiler<?> compiler,
@NotNull String libraryName,
@NotNull File destination,
@NotNull File result,
@NotNull String... additionalOptions
) throws Exception {
// Compiles the library with the "pre-release" flag, then compiles a usage of this library in the release mode
File library;
try {
System.setProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY, "true");
library = compileLibrary(libraryName);
compileLibrary(compiler, libraryName, destination);
}
finally {
System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY);
@@ -293,7 +333,7 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
Pair<String, ExitCode> output;
try {
System.setProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY, "false");
output = compileKotlin("source.kt", tmpdir, Arrays.asList(additionalOptions), library);
output = compileKotlin(compiler, "source.kt", tmpdir, Arrays.asList(additionalOptions), result);
}
finally {
System.clearProperty(TEST_IS_PRE_RELEASE_SYSTEM_PROPERTY);
@@ -414,11 +454,20 @@ public class CompileKotlinAgainstCustomBinariesTest extends TestCaseWithTmpdir {
}
public void testReleaseCompilerAgainstPreReleaseLibrary() throws Exception {
doTestPreReleaseKotlinLibrary("library");
File destination = new File(tmpdir, "library.jar");
doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination);
}
public void testReleaseCompilerAgainstPreReleaseLibraryJs() throws Exception {
doTestPreReleaseKotlinLibrary(new K2JSCompiler(), "library",
new File(tmpdir, "library.js"),
new File(tmpdir, "library.meta.js"));
}
public void testReleaseCompilerAgainstPreReleaseLibrarySkipVersionCheck() throws Exception {
doTestPreReleaseKotlinLibrary("library", "-Xskip-metadata-version-check");
File destination = new File(tmpdir, "library.jar");
doTestPreReleaseKotlinLibrary(new K2JVMCompiler(), "library", destination, destination,
"-Xskip-metadata-version-check");
}
public void testWrongMetadataVersion() throws Exception {