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

Commit

Permalink
[breaking change] now server doesnt build the project during sync | #…
Browse files Browse the repository at this point in the history
…BAZEL-436 Done

reviews

imports

review comment

bsp version fix

nullable revert

buildifier

rebase fix

moree e2e tesssts

e2e tests should work now

e2e tests fix v2

e2e tests fix

e2e tests fix

upps

rollback the manual flag

lil bump

datalore should work now

test fix

e2e fix

and now we are not returning uri if the file doesnt exist

now we dont query bazel for the outputs when we run aspects


Merge-request: BAZEL-MR-301
Merged-by: Marcin Abramowicz <marcin.abramowicz@jetbrains.com>
  • Loading branch information
abrams27 authored and qodana-bot committed Aug 3, 2023
1 parent 9d5cd19 commit ba44564
Show file tree
Hide file tree
Showing 13 changed files with 250 additions and 103 deletions.
4 changes: 2 additions & 2 deletions aspects/core.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def _bsp_target_info_aspect_impl(target, ctx):
for f in t.files.to_list()
]

java_target_info = extract_java_info(target, ctx, output_groups) if not "manual" in rule_attrs.tags else None
scala_toolchain_info = extract_scala_toolchain_info(target, ctx, output_groups) if not "manual" in rule_attrs.tags else None
java_target_info = extract_java_info(target, ctx, output_groups)
scala_toolchain_info = extract_scala_toolchain_info(target, ctx, output_groups)
scala_target_info = extract_scala_info(target, ctx, output_groups)
java_toolchain_info, java_toolchain_info_exported = extract_java_toolchain(target, ctx, dep_targets)
java_runtime_info, java_runtime_info_exported = extract_java_runtime(target, ctx, dep_targets)
Expand Down
4 changes: 1 addition & 3 deletions aspects/rules/java/java_info.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//aspects:utils/java_utils.bzl", "get_java_provider")
load("//aspects:utils/utils.bzl", "create_struct", "file_location", "map", "to_file_location", "update_sync_output_groups")
load("//aspects:utils/utils.bzl", "create_struct", "file_location", "map", "to_file_location")

def map_with_resolve_files(f, xs):
results = []
Expand Down Expand Up @@ -127,8 +127,6 @@ def extract_java_info(target, ctx, output_groups):
args = getattr(ctx.rule.attr, "args", [])
main_class = getattr(ctx.rule.attr, "main_class", None)

update_sync_output_groups(output_groups, "bsp-ide-resolve", depset(resolve_files))

