Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
[fix] Correctly determine language type for JVM binary targets (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
sellophane committed Oct 27, 2022
1 parent e8d8810 commit 76d6774
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@
- `JVMLanguagePluginParser.calculateJVMSourceRoot` does not throw
an exception for package longer than the path.
| [#294](https://github.com/JetBrains/bazel-bsp/pull/294)
- Fix transitive target failure check in bloop export.
- Fix transitive target failure check in bloop export.aa
| [#287](https://github.com/JetBrains/bazel-bsp/pull/287)
- Use direct source dependencies for thrift targets if present.
| [#298](https://github.com/JetBrains/bazel-bsp/pull/298)
- Postpone bazel info.
| [#300](https://github.com/JetBrains/bazel-bsp/pull/300)
- Correctly determine language type for JVM binary targets.
| [#306](https://github.com/JetBrains/bazel-bsp/pull/306)

## [2.2.1] - 09.08.2022

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,22 @@ class BazelProjectMapper(
target.dependenciesList.map { Label(it.id) }

private fun inferLanguages(target: TargetInfo): Set<Language> =
target.sourcesList.flatMap { source: FileLocation ->
Language.all().filter { isLanguageFile(source, it) }
}.toHashSet()
if (target.sourcesList.isEmpty()) {
Language.all().filter { isBinaryTargetOfLanguage(target.kind, it) }.toHashSet()
} else {
target.sourcesList.flatMap { source: FileLocation ->
Language.all().filter { isLanguageFile(source, it) }
}.toHashSet()
}

private fun isLanguageFile(file: FileLocation, language: Language): Boolean =
language.extensions.any {
file.relativePath.endsWith(it)
}

private fun isBinaryTargetOfLanguage(kind: String, language: Language): Boolean =
language.binary_targets.contains(kind)

private fun resolveSourceSet(target: TargetInfo, languagePlugin: LanguagePlugin<*>): SourceSet {
val sources = target.sourcesList.asSequence().map(bazelPathsResolver::resolve)
val sourceRoots = sources.mapNotNull(languagePlugin::calculateSourceRoot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package org.jetbrains.bsp.bazel.server.sync.model
enum class Language(
val id: String,
val extensions: Set<String>,
dependentNames: Set<String> = hashSetOf()
val binary_targets: Set<String> = hashSetOf(),
dependentNames: Set<String> = hashSetOf(),
) {
SCALA("scala", hashSetOf(".scala")),
JAVA("java", hashSetOf(".java")),
KOTLIN("kotlin", hashSetOf(".kt"), hashSetOf(JAVA.id)),
JAVA("java", hashSetOf(".java"), binary_targets = setOf("java_binary")),
KOTLIN("kotlin", hashSetOf(".kt"), setOf("kt_jvm_binary"), hashSetOf(JAVA.id)),
CPP("cpp", hashSetOf(".C", ".cc", ".cpp", ".CPP", ".c++", ".cp", "cxx", ".h", ".hpp")),
THRIFT("thrift", hashSetOf(".thrift"));

Expand Down

0 comments on commit 76d6774

Please sign in to comment.