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

[change] JvmEnvironmentItem is set using env from target #260

Merged
merged 79 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
e4d07cb
merged from master
Jun 17, 2022
590211a
formatting fixed, bsp_target_info.proto updated
Jun 17, 2022
69b7547
formatting fixed
Jun 17, 2022
8ad1a3f
aspects updated
Jun 17, 2022
787e451
JavaLanguagePlugin and Module updated
Jun 17, 2022
66f376c
formatting
Jun 17, 2022
895d9c3
not sure
Jun 17, 2022
f68f5d0
Intellij Project Tree View Fix updated but gives a strange error
Jun 17, 2022
760e883
some updates but lots of errors
Jun 17, 2022
0c46f7a
ProjectStorageTest.java updated
Jun 20, 2022
991c9e2
ProjectStorageTest.java formatting
Jun 20, 2022
ecc2cc1
ProjectStorageTest.java formatting
Jun 20, 2022
e88c1e0
ProjectStorageTest.java formatting
Jun 20, 2022
a71473e
ProjectStorageTest.java formatting
Jun 20, 2022
8aee885
formatting
Jun 20, 2022
205f052
bsp_target_info.proto env_inherit added
Jun 20, 2022
ef85394
buildifier
Jun 20, 2022
4c51765
env_inherit added to BazelProjectMapper
Jun 20, 2022
f77d734
formatting
Jun 20, 2022
44c7e8c
changes in aspects
Jun 20, 2022
089b6a3
small fix
Jun 21, 2022
258a522
aspects.bzl file updated
Jun 21, 2022
66df83e
environment type fixed, javaLanguagePlugin fixed, working on environm…
Jun 21, 2022
83ebb32
format
Jun 21, 2022
fe01d3c
ProjectStorageTest and IntellijProjectTreeViewFix type correction
Jun 21, 2022
8bb0dd8
format
Jun 21, 2022
7b3a1fe
format
Jun 21, 2022
7c6ebff
current not working situation
Jun 21, 2022
829fa4c
BazelProjectMapper updated
Jun 21, 2022
99b978e
format
Jun 21, 2022
b6774c0
format
Jun 21, 2022
4da6660
BazelProjectMapper fix
Jun 21, 2022
2c0de6f
BazelProjectMapper fix, name change in Module, started adding e2e test
Jul 1, 2022
7a1158e
Merge branch 'master' into issue-90
Jul 1, 2022
6ee24e7
BspModuleExporterTest updated, merged from master
Jul 1, 2022
42d429b
small fix
Jul 1, 2022
ca93287
small fix
Jul 1, 2022
eed33c9
environment_variables build file updated
Jul 1, 2022
51c30da
BazelBspSampleRepoTest updated
Jul 1, 2022
70cb68f
BazelBspSampleRepoTest updated
Jul 1, 2022
3369627
BazelProjectMapper and BUILD file for environment_variables modified
Jul 1, 2022
89bf300
BazelPRojectMapper new method
Jul 1, 2022
7f239ba
mapper fix
Jul 4, 2022
cec5aee
bash file updated and formatting fixed
Jul 4, 2022
3f7a2df
BazelBspSampleRepoTest update
Jul 4, 2022
133a167
bash file and test updated
Jul 4, 2022
3b4bcb2
buildifier
Jul 4, 2022
97da6ff
fix
Jul 4, 2022
c44a431
test
Jul 4, 2022
dfea8c7
test
Jul 4, 2022
2e31ce6
test
Jul 4, 2022
e116a07
test
Jul 4, 2022
b969342
test
Jul 4, 2022
6d7b894
test
Jul 4, 2022
12fa05f
test
Jul 4, 2022
f87de4f
test
Jul 4, 2022
9496835
dependency try
Jul 5, 2022
d407b50
BazelBspSampleRepoTest fix
Jul 5, 2022
a692e25
gh comments fix
Jul 5, 2022
fc4297c
Merge branch 'master' into issue-90
Jul 11, 2022
14b91ee
Merge branch 'master' into issue-90
Jul 11, 2022
8ab010f
merged from master
Jul 11, 2022
fe4d9eb
IntellijProjectTreeViewFix correction
Jul 11, 2022
9304f52
additions for some tests
Jul 11, 2022
114948f
BazelProjectMapper fix
Jul 11, 2022
3436b1b
BazelBspSampleRepoTest try
Jul 11, 2022
f36e112
BazelBspSampleRepoTest try
Jul 11, 2022
8e7ecf4
JavaLanguagePlugin fix
Jul 12, 2022
e51a172
JavaLanguagePlugin fix
Jul 12, 2022
b37547e
JavaLanguagePlugin fix
Jul 12, 2022
0f7cdcf
BazelBspSampleRepoTest correction
Jul 12, 2022
abed250
BazelBspSampleRepoTest correction
Jul 12, 2022
e01ccde
module.java removed changelog updated
Jul 13, 2022
795890f
Merge branch 'master' into issue-90
Jul 18, 2022
3c1adba
dependency sources try
Jul 18, 2022
4c1becc
dependency sources try
Jul 18, 2022
e9b999d
Merge branch 'master' into issue-90
Jul 18, 2022
d61e76d
rebase
Jul 18, 2022
51edebe
dependency sources fix
Jul 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
| [#249](https://github.com/JetBrains/bazel-bsp/pull/249)
- e2e test for local jdk and remote jdk
| [#253](https://github.com/JetBrains/bazel-bsp/pull/253)
- Dependency sources are now filtered if they belong to other root target
| [#265](https://github.com/JetBrains/bazel-bsp/pull/265)
- JvmEnvironmentItem is set using env from target
| [#260](https://github.com/JetBrains/bazel-bsp/pull/260)

### Fixes 🛠️
- CLI project view generator now supports `--excluded-targets` and `--excluded-directories` instead of excluded `-` prefix.
Expand Down
3 changes: 2 additions & 1 deletion e2e/runTest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ TEST_TARGET="$1"
# second argument (optional) of the script should be a path to the directory with tested project (relative to the project root)
TEST_PROJECT_PATH="$2"


GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
Expand Down Expand Up @@ -52,7 +53,7 @@ echo -e "-----------------------------------\n"

cd "$BUILD_WORKSPACE_DIRECTORY" || exit

bazel run "$TEST_TARGET"
foo1=invalid_val1 foo2=invalid_val2 foo3=val3 foo4=val4 bazel run "$TEST_TARGET"
EXECUTION_CODE=$?

if [ $EXECUTION_CODE -ne 0 ]; then
Expand Down
131 changes: 108 additions & 23 deletions e2e/src/main/java/org/jetbrains/bsp/bazel/BazelBspSampleRepoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,20 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
)
manualTargetTestScalaBinarySources.roots = listOf("file://\$WORKSPACE/")

val environmentVariablesJavaBinary = SourceItem("file://\$WORKSPACE/environment_variables/JavaEnv.java", SourceItemKind.FILE, false)
val environmentVariablesJavaBinarySources = SourcesItem(
BuildTargetIdentifier("//environment_variables:java_binary"),
listOf(environmentVariablesJavaBinary)
)
environmentVariablesJavaBinarySources.roots = listOf("file://\$WORKSPACE/")

val environmentVariablesJavaTest = SourceItem("file://\$WORKSPACE/environment_variables/JavaTest.java", SourceItemKind.FILE, false)
val environmentVariablesJavaTestSources = SourcesItem(
BuildTargetIdentifier("//environment_variables:java_test"),
listOf(environmentVariablesJavaTest)
)
environmentVariablesJavaTestSources.roots = listOf("file://\$WORKSPACE/")

val sourcesParams = SourcesParams(expectedTargetIdentifiers())
val expectedSourcesResult = SourcesResult(
listOf(
Expand All @@ -248,7 +262,9 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
manualTargetTestJavaBinarySources,
manualTargetTestScalaBinarySources,
manualTargetTestJavaTestSources,
manualTargetTestScalaTestSources
manualTargetTestScalaTestSources,
environmentVariablesJavaBinarySources,
environmentVariablesJavaTestSources
)
)
return BazelBspTestScenarioStep("sources results") {
Expand Down Expand Up @@ -301,6 +317,10 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
ResourcesItem(BuildTargetIdentifier("//manual_target:java_test"), emptyList())
val manualTargetScalaTest =
ResourcesItem(BuildTargetIdentifier("//manual_target:scala_test"), emptyList())
val environmentVariablesJavaBinary =
ResourcesItem(BuildTargetIdentifier("//environment_variables:java_binary"), emptyList())
val environmentVariablesJavaTest =
ResourcesItem(BuildTargetIdentifier("//environment_variables:java_test"), emptyList())

val expectedResourcesResult = ResourcesResult(
listOf(
Expand All @@ -320,7 +340,9 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
manualTargetJavaBinary,
manualTargetScalaBinary,
manualTargetJavaTest,
manualTargetScalaTest
manualTargetScalaTest,
environmentVariablesJavaBinary,
environmentVariablesJavaTest
)
)
val resourcesParams = ResourcesParams(expectedTargetIdentifiers())
Expand Down Expand Up @@ -409,12 +431,10 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {

private fun dependencySourcesResults(): BazelBspTestScenarioStep {
val javaTargetsJavaBinary = DependencySourcesItem(
BuildTargetIdentifier("//java_targets:java_binary"),
emptyList()
BuildTargetIdentifier("//java_targets:java_binary"), emptyList()
)
val javaTargetsJavaLibrary = DependencySourcesItem(
BuildTargetIdentifier("//java_targets:java_library"),
emptyList()
BuildTargetIdentifier("//java_targets:java_library"), emptyList()
)
val targetWithDependencyJavaBinary = DependencySourcesItem(
BuildTargetIdentifier("//target_with_dependency:java_binary"),
Expand All @@ -423,32 +443,25 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
)
)
val javaTargetsSubpackageJavaLibrary = DependencySourcesItem(
BuildTargetIdentifier("//java_targets/subpackage:java_library"),
emptyList()
BuildTargetIdentifier("//java_targets/subpackage:java_library"), emptyList()
)
val scalaTargetsScalaBinary = DependencySourcesItem(
BuildTargetIdentifier("//scala_targets:scala_binary"),
emptyList()
BuildTargetIdentifier("//scala_targets:scala_binary"), emptyList()
)
val scalaTargetsScalaTest = DependencySourcesItem(
BuildTargetIdentifier("//scala_targets:scala_test"),
emptyList()
BuildTargetIdentifier("//scala_targets:scala_test"), emptyList()
)
val targetWithResourcesJavaBinary = DependencySourcesItem(
BuildTargetIdentifier("//target_with_resources:java_binary"),
emptyList()
BuildTargetIdentifier("//target_with_resources:java_binary"), emptyList()
)
val targetWithoutArgsBinary = DependencySourcesItem(
BuildTargetIdentifier("//target_without_args:binary"),
emptyList()
BuildTargetIdentifier("//target_without_args:binary"), emptyList()
)
val targetWithoutJvmFlagsBinary = DependencySourcesItem(
BuildTargetIdentifier("//target_without_jvm_flags:binary"),
emptyList()
BuildTargetIdentifier("//target_without_jvm_flags:binary"), emptyList()
)
val targetWithoutMainClassLibrary = DependencySourcesItem(
BuildTargetIdentifier("//target_without_main_class:library"),
emptyList()
BuildTargetIdentifier("//target_without_main_class:library"), emptyList()
)
val javaTargetsJavaLibraryExported = DependencySourcesItem(
BuildTargetIdentifier("//java_targets:java_library_exported"), emptyList()
Expand All @@ -471,6 +484,12 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
val manualTargetScalaTest = DependencySourcesItem(
BuildTargetIdentifier("//manual_target:scala_test"), emptyList()
)
val environmentVariablesJavaBinary = DependencySourcesItem(
BuildTargetIdentifier("//environment_variables:java_binary"), emptyList()
)
val environmentVariablesJavaTest = DependencySourcesItem(
BuildTargetIdentifier("//environment_variables:java_test"), emptyList()
)
val expectedDependencies = DependencySourcesResult(
listOf(
javaTargetsJavaBinary,
Expand All @@ -489,7 +508,9 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
manualTargetJavaBinary,
manualTargetScalaBinary,
manualTargetJavaTest,
manualTargetScalaTest
manualTargetScalaTest,
environmentVariablesJavaBinary,
environmentVariablesJavaTest
)
)
val dependencySourcesParams = DependencySourcesParams(expectedTargetIdentifiers())
Expand Down Expand Up @@ -622,6 +643,25 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
emptyList(),
"\$WORKSPACE",
mapOf()
),
JvmEnvironmentItem(
BuildTargetIdentifier("//environment_variables:java_binary"),
listOf(
"file://\$BAZEL_CACHE/bazel-out/k8-fastbuild/bin/environment_variables/java_binary.jar"
),
emptyList(),
"\$WORKSPACE",
mapOf("foo1" to "val1" , "foo2" to "val2")
),
JvmEnvironmentItem(
BuildTargetIdentifier("//environment_variables:java_test"),
listOf(
"file://\$BAZEL_CACHE/bazel-out/k8-fastbuild/bin/environment_variables/java_test.jar",
"file://\$BAZEL_CACHE/external/remote_java_tools/java_tools/Runner_deploy.jar"
),
emptyList(),
"\$WORKSPACE",
mapOf("foo1" to "val1" , "foo2" to "val2", "foo3" to "val3", "foo4" to "val4")
)
)
)
Expand Down Expand Up @@ -748,7 +788,26 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
emptyList(),
"\$WORKSPACE",
mapOf()
)
),
JvmEnvironmentItem(
BuildTargetIdentifier("//environment_variables:java_binary"),
listOf(
"file://\$BAZEL_CACHE/bazel-out/k8-fastbuild/bin/environment_variables/java_binary.jar"
),
emptyList(),
"\$WORKSPACE",
mapOf("foo1" to "val1" , "foo2" to "val2")
),
JvmEnvironmentItem(
BuildTargetIdentifier("//environment_variables:java_test"),
listOf(
"file://\$BAZEL_CACHE/bazel-out/k8-fastbuild/bin/environment_variables/java_test.jar",
"file://\$BAZEL_CACHE/external/remote_java_tools/java_tools/Runner_deploy.jar"
),
emptyList(),
"\$WORKSPACE",
mapOf("foo1" to "val1" , "foo2" to "val2", "foo3" to "val3", "foo4" to "val4")
),
)
)
return BazelBspTestScenarioStep(
Expand Down Expand Up @@ -992,6 +1051,30 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
manualTargetJavaTest.displayName = "//manual_target:java_test"
manualTargetJavaTest.baseDirectory = "file://\$WORKSPACE/manual_target/"

val environmentVariablesJavaLibrary = BuildTarget(
BuildTargetIdentifier("//environment_variables:java_binary"),
listOf("application"),
listOf("java"),
emptyList(),
BuildTargetCapabilities(true, false, true, false)
)
environmentVariablesJavaLibrary.displayName = "//environment_variables:java_binary"
environmentVariablesJavaLibrary.baseDirectory = "file://\$WORKSPACE/environment_variables/"
environmentVariablesJavaLibrary.dataKind = "jvm"
environmentVariablesJavaLibrary.data = jvmBuildTarget

val environmentVariablesJavaTest = BuildTarget(
BuildTargetIdentifier("//environment_variables:java_test"),
listOf("test"),
listOf("java"),
emptyList(),
BuildTargetCapabilities(true, true, false, false)
)
environmentVariablesJavaTest.displayName = "//environment_variables:java_test"
environmentVariablesJavaTest.baseDirectory = "file://\$WORKSPACE/environment_variables/"
environmentVariablesJavaTest.dataKind = "jvm"
environmentVariablesJavaTest.data = jvmBuildTarget

basakkapusuzoglu marked this conversation as resolved.
Show resolved Hide resolved
return WorkspaceBuildTargetsResult(
listOf(
javaTargetsJavaBinary,
Expand All @@ -1010,7 +1093,9 @@ object BazelBspSampleRepoTest : BazelBspTestBaseScenario() {
manualTargetJavaBinary,
manualTargetScalaBinary,
manualTargetJavaTest,
manualTargetScalaTest
manualTargetScalaTest,
environmentVariablesJavaLibrary,
environmentVariablesJavaTest
)
)
}
Expand Down
27 changes: 27 additions & 0 deletions e2e/test-resources/sample-repo/environment_variables/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
load("@rules_java//java:defs.bzl", "java_binary", "java_test")

java_binary(
name = "java_binary",
srcs = ["JavaEnv.java"],
env = {
"foo1": "val1",
"foo2": "val2",
},
main_class = "environment_variables.JavaEnv",
visibility = ["//visibility:public"],
)

java_test(
name = "java_test",
srcs = ["JavaTest.java"],
env = {
"foo1": "val1",
"foo2": "val2",
},
env_inherit = [
"foo3",
"foo4",
],
test_class = "environment_variables.JavaTest",
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package environment_variables;

public class JavaEnv {
public static final String value = "value";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package environment_variables;

public class JavaTest {
public static final String value = "value";
}
2 changes: 2 additions & 0 deletions install/src/main/resources/aspects.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,8 @@ def _bsp_target_info_aspect_impl(target, ctx):
java_target_info = java_target_info,
java_toolchain_info = java_toolchain_info,
java_runtime_info = java_runtime_info,
env = getattr(rule_attrs, "env", {}),
env_inherit = getattr(rule_attrs, "env_inherit", []),
)

file_name = target.label.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import kotlinx.coroutines.flow.filterNot
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking
import org.jetbrains.bsp.bazel.info.BspTargetInfo
import org.jetbrains.bsp.bazel.info.BspTargetInfo.FileLocation
import org.jetbrains.bsp.bazel.info.BspTargetInfo.TargetInfo
import org.jetbrains.bsp.bazel.server.sync.dependencytree.DependencyTree
import org.jetbrains.bsp.bazel.server.sync.languages.LanguageData
import org.jetbrains.bsp.bazel.server.sync.languages.LanguagePlugin
import org.jetbrains.bsp.bazel.server.sync.languages.LanguagePluginsService
import org.jetbrains.bsp.bazel.server.sync.model.Label
Expand All @@ -18,6 +20,8 @@ import org.jetbrains.bsp.bazel.server.sync.model.SourceSet
import org.jetbrains.bsp.bazel.server.sync.model.Tag
import org.jetbrains.bsp.bazel.workspacecontext.WorkspaceContext
import java.net.URI
import java.util.stream.Collector
import java.util.stream.Collectors

class BazelProjectMapper(
private val languagePluginsService: LanguagePluginsService,
Expand Down Expand Up @@ -74,6 +78,7 @@ class BazelProjectMapper(
val resources = resolveResources(target)
val languageData = languagePlugin.resolveModule(target)
val sourceDependencies = languagePlugin.dependencySources(target, dependencyTree)
val environment = environmentItem(target)
return Module(
label = label,
isSynthetic = false,
Expand All @@ -84,7 +89,8 @@ class BazelProjectMapper(
sourceSet = sourceSet,
resources = resources,
sourceDependencies = sourceDependencies,
languageData = languageData
languageData = languageData,
environmentVariables = environment
)
}

Expand Down Expand Up @@ -129,4 +135,14 @@ class BazelProjectMapper(
with(module) {
(sourceSet.sources + resources).map { Pair(it, label) }
}

private fun environmentItem(target: TargetInfo): Map<String, String> {
val inheritedEnvs = collectInheritedEnvs(target)
val targetEnv = target.envMap
return inheritedEnvs + targetEnv
}

private fun collectInheritedEnvs(targetInfo: TargetInfo): Map<String, String> =
targetInfo.envInheritList.associateWith { System.getenv(it)}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ class IntelliJProjectTreeViewFix(private val bazelPathsResolver: BazelPathsResol
SourceSet(emptySet(), emptySet()),
resources,
emptySet(),
null
null,
hashMapOf()
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class JavaLanguagePlugin(
javaModule.runtimeClasspath.map { obj: URI -> obj.toString() }.toList(),
javaModule.jvmOps.toList(),
bazelInfo.workspaceRoot.toString(),
mapOf()
module.environmentVariables
)
// FIXME: figure out what we should pass here, because passing the environment
// of the *SERVER* makes little sense
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ data class Module(
val resources: Set<URI>,
val sourceDependencies: Set<URI>,
val languageData: LanguageData?,
val environmentVariables: Map<String, String>
)
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ message TargetInfo {
repeated Dependency dependencies = 40;
repeated FileLocation sources = 50;
repeated FileLocation resources = 60;
map <string, string> env = 70;
repeated string env_inherit = 80;
JavaTargetInfo java_target_info = 1000;
JavaToolchainInfo java_toolchain_info = 2000;
JavaRuntimeInfo java_runtime_info = 3000;
Expand Down
Loading