Command-line tool for JS DCE
This commit is contained in:
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2010-2017 JetBrains s.r.o.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
export KOTLIN_COMPILER=org.jetbrains.kotlin.cli.js.dce.K2JSDce
|
||||
|
||||
DIR="${BASH_SOURCE[0]%/*}"
|
||||
: ${DIR:="."}
|
||||
|
||||
"${DIR}"/kotlinc "$@"
|
||||
@@ -0,0 +1,20 @@
|
||||
@echo off
|
||||
|
||||
rem Copyright 2010-2015 JetBrains s.r.o.
|
||||
rem
|
||||
rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
rem you may not use this file except in compliance with the License.
|
||||
rem You may obtain a copy of the License at
|
||||
rem
|
||||
rem http://www.apache.org/licenses/LICENSE-2.0
|
||||
rem
|
||||
rem Unless required by applicable law or agreed to in writing, software
|
||||
rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
rem See the License for the specific language governing permissions and
|
||||
rem limitations under the License.
|
||||
|
||||
setlocal
|
||||
set _KOTLIN_COMPILER=org.jetbrains.kotlin.cli.js.dce.K2JSDce
|
||||
|
||||
call %~dps0kotlinc.bat %*
|
||||
+1
-28
@@ -16,15 +16,9 @@
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.arguments;
|
||||
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class CommonCompilerArguments implements Serializable {
|
||||
public abstract class CommonCompilerArguments extends CommonToolArguments {
|
||||
public static final long serialVersionUID = 0L;
|
||||
|
||||
public static final String PLUGIN_OPTION_FORMAT = "plugin:<pluginId>:<optionName>=<value>";
|
||||
@@ -45,23 +39,6 @@ public abstract class CommonCompilerArguments implements Serializable {
|
||||
)
|
||||
public String apiVersion;
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault.class)
|
||||
@Argument(value = "-nowarn", description = "Generate no warnings")
|
||||
public boolean suppressWarnings;
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault.class)
|
||||
@Argument(value = "-verbose", description = "Enable verbose logging output")
|
||||
public boolean verbose;
|
||||
|
||||
@Argument(value = "-version", description = "Display compiler version")
|
||||
public boolean version;
|
||||
|
||||
@Argument(value = "-help", shortName = "-h", description = "Print a synopsis of standard options")
|
||||
public boolean help;
|
||||
|
||||
@Argument(value = "-X", description = "Print a synopsis of advanced options")
|
||||
public boolean extraHelp;
|
||||
|
||||
@Argument(value = "-P", valueDescription = PLUGIN_OPTION_FORMAT, description = "Pass an option to a plugin")
|
||||
public String[] pluginOptions;
|
||||
|
||||
@@ -110,10 +87,6 @@ public abstract class CommonCompilerArguments implements Serializable {
|
||||
)
|
||||
public String coroutinesState = WARN;
|
||||
|
||||
public List<String> freeArgs = new SmartList<>();
|
||||
|
||||
public transient ArgumentParseErrors errors = new ArgumentParseErrors();
|
||||
|
||||
@NotNull
|
||||
public static CommonCompilerArguments createDefaultInstance() {
|
||||
return new DummyImpl();
|
||||
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.arguments;
|
||||
|
||||
import org.jetbrains.kotlin.utils.SmartList;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class CommonToolArguments implements Serializable {
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
public List<String> freeArgs = new SmartList<>();
|
||||
|
||||
public transient ArgumentParseErrors errors = new ArgumentParseErrors();
|
||||
|
||||
@Argument(value = "-help", shortName = "-h", description = "Print a synopsis of standard options")
|
||||
public boolean help;
|
||||
|
||||
@Argument(value = "-X", description = "Print a synopsis of advanced options")
|
||||
public boolean extraHelp;
|
||||
|
||||
@Argument(value = "-version", description = "Display compiler version")
|
||||
public boolean version;
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault.class)
|
||||
@Argument(value = "-verbose", description = "Enable verbose logging output")
|
||||
public boolean verbose;
|
||||
|
||||
@GradleOption(DefaultValues.BooleanFalseDefault.class)
|
||||
@Argument(value = "-nowarn", description = "Generate no warnings")
|
||||
public boolean suppressWarnings;
|
||||
}
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.common.arguments
|
||||
|
||||
class K2JSDceArguments : CommonToolArguments() {
|
||||
companion object {
|
||||
const val serialVersionUID = 0L
|
||||
}
|
||||
|
||||
@field:GradleOption(DefaultValues.StringNullDefault::class)
|
||||
@field:Argument(value = "-output-dir", valueDescription = "<path>", description = "Output directory")
|
||||
@JvmField
|
||||
var outputDirectory: String? = null
|
||||
|
||||
@field:GradleOption(DefaultValues.BooleanFalseDefault::class)
|
||||
@field:Argument(value = "-Xprint-reachability-info", description = "Print declarations marked as reachable")
|
||||
@JvmField
|
||||
var printReachabilityInfo: Boolean = false
|
||||
}
|
||||
+2
-2
@@ -50,7 +50,7 @@ data class ArgumentParseErrors(
|
||||
)
|
||||
|
||||
// Parses arguments in the passed [result] object, or throws an [IllegalArgumentException] with the message to be displayed to the user
|
||||
fun <A : CommonCompilerArguments> parseCommandLineArguments(args: Array<String>, result: A) {
|
||||
fun <A : CommonToolArguments> parseCommandLineArguments(args: Array<out String>, result: A) {
|
||||
data class ArgumentField(val field: Field, val argument: Argument)
|
||||
|
||||
val fields = result::class.java.fields.mapNotNull { field ->
|
||||
@@ -118,7 +118,7 @@ fun <A : CommonCompilerArguments> parseCommandLineArguments(args: Array<String>,
|
||||
}
|
||||
}
|
||||
|
||||
private fun <A : CommonCompilerArguments> updateField(field: Field, result: A, value: Any, delimiter: String) {
|
||||
private fun <A : CommonToolArguments> updateField(field: Field, result: A, value: Any, delimiter: String) {
|
||||
when (field.type) {
|
||||
Boolean::class.java, String::class.java -> field.set(result, value)
|
||||
Array<String>::class.java -> {
|
||||
|
||||
@@ -19,15 +19,14 @@ package org.jetbrains.kotlin.cli.common;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import kotlin.collections.ArraysKt;
|
||||
import org.fusesource.jansi.AnsiConsole;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.ArgumentParseErrors;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.ParseCommandLineArgumentsKt;
|
||||
import org.jetbrains.kotlin.cli.common.messages.*;
|
||||
import org.jetbrains.kotlin.cli.common.messages.GroupingMessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageRenderer;
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentException;
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CompilerJarLocator;
|
||||
import org.jetbrains.kotlin.config.*;
|
||||
import org.jetbrains.kotlin.progress.CompilationCanceledException;
|
||||
@@ -39,19 +38,12 @@ import java.io.PrintStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
import static org.jetbrains.kotlin.cli.common.ExitCode.*;
|
||||
import static org.jetbrains.kotlin.cli.common.environment.UtilKt.setIdeaIoUseFallback;
|
||||
import static org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.*;
|
||||
|
||||
public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
|
||||
@NotNull
|
||||
public ExitCode exec(@NotNull PrintStream errStream, @NotNull String... args) {
|
||||
return exec(errStream, Services.EMPTY, MessageRenderer.PLAIN_RELATIVE_PATHS, args);
|
||||
}
|
||||
|
||||
public abstract class CLICompiler<A extends CommonCompilerArguments> extends CLITool<A> {
|
||||
// Used in CompilerRunnerUtil#invokeExecMethod, in Eclipse plugin (KotlinCLICompiler) and in kotlin-gradle-plugin (GradleCompilerRunner)
|
||||
@NotNull
|
||||
public ExitCode execAndOutputXml(@NotNull PrintStream errStream, @NotNull Services services, @NotNull String... args) {
|
||||
@@ -65,90 +57,9 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
return exec(errStream, Services.EMPTY, MessageRenderer.PLAIN_FULL_PATHS, args);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private A parseArguments(@NotNull MessageCollector messageCollector, @NotNull String[] args) {
|
||||
try {
|
||||
A arguments = createArguments();
|
||||
parseArguments(args, arguments);
|
||||
return arguments;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable t) {
|
||||
messageCollector.report(EXCEPTION, OutputMessageUtil.renderException(t), null);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Used in kotlin-maven-plugin (KotlinCompileMojoBase) and in kotlin-gradle-plugin (KotlinJvmOptionsImpl, KotlinJsOptionsImpl)
|
||||
public void parseArguments(@NotNull String[] args, @NotNull A arguments) {
|
||||
ParseCommandLineArgumentsKt.parseCommandLineArguments(args, arguments);
|
||||
String message = ParseCommandLineArgumentsKt.validateArguments(arguments.errors);
|
||||
if (message != null) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract A createArguments();
|
||||
|
||||
@NotNull
|
||||
private ExitCode exec(
|
||||
@NotNull PrintStream errStream,
|
||||
@NotNull Services services,
|
||||
@NotNull MessageRenderer messageRenderer,
|
||||
@NotNull String[] args
|
||||
) {
|
||||
K2JVMCompiler.Companion.resetInitStartTime();
|
||||
|
||||
MessageCollector parseArgumentsCollector = new PrintingMessageCollector(errStream, messageRenderer, false);
|
||||
A arguments;
|
||||
try {
|
||||
arguments = parseArguments(parseArgumentsCollector, args);
|
||||
if (arguments == null) return INTERNAL_ERROR;
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
parseArgumentsCollector.report(ERROR, e.getMessage(), null);
|
||||
parseArgumentsCollector.report(INFO, "Use -help for more information", null);
|
||||
return COMPILATION_ERROR;
|
||||
}
|
||||
|
||||
if (arguments.help || arguments.extraHelp) {
|
||||
Usage.print(errStream, this, arguments);
|
||||
return OK;
|
||||
}
|
||||
|
||||
MessageCollector collector = new PrintingMessageCollector(errStream, messageRenderer, arguments.verbose);
|
||||
|
||||
try {
|
||||
if (PlainTextMessageRenderer.COLOR_ENABLED) {
|
||||
AnsiConsole.systemInstall();
|
||||
}
|
||||
|
||||
errStream.print(messageRenderer.renderPreamble());
|
||||
return exec(collector, services, arguments);
|
||||
}
|
||||
finally {
|
||||
errStream.print(messageRenderer.renderConclusion());
|
||||
|
||||
if (PlainTextMessageRenderer.COLOR_ENABLED) {
|
||||
AnsiConsole.systemUninstall();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Used in kotlin-maven-plugin (KotlinCompileMojoBase)
|
||||
@NotNull
|
||||
public ExitCode exec(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) {
|
||||
printVersionIfNeeded(messageCollector, arguments);
|
||||
|
||||
if (arguments.suppressWarnings) {
|
||||
messageCollector = new FilteringMessageCollector(messageCollector, Predicate.isEqual(WARNING));
|
||||
}
|
||||
|
||||
reportArgumentParseProblems(messageCollector, arguments.errors);
|
||||
|
||||
@Override
|
||||
public ExitCode execImpl(@NotNull MessageCollector messageCollector, @NotNull Services services, @NotNull A arguments) {
|
||||
GroupingMessageCollector groupingCollector = new GroupingMessageCollector(messageCollector);
|
||||
|
||||
CompilerConfiguration configuration = new CompilerConfiguration();
|
||||
@@ -328,63 +239,10 @@ public abstract class CLICompiler<A extends CommonCompilerArguments> {
|
||||
@NotNull CompilerConfiguration configuration, @NotNull A arguments, @NotNull Services services
|
||||
);
|
||||
|
||||
private static void reportArgumentParseProblems(@NotNull MessageCollector collector, @NotNull ArgumentParseErrors errors) {
|
||||
for (String flag : errors.getUnknownExtraFlags()) {
|
||||
collector.report(STRONG_WARNING, "Flag is not supported by this version of the compiler: " + flag, null);
|
||||
}
|
||||
for (String argument : errors.getExtraArgumentsPassedInObsoleteForm()) {
|
||||
collector.report(STRONG_WARNING, "Advanced option value is passed in an obsolete form. Please use the '=' character " +
|
||||
"to specify the value: " + argument + "=...", null);
|
||||
}
|
||||
for (Map.Entry<String, String> argument : errors.getDuplicateArguments().entrySet()) {
|
||||
collector.report(STRONG_WARNING, "Argument " + argument.getKey() + " is passed multiple times. " +
|
||||
"Only the last value will be used: " + argument.getValue(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract ExitCode doExecute(
|
||||
@NotNull A arguments,
|
||||
@NotNull CompilerConfiguration configuration,
|
||||
@NotNull Disposable rootDisposable
|
||||
);
|
||||
|
||||
private void printVersionIfNeeded(@NotNull MessageCollector messageCollector, @NotNull A arguments) {
|
||||
if (arguments.version) {
|
||||
messageCollector.report(
|
||||
CompilerMessageSeverity.INFO,
|
||||
executableScriptFileName() + " " + KotlinCompilerVersion.VERSION +
|
||||
" (JRE " + System.getProperty("java.runtime.version") + ")",
|
||||
null
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public abstract String executableScriptFileName();
|
||||
|
||||
/**
|
||||
* Useful main for derived command line tools
|
||||
*/
|
||||
public static void doMain(@NotNull CLICompiler compiler, @NotNull String[] args) {
|
||||
// We depend on swing (indirectly through PSI or something), so we want to declare headless mode,
|
||||
// to avoid accidentally starting the UI thread
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
ExitCode exitCode = doMainNoExit(compiler, args);
|
||||
if (exitCode != OK) {
|
||||
System.exit(exitCode.getCode());
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("UseOfSystemOutOrSystemErr")
|
||||
@NotNull
|
||||
public static ExitCode doMainNoExit(@NotNull CLICompiler compiler, @NotNull String[] args) {
|
||||
try {
|
||||
return compiler.exec(System.err, args);
|
||||
}
|
||||
catch (CompileEnvironmentException e) {
|
||||
System.err.println(e.getMessage());
|
||||
return INTERNAL_ERROR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.cli.common
|
||||
|
||||
import org.fusesource.jansi.AnsiConsole
|
||||
import org.jetbrains.kotlin.cli.common.arguments.ArgumentParseErrors
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
|
||||
import org.jetbrains.kotlin.cli.common.arguments.validateArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.*
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.CompileEnvironmentException
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import java.io.PrintStream
|
||||
import java.util.function.Predicate
|
||||
|
||||
abstract class CLITool<A : CommonToolArguments> {
|
||||
fun exec(errStream: PrintStream, vararg args: String): ExitCode {
|
||||
return exec(errStream, Services.EMPTY, MessageRenderer.PLAIN_RELATIVE_PATHS, args)
|
||||
}
|
||||
|
||||
protected fun exec(
|
||||
errStream: PrintStream,
|
||||
services: Services,
|
||||
messageRenderer: MessageRenderer,
|
||||
args: Array<out String>
|
||||
): ExitCode {
|
||||
K2JVMCompiler.resetInitStartTime()
|
||||
|
||||
val parseArgumentsCollector = PrintingMessageCollector(errStream, messageRenderer, false)
|
||||
val arguments = try {
|
||||
parseArguments(parseArgumentsCollector, args) ?: return ExitCode.INTERNAL_ERROR
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
parseArgumentsCollector.report(CompilerMessageSeverity.ERROR, e.message!!, null)
|
||||
parseArgumentsCollector.report(CompilerMessageSeverity.INFO, "Use -help for more information", null)
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
}
|
||||
|
||||
if (arguments.help || arguments.extraHelp) {
|
||||
Usage.print(errStream, this, arguments)
|
||||
return ExitCode.OK
|
||||
}
|
||||
|
||||
val collector = PrintingMessageCollector(errStream, messageRenderer, arguments.verbose)
|
||||
|
||||
try {
|
||||
if (PlainTextMessageRenderer.COLOR_ENABLED) {
|
||||
AnsiConsole.systemInstall()
|
||||
}
|
||||
|
||||
errStream.print(messageRenderer.renderPreamble())
|
||||
return exec(collector, services, arguments)
|
||||
}
|
||||
finally {
|
||||
errStream.print(messageRenderer.renderConclusion())
|
||||
|
||||
if (PlainTextMessageRenderer.COLOR_ENABLED) {
|
||||
AnsiConsole.systemUninstall()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun exec(messageCollector: MessageCollector, services: Services, arguments: A): ExitCode {
|
||||
printVersionIfNeeded(messageCollector, arguments)
|
||||
|
||||
val fixedMessageCollector = if (arguments.suppressWarnings) {
|
||||
FilteringMessageCollector(messageCollector, Predicate.isEqual(CompilerMessageSeverity.WARNING))
|
||||
}
|
||||
else {
|
||||
messageCollector
|
||||
}
|
||||
|
||||
reportArgumentParseProblems(fixedMessageCollector, arguments.errors)
|
||||
return execImpl(fixedMessageCollector, services, arguments)
|
||||
}
|
||||
|
||||
// Used in kotlin-maven-plugin (KotlinCompileMojoBase)
|
||||
protected abstract fun execImpl(messageCollector: MessageCollector, services: Services, arguments: A): ExitCode
|
||||
|
||||
private fun parseArguments(messageCollector: MessageCollector, args: Array<out String>): A? {
|
||||
return try {
|
||||
createArguments().also { parseArguments(args, it) }
|
||||
}
|
||||
catch (e: IllegalArgumentException) {
|
||||
throw e
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
messageCollector.report(CompilerMessageSeverity.EXCEPTION, OutputMessageUtil.renderException(t), null)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract fun createArguments(): A
|
||||
|
||||
// Used in kotlin-maven-plugin (KotlinCompileMojoBase) and in kotlin-gradle-plugin (KotlinJvmOptionsImpl, KotlinJsOptionsImpl)
|
||||
fun parseArguments(args: Array<out String>, arguments: A) {
|
||||
parseCommandLineArguments(args, arguments)
|
||||
val message = validateArguments(arguments.errors)
|
||||
if (message != null) {
|
||||
throw IllegalArgumentException(message)
|
||||
}
|
||||
}
|
||||
|
||||
private fun reportArgumentParseProblems(collector: MessageCollector, errors: ArgumentParseErrors) {
|
||||
for (flag in errors.unknownExtraFlags) {
|
||||
collector.report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
"Flag is not supported by this version of the compiler: " + flag, null)
|
||||
}
|
||||
for (argument in errors.extraArgumentsPassedInObsoleteForm) {
|
||||
collector.report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
"Advanced option value is passed in an obsolete form. Please use the '=' character " +
|
||||
"to specify the value: " + argument + "=...", null)
|
||||
}
|
||||
for ((key, value) in errors.duplicateArguments) {
|
||||
collector.report(
|
||||
CompilerMessageSeverity.STRONG_WARNING,
|
||||
"Argument $key is passed multiple times. Only the last value will be used: $value", null)
|
||||
}
|
||||
}
|
||||
|
||||
protected fun <A : CommonToolArguments> printVersionIfNeeded(messageCollector: MessageCollector, arguments: A) {
|
||||
if (!arguments.version) return
|
||||
|
||||
if (arguments.version) {
|
||||
val jreVersion = System.getProperty("java.runtime.version")
|
||||
messageCollector.report(CompilerMessageSeverity.INFO,
|
||||
"${executableScriptFileName()} ${KotlinCompilerVersion.VERSION} (JRE $jreVersion)",
|
||||
null
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
abstract fun executableScriptFileName(): String
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Useful main for derived command line tools
|
||||
*/
|
||||
@JvmStatic
|
||||
fun doMain(compiler: CLITool<*>, args: Array<String>) {
|
||||
// We depend on swing (indirectly through PSI or something), so we want to declare headless mode,
|
||||
// to avoid accidentally starting the UI thread
|
||||
System.setProperty("java.awt.headless", "true")
|
||||
val exitCode = doMainNoExit(compiler, args)
|
||||
if (exitCode != ExitCode.OK) {
|
||||
System.exit(exitCode.code)
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun doMainNoExit(compiler: CLITool<*>, args: Array<String>): ExitCode {
|
||||
try {
|
||||
return compiler.exec(System.err, *args)
|
||||
}
|
||||
catch (e: CompileEnvironmentException) {
|
||||
System.err.println(e.message)
|
||||
return ExitCode.INTERNAL_ERROR
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.kotlin.cli.common;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.Argument;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonToolArguments;
|
||||
import org.jetbrains.kotlin.cli.common.arguments.ParseCommandLineArgumentsKt;
|
||||
|
||||
import java.io.PrintStream;
|
||||
@@ -29,8 +29,8 @@ class Usage {
|
||||
// The magic number 29 corresponds to the similar padding width in javac and scalac command line compilers
|
||||
private static final int OPTION_NAME_PADDING_WIDTH = 29;
|
||||
|
||||
public static <A extends CommonCompilerArguments> void print(
|
||||
@NotNull PrintStream target, @NotNull CLICompiler<A> compiler, @NotNull A arguments
|
||||
public static <A extends CommonToolArguments> void print(
|
||||
@NotNull PrintStream target, @NotNull CLITool<A> compiler, @NotNull A arguments
|
||||
) {
|
||||
target.println("Usage: " + compiler.executableScriptFileName() + " <options> <source files>");
|
||||
target.println("where " + (arguments.extraHelp ? "advanced" : "possible") + " options include:");
|
||||
|
||||
@@ -14,20 +14,91 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
@file:JvmName("K2JSDce")
|
||||
package org.jetbrains.kotlin.cli.js.dce
|
||||
|
||||
import org.jetbrains.kotlin.cli.common.CLITool
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JSDceArguments
|
||||
import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
|
||||
import org.jetbrains.kotlin.config.Services
|
||||
import org.jetbrains.kotlin.js.dce.DeadCodeElimination
|
||||
import org.jetbrains.kotlin.js.dce.InputFile
|
||||
import org.jetbrains.kotlin.js.dce.extractRoots
|
||||
import org.jetbrains.kotlin.js.dce.printTree
|
||||
import java.io.File
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val files = args.map { InputFile(it) }
|
||||
val nodes = DeadCodeElimination.run(files, emptySet()) { println(it) }
|
||||
class K2JSDce : CLITool<K2JSDceArguments>() {
|
||||
override fun createArguments(): K2JSDceArguments = K2JSDceArguments()
|
||||
|
||||
println()
|
||||
for (node in nodes.extractRoots()) {
|
||||
printTree(node, { println(it) }, printNestedMembers = false, showLocations = true)
|
||||
override fun execImpl(messageCollector: MessageCollector, services: Services, arguments: K2JSDceArguments): ExitCode {
|
||||
val baseDir = File(arguments.outputDirectory ?: "min")
|
||||
val files = arguments.freeArgs.map { arg ->
|
||||
val parts = arg.split(File.pathSeparator, ignoreCase = false, limit = 2)
|
||||
val inputName = parts[0]
|
||||
val moduleName = parts.getOrNull(1) ?: ""
|
||||
val resolvedModuleName = if (!moduleName.isEmpty()) moduleName else File(inputName).nameWithoutExtension
|
||||
InputFile(inputName, File(baseDir, resolvedModuleName + ".js").absolutePath, resolvedModuleName)
|
||||
}
|
||||
|
||||
if (files.isEmpty() && !arguments.version) {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "no source files")
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
}
|
||||
if (!checkSourceFiles(messageCollector, files)) {
|
||||
return ExitCode.COMPILATION_ERROR
|
||||
}
|
||||
|
||||
val dceResult = DeadCodeElimination.run(files, emptySet()) {
|
||||
messageCollector.report(CompilerMessageSeverity.LOGGING, it)
|
||||
}
|
||||
val nodes = dceResult.reachableNodes
|
||||
|
||||
val reachabilitySeverity = if (arguments.printReachabilityInfo) CompilerMessageSeverity.INFO else CompilerMessageSeverity.LOGGING
|
||||
messageCollector.report(reachabilitySeverity, "")
|
||||
for (node in nodes.extractRoots()) {
|
||||
printTree(node, { messageCollector.report(reachabilitySeverity, it) },
|
||||
printNestedMembers = false, showLocations = true)
|
||||
}
|
||||
|
||||
return ExitCode.OK
|
||||
}
|
||||
|
||||
private fun checkSourceFiles(messageCollector: MessageCollector, files: List<InputFile>): Boolean {
|
||||
return files.fold(true) { ok, file ->
|
||||
val inputFile = File(file.path)
|
||||
val outputFile = File(file.outputPath)
|
||||
|
||||
val inputOk = when {
|
||||
!inputFile.exists() -> {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "source file or directory not found: " + file.path)
|
||||
false
|
||||
}
|
||||
inputFile.isDirectory -> {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "input file '" + file.path + "' is a directory")
|
||||
false
|
||||
}
|
||||
else -> true
|
||||
}
|
||||
|
||||
val outputOk = when {
|
||||
outputFile.exists() && outputFile.isDirectory -> {
|
||||
messageCollector.report(CompilerMessageSeverity.ERROR, "cannot open output file '${outputFile.path}': is a directory")
|
||||
false
|
||||
}
|
||||
else -> true
|
||||
}
|
||||
|
||||
ok and inputOk and outputOk
|
||||
}
|
||||
}
|
||||
|
||||
override fun executableScriptFileName(): String = "kotlin-dce-js"
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
CLITool.doMain(K2JSDce(), args)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import com.intellij.ide.highlighter.JavaFileType
|
||||
import com.intellij.openapi.Disposable
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.CLITool
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode.*
|
||||
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
|
||||
@@ -309,7 +310,7 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
|
||||
}
|
||||
|
||||
@JvmStatic fun main(args: Array<String>) {
|
||||
CLICompiler.doMain(K2JVMCompiler(), args)
|
||||
CLITool.doMain(K2JVMCompiler(), args)
|
||||
}
|
||||
|
||||
fun reportPerf(configuration: CompilerConfiguration, message: String) {
|
||||
|
||||
+1
@@ -0,0 +1 @@
|
||||
-help
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
Usage: kotlin-dce-js <options> <source files>
|
||||
where possible options include:
|
||||
-output-dir <path> Output directory
|
||||
-help (-h) Print a synopsis of standard options
|
||||
-X Print a synopsis of advanced options
|
||||
-version Display compiler version
|
||||
-verbose Enable verbose logging output
|
||||
-nowarn Generate no warnings
|
||||
OK
|
||||
@@ -0,0 +1,2 @@
|
||||
-output-dir
|
||||
$TESTDATA_DIR$/min
|
||||
@@ -0,0 +1,2 @@
|
||||
error: no source files
|
||||
COMPILATION_ERROR
|
||||
@@ -0,0 +1,8 @@
|
||||
info:
|
||||
info: <unknown>
|
||||
info: global
|
||||
info: bar (reachable)
|
||||
info: foo (reachable)
|
||||
info: include
|
||||
info: baz (reachable from include.js:14)
|
||||
OK
|
||||
@@ -0,0 +1 @@
|
||||
-X
|
||||
@@ -0,0 +1,6 @@
|
||||
Usage: kotlin-dce-js <options> <source files>
|
||||
where advanced options include:
|
||||
-Xprint-reachability-info Print declarations marked as reachable
|
||||
|
||||
Advanced options are non-standard and may be changed or removed without any notice.
|
||||
OK
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
function bar() {
|
||||
return 'bar';
|
||||
}
|
||||
console.log(bar());
|
||||
@@ -0,0 +1,3 @@
|
||||
nonExistingSourceFile.js
|
||||
-output-dir
|
||||
$TEMP_DIR/min
|
||||
@@ -0,0 +1,2 @@
|
||||
error: source file or directory not found: nonExistingSourceFile.js
|
||||
COMPILATION_ERROR
|
||||
@@ -0,0 +1 @@
|
||||
// ABSENT: min/nonExistingSourceFile.js
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
$TESTDATA_DIR$
|
||||
-output-dir
|
||||
$TEMP_DIR/min
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
error: input file 'compiler/testData/cli/js-dce' is a directory
|
||||
COMPILATION_ERROR
|
||||
@@ -0,0 +1,3 @@
|
||||
$TESTDATA_DIR$/simple.js
|
||||
-output-dir
|
||||
$TESTDATA_DIR$/min
|
||||
@@ -0,0 +1,2 @@
|
||||
error: cannot open output file '$TESTDATA_DIR$/min/simple.js': is a directory
|
||||
COMPILATION_ERROR
|
||||
@@ -0,0 +1 @@
|
||||
// ABSENT: out.js
|
||||
@@ -0,0 +1,3 @@
|
||||
$TESTDATA_DIR$/simple.js:bar
|
||||
-output-dir
|
||||
$TEMP_DIR$/min
|
||||
@@ -0,0 +1 @@
|
||||
OK
|
||||
@@ -0,0 +1 @@
|
||||
// EXISTS: min/bar.js
|
||||
@@ -0,0 +1,4 @@
|
||||
$TESTDATA_DIR$/simple.js
|
||||
-output-dir
|
||||
$TEMP_DIR$/min
|
||||
-Xprint-reachability-info
|
||||
@@ -0,0 +1,6 @@
|
||||
info:
|
||||
info: <unknown>
|
||||
info: bar (reachable from simple.js:7)
|
||||
info: console
|
||||
info: log (reachable from simple.js:7)
|
||||
OK
|
||||
@@ -0,0 +1 @@
|
||||
// EXISTS: min/simple.js
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
$TESTDATA_DIR$/simple.js
|
||||
-output-dir
|
||||
$TEMP_DIR$/min
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
function foo() {
|
||||
return "foo";
|
||||
}
|
||||
function bar() {
|
||||
return "bar";
|
||||
}
|
||||
console.log(bar());
|
||||
+1
@@ -0,0 +1 @@
|
||||
OK
|
||||
+1
@@ -0,0 +1 @@
|
||||
// EXISTS: min/simple.js
|
||||
Vendored
+5
-5
@@ -13,11 +13,11 @@ where possible options include:
|
||||
-output-postfix <path> Path to file which will be added to the end of output file
|
||||
-language-version <version> Provide source compatibility with specified language version
|
||||
-api-version <version> Allow to use declarations only from the specified version of bundled libraries
|
||||
-nowarn Generate no warnings
|
||||
-verbose Enable verbose logging output
|
||||
-version Display compiler version
|
||||
-help (-h) Print a synopsis of standard options
|
||||
-X Print a synopsis of advanced options
|
||||
-P plugin:<pluginId>:<optionName>=<value>
|
||||
Pass an option to a plugin
|
||||
-help (-h) Print a synopsis of standard options
|
||||
-X Print a synopsis of advanced options
|
||||
-version Display compiler version
|
||||
-verbose Enable verbose logging output
|
||||
-nowarn Generate no warnings
|
||||
OK
|
||||
Vendored
+5
-5
@@ -17,11 +17,11 @@ where possible options include:
|
||||
-java-parameters Generate metadata for Java 1.8 reflection on method parameters
|
||||
-language-version <version> Provide source compatibility with specified language version
|
||||
-api-version <version> Allow to use declarations only from the specified version of bundled libraries
|
||||
-nowarn Generate no warnings
|
||||
-verbose Enable verbose logging output
|
||||
-version Display compiler version
|
||||
-help (-h) Print a synopsis of standard options
|
||||
-X Print a synopsis of advanced options
|
||||
-P plugin:<pluginId>:<optionName>=<value>
|
||||
Pass an option to a plugin
|
||||
-help (-h) Print a synopsis of standard options
|
||||
-X Print a synopsis of advanced options
|
||||
-version Display compiler version
|
||||
-verbose Enable verbose logging output
|
||||
-nowarn Generate no warnings
|
||||
OK
|
||||
@@ -25,8 +25,10 @@ import kotlin.io.FilesKt;
|
||||
import kotlin.text.Charsets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler;
|
||||
import org.jetbrains.kotlin.cli.common.CLITool;
|
||||
import org.jetbrains.kotlin.cli.common.ExitCode;
|
||||
import org.jetbrains.kotlin.cli.js.K2JSCompiler;
|
||||
import org.jetbrains.kotlin.cli.js.dce.K2JSDce;
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler;
|
||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion;
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmMetadataVersion;
|
||||
@@ -48,12 +50,12 @@ import java.util.List;
|
||||
|
||||
public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
||||
@NotNull
|
||||
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLICompiler<?> compiler, @NotNull List<String> args) {
|
||||
public static Pair<String, ExitCode> executeCompilerGrabOutput(@NotNull CLITool<?> compiler, @NotNull List<String> args) {
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
PrintStream origErr = System.err;
|
||||
try {
|
||||
System.setErr(new PrintStream(bytes));
|
||||
ExitCode exitCode = CLICompiler.doMainNoExit(compiler, ArrayUtil.toStringArray(args));
|
||||
ExitCode exitCode = CLITool.doMainNoExit(compiler, ArrayUtil.toStringArray(args));
|
||||
return new Pair<>(bytes.toString("utf-8"), exitCode);
|
||||
}
|
||||
catch (Exception e) {
|
||||
@@ -79,7 +81,7 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
||||
return normalizedOutputWithoutExitCode + exitCode;
|
||||
}
|
||||
|
||||
private void doTest(@NotNull String fileName, @NotNull CLICompiler<?> compiler) throws Exception {
|
||||
private void doTest(@NotNull String fileName, @NotNull CLITool<?> compiler) throws Exception {
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
Pair<String, ExitCode> outputAndExitCode = executeCompilerGrabOutput(compiler, readArgs(fileName, tmpdir.getPath()));
|
||||
String actual = getNormalizedCompilerOutput(
|
||||
@@ -153,6 +155,10 @@ public abstract class AbstractCliTest extends TestCaseWithTmpdir {
|
||||
doTest(fileName, new K2JSCompiler());
|
||||
}
|
||||
|
||||
protected void doJsDceTest(@NotNull String fileName) throws Exception {
|
||||
doTest(fileName, new K2JSDce());
|
||||
}
|
||||
|
||||
public static String removePerfOutput(String output) {
|
||||
String[] lines = StringUtil.splitByLinesKeepSeparators(output);
|
||||
StringBuilder result = new StringBuilder();
|
||||
|
||||
@@ -539,4 +539,67 @@ public class CliTestGenerated extends AbstractCliTest {
|
||||
doJsTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/cli/js-dce")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Js_dce extends AbstractCliTest {
|
||||
public void testAllFilesPresentInJs_dce() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/cli/js-dce"), Pattern.compile("^(.+)\\.args$"), TargetBackend.ANY, false);
|
||||
}
|
||||
|
||||
@TestMetadata("dceHelp.args")
|
||||
public void testDceHelp() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/dceHelp.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("emptySources.args")
|
||||
public void testEmptySources() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/emptySources.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("jsExtraHelp.args")
|
||||
public void testJsExtraHelp() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/jsExtraHelp.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("nonExistingSourcePath.args")
|
||||
public void testNonExistingSourcePath() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/nonExistingSourcePath.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("notFile.args")
|
||||
public void testNotFile() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/notFile.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("outputIsDirectory.args")
|
||||
public void testOutputIsDirectory() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/outputIsDirectory.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overrideOutputName.args")
|
||||
public void testOverrideOutputName() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/overrideOutputName.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("printReachability.args")
|
||||
public void testPrintReachability() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/printReachability.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("simple.args")
|
||||
public void testSimple() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/js-dce/simple.args");
|
||||
doJsDceTest(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ fun generateKotlinGradleOptions(withPrinterToFile: (targetFile: File, Printer.()
|
||||
|
||||
// common interface
|
||||
val commonInterfaceFqName = FqName("org.jetbrains.kotlin.gradle.dsl.KotlinCommonOptions")
|
||||
val commonOptions = gradleOptions<CommonCompilerArguments>()
|
||||
val commonOptions = gradleOptions<CommonCompilerArguments>() + gradleOptions<CommonToolArguments>()
|
||||
val additionalOptions = gradleOptions<AdditionalGradleProperties>()
|
||||
withPrinterToFile(File(srcDir, commonInterfaceFqName)) {
|
||||
generateInterface(commonInterfaceFqName,
|
||||
|
||||
@@ -377,6 +377,7 @@ fun main(args: Array<String>) {
|
||||
testClass<AbstractCliTest> {
|
||||
model("cli/jvm", extension = "args", testMethod = "doJvmTest", recursive = false)
|
||||
model("cli/js", extension = "args", testMethod = "doJsTest", recursive = false)
|
||||
model("cli/js-dce", extension = "args", testMethod = "doJsDceTest", recursive = false)
|
||||
}
|
||||
|
||||
testClass<AbstractReplInterpreterTest> {
|
||||
|
||||
@@ -207,7 +207,7 @@ class JpsKotlinCompilerRunner : KotlinCompilerRunner<JpsCompilerEnvironment>() {
|
||||
private fun setupK2JsArguments(_outputFile: File, sourceFiles: Collection<File>, _libraries: List<String>, _friendModules: List<String>, settings: K2JSCompilerArguments) {
|
||||
with(settings) {
|
||||
noStdlib = true
|
||||
freeArgs = sourceFiles.map { it.path }
|
||||
freeArgs = sourceFiles.map { it.path }.toMutableList()
|
||||
outputFile = _outputFile.path
|
||||
metaInfo = true
|
||||
libraries = _libraries.joinToString(File.pathSeparator)
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@ package org.jetbrains.kotlin.sourceSections
|
||||
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.cli.common.CLICompiler
|
||||
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.kotlin.cli.common.CLITool
|
||||
import org.jetbrains.kotlin.cli.common.messages.*
|
||||
import org.jetbrains.kotlin.cli.jvm.K2JVMCompiler
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
@@ -179,7 +179,7 @@ class SourceSectionsTest : TestCaseWithTmpdir() {
|
||||
"-Xplugin=${sourceSectionsPluginJar.canonicalPath}",
|
||||
"-P", TEST_ALLOWED_SECTIONS.joinToString(",") { "plugin:${SourceSectionsCommandLineProcessor.PLUGIN_ID}:${SourceSectionsCommandLineProcessor.SECTIONS_OPTION.name}=$it" })
|
||||
val (output, code) = captureOut {
|
||||
CLICompiler.doMainNoExit(K2JVMCompiler(), args)
|
||||
CLITool.doMainNoExit(K2JVMCompiler(), args)
|
||||
}
|
||||
|
||||
TestCase.assertEquals("Compilation failed:\n$output", 0, code.code)
|
||||
|
||||
Reference in New Issue
Block a user