[JS] Implementation dependencies for JS klibs
^KT-56158 fixed
This commit is contained in:
committed by
Space Team
parent
ca0b3ffa78
commit
1150ec6882
-7
@@ -56,13 +56,6 @@ class K2JSCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var libraries: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@Argument(
|
||||
value = "-Xrepositories",
|
||||
valueDescription = "<path>",
|
||||
description = "Paths to additional places where libraries could be found"
|
||||
)
|
||||
var repositries: String? by NullableStringFreezableVar(null)
|
||||
|
||||
@GradleOption(
|
||||
value = DefaultValue.BOOLEAN_FALSE_DEFAULT,
|
||||
gradleInputType = GradleInputTypes.INPUT,
|
||||
|
||||
@@ -193,11 +193,9 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
|
||||
val libraries: List<String> = configureLibraries(arguments.libraries) + listOfNotNull(arguments.includes)
|
||||
val friendLibraries: List<String> = configureLibraries(arguments.friendModules)
|
||||
val repositories: List<String> = configureLibraries(arguments.repositries)
|
||||
|
||||
configuration.put(JSConfigurationKeys.LIBRARIES, libraries)
|
||||
configuration.put(JSConfigurationKeys.TRANSITIVE_LIBRARIES, libraries)
|
||||
configuration.put(JSConfigurationKeys.REPOSITORIES, repositories)
|
||||
|
||||
configuration.put(JSConfigurationKeys.PARTIAL_LINKAGE, arguments.partialLinkage)
|
||||
|
||||
@@ -449,7 +447,7 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
moduleSourceFiles,
|
||||
environmentForJS.configuration,
|
||||
sourceModule.jsFrontEndResult.jsAnalysisResult,
|
||||
sortDependencies(sourceModule.moduleDependencies),
|
||||
sourceModule.allDependencies,
|
||||
icData,
|
||||
expectDescriptorToSymbol,
|
||||
IrFactoryImpl,
|
||||
@@ -514,9 +512,8 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
||||
// TODO: !!! dependencies module data?
|
||||
}
|
||||
|
||||
val repositories = configuration[JSConfigurationKeys.REPOSITORIES] ?: emptyList()
|
||||
val logger = configuration.resolverLogger
|
||||
val resolvedLibraries = jsResolveLibraries(libraries + friendLibraries, repositories, logger).getFullResolvedList()
|
||||
val resolvedLibraries = jsResolveLibraries(libraries + friendLibraries, logger).getFullResolvedList()
|
||||
|
||||
FirJsSessionFactory.createJsLibrarySession(
|
||||
mainModuleName,
|
||||
|
||||
-1
@@ -25,7 +25,6 @@ abstract class AbstractIncrementalMultiModuleJsKlibCompilerRunnerTest :
|
||||
irProduceKlibDir = false
|
||||
irProduceKlibFile = true
|
||||
irOnly = true
|
||||
repositries = repository.absolutePath
|
||||
}
|
||||
|
||||
override val buildLogFinder: BuildLogFinder
|
||||
|
||||
@@ -88,8 +88,7 @@ class CacheUpdater(
|
||||
|
||||
// libraries in topological order: [stdlib, ..., main]
|
||||
val libraryDependencies = stopwatch.measure("Resolving and loading klib dependencies") {
|
||||
val repositories = compilerConfiguration[JSConfigurationKeys.REPOSITORIES] ?: emptyList()
|
||||
val allResolvedDependencies = jsResolveLibraries(allModules, repositories, compilerConfiguration.resolverLogger)
|
||||
val allResolvedDependencies = jsResolveLibraries(allModules, compilerConfiguration.resolverLogger)
|
||||
|
||||
val libraries = allResolvedDependencies.getFullList(TopologicalLibraryOrder).let { resolvedLibraries ->
|
||||
val mainLibraryIndex = resolvedLibraries.indexOfLast {
|
||||
|
||||
+28
-5
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.library.KotlinLibraryProperResolverWithAttributes
|
||||
import org.jetbrains.kotlin.library.UnresolvedLibrary
|
||||
import org.jetbrains.kotlin.library.impl.createKotlinLibraryComponents
|
||||
import org.jetbrains.kotlin.library.metadata.resolver.KotlinLibraryResolveResult
|
||||
import org.jetbrains.kotlin.library.metadata.resolver.KotlinLibraryResolver
|
||||
import org.jetbrains.kotlin.library.metadata.resolver.impl.libraryResolver
|
||||
import org.jetbrains.kotlin.util.Logger
|
||||
|
||||
@@ -35,24 +36,46 @@ class JsLibraryResolver(
|
||||
}
|
||||
|
||||
// TODO: This is a temporary set of library resolver policies for js compiler.
|
||||
fun jsResolveLibraries(libraries: Collection<String>, repositories: Collection<String>, logger: Logger): KotlinLibraryResolveResult {
|
||||
fun jsResolveLibraries(libraries: Collection<String>, logger: Logger): KotlinLibraryResolveResult =
|
||||
jsResolveLibrariesWithoutDependencies(
|
||||
libraries,
|
||||
logger
|
||||
).resolveWithDependencies()
|
||||
|
||||
fun jsResolveLibrariesWithoutDependencies(
|
||||
libraries: Collection<String>,
|
||||
logger: Logger
|
||||
): JsResolution {
|
||||
val unresolvedLibraries = libraries.map { UnresolvedLibrary(it, null) }
|
||||
val libraryAbsolutePaths = libraries.map { File(it).absolutePath }
|
||||
// Configure the resolver to only work with absolute paths for now.
|
||||
val libraryResolver = JsLibraryResolver(
|
||||
repositories = repositories.toList(),
|
||||
repositories = emptyList(),
|
||||
directLibs = libraryAbsolutePaths,
|
||||
distributionKlib = null,
|
||||
localKotlinDir = null,
|
||||
skipCurrentDir = false,
|
||||
logger = logger
|
||||
).libraryResolver()
|
||||
val resolvedLibraries =
|
||||
libraryResolver.resolveWithDependencies(
|
||||
|
||||
return JsResolution(
|
||||
libraryResolver,
|
||||
libraryResolver.resolveWithoutDependencies(
|
||||
unresolvedLibraries = unresolvedLibraries,
|
||||
noStdLib = true,
|
||||
noDefaultLibs = true,
|
||||
noEndorsedLibs = true
|
||||
)
|
||||
return resolvedLibraries
|
||||
)
|
||||
}
|
||||
|
||||
class JsResolution(
|
||||
private val libraryResolver: KotlinLibraryResolver<KotlinLibrary>,
|
||||
val libraries: List<KotlinLibrary>
|
||||
) {
|
||||
fun resolveWithDependencies(): KotlinLibraryResolveResult {
|
||||
return with(libraryResolver) {
|
||||
libraries.resolveDependencies()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,7 +128,7 @@ fun generateKLib(
|
||||
) {
|
||||
val files = (depsDescriptors.mainModule as MainModule.SourceFiles).files.map(::KtPsiSourceFile)
|
||||
val configuration = depsDescriptors.compilerConfiguration
|
||||
val allDependencies = depsDescriptors.allDependencies.map { it.library }
|
||||
val allDependencies = depsDescriptors.allDependencies
|
||||
val messageLogger = configuration.irMessageLogger
|
||||
|
||||
serializeModuleIntoKlib(
|
||||
@@ -202,7 +202,7 @@ fun loadIr(
|
||||
val project = depsDescriptors.project
|
||||
val mainModule = depsDescriptors.mainModule
|
||||
val configuration = depsDescriptors.compilerConfiguration
|
||||
val allDependencies = depsDescriptors.allDependencies.map { it.library }
|
||||
val allDependencies = depsDescriptors.allDependencies
|
||||
val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT
|
||||
val messageLogger = configuration.irMessageLogger
|
||||
val partialLinkageEnabled = configuration[JSConfigurationKeys.PARTIAL_LINKAGE] ?: false
|
||||
@@ -215,7 +215,7 @@ fun loadIr(
|
||||
assert(filesToLoad == null)
|
||||
val psi2IrContext = preparePsi2Ir(depsDescriptors, errorPolicy, symbolTable, partialLinkageEnabled)
|
||||
val friendModules =
|
||||
mapOf(psi2IrContext.moduleDescriptor.name.asString() to depsDescriptors.friendDependencies.map { it.library.uniqueName })
|
||||
mapOf(psi2IrContext.moduleDescriptor.name.asString() to depsDescriptors.friendDependencies.map { it.uniqueName })
|
||||
|
||||
return getIrModuleInfoForSourceFiles(
|
||||
psi2IrContext,
|
||||
@@ -236,7 +236,7 @@ fun loadIr(
|
||||
?: error("No module with ${mainModule.libPath} found")
|
||||
val moduleDescriptor = depsDescriptors.getModuleDescriptor(mainModuleLib)
|
||||
val sortedDependencies = sortDependencies(depsDescriptors.moduleDependencies)
|
||||
val friendModules = mapOf(mainModuleLib.uniqueName to depsDescriptors.friendDependencies.map { it.library.uniqueName })
|
||||
val friendModules = mapOf(mainModuleLib.uniqueName to depsDescriptors.friendDependencies.map { it.uniqueName })
|
||||
|
||||
return getIrModuleInfoForKlib(
|
||||
moduleDescriptor,
|
||||
@@ -474,29 +474,29 @@ class ModulesStructure(
|
||||
friendDependenciesPaths: Collection<String>,
|
||||
) {
|
||||
|
||||
val allResolvedDependencies = jsResolveLibraries(
|
||||
val allDependenciesResolution = jsResolveLibrariesWithoutDependencies(
|
||||
dependencies,
|
||||
compilerConfiguration[JSConfigurationKeys.REPOSITORIES] ?: emptyList(),
|
||||
compilerConfiguration.resolverLogger
|
||||
)
|
||||
|
||||
val allDependencies = allResolvedDependencies.getFullResolvedList()
|
||||
val allDependencies: List<KotlinLibrary>
|
||||
get() = allDependenciesResolution.libraries
|
||||
|
||||
val friendDependencies = allDependencies.run {
|
||||
val friendAbsolutePaths = friendDependenciesPaths.map { File(it).canonicalPath }
|
||||
filter {
|
||||
it.library.libraryFile.absolutePath in friendAbsolutePaths
|
||||
it.libraryFile.absolutePath in friendAbsolutePaths
|
||||
}
|
||||
}
|
||||
|
||||
val moduleDependencies: Map<KotlinLibrary, List<KotlinLibrary>> = run {
|
||||
val transitives = allDependencies
|
||||
val moduleDependencies: Map<KotlinLibrary, List<KotlinLibrary>> by lazy {
|
||||
val transitives = allDependenciesResolution.resolveWithDependencies().getFullResolvedList()
|
||||
transitives.associate { klib ->
|
||||
klib.library to klib.resolvedDependencies.map { d -> d.library }
|
||||
}.toMap()
|
||||
}
|
||||
|
||||
private val builtInsDep = allDependencies.find { it.library.isBuiltIns }
|
||||
private val builtInsDep = allDependencies.find { it.isBuiltIns }
|
||||
|
||||
class JsFrontEndResult(val jsAnalysisResult: AnalysisResult, val hasErrors: Boolean) {
|
||||
val moduleDescriptor: ModuleDescriptor
|
||||
@@ -508,7 +508,11 @@ class ModulesStructure(
|
||||
|
||||
lateinit var jsFrontEndResult: JsFrontEndResult
|
||||
|
||||
fun runAnalysis(errorPolicy: ErrorTolerancePolicy, analyzer: AbstractAnalyzerWithCompilerReport, analyzerFacade: AbstractTopDownAnalyzerFacadeForJS) {
|
||||
fun runAnalysis(
|
||||
errorPolicy: ErrorTolerancePolicy,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
analyzerFacade: AbstractTopDownAnalyzerFacadeForJS
|
||||
) {
|
||||
require(mainModule is MainModule.SourceFiles)
|
||||
val files = mainModule.files
|
||||
|
||||
@@ -517,8 +521,8 @@ class ModulesStructure(
|
||||
files,
|
||||
project,
|
||||
compilerConfiguration,
|
||||
allModuleDescriptors,
|
||||
friendDependencies.map { getModuleDescriptor(it.library) },
|
||||
descriptors.values.toList(),
|
||||
friendDependencies.map { getModuleDescriptor(it) },
|
||||
analyzer.targetEnvironment,
|
||||
thisIsBuiltInsModule = builtInModuleDescriptor == null,
|
||||
customBuiltInsModule = builtInModuleDescriptor
|
||||
@@ -550,22 +554,23 @@ class ModulesStructure(
|
||||
private val storageManager: LockBasedStorageManager = LockBasedStorageManager("ModulesStructure")
|
||||
private var runtimeModule: ModuleDescriptorImpl? = null
|
||||
|
||||
// TODO: these are roughly equivalent to KlibResolvedModuleDescriptorsFactoryImpl. Refactor me.
|
||||
val descriptors = mutableMapOf<KotlinLibrary, ModuleDescriptorImpl>()
|
||||
private val _descriptors: MutableMap<KotlinLibrary, ModuleDescriptorImpl> = mutableMapOf()
|
||||
|
||||
val allModuleDescriptors = run {
|
||||
val descriptors = allDependencies.map { getModuleDescriptor(it.library) }
|
||||
init {
|
||||
val descriptors = allDependencies.map { getModuleDescriptorImpl(it) }
|
||||
|
||||
descriptors.forEach { descriptor ->
|
||||
descriptor.setDependencies(descriptors)
|
||||
}
|
||||
|
||||
descriptors
|
||||
}
|
||||
|
||||
fun getModuleDescriptor(current: KotlinLibrary): ModuleDescriptorImpl {
|
||||
if (current in descriptors) {
|
||||
return descriptors.getValue(current)
|
||||
// TODO: these are roughly equivalent to KlibResolvedModuleDescriptorsFactoryImpl. Refactor me.
|
||||
val descriptors: Map<KotlinLibrary, ModuleDescriptor>
|
||||
get() = _descriptors
|
||||
|
||||
private fun getModuleDescriptorImpl(current: KotlinLibrary): ModuleDescriptorImpl {
|
||||
if (current in _descriptors) {
|
||||
return _descriptors.getValue(current)
|
||||
}
|
||||
|
||||
val isBuiltIns = current.unresolvedDependencies.isEmpty()
|
||||
@@ -581,14 +586,17 @@ class ModulesStructure(
|
||||
)
|
||||
if (isBuiltIns) runtimeModule = md
|
||||
|
||||
descriptors[current] = md
|
||||
_descriptors[current] = md
|
||||
|
||||
return md
|
||||
}
|
||||
|
||||
fun getModuleDescriptor(current: KotlinLibrary): ModuleDescriptor =
|
||||
getModuleDescriptorImpl(current)
|
||||
|
||||
val builtInModuleDescriptor =
|
||||
if (builtInsDep != null)
|
||||
getModuleDescriptor(builtInsDep.library)
|
||||
getModuleDescriptor(builtInsDep)
|
||||
else
|
||||
null // null in case compiling builtInModule itself
|
||||
}
|
||||
|
||||
-1
@@ -40,7 +40,6 @@ where advanced options include:
|
||||
-Xlegacy-deprecated-no-warn Disable warnings of deprecation of legacy compiler
|
||||
-Xmetadata-only Generate *.meta.js and *.kjsm files only
|
||||
-Xpartial-linkage Allow unlinked symbols
|
||||
-Xrepositories=<path> Paths to additional places where libraries could be found
|
||||
-Xstrict-implicit-export-types Generate strict types for implicitly exported entities inside d.ts files. Available in IR backend only.
|
||||
-Xtyped-arrays Translate primitive arrays to JS typed arrays
|
||||
-Xuse-deprecated-legacy-compiler
|
||||
|
||||
-1
@@ -256,7 +256,6 @@ class ClassicFrontendFacade(
|
||||
private fun loadKlib(names: List<String>, configuration: CompilerConfiguration): List<ModuleDescriptor> {
|
||||
val resolvedLibraries = jsResolveLibraries(
|
||||
names,
|
||||
configuration[JSConfigurationKeys.REPOSITORIES] ?: emptyList(),
|
||||
configuration.resolverLogger
|
||||
).getFullResolvedList()
|
||||
|
||||
|
||||
+2
-4
@@ -37,10 +37,9 @@ object TestFirJsSessionFactory {
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
registerExtraComponents: ((FirSession) -> Unit),
|
||||
): FirSession {
|
||||
val repositories = configuration[JSConfigurationKeys.REPOSITORIES] ?: emptyList()
|
||||
val logger = configuration.resolverLogger
|
||||
val libraries = getAllJsDependenciesPaths(module, testServices)
|
||||
val resolvedLibraries = jsResolveLibraries(libraries, repositories, logger).getFullResolvedList()
|
||||
val resolvedLibraries = jsResolveLibraries(libraries, logger).getFullResolvedList()
|
||||
|
||||
return FirJsSessionFactory.createJsLibrarySession(
|
||||
mainModuleName,
|
||||
@@ -75,9 +74,8 @@ fun resolveJsLibraries(
|
||||
configuration: CompilerConfiguration
|
||||
): List<KotlinResolvedLibrary> {
|
||||
val paths = getAllJsDependenciesPaths(module, testServices)
|
||||
val repositories = configuration[JSConfigurationKeys.REPOSITORIES] ?: emptyList()
|
||||
val logger = configuration.resolverLogger
|
||||
return jsResolveLibraries(paths, repositories, logger).getFullResolvedList()
|
||||
return jsResolveLibraries(paths, logger).getFullResolvedList()
|
||||
}
|
||||
|
||||
fun getAllJsDependenciesPaths(module: TestModule, testServices: TestServices): List<String> {
|
||||
|
||||
@@ -236,7 +236,7 @@ abstract class AbstractKlibTextTestCase : CodegenTestCase() {
|
||||
}
|
||||
|
||||
private fun loadKlibFromPath(paths: List<String>): List<KotlinLibrary> {
|
||||
val result = jsResolveLibraries(paths, emptyList(), DummyLogger)
|
||||
val result = jsResolveLibraries(paths, DummyLogger)
|
||||
return result.getFullList(TopologicalLibraryOrder)
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ class FilePathsInKlibTest : CodegenTestCase() {
|
||||
private fun File.md5(): Long = readBytes().md5()
|
||||
|
||||
private fun File.loadKlibFilePaths(): List<String> {
|
||||
val libs = jsResolveLibraries(listOf(runtimeKlibPath, canonicalPath), emptyList(), DummyLogger).getFullList()
|
||||
val libs = jsResolveLibraries(listOf(runtimeKlibPath, canonicalPath), DummyLogger).getFullList()
|
||||
val lib = libs.last()
|
||||
val fileSize = lib.fileCount()
|
||||
val extReg = ExtensionRegistryLite.newInstance()
|
||||
|
||||
+16
-1
@@ -18,7 +18,22 @@ interface KotlinLibraryResolver<L: KotlinLibrary> {
|
||||
noStdLib: Boolean = false,
|
||||
noDefaultLibs: Boolean = false,
|
||||
noEndorsedLibs: Boolean = false
|
||||
): KotlinLibraryResolveResult
|
||||
): KotlinLibraryResolveResult =
|
||||
resolveWithoutDependencies(
|
||||
unresolvedLibraries,
|
||||
noStdLib,
|
||||
noDefaultLibs,
|
||||
noEndorsedLibs
|
||||
).resolveDependencies()
|
||||
|
||||
fun resolveWithoutDependencies(
|
||||
unresolvedLibraries: List<UnresolvedLibrary>,
|
||||
noStdLib: Boolean = false,
|
||||
noDefaultLibs: Boolean = false,
|
||||
noEndorsedLibs: Boolean = false
|
||||
): List<KotlinLibrary>
|
||||
|
||||
fun List<KotlinLibrary>.resolveDependencies(): KotlinLibraryResolveResult
|
||||
}
|
||||
|
||||
interface KotlinLibraryResolveResult {
|
||||
|
||||
+4
-6
@@ -32,16 +32,14 @@ class KotlinLibraryResolverImpl<L: KotlinLibrary> internal constructor(
|
||||
override val searchPathResolver: SearchPathResolver<L>,
|
||||
val resolveManifestDependenciesLenient: Boolean
|
||||
): KotlinLibraryResolver<L>, WithLogger by searchPathResolver {
|
||||
|
||||
override fun resolveWithDependencies(
|
||||
override fun resolveWithoutDependencies(
|
||||
unresolvedLibraries: List<UnresolvedLibrary>,
|
||||
noStdLib: Boolean,
|
||||
noDefaultLibs: Boolean,
|
||||
noEndorsedLibs: Boolean
|
||||
) = findLibraries(unresolvedLibraries, noStdLib, noDefaultLibs, noEndorsedLibs)
|
||||
.leaveDistinct()
|
||||
.omitDuplicateNames()
|
||||
.resolveDependencies()
|
||||
.leaveDistinct()
|
||||
.omitDuplicateNames()
|
||||
|
||||
/**
|
||||
* Returns the list of libraries based on [libraryNames], [noStdLib], [noDefaultLibs] and [noEndorsedLibs] criteria.
|
||||
@@ -102,7 +100,7 @@ class KotlinLibraryResolverImpl<L: KotlinLibrary> internal constructor(
|
||||
* 2. Wraps each [KotlinLibrary] into a [KotlinResolvedLibrary] with information about dependencies on other libraries.
|
||||
* 3. Creates resulting [KotlinLibraryResolveResult] object.
|
||||
*/
|
||||
private fun List<KotlinLibrary>.resolveDependencies(): KotlinLibraryResolveResult {
|
||||
override fun List<KotlinLibrary>.resolveDependencies(): KotlinLibraryResolveResult {
|
||||
|
||||
val rootLibraries = this.map { KotlinResolvedLibraryImpl(it) }
|
||||
|
||||
|
||||
@@ -253,7 +253,6 @@ class CompilerArgumentsContentProspectorTest {
|
||||
K2JSCompilerArguments::friendModules,
|
||||
K2JSCompilerArguments::errorTolerancePolicy,
|
||||
K2JSCompilerArguments::irDceRuntimeDiagnostic,
|
||||
K2JSCompilerArguments::repositries,
|
||||
)
|
||||
private val k2JSCompilerArgumentsArrayProperties = commonCompilerArgumentsArrayProperties
|
||||
|
||||
|
||||
@@ -100,9 +100,6 @@ public class JSConfigurationKeys {
|
||||
public static final CompilerConfigurationKey<ErrorTolerancePolicy> ERROR_TOLERANCE_POLICY =
|
||||
CompilerConfigurationKey.create("set up policy to ignore compilation errors");
|
||||
|
||||
public static final CompilerConfigurationKey<Collection<String>> REPOSITORIES =
|
||||
CompilerConfigurationKey.create("set up additional repository paths");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> PARTIAL_LINKAGE =
|
||||
CompilerConfigurationKey.create("allows some symbols in klibs be missed");
|
||||
|
||||
|
||||
@@ -77,7 +77,6 @@ class FirJsKlibBackendFacade(
|
||||
// TODO: consider avoiding repeated libraries resolution
|
||||
val lib = jsResolveLibraries(
|
||||
getAllJsDependenciesPaths(module, testServices) + listOf(outputFile),
|
||||
emptyList(),
|
||||
configuration.resolverLogger
|
||||
).getFullResolvedList().last().library
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ class JsKlibBackendFacade(
|
||||
val dependencies = JsEnvironmentConfigurator.getAllRecursiveDependenciesFor(module, testServices).toList()
|
||||
val lib = jsResolveLibraries(
|
||||
dependencies.map { testServices.jsLibraryProvider.getPathByDescriptor(it) } + listOf(outputFile),
|
||||
configuration[JSConfigurationKeys.REPOSITORIES] ?: emptyList(),
|
||||
configuration.resolverLogger
|
||||
).getFullResolvedList().last().library
|
||||
|
||||
|
||||
+17
-3
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.js.testOld.V8JsTestChecker
|
||||
import org.jetbrains.kotlin.library.KLIB_FILE_EXTENSION
|
||||
import org.jetbrains.kotlin.test.KotlinBaseTest
|
||||
import java.io.File
|
||||
|
||||
abstract class AbstractJsKlibBinaryCompatibilityTest : AbstractKlibBinaryCompatibilityTest() {
|
||||
@@ -32,7 +33,22 @@ abstract class AbstractJsKlibBinaryCompatibilityTest : AbstractKlibBinaryCompati
|
||||
}
|
||||
|
||||
private fun TestModule.dependenciesToLibrariesArg(version: Int): String =
|
||||
this.dependencies.map { it as? TestModule ?: error("Unexpected dependency kind: $it") }.toLibrariesArg(version)
|
||||
this.dependencies
|
||||
.flatMap { it.transitiveDependencies() }
|
||||
.map { it as? TestModule ?: error("Unexpected dependency kind: $it") }
|
||||
.toLibrariesArg(version)
|
||||
|
||||
private fun KotlinBaseTest.TestModule.transitiveDependencies(): Set<KotlinBaseTest.TestModule> {
|
||||
val uniqueDependencies = mutableSetOf(this)
|
||||
dependencies.forEach { testModule ->
|
||||
if (testModule !in uniqueDependencies) {
|
||||
val transitiveDependencies = testModule.transitiveDependencies()
|
||||
uniqueDependencies.addAll(transitiveDependencies)
|
||||
}
|
||||
}
|
||||
|
||||
return uniqueDependencies
|
||||
}
|
||||
|
||||
private val TestModule.jsPath get() = File(workingDir, "${this.name}.js").absolutePath
|
||||
|
||||
@@ -58,7 +74,6 @@ abstract class AbstractJsKlibBinaryCompatibilityTest : AbstractKlibBinaryCompati
|
||||
irProduceKlibFile = true
|
||||
irOnly = true
|
||||
irModuleName = module.name
|
||||
repositries = "$workingDir${File.pathSeparator}$workingDir/version$version"
|
||||
}
|
||||
K2JSCompiler().exec(TestMessageCollector(), Services.EMPTY, args)
|
||||
}
|
||||
@@ -73,7 +88,6 @@ abstract class AbstractJsKlibBinaryCompatibilityTest : AbstractKlibBinaryCompati
|
||||
irProduceJs = true
|
||||
irOnly = true
|
||||
irModuleName = module.name
|
||||
repositries = "$workingDir${File.pathSeparator}$workingDir/version2"
|
||||
}
|
||||
K2JSCompiler().exec(TestMessageCollector(), Services.EMPTY, args)
|
||||
}
|
||||
|
||||
+16
@@ -425,6 +425,22 @@ class Kotlin2JsIrGradlePluginIT : AbstractKotlin2JsGradlePluginIT(true) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@DisplayName("JS IR implementation dependency")
|
||||
@GradleTest
|
||||
fun testJsIrImplementationDependency(gradleVersion: GradleVersion) {
|
||||
project("kotlin-js-browser-project", gradleVersion) {
|
||||
buildGradleKts.modify(::transformBuildScriptWithPluginsDsl)
|
||||
|
||||
build("assemble")
|
||||
|
||||
projectPath.resolve("app/src/main/kotlin/App.kt").modify {
|
||||
it.replace("sheldon()", "best()")
|
||||
}
|
||||
|
||||
buildAndFail("assemble")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@JsGradlePluginTests
|
||||
|
||||
+2
-1
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.gradle.tasks.Kotlin2JsCompile
|
||||
import org.jetbrains.kotlin.gradle.tasks.KotlinTasksProvider
|
||||
import org.jetbrains.kotlin.gradle.tasks.configuration.Kotlin2JsCompileConfig
|
||||
import org.jetbrains.kotlin.gradle.tasks.configuration.KotlinJsIrLinkConfig
|
||||
import org.jetbrains.kotlin.gradle.utils.filesProvider
|
||||
|
||||
internal class KotlinJsIrSourceSetProcessor(
|
||||
tasksProvider: KotlinTasksProvider,
|
||||
@@ -46,7 +47,7 @@ internal class KotlinJsIrSourceSetProcessor(
|
||||
val configAction = KotlinJsIrLinkConfig(binary)
|
||||
configAction.configureTask {
|
||||
it.description = taskDescription
|
||||
it.libraries.from({ compilationInfo.compileDependencyFiles })
|
||||
it.libraries.from(compilation.runtimeDependencyFiles)
|
||||
}
|
||||
configAction.configureTask { task ->
|
||||
task.modeProperty.set(binary.mode)
|
||||
|
||||
+3
-1
@@ -66,6 +66,8 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
|
||||
internal val createTestCompilation: Boolean
|
||||
) : KotlinTargetConfigurator<KotlinTargetType> {
|
||||
|
||||
protected open val runtimeIncludesCompilationOutputs = true
|
||||
|
||||
protected open fun setupCompilationDependencyFiles(compilation: KotlinCompilation<KotlinCommonOptions>) {
|
||||
val project = compilation.target.project
|
||||
|
||||
@@ -87,7 +89,7 @@ abstract class AbstractKotlinTargetConfigurator<KotlinTargetType : KotlinTarget>
|
||||
target.compilations.create(KotlinCompilation.TEST_COMPILATION_NAME).apply {
|
||||
associateWith(main)
|
||||
|
||||
if (this is KotlinCompilationToRunnableFiles) {
|
||||
if (runtimeIncludesCompilationOutputs && this is KotlinCompilationToRunnableFiles) {
|
||||
// TODO: fix inconsistency? KT-27272
|
||||
runtimeDependencyFiles += project.files(output.allOutputs)
|
||||
}
|
||||
|
||||
+2
-1
@@ -23,6 +23,8 @@ open class KotlinJsIrTargetConfigurator() :
|
||||
KotlinOnlyTargetConfigurator<KotlinJsIrCompilation, KotlinJsIrTarget>(true),
|
||||
KotlinTargetWithTestsConfigurator<KotlinJsReportAggregatingTestRun, KotlinJsIrTarget> {
|
||||
|
||||
override val runtimeIncludesCompilationOutputs: Boolean = false
|
||||
|
||||
override val testRunClass: Class<KotlinJsReportAggregatingTestRun> get() = KotlinJsReportAggregatingTestRun::class.java
|
||||
|
||||
override val archiveType: String
|
||||
@@ -104,7 +106,6 @@ open class KotlinJsIrTargetConfigurator() :
|
||||
|
||||
override fun defineConfigurationsForTarget(target: KotlinJsIrTarget) {
|
||||
super.defineConfigurationsForTarget(target)
|
||||
implementationToApiElements(target)
|
||||
|
||||
if (target.isMpp!!) return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user