From 005aa57f6d4060d416399bb884f97ea1a3ef676d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Sun, 11 Apr 2021 14:01:15 +0200 Subject: [PATCH] Remove obsolete module cli-js-klib It's no longer used anywhere in the build. --- compiler/cli/cli-js-klib/build.gradle.kts | 20 --- .../cli/cli-js-klib/src/GenerateJsIrKlib.kt | 153 ------------------ js/js.tests/build.gradle.kts | 1 - .../kotlin-compiler-for-ide/build.gradle.kts | 3 +- settings.gradle | 2 - 5 files changed, 1 insertion(+), 178 deletions(-) delete mode 100644 compiler/cli/cli-js-klib/build.gradle.kts delete mode 100644 compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt diff --git a/compiler/cli/cli-js-klib/build.gradle.kts b/compiler/cli/cli-js-klib/build.gradle.kts deleted file mode 100644 index f1fa227487d..00000000000 --- a/compiler/cli/cli-js-klib/build.gradle.kts +++ /dev/null @@ -1,20 +0,0 @@ -plugins { - kotlin("jvm") - id("jps-compatible") -} - -dependencies { - compile(project(":compiler:cli")) - compile(project(":compiler:ir.serialization.js")) - compileOnly(project(":compiler:ir.tree.persistent")) - runtimeOnly(project(":kotlin-reflect")) - if (Platform[193].orLower()) { - compile(intellijDep()) { includeJars("picocontainer", rootProject = rootProject) } - } - compile(intellijDep()) { includeJars("trove4j", "guava", "jdom", rootProject = rootProject) } - compile(intellijCoreDep()) { includeJars("intellij-core") } -} - -sourceSets { - "main" { projectDefault() } -} diff --git a/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt b/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt deleted file mode 100644 index 6eedb3d3519..00000000000 --- a/compiler/cli/cli-js-klib/src/GenerateJsIrKlib.kt +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -// Internal CLI for building JS IR libraries - -package org.jetbrains.kotlin.ir.backend.js - -import com.intellij.openapi.Disposable -import com.intellij.openapi.vfs.StandardFileSystems -import com.intellij.openapi.vfs.VirtualFileManager -import com.intellij.psi.PsiManager -import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys -import org.jetbrains.kotlin.cli.common.messages.* -import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.config.* -import org.jetbrains.kotlin.ir.declarations.persistent.PersistentIrFactory -import org.jetbrains.kotlin.js.config.JSConfigurationKeys -import org.jetbrains.kotlin.library.resolver.KotlinLibraryResolveResult -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.resolve.multiplatform.isCommonSource -import org.jetbrains.kotlin.serialization.js.ModuleKind -import org.jetbrains.kotlin.util.Logger -import java.io.File - -fun buildConfiguration(environment: KotlinCoreEnvironment, moduleName: String): CompilerConfiguration { - val runtimeConfiguration = environment.configuration.copy() - runtimeConfiguration.put(CommonConfigurationKeys.MODULE_NAME, moduleName) - runtimeConfiguration.put(JSConfigurationKeys.MODULE_KIND, ModuleKind.PLAIN) - runtimeConfiguration.put( - CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, - PrintingMessageCollector(System.err, MessageRenderer.PLAIN_RELATIVE_PATHS, false) - ) - - runtimeConfiguration.languageVersionSettings = LanguageVersionSettingsImpl( - LanguageVersion.LATEST_STABLE, ApiVersion.LATEST_STABLE, - specificFeatures = mapOf( - LanguageFeature.AllowContractsForCustomFunctions to LanguageFeature.State.ENABLED, - LanguageFeature.MultiPlatformProjects to LanguageFeature.State.ENABLED - ), - analysisFlags = mapOf( - AnalysisFlags.useExperimental to listOf( - "kotlin.RequiresOptIn", - "kotlin.contracts.ExperimentalContracts", - "kotlin.ExperimentalMultiplatform", - ), - AnalysisFlags.allowResultReturnType to true - ) - ) - - return runtimeConfiguration -} - -@Suppress("RedundantSamConstructor") -private val environment = - KotlinCoreEnvironment.createForProduction(Disposable { }, CompilerConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES) - -fun createPsiFile(fileName: String): KtFile { - val psiManager = PsiManager.getInstance(environment.project) - val fileSystem = VirtualFileManager.getInstance().getFileSystem(StandardFileSystems.FILE_PROTOCOL) - - val file = fileSystem.findFileByPath(fileName) ?: error("File not found: $fileName") - - return psiManager.findFile(file) as KtFile -} - - -fun buildKLib( - moduleName: String, - sources: List, - outputPath: String, - allDependencies: KotlinLibraryResolveResult, - commonSources: List -) { - val configuration = buildConfiguration(environment, moduleName) - generateKLib( - project = environment.project, - files = sources.map { source -> - val file = createPsiFile(source) - if (source in commonSources) { - file.isCommonSource = true - } - file - }, - analyzer = AnalyzerWithCompilerReport(configuration), - configuration = configuration, - allDependencies = allDependencies, - friendDependencies = emptyList(), - irFactory = PersistentIrFactory(), // TODO: IrFactoryImpl? - outputKlibPath = outputPath, - nopack = true - ) -} - -private fun listOfKtFilesFrom(paths: List): List { - val currentDir = File("") - return paths.flatMap { path -> - File(path) - .walkTopDown() - .filter { it.extension == "kt" } - .map { it.relativeToOrSelf(currentDir).path } - .asIterable() - }.distinct() -} - -fun main(args: Array) { - val inputFiles = mutableListOf() - var outputPath: String? = null - val dependencies = mutableListOf() - val commonSources = mutableListOf() - var moduleName: String? = null - - var index = 0 - while (index < args.size) { - val arg = args[index++] - - when (arg) { - "-n" -> moduleName = args[index++] - "-o" -> outputPath = args[index++] - "-d" -> dependencies += args[index++] - "-c" -> commonSources += args[index++] - else -> inputFiles += arg - } - } - - if (outputPath == null) { - error("Please set path to .klm file: `-o some/dir/module-name.klm`") - } - - if (moduleName == null) { - error("Please set module name: `-n module-name`") - } - - val resolvedLibraries = jsResolveLibraries( - dependencies, emptyList(), messageCollectorLogger(MessageCollector.NONE) - ) - - buildKLib(moduleName, listOfKtFilesFrom(inputFiles), outputPath, resolvedLibraries, listOfKtFilesFrom(commonSources)) -} - -// Copied here from `K2JsIrCompiler` instead of reusing in order to avoid circular dependencies between Gradle tasks -private fun messageCollectorLogger(collector: MessageCollector) = object : Logger { - override fun warning(message: String)= collector.report(CompilerMessageSeverity.STRONG_WARNING, message) - override fun error(message: String) = collector.report(CompilerMessageSeverity.ERROR, message) - override fun log(message: String) = collector.report(CompilerMessageSeverity.LOGGING, message) - override fun fatal(message: String): Nothing { - collector.report(CompilerMessageSeverity.ERROR, message) - (collector as? GroupingMessageCollector)?.flush() - kotlin.error(message) - } -} diff --git a/js/js.tests/build.gradle.kts b/js/js.tests/build.gradle.kts index 0bb7d31eff3..746f3a6ebd8 100644 --- a/js/js.tests/build.gradle.kts +++ b/js/js.tests/build.gradle.kts @@ -43,7 +43,6 @@ dependencies { testCompileOnly(project(":compiler:frontend")) testCompileOnly(project(":compiler:cli")) testCompileOnly(project(":compiler:cli-js")) - testCompileOnly(project(":compiler:cli-js-klib")) testCompileOnly(project(":compiler:util")) testCompileOnly(intellijCoreDep()) { includeJars("intellij-core") } testCompileOnly(intellijDep()) { includeJars("idea", "idea_rt", "util") } diff --git a/prepare/ide-plugin-dependencies/kotlin-compiler-for-ide/build.gradle.kts b/prepare/ide-plugin-dependencies/kotlin-compiler-for-ide/build.gradle.kts index 97e4e0541b9..2ba95b55e40 100644 --- a/prepare/ide-plugin-dependencies/kotlin-compiler-for-ide/build.gradle.kts +++ b/prepare/ide-plugin-dependencies/kotlin-compiler-for-ide/build.gradle.kts @@ -2,7 +2,6 @@ idePluginDependency { val compilerModules: Array by rootProject.extra val excludedCompilerModules = listOf( - ":compiler:cli-js-klib", ":compiler:javac-wrapper", ":compiler:backend.js", ":compiler:backend.wasm", @@ -26,4 +25,4 @@ idePluginDependency { projects = projects, libraryDependencies = listOf(protobufFull()) ) -} \ No newline at end of file +} diff --git a/settings.gradle b/settings.gradle index 2b2e6ff975c..33ff0624b18 100644 --- a/settings.gradle +++ b/settings.gradle @@ -117,7 +117,6 @@ include ":benchmarks", ":compiler:javac-wrapper", ":compiler:cli", ":compiler:cli-js", - ":compiler:cli-js-klib", ":compiler:incremental-compilation-impl", ":compiler:android-tests", ":compiler:tests-compiler-utils", @@ -465,7 +464,6 @@ project(':kotlin-preloader').projectDir = "$rootDir/compiler/preloader" as File project(':kotlin-build-common').projectDir = "$rootDir/build-common" as File project(':compiler:cli-common').projectDir = "$rootDir/compiler/cli/cli-common" as File project(':compiler:cli-js').projectDir = "$rootDir/compiler/cli/cli-js" as File -project(':compiler:cli-js-klib').projectDir = "$rootDir/compiler/cli/cli-js-klib" as File project(':kotlin-runner').projectDir = "$rootDir/compiler/cli/cli-runner" as File project(':kotlin-daemon').projectDir = "$rootDir/compiler/daemon" as File project(':daemon-common').projectDir = "$rootDir/compiler/daemon/daemon-common" as File