-
Notifications
You must be signed in to change notification settings - Fork 311
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d777506
basic google test support
LeFrosch 4886caf
test filter for google test
LeFrosch e09796f
introduce `select_since` for backwards incompatible dependencies in c…
LeFrosch 584296e
update CLion CI build targets
LeFrosch 9d92a75
update clwb integration to suppress radler plugins
LeFrosch 1f0d50f
refactor to use coroutines instead of Futures.transform
LeFrosch 3f604ee
rename plugin.xml file for optional-plugin.xml
LeFrosch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "optional-plugin.xml", | ||
) | ||
|
||
kt_jvm_library( | ||
name = "lib", | ||
srcs = glob(["*.kt"]), | ||
deps = [ | ||
"//intellij_platform_sdk:plugin_api", | ||
"//clwb:clwb_lib", | ||
], | ||
) |
91 changes: 91 additions & 0 deletions
91
clwb/src/com/google/idea/blaze/clwb/radler/RadGoogleTestContextProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* 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.base.util.pluginProjectScope | ||
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 kotlinx.coroutines.async | ||
import kotlinx.coroutines.guava.await | ||
import kotlinx.coroutines.guava.asListenableFuture | ||
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 target = pluginProjectScope(context.project).async { | ||
chooseTargetForFile(context, findTargets(context).await()) | ||
}.asListenableFuture() | ||
|
||
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
20
clwb/src/com/google/idea/blaze/clwb/radler/optional-plugin.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 purposesThere was a problem hiding this comment.
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.