always specify all java deps for kotlinc; support CONTEXT_PARAMETERS option

Merge-request: IJ-MR-166812
Merged-by: Eugene Zhuravlev <eugene.zhuravlev@jetbrains.com>

GitOrigin-RevId: 5d1f6e62e9c4320a5f9bc9f0a5a42573e2da6fb8
This commit is contained in:
Eugene Zhuravlev
2025-06-24 21:10:43 +00:00
committed by intellij-monorepo-bot
parent ba5bb522c6
commit 4280df9a08
2 changed files with 11 additions and 7 deletions
@@ -34,6 +34,7 @@ public enum CLFlags {
JVM_DEFAULT,
INLINE_CLASSES,
CONTEXT_RECEIVERS,
CONTEXT_PARAMETERS,
WARN,
@@ -64,6 +64,7 @@ public class KotlinCompilerRunner implements CompilerRunner {
private EnumWhenTrackerImpl enumWhenTracker;
private ImportTrackerImpl importTracker;
private final @NotNull Map<@NotNull String, @NotNull String> myPluginIdToPluginClasspath = new HashMap<>();
private final List<String> myJavaSources;
private final @Nullable String myModuleEntryPath;
private byte @Nullable [] myLastGoodModuleEntryContent;
@@ -80,6 +81,10 @@ public class KotlinCompilerRunner implements CompilerRunner {
myPluginIdToPluginClasspath.put(pluginId, pluginCp.hasNext()? pluginCp.next() : "");
}
myJavaSources = collect(
map(filter(context.getSources().getElements(), KotlinCompilerRunner::isJavaSource), ns -> myPathMapper.toPath(ns).toString()), new ArrayList<>()
);
String moduleEntryPath = null;
try {
ZipOutputBuilderImpl outBuilder = storageManager.getOutputBuilder();
@@ -101,7 +106,7 @@ public class KotlinCompilerRunner implements CompilerRunner {
@Override
public boolean canCompile(NodeSource src) {
return isKotlinSource(src) || isJavaSource(src);
return isKotlinSource(src);
}
private static boolean isKotlinSource(NodeSource src) {
@@ -120,11 +125,8 @@ public class KotlinCompilerRunner implements CompilerRunner {
@Override
public ExitCode compile(Iterable<NodeSource> sources, Iterable<NodeSource> deletedSources, DiagnosticSink diagnostic, OutputSink out) throws Exception {
try {
if (find(sources, KotlinCompilerRunner::isKotlinSource) == null) {
return ExitCode.OK; // nothing to do
}
K2JVMCompilerArguments kotlinArgs = buildKotlinCompilerArguments(myContext, sources);
KotlinIncrementalCacheImpl incCache = new KotlinIncrementalCacheImpl(myStorageManager, filter(flat(deletedSources, sources), KotlinCompilerRunner::isKotlinSource), myModuleEntryPath, myLastGoodModuleEntryContent);
KotlinIncrementalCacheImpl incCache = new KotlinIncrementalCacheImpl(myStorageManager, flat(deletedSources, sources), myModuleEntryPath, myLastGoodModuleEntryContent);
OutputVirtualFile outputFileSystemRoot = new OutputFileSystem(new KotlinVirtualFileProvider(out)).root;
Services services = buildServices(kotlinArgs.getModuleName(), incCache, outputFileSystemRoot);
MessageCollector messageCollector = new KotlinMessageCollector(diagnostic, this);
@@ -344,7 +346,7 @@ public class KotlinCompilerRunner implements CompilerRunner {
};
}
private static K2JVMCompilerArguments buildKotlinCompilerArguments(BuildContext context, Iterable<NodeSource> sources) {
private K2JVMCompilerArguments buildKotlinCompilerArguments(BuildContext context, Iterable<NodeSource> sources) {
// todo: hash compiler configuration
K2JVMCompilerArguments arguments = new K2JVMCompilerArguments();
parseCommandLineArguments(context.getBuilderOptions().getKotlinOptions(), arguments, true);
@@ -372,12 +374,13 @@ public class KotlinCompilerRunner implements CompilerRunner {
arguments.setJvmDefault(CLFlags.JVM_DEFAULT.getOptionalScalarValue(flags));
arguments.setInlineClasses(CLFlags.INLINE_CLASSES.isFlagSet(flags));
arguments.setContextReceivers(CLFlags.CONTEXT_RECEIVERS.isFlagSet(flags));
arguments.setContextParameters(CLFlags.CONTEXT_PARAMETERS.isFlagSet(flags));
Iterable<String> friends = CLFlags.FRIENDS.getValue(flags);
if (!isEmpty(friends)) {
arguments.setFriendPaths(ensureCollection(map(friends, p -> context.getBaseDir().resolve(p).normalize().toString())).toArray(String[]::new));
}
NodeSourcePathMapper pathMapper = context.getPathMapper();
arguments.setFreeArgs(collect(map(sources, ns -> pathMapper.toPath(ns).toString()), new ArrayList<>()));
arguments.setFreeArgs(collect(flat(map(sources, ns -> pathMapper.toPath(ns).toString()), myJavaSources), new ArrayList<>()));
return arguments;
}