set default language and api levels for kotlinc to 2.2; remove unneeded apis

GitOrigin-RevId: 14136fd409db418902b85c0decf57b75affa9f4e
This commit is contained in:
Eugene Zhuravlev
2025-05-31 22:05:25 +02:00
committed by intellij-monorepo-bot
parent c2b77977bb
commit bd4de1c2b9
6 changed files with 35 additions and 98 deletions

View File

@@ -8,7 +8,10 @@ import com.intellij.tools.build.bazel.jvmIncBuilder.impl.graph.LibraryGraphLoade
import com.intellij.tools.build.bazel.jvmIncBuilder.instrumentation.FailSafeClassReader;
import com.intellij.tools.build.bazel.jvmIncBuilder.instrumentation.InstrumentationClassFinder;
import com.intellij.tools.build.bazel.jvmIncBuilder.instrumentation.InstrumenterClassWriter;
import com.intellij.tools.build.bazel.jvmIncBuilder.runner.*;
import com.intellij.tools.build.bazel.jvmIncBuilder.runner.BytecodeInstrumenter;
import com.intellij.tools.build.bazel.jvmIncBuilder.runner.CompilerRunner;
import com.intellij.tools.build.bazel.jvmIncBuilder.runner.OutputFile;
import com.intellij.tools.build.bazel.jvmIncBuilder.runner.OutputOrigin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.dependency.*;
import org.jetbrains.jps.dependency.java.JVMClassNode;
@@ -179,7 +182,7 @@ public class BazelIncBuilder {
if (!srcSnapshotDelta.isRecompileAll()) {
// delete outputs corresponding to deleted or recompiled sources
for (CompilerRunner compiler : roundCompilers) {
cleanOutputsForCompiledFiles(context, srcSnapshotDelta, storageManager.getGraph(), compiler, outSink);
cleanOutputsForCompiledFiles(context, srcSnapshotDelta, storageManager.getGraph(), compiler, storageManager.getCompositeOutputBuilder());
}
}
@@ -258,7 +261,7 @@ public class BazelIncBuilder {
private static void runInstrumenters(OutputSinkImpl outSink, StorageManager storageManager, List<BytecodeInstrumenter> instrumenters, DiagnosticSink diagnostic) throws IOException {
for (OutputOrigin.Kind originKind : OutputOrigin.Kind.values()) {
for (String generatedFile : outSink.getOutputPaths(originKind, OutputFile.Kind.bytecode)) {
for (String generatedFile : outSink.getGeneratedOutputPaths(originKind, OutputFile.Kind.bytecode)) {
boolean changes = false;
byte[] content = null;
ClassReader reader = null;
@@ -339,20 +342,20 @@ public class BazelIncBuilder {
return srcSnapshotDelta.isRecompileAll() || srcSnapshotDelta.getChangedPercent() > RECOMPILE_CHANGED_RATIO_PERCENT;
}
private static void cleanOutputsForCompiledFiles(BuildContext context, NodeSourceSnapshotDelta snapshotDelta, DependencyGraph depGraph, CompilerRunner compiler, OutputSink outSink) {
private static void cleanOutputsForCompiledFiles(BuildContext context, NodeSourceSnapshotDelta snapshotDelta, DependencyGraph depGraph, CompilerRunner compiler, ZipOutputBuilder outBuilder) {
// separately logging deleted outputs for 'deleted' and 'modified' sources to adjust for existing test data
Collection<String> cleanedOutputsOfDeletedSources = deleteCompilerOutputs(
depGraph, filter(snapshotDelta.getDeleted(), compiler::canCompile), outSink, new ArrayList<>()
depGraph, filter(snapshotDelta.getDeleted(), compiler::canCompile), outBuilder, new ArrayList<>()
);
logDeletedPaths(context, cleanedOutputsOfDeletedSources);
Collection<String> cleanedOutputsOfModifiedSources = deleteCompilerOutputs(
depGraph, filter(snapshotDelta.getModified(), compiler::canCompile), outSink, new ArrayList<>()
depGraph, filter(snapshotDelta.getModified(), compiler::canCompile), outBuilder, new ArrayList<>()
);
if (!cleanedOutputsOfDeletedSources.isEmpty() || !cleanedOutputsOfModifiedSources.isEmpty()) {
// delete additional paths only if there are any changes in the output caused by changes in sources
for (String toDelete : compiler.getOutputPathsToDelete()) {
if (outSink.deletePath(toDelete)) {
if (outBuilder.deleteEntry(toDelete)) {
cleanedOutputsOfModifiedSources.add(toDelete);
}
}
@@ -361,11 +364,11 @@ public class BazelIncBuilder {
}
private static Collection<String> deleteCompilerOutputs(
DependencyGraph depGraph, Iterable<@NotNull NodeSource> sourcesToCompile, OutputSink outSink, Collection<String> deletedPathsAcc
DependencyGraph depGraph, Iterable<@NotNull NodeSource> sourcesToCompile, ZipOutputBuilder outBuilder, Collection<String> deletedPathsAcc
) {
for (Node<?, ?> node : filter(flat(map(sourcesToCompile, depGraph::getNodes)), n -> n instanceof JVMClassNode)) {
String outputPath = ((JVMClassNode<?, ?>) node).getOutFilePath();
if (outSink.deletePath(outputPath)) {
if (outBuilder.deleteEntry(outputPath)) {
deletedPathsAcc.add(outputPath);
}
}

View File

@@ -58,7 +58,10 @@ public class JavaAbiFilter implements ZipOutputBuilder {
private byte @Nullable [] filterAbiJarContent(String entryName, byte[] content) {
if (content == null || !entryName.endsWith(".class")) {
if (entryName.endsWith(".java")) {
return null; // do not save AP-produced sources in abi jar
// do not save annotation processors (AP)-produced sources in abi jar
// AP generate sources that we must store somewhere during the compilation to give them back to javac, if it needs them.
// Eventually those sources are deleted from the output. With this check the JavaAbiFilter filter ensures that no sources get into the ABI output.
return null;
}
return content; // no instrumentation, if the entry is not a class file, or the class finder is not specified
}

View File

@@ -9,7 +9,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.builders.impl.java.JavacCompilerTool;
import org.jetbrains.jps.dependency.NodeSource;
import org.jetbrains.jps.dependency.NodeSourcePathMapper;
import org.jetbrains.jps.dependency.Usage;
import org.jetbrains.jps.incremental.BinaryContent;
import org.jetbrains.jps.javac.*;
import org.jetbrains.jps.javac.ast.api.JavacDef;
@@ -41,12 +40,14 @@ public class JavaCompilerRunner implements CompilerRunner {
private final BuildContext myContext;
private final List<String> myOptions;
private final StorageManager myStorageManager;
private final ModulePath myModulePath;
private final Iterable<File> myClassPath;
public JavaCompilerRunner(BuildContext context, StorageManager storageManager) {
myContext = context;
myOptions = getFilteredOptions(context);
myStorageManager = storageManager;
NodeSourcePathMapper pathMapper = context.getPathMapper();
Collection<File> classpath = collect(map(context.getBinaryDependencies().getElements(), ns -> pathMapper.toPath(ns).toFile()), new ArrayList<>());
@@ -96,8 +97,7 @@ public class JavaCompilerRunner implements CompilerRunner {
@Override
public ExitCode compile(Iterable<NodeSource> sources, Iterable<NodeSource> deletedSources, DiagnosticSink diagnosticSink, OutputSink outSink) throws Exception {
NodeSourcePathMapper pathMapper = myContext.getPathMapper();
SourcesFilteringOutputSink srcFilteringSink = new SourcesFilteringOutputSink(outSink);
OutputCollector outCollector = new OutputCollector(this, pathMapper, diagnosticSink, srcFilteringSink);
OutputCollector outCollector = new OutputCollector(this, pathMapper, diagnosticSink, outSink);
JavacCompilerTool javacTool = new JavacCompilerTool();
// set non-null output, pointing to a non-existent dir. Need this to enable JavacFileManager creating OutputFileObjects
Map<File, Set<File>> outputDir = Map.of(myContext.getDataDir().resolve("__temp__").toFile(), Set.of());
@@ -126,8 +126,9 @@ public class JavaCompilerRunner implements CompilerRunner {
return compileOk ? ExitCode.OK : ExitCode.ERROR;
}
finally {
for (String generatedSourcesPath : srcFilteringSink.getGeneratedSourcesPaths()) {
outSink.deletePath(generatedSourcesPath); // for now, remove generated sources from the resulting artifact
ZipOutputBuilder outputBuilder = myStorageManager.getCompositeOutputBuilder();
for (String generatedSourcesPath : outSink.getGeneratedOutputPaths(OutputOrigin.Kind.java, OutputFile.Kind.source)) {
outputBuilder.deleteEntry(generatedSourcesPath); // for now, remove generated sources from the resulting artifact
}
}
}
@@ -359,74 +360,4 @@ public class JavaCompilerRunner implements CompilerRunner {
return options;
}
private static final class SourcesFilteringOutputSink implements OutputSink {
private final OutputSink myDelegate;
private final Set<String> myGeneratedSourcesPaths = new HashSet<>();
SourcesFilteringOutputSink(OutputSink delegate) {
myDelegate = delegate;
}
@Override
public void addFile(OutputFile outFile, OutputOrigin origin) {
if (outFile.getKind() == OutputFile.Kind.source) {
myGeneratedSourcesPaths.add(outFile.getPath());
}
myDelegate.addFile(outFile, origin);
}
public Iterable<String> getGeneratedSourcesPaths() {
return myGeneratedSourcesPaths;
}
@Override
public boolean deletePath(String path) {
return myDelegate.deletePath(path);
}
@Override
public Iterable<String> list(String packageName, boolean recurse) {
return myDelegate.list(packageName, recurse);
}
@Override
public Iterable<String> listFiles(String packageName, boolean recurse) {
return myDelegate.listFiles(packageName, recurse);
}
@Override
public byte @Nullable [] getFileContent(String path) {
return myDelegate.getFileContent(path);
}
@Override
public void registerImports(String className, Collection<String> classImports, Collection<String> staticImports) {
myDelegate.registerImports(className, classImports, staticImports);
}
@Override
public void registerConstantReferences(String className, Collection<ConstantRef> cRefs) {
myDelegate.registerConstantReferences(className, cRefs);
}
@Override
public void registerUsage(String className, Usage usage) {
myDelegate.registerUsage(className, usage);
}
@Override
public void registerUsage(NodeSource source, Usage usage) {
myDelegate.registerUsage(source, usage);
}
@Override
public Iterable<NodeWithSources> getNodes() {
return myDelegate.getNodes();
}
@Override
public Iterable<String> getOutputPaths(OutputOrigin.Kind originKind, OutputFile.Kind outputKind) {
return myDelegate.getOutputPaths(originKind, outputKind);
}
}
}

View File

@@ -341,8 +341,17 @@ public class KotlinCompilerRunner implements CompilerRunner {
arguments.setSkipPrereleaseCheck(true);
arguments.setAllowUnstableDependencies(true);
arguments.setDisableStandardScript(true);
arguments.setApiVersion("2.1"); // todo: find a way to configure this in input parameters
arguments.setLanguageVersion("2.1"); // todo: find a way to configure this in input parameters
if (arguments.getLanguageVersion() == null && arguments.getApiVersion() == null) {
// defaults
arguments.setApiVersion("2.2"); // todo: find a way to configure this in input parameters
arguments.setLanguageVersion("2.2"); // todo: find a way to configure this in input parameters
}
else if (arguments.getLanguageVersion() == null) {
arguments.setLanguageVersion(arguments.getApiVersion());
}
else if (arguments.getApiVersion() == null) {
arguments.setApiVersion(arguments.getLanguageVersion());
}
arguments.setAllowKotlinPackage(CLFlags.ALLOW_KOTLIN_PACKAGE.isFlagSet(flags));
arguments.setWhenGuards(CLFlags.WHEN_GUARDS.isFlagSet(flags));
arguments.setLambdas(CLFlags.LAMBDAS.getOptionalScalarValue(flags));

View File

@@ -22,7 +22,6 @@ import java.util.*;
public class OutputSinkImpl implements OutputSink {
private static final String IMPORT_WILDCARD_SUFFIX = ".*";
private final ZipOutputBuilder myOut;
private final ZipOutputBuilder myComposite;
private @Nullable final ZipOutputBuilder myAbiOut;
private @Nullable final ZipOutputBuilder myJavaAbiOut;
private final Map<OutputOrigin.Kind, Map<OutputFile.Kind, Set<String>>> myOutputsIndex = new EnumMap<>(OutputOrigin.Kind.class);
@@ -38,7 +37,6 @@ public class OutputSinkImpl implements OutputSink {
public OutputSinkImpl(StorageManager sm) throws IOException {
myOut = sm.getOutputBuilder();
myComposite = sm.getCompositeOutputBuilder();
myAbiOut = sm.getAbiOutputBuilder();
myJavaAbiOut = myAbiOut != null? new JavaAbiFilter(myAbiOut, sm.getInstrumentationClassFinder()) : null;
}
@@ -50,15 +48,10 @@ public class OutputSinkImpl implements OutputSink {
}
@Override
public Iterable<String> getOutputPaths(OutputOrigin.Kind originKind, OutputFile.Kind outputKind) {
public Iterable<String> getGeneratedOutputPaths(OutputOrigin.Kind originKind, OutputFile.Kind outputKind) {
return getOutputs(originKind, outputKind);
}
@Override
public boolean deletePath(String path) {
return myComposite.deleteEntry(path);
}
@Override
public Iterable<String> listFiles(String packageName, boolean recurse) {
String dirName = packageName.replace('.', '/') + "/";

View File

@@ -20,7 +20,5 @@ public interface OutputSink extends OutputExplorer, CompilerDataSink{
void addFile(OutputFile outFile, OutputOrigin origin);
Iterable<String> getOutputPaths(OutputOrigin.Kind originKind, OutputFile.Kind outputKind);
boolean deletePath(String path);
Iterable<String> getGeneratedOutputPaths(OutputOrigin.Kind originKind, OutputFile.Kind outputKind);
}