Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for the google test run button in nova #7062

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
27 changes: 18 additions & 9 deletions .bazelci/clion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ tasks:
build_flags:
- --define=ij_product=clion-oss-oldest-stable
build_targets:
- //clwb/...
- //clwb:clwb_bazel_zip
- //:clwb_tests
test_flags:
- --define=ij_product=clion-oss-oldest-stable
- --test_output=errors
Expand All @@ -18,7 +19,8 @@ tasks:
build_flags:
- --define=ij_product=clion-oss-latest-stable
build_targets:
- //clwb/...
- //clwb:clwb_bazel_zip
- //:clwb_tests
test_flags:
- --define=ij_product=clion-oss-latest-stable
- --test_output=errors
Expand All @@ -30,7 +32,8 @@ tasks:
build_flags:
- --define=ij_product=clion-oss-oldest-stable
build_targets:
- //clwb/...
- //clwb:clwb_bazel_zip
- //:clwb_tests
test_flags:
- --define=ij_product=clion-oss-oldest-stable
- --test_output=errors
Expand All @@ -42,7 +45,8 @@ tasks:
build_flags:
- --define=ij_product=clion-oss-latest-stable
build_targets:
- //clwb/...
- //clwb:clwb_bazel_zip
- //:clwb_tests
test_flags:
- --define=ij_product=clion-oss-latest-stable
- --test_output=errors
Expand All @@ -54,7 +58,8 @@ tasks:
build_flags:
- --define=ij_product=clion-oss-oldest-stable
build_targets:
- //clwb/...
- //clwb:clwb_bazel_zip
- //:clwb_tests
test_flags:
- --define=ij_product=clion-oss-oldest-stable
- --test_output=errors
Expand All @@ -66,7 +71,8 @@ tasks:
build_flags:
- --define=ij_product=clion-oss-latest-stable
build_targets:
- //clwb/...
- //clwb:clwb_bazel_zip
- //:clwb_tests
test_flags:
- --define=ij_product=clion-oss-latest-stable
- --test_output=errors
Expand All @@ -78,7 +84,8 @@ tasks:
build_flags:
- --define=ij_product=clion-oss-under-dev
build_targets:
- //clwb/...
- //clwb:clwb_bazel_zip
- //:clwb_tests
test_flags:
- --define=ij_product=clion-oss-under-dev
- --test_output=errors
Expand All @@ -92,7 +99,8 @@ tasks:
build_flags:
- --define=ij_product=clion-oss-under-dev
build_targets:
- //clwb/...
- //clwb:clwb_bazel_zip
- //:clwb_tests
test_flags:
- --define=ij_product=clion-oss-under-dev
- --test_output=errors
Expand All @@ -106,7 +114,8 @@ tasks:
build_flags:
- --define=ij_product=clion-oss-under-dev
build_targets:
- //clwb/...
- //clwb:clwb_bazel_zip
- //:clwb_tests
test_flags:
- --define=ij_product=clion-oss-under-dev
- --test_output=errors
Expand Down
18 changes: 16 additions & 2 deletions clwb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,29 @@ load(
"//testing:test_defs.bzl",
"intellij_unit_test_suite",
)
load(":build_defs.bzl", "select_since")
load(":test_defs.bzl", "clwb_integration_test")

licenses(["notice"])

intellij_plugin_library(
name = "plugin_library",
optional_plugin_xmls = ["optional_clwb_oclang"],
optional_plugin_xmls = [
"optional_clwb_oclang",
] + select_since(
"2024.3",
["//clwb/src/com/google/idea/blaze/clwb/radler:plugin_xml"],
default = [],
),
plugin_xmls = ["src/META-INF/clwb.xml"],
visibility = PLUGIN_PACKAGES_VISIBILITY,
deps = [":clwb_lib"],
deps = [
":clwb_lib",
] + select_since(
"2024.3",
["//clwb/src/com/google/idea/blaze/clwb/radler:lib"],
default = [],
),
)