return create_struct(
jars = jars,
generated_jars = generated_jars,
Expand Down
4 changes: 1 addition & 3 deletions aspects/rules/scala/scala_info.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("//aspects:utils/java_utils.bzl", "get_java_provider")
load("//aspects:utils/utils.bzl", "file_location", "map", "update_sync_output_groups")
load("//aspects:utils/utils.bzl", "file_location", "map")

def find_scalac_classpath(runfiles):
result = []
Expand All @@ -24,8 +24,6 @@ def extract_scala_toolchain_info(target, ctx, output_groups):
resolve_files = classpath
compiler_classpath = map(file_location, classpath)

update_sync_output_groups(output_groups, "bsp-ide-resolve", depset(resolve_files))

return struct(compiler_classpath = compiler_classpath)

def extract_scala_info(target, ctx, output_groups):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
public class Constants {
public static final String NAME = "bazelbsp";
public static final String VERSION = "2.7.2";
public static final String BSP_VERSION = "2.1.0-M4";
public static final String BSP_VERSION = "2.1.0";
public static final String SCALA = "scala";
public static final String JAVA = "java";
public static final String KOTLIN = "kotlin";
Expand Down
8 changes: 0 additions & 8 deletions e2e/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ sh_binary(
],
)

sh_binary(
name = "BazelBspEntireRepositoryImportTest",
srcs = ["runTest.sh"],
args = [
"//e2e/src/main/java/org/jetbrains/bsp/bazel:BazelBspEntireRepositoryImportTest",
],
)

# simply a wrapper for the bash script to keep the convention
sh_binary(
name = "all",
Expand Down
281 changes: 210 additions & 71 deletions e2e/src/main/java/org/jetbrains/bsp/bazel/BazelBspSampleRepoTest.kt

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion e2e/test-resources/sample-repo/manual_target/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ java_binary(
scala_test(
name = "scala_test",
srcs = ["ScalaTest.scala"],
main_class = "manual_target.ScalaTest",
tags = ["manual"],
visibility = ["//visibility:public"],
)
Expand Down
19 changes: 15 additions & 4 deletions e2e/test-resources/sample-repo/manual_target/ScalaTest.scala
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
package manual_target

object ExampleTest {
def main(args: Array[String]): Unit = {
val s = "Sup"
println(s)
class ExampleSpec extends AnyFlatSpec with should.Matchers {

"A Stack" should "pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
stack.pop() should be (2)
stack.pop() should be (1)
}

it should "throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[Int]
a [NoSuchElementException] should be thrownBy {
emptyStack.pop()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.vavr.collection.Array;
import java.util.List;
import java.util.Objects;
import org.eclipse.lsp4j.jsonrpc.CancelChecker;
import org.jetbrains.bsp.bazel.bazelrunner.params.BazelFlag;
import org.jetbrains.bsp.bazel.commons.Constants;
Expand Down Expand Up @@ -38,7 +39,8 @@ public BepOutput fetchFilesFromOutputGroups(
BazelFlag.keepGoing(),
BazelFlag.color(true),
BazelFlag.buildManualTests(),
BazelFlag.curses(false)),
BazelFlag.curses(false)
),
null);
return result.bepOutput();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.concurrent.ConcurrentHashMap
import kotlin.io.path.exists
import kotlin.io.path.toPath

class BazelPathsResolver(private val bazelInfo: BazelInfo) {
private val uris = ConcurrentHashMap<Path, URI>()
Expand All @@ -17,7 +19,10 @@ class BazelPathsResolver(private val bazelInfo: BazelInfo) {

fun workspaceRoot(): URI = resolveUri(bazelInfo.workspaceRoot.toAbsolutePath())

fun resolveUris(fileLocations: List<FileLocation>): List<URI> = fileLocations.map(::resolveUri)
fun resolveUris(fileLocations: List<FileLocation>, shouldFilterExisting: Boolean = false): List<URI> =
fileLocations
.map(::resolveUri)
.filter { !shouldFilterExisting || it.toPath().exists() }

fun resolvePaths(fileLocations: List<FileLocation>): List<Path> = fileLocations.map(::resolve)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ class ExecuteService(

fun compile(cancelChecker: CancelChecker, params: CompileParams): CompileResult {
val targets = selectTargets(cancelChecker, params.targets)
val result = build(cancelChecker, targets, params.originId)
return CompileResult(result.statusCode).apply { originId = params.originId }

return if (targets.isNotEmpty()) {
val result = build(cancelChecker, targets, params.originId)
CompileResult(result.statusCode).apply { originId = params.originId }
} else {
CompileResult(StatusCode.ERROR).apply { originId = params.originId }
}
}

fun test(cancelChecker: CancelChecker, params: TestParams): TestResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,11 @@ class ProjectResolver(
cancelChecker,
workspaceContext.targets,
ASPECT_NAME,
listOf(BSP_INFO_OUTPUT_GROUP, ARTIFACTS_OUTPUT_GROUP)
listOf(BSP_INFO_OUTPUT_GROUP)
)


companion object {
private const val ASPECT_NAME = "bsp_target_info_aspect"
private const val BSP_INFO_OUTPUT_GROUP = "bsp-target-info-transitive-deps"
private const val ARTIFACTS_OUTPUT_GROUP = "bsp-ide-resolve-transitive-deps"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class JavaLanguagePlugin(
it.interfaceJarsList + it.binaryJarsList
}.map(bazelPathsResolver::resolveUri)
val mainClass = getMainClass(this)
val runtimeClasspath = bazelPathsResolver.resolveUris(runtimeClasspathList)
val compileClasspath = bazelPathsResolver.resolveUris(compileClasspathList + generatedJarsList.flatMap { it.binaryJarsList })
val sourcesClasspath = bazelPathsResolver.resolveUris(sourceClasspathList)
val runtimeClasspath = bazelPathsResolver.resolveUris(runtimeClasspathList, true)
val compileClasspath = bazelPathsResolver.resolveUris(compileClasspathList + generatedJarsList.flatMap { it.binaryJarsList }, true)
val sourcesClasspath = bazelPathsResolver.resolveUris(sourceClasspathList, true)
val ideClasspath = resolveIdeClasspath(Label(targetInfo.id),
bazelPathsResolver,
runtimeClasspath.asSequence(), compileClasspath.asSequence()
Expand Down

0 comments on commit ba44564

Please sign in to comment.