[JS IR] Commonize CLI error reporting
Use general `AnalysisResult.CompilationErrorException` instead of custom JsIrCompilationError to indicate about unsuccessful compilation - Drop JsIrCompilationError
This commit is contained in:
@@ -192,21 +192,17 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
require(outputFile.extension == KLIB_FILE_EXTENSION) { "Please set up .klib file as output" }
|
require(outputFile.extension == KLIB_FILE_EXTENSION) { "Please set up .klib file as output" }
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
generateKLib(
|
||||||
generateKLib(
|
project = config.project,
|
||||||
project = config.project,
|
files = sourcesFiles,
|
||||||
files = sourcesFiles,
|
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
configuration = config.configuration,
|
||||||
configuration = config.configuration,
|
allDependencies = resolvedLibraries,
|
||||||
allDependencies = resolvedLibraries,
|
friendDependencies = friendDependencies,
|
||||||
friendDependencies = friendDependencies,
|
irFactory = PersistentIrFactory,
|
||||||
irFactory = PersistentIrFactory,
|
outputKlibPath = outputFile.path,
|
||||||
outputKlibPath = outputFile.path,
|
nopack = arguments.irProduceKlibDir
|
||||||
nopack = arguments.irProduceKlibDir
|
)
|
||||||
)
|
|
||||||
} catch (e: JsIrCompilationError) {
|
|
||||||
return COMPILATION_ERROR
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (arguments.irProduceJs) {
|
if (arguments.irProduceJs) {
|
||||||
@@ -252,26 +248,22 @@ class K2JsIrCompiler : CLICompiler<K2JSCompilerArguments>() {
|
|||||||
return OK
|
return OK
|
||||||
}
|
}
|
||||||
|
|
||||||
val compiledModule = try {
|
val compiledModule = compile(
|
||||||
compile(
|
projectJs,
|
||||||
projectJs,
|
mainModule,
|
||||||
mainModule,
|
AnalyzerWithCompilerReport(config.configuration),
|
||||||
AnalyzerWithCompilerReport(config.configuration),
|
config.configuration,
|
||||||
config.configuration,
|
phaseConfig,
|
||||||
phaseConfig,
|
allDependencies = resolvedLibraries,
|
||||||
allDependencies = resolvedLibraries,
|
friendDependencies = friendDependencies,
|
||||||
friendDependencies = friendDependencies,
|
mainArguments = mainCallArguments,
|
||||||
mainArguments = mainCallArguments,
|
generateFullJs = !arguments.irDce,
|
||||||
generateFullJs = !arguments.irDce,
|
generateDceJs = arguments.irDce,
|
||||||
generateDceJs = arguments.irDce,
|
dceDriven = arguments.irDceDriven,
|
||||||
dceDriven = arguments.irDceDriven,
|
multiModule = arguments.irPerModule,
|
||||||
multiModule = arguments.irPerModule,
|
relativeRequirePath = true,
|
||||||
relativeRequirePath = true,
|
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
|
||||||
propertyLazyInitialization = arguments.irPropertyLazyInitialization,
|
)
|
||||||
)
|
|
||||||
} catch (e: JsIrCompilationError) {
|
|
||||||
return COMPILATION_ERROR
|
|
||||||
}
|
|
||||||
|
|
||||||
val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!!
|
val jsCode = if (arguments.irDce && !arguments.irDceDriven) compiledModule.dceJsCode!! else compiledModule.jsCode!!
|
||||||
outputFile.writeText(jsCode.mainModule)
|
outputFile.writeText(jsCode.mainModule)
|
||||||
|
|||||||
@@ -363,8 +363,6 @@ fun getModuleDescriptorByLibrary(current: KotlinLibrary, mapping: Map<String, Mo
|
|||||||
return md
|
return md
|
||||||
}
|
}
|
||||||
|
|
||||||
object JsIrCompilationError : Throwable()
|
|
||||||
|
|
||||||
sealed class MainModule {
|
sealed class MainModule {
|
||||||
class SourceFiles(val files: List<KtFile>) : MainModule()
|
class SourceFiles(val files: List<KtFile>) : MainModule()
|
||||||
class Klib(val lib: KotlinLibrary) : MainModule()
|
class Klib(val lib: KotlinLibrary) : MainModule()
|
||||||
@@ -416,7 +414,7 @@ private class ModulesStructure(
|
|||||||
var hasErrors = false
|
var hasErrors = false
|
||||||
if (analyzer.hasErrors() || analysisResult !is JsAnalysisResult) {
|
if (analyzer.hasErrors() || analysisResult !is JsAnalysisResult) {
|
||||||
if (!errorPolicy.allowErrors)
|
if (!errorPolicy.allowErrors)
|
||||||
throw JsIrCompilationError
|
throw AnalysisResult.CompilationErrorException()
|
||||||
else hasErrors = true
|
else hasErrors = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user