optional_plugin_xml(
Expand All @@ -60,6 +73,7 @@ stamped_plugin_xml(
java_library(
name = "clwb_lib",
srcs = glob(["src/**/*.java"]),
visibility = ["//clwb:__subpackages__"],
deps = [
"//base",
"//common/actions",
Expand Down
48 changes: 48 additions & 0 deletions clwb/build_defs.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
load("//intellij_platform_sdk:build_defs.bzl", "INDIRECT_IJ_PRODUCTS")

SUPPORTED_VERSIONS = {
"clion-oss-oldest-stable": INDIRECT_IJ_PRODUCTS["clion-oss-oldest-stable"],
"clion-oss-latest-stable": INDIRECT_IJ_PRODUCTS["clion-oss-latest-stable"],
"clion-oss-under-dev": INDIRECT_IJ_PRODUCTS["clion-oss-under-dev"],
}

def _version_to_number(version):
"""
Turns a clion version `clion-20xx.x` to an integer. Used for comparing clion versions.
"""

# take the last six characters of the version `20xx.x `
version = version[-6:]

# replace the dot with a 0
version = version.replace(".", "0")

return int(version)

def select_since(since, value, default = None):
"""
Returns a select that on targeted clion version. The select returns the `value` if the target version is bigger or
equal to the specified `version`. If a default value is defined this value is returned otherwise.

Might be a good replacement for sdkcompat if only future versions are targeted.

Args:
since: the minimum supported version
value: the value to select if the current target version is bigger or equal than `since`
default: a optional default value
"""

select_params = dict()

for name, version in SUPPORTED_VERSIONS.items():
if _version_to_number(version) >= _version_to_number(since):
select_params["//intellij_platform_sdk:" + version] = value
select_params["//intellij_platform_sdk:" + name] = value

if default != None:
select_params["//conditions:default"] = default

return select(
select_params,
no_match_error = "unsupported clion version, min version: clion-" + since,
)
21 changes: 21 additions & 0 deletions clwb/src/com/google/idea/blaze/clwb/radler/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")
load("//build_defs:build_defs.bzl", "optional_plugin_xml")

licenses(["notice"])

package(default_visibility = ["//clwb:__subpackages__"])

optional_plugin_xml(
name = "plugin_xml",
module = ["org.jetbrains.plugins.clion.radler"],
plugin_xml = "plugin.xml",
)

kt_jvm_library(
name = "lib",
srcs = glob(["*.kt"]),
deps = [
"//intellij_platform_sdk:plugin_api",
"//clwb:clwb_lib",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/*
* Copyright 2024 The Bazel Authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.idea.blaze.clwb.radler

import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
import com.google.idea.blaze.base.dependencies.TargetInfo
import com.google.idea.blaze.base.model.primitives.RuleType
import com.google.idea.blaze.base.run.ExecutorType
import com.google.idea.blaze.base.run.SourceToTargetFinder
import com.google.idea.blaze.base.run.TestTargetHeuristic
import com.google.idea.blaze.base.run.producers.RunConfigurationContext
import com.google.idea.blaze.base.run.producers.TestContext
import com.google.idea.blaze.base.run.producers.TestContextProvider
import com.google.idea.blaze.cpp.CppBlazeRules.RuleTypes
import com.intellij.execution.actions.ConfigurationContext
import com.intellij.util.asSafely
import com.jetbrains.cidr.radler.testing.RadTestPsiElement
import com.jetbrains.rider.model.RadTestElementModel
import com.jetbrains.rider.model.RadTestFramework
import org.jetbrains.ide.PooledThreadExecutor
import java.io.File
import java.util.*

class RadGoogleTestContextProvider : TestContextProvider {

override fun getTestContext(context: ConfigurationContext): RunConfigurationContext? {
val psiElement = context.psiLocation.asSafely<RadTestPsiElement>() ?: return null

if (psiElement.test.framework != RadTestFramework.GTest) {
return null
}

val targets = findTargets(context)
val target = Futures.transform(targets, { chooseTargetForFile(context, it) }, PooledThreadExecutor.INSTANCE)

return TestContext.builder(psiElement, ExecutorType.DEBUG_SUPPORTED_TYPES)
.setTarget(target)
.setTestFilter(createTestFilter(psiElement.test))
.build()
}
}

private fun findTargets(context: ConfigurationContext): ListenableFuture<Collection<TargetInfo>> {
val virtualFile = context.location?.virtualFile ?: return Futures.immediateFuture(emptyList())

return SourceToTargetFinder.findTargetInfoFuture(
context.project,
File(virtualFile.path),
Optional.of(RuleType.TEST),
) ?: Futures.immediateFuture(emptyList())
}

private fun chooseTargetForFile(context: ConfigurationContext, targets: Collection<TargetInfo>): TargetInfo? {
val psiFile = context.psiLocation?.containingFile ?: return null
val virtualFile = psiFile.virtualFile ?: return null

val ccTargets = targets.filter { it -> it.kind == RuleTypes.CC_TEST.kind }

return TestTargetHeuristic.chooseTestTargetForSourceFile(
context.project,
psiFile,
File(virtualFile.path),
ccTargets,
null,
)
}

private fun createTestFilter(test: RadTestElementModel): String? {
val suite = test.suites?.firstOrNull() ?: "*"
val name = test.test ?: "*"

return "$suite.$name"
}
20 changes: 20 additions & 0 deletions clwb/src/com/google/idea/blaze/clwb/radler/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
~ Copyright 2024 The Bazel Authors. All rights reserved.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<idea-plugin>
<extensions defaultExtensionNs="com.google.idea.blaze">
<TestContextProvider implementation="com.google.idea.blaze.clwb.radler.RadGoogleTestContextProvider"/>
</extensions>
</idea-plugin>
2 changes: 2 additions & 0 deletions intellij_platform_sdk/BUILD.clion243
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ java_import(
"plugins/clion-test-google/lib/*.jar",
"plugins/clion-test-catch/lib/*.jar",
"plugins/clion-test-boost/lib/*.jar",
"plugins/clion-radler/lib/*.jar",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a possible solution: define this in a separate java_import statement, use that library in https://github.com/bazelbuild/intellij/pull/7062/files#diff-242eb0d3dc78241907aa160705183dba65b9f3cb747ee146887eaf081f7622f5R18 and let's keep using classic so far for development purposes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I played around with multiple options, I think just using the suppressed plugin set options is the easiest for now. This allows us later to run test for classic and radler. Tho radler requires the path to the backend binary which I could not get working for now.

"plugins/clion-rd-components/lib/*.jar",
"plugins/nativeDebug-plugin/lib/*.jar",
"plugins/clion-ide/lib/clion-ide.jar", # for CMakeNotificationProvider
"plugins/clion-test-google-plugin/lib/clion-test-google-plugin.jar", # for com.jetbrains.cidr.execution.testing.google
Expand Down