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

Commit

Permalink
changes after CR v1
Browse files Browse the repository at this point in the history
  • Loading branch information
azdrojowa123 committed Jul 22, 2022
1 parent cbe0398 commit 23b4fc7
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 83 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ jobs:
- name: Run test
run: bazel run //e2e:BazelBspRemoteJdkTest

# cpp-project-test:
# runs-on: ubuntu-latest
# needs: setup
# steps:
# - uses: actions/checkout@v2
# - name: Set up JDK 11
# uses: actions/setup-java@v1
# with:
# java-version: 11
# - name: Cache bazel
# uses: actions/cache@v2
# env:
# cache-name: cache-bazel
# with:
# path: ~/.cache/bazel
# key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.sha }}
# - name: Run test
# run: bazel run //e2e:BazelBspCppProjectTest
cpp-project-test:
runs-on: ubuntu-latest
needs: setup
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache bazel
uses: actions/cache@v2
env:
cache-name: cache-bazel
with:
path: ~/.cache/bazel
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.sha }}
- name: Run test
run: bazel run //e2e:BazelBspCppProjectTest
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
| [#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)
- Server has undergone basic changes leading to the ability to work with CPP language.
| [#277](https://github.com/JetBrains/bazel-bsp/pull/277)

### Fixes 🛠️
- CLI project view generator now supports `--excluded-targets` and `--excluded-directories` instead of excluded `-` prefix.
Expand Down
Empty file removed all.log
Empty file.
22 changes: 11 additions & 11 deletions e2e/src/main/java/org/jetbrains/bsp/bazel/BazelBspCppProjectTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,31 @@ object BazelBspCppProjectTest : BazelBspTestBaseScenario() {
private fun compareWorkspaceTargetsResults(): BazelBspTestScenarioStep {
val exampleExampleCppBuildTarget = CppBuildTarget(null, "compiler", "/bin/gcc", "/bin/gcc")

val exampleBuildTarget1 =
val exampleExampleBuildTarget1 =
BuildTarget(
BuildTargetIdentifier("//example:example"),
ImmutableList.of("application"),
ImmutableList.of(Constants.CPP),
ImmutableList.of(BuildTargetIdentifier("@com_google_googletest//:gtest_main")),
BuildTargetCapabilities(true, false, true)
)
exampleBuildTarget1.displayName = "//example:example"
exampleBuildTarget1.baseDirectory = "file://\$WORKSPACE/example/"
exampleBuildTarget1.data = exampleExampleCppBuildTarget
exampleBuildTarget1.dataKind = BuildTargetDataKind.CPP
exampleExampleBuildTarget1.displayName = "//example:example"
exampleExampleBuildTarget1.baseDirectory = "file://\$WORKSPACE/example/"
exampleExampleBuildTarget1.data = exampleExampleCppBuildTarget
exampleExampleBuildTarget1.dataKind = BuildTargetDataKind.CPP

val exampleBuildTarget2 =
val exampleExampleBuildTarget2 =
BuildTarget(
BuildTargetIdentifier("bsp-workspace-root"),
ImmutableList.of(),
ImmutableList.of(),
ImmutableList.of(),
BuildTargetCapabilities(false, false, false)
)
exampleBuildTarget2.baseDirectory = "file://\$WORKSPACE/"
exampleBuildTarget2.displayName = "bsp-workspace-root"
exampleExampleBuildTarget2.baseDirectory = "file://\$WORKSPACE/"
exampleExampleBuildTarget2.displayName = "bsp-workspace-root"
val expectedWorkspaceBuildTargetsResult =
WorkspaceBuildTargetsResult(ImmutableList.of(exampleBuildTarget1, exampleBuildTarget2))
WorkspaceBuildTargetsResult(ImmutableList.of(exampleExampleBuildTarget1, exampleExampleBuildTarget2))

return BazelBspTestScenarioStep("cpp project") {
testClient.testWorkspaceTargets(Duration.ofSeconds(20), expectedWorkspaceBuildTargetsResult)
Expand All @@ -63,7 +63,7 @@ object BazelBspCppProjectTest : BazelBspTestBaseScenario() {
val cppOptionsParams =
CppOptionsParams(ImmutableList.of(BuildTargetIdentifier("//example:example")))

val exampleCppOptionsItem =
val exampleExampleCppOptionsItem =
CppOptionsItem(
BuildTargetIdentifier("//example:example"),
ImmutableList.of("-Iexternal/gtest/include"),
Expand All @@ -72,7 +72,7 @@ object BazelBspCppProjectTest : BazelBspTestBaseScenario() {
)

val expectedCppOptionsResult =
CppOptionsResult(ImmutableList.of(exampleCppOptionsItem))
CppOptionsResult(ImmutableList.of(exampleExampleCppOptionsItem))

return BazelBspTestScenarioStep("cpp options") {
testClient.testCppOptions(Duration.ofSeconds(20), cppOptionsParams, expectedCppOptionsResult)
Expand Down
40 changes: 7 additions & 33 deletions install/src/main/resources/aspects.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,6 @@ def _bsp_target_info_aspect_impl(target, ctx):
java_runtime_info, java_runtime_info_exported = extract_java_runtime(target, ctx, dep_targets)
cpp_target_info = extract_cpp_target_info(target, ctx)

# TODO retrieve cpp compiler info and use it
cpp_compiler_info = _fetch_cpp_compiler(target, ctx)

result = dict(
id = str(target.label),
kind = ctx.rule.kind,
Expand Down Expand Up @@ -540,20 +537,6 @@ bsp_target_info_aspect = aspect(
attr_aspects = ALL_DEPS,
)

def _fetch_cpp_compiler(target, ctx):
if cc_common.CcToolchainInfo in target:
toolchain_info = target[cc_common.CcToolchainInfo]
print(toolchain_info.compiler)
print(toolchain_info.compiler_executable)
return []

fetch_cpp_compiler = aspect(
implementation = _fetch_cpp_compiler,
fragments = ["cpp"],
attr_aspects = ["_cc_toolchain"],
required_aspect_providers = [[CcInfo]],
)

def _fetch_java_target_version(target, ctx):
print(target[java_common.JavaToolchainInfo].target_version)
return []
Expand Down Expand Up @@ -585,26 +568,17 @@ def _print_fields(fields):

def extract_cpp_target_info(target, ctx):
if CcInfo not in target:
return []
return None

#TODO: Get copts from semantics
copts = _get_target_info(ctx, "copts")
defines = _get_target_info(ctx, "defines")
linkopts = _get_target_info(ctx, "linkopts")

linkshared = False
if hasattr(ctx.rule.attr, "linkshared"):
linkshared = ctx.rule.attr.linkshared
copts = getattr(ctx.rule.attr, "copts", [])
defines = getattr(ctx.rule.attr, "defines", [])
link_opts = getattr(ctx.rule.attr, "linkopts", [])
link_shared = getattr(ctx.rule.attr, "linkshared", False)

return create_struct(
copts = copts,
defines = defines,
linkopts = linkopts,
linkshared = linkshared,
link_opts = link_opts,
link_shared = link_shared,
)

get_cpp_target_info = aspect(
implementation = extract_cpp_target_info,
fragments = ["cpp"],
required_aspect_providers = [[CcInfo]],
)
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ import java.net.URI
class CppLanguagePlugin(private val bazelPathsResolver: BazelPathsResolver) : LanguagePlugin<CppModule>() {

override fun resolveModule(targetInfo: TargetInfo): CppModule? {
return targetInfo.takeIf(TargetInfo::hasCppTargetInfo)?.cppTargetInfo?.run {
return targetInfo.getCppTargetInfoOrNull()?.run {
CppModule(
listOf(targetInfo.cppTargetInfo.copts),
listOf(targetInfo.cppTargetInfo.defines),
listOf(targetInfo.cppTargetInfo.linkopts),
targetInfo.cppTargetInfo.linkshared
copts = targetInfo.cppTargetInfo.coptsList ,
defines = targetInfo.cppTargetInfo.definesList,
linkOpts = targetInfo.cppTargetInfo.linkOptsList,
linkShared = targetInfo.cppTargetInfo.linkShared
)
}
}

override fun applyModuleData(moduleData: CppModule, buildTarget: BuildTarget) {
// TODO retrieve real information about cpp compiler
val cppBuildTarget = CppBuildTarget(null, "compiler", "/bin/gcc", "/bin/gcc")
buildTarget.data = cppBuildTarget
buildTarget.dataKind = BuildTargetDataKind.CPP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@ package org.jetbrains.bsp.bazel.server.sync.languages.cpp
import org.jetbrains.bsp.bazel.server.sync.languages.LanguageData

data class CppModule(
val copts: List<String>?,
val defines: List<String>?,
val linkOpts: List<String>?,
val linkShared: Boolean
) : LanguageData {
val copts: List<String>,
val defines: List<String>,
val linkOpts: List<String>,
val linkShared: Boolean) : LanguageData


companion object {
@JvmStatic
fun fromLanguageData(languageData: LanguageData?) = languageData as? CppModule
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ message ScalaToolchainInfo {
}

message CppTargetInfo {
string copts = 1;
string defines = 2;
string linkopts = 3;
bool linkshared = 4;
repeated string copts = 1;
repeated string defines = 2;
repeated string link_opts = 3;
bool link_shared = 4;
}

message TargetInfo {
Expand Down

0 comments on commit 23b4fc7

Please sign in to comment.