diff --git a/.bazelci/clion.yml b/.bazelci/clion.yml index f62e4044241..04261221c73 100644 --- a/.bazelci/clion.yml +++ b/.bazelci/clion.yml @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/clwb/BUILD b/clwb/BUILD index af9f78a9514..9a8c8e5d354 100644 --- a/clwb/BUILD +++ b/clwb/BUILD @@ -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( @@ -60,6 +73,7 @@ stamped_plugin_xml( java_library( name = "clwb_lib", srcs = glob(["src/**/*.java"]), + visibility = ["//clwb:__subpackages__"], deps = [ "//base", "//common/actions", diff --git a/clwb/build_defs.bzl b/clwb/build_defs.bzl new file mode 100644 index 00000000000..4363456bc52 --- /dev/null +++ b/clwb/build_defs.bzl @@ -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, + ) diff --git a/clwb/src/com/google/idea/blaze/clwb/radler/BUILD b/clwb/src/com/google/idea/blaze/clwb/radler/BUILD new file mode 100644 index 00000000000..51a5aacf416 --- /dev/null +++ b/clwb/src/com/google/idea/blaze/clwb/radler/BUILD @@ -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", + ], +) diff --git a/clwb/src/com/google/idea/blaze/clwb/radler/RadGoogleTestContextProvider.kt b/clwb/src/com/google/idea/blaze/clwb/radler/RadGoogleTestContextProvider.kt new file mode 100644 index 00000000000..2d710db86f5 --- /dev/null +++ b/clwb/src/com/google/idea/blaze/clwb/radler/RadGoogleTestContextProvider.kt @@ -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() ?: 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> { + 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? { + 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" +} \ No newline at end of file diff --git a/clwb/src/com/google/idea/blaze/clwb/radler/optional-plugin.xml b/clwb/src/com/google/idea/blaze/clwb/radler/optional-plugin.xml new file mode 100644 index 00000000000..d1904e5f172 --- /dev/null +++ b/clwb/src/com/google/idea/blaze/clwb/radler/optional-plugin.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/clwb/test_defs.bzl b/clwb/test_defs.bzl index 1cdccf5f140..35ce4188a11 100644 --- a/clwb/test_defs.bzl +++ b/clwb/test_defs.bzl @@ -35,6 +35,9 @@ def clwb_integration_test(name, project, srcs, deps = []): "-Dcom.google.testing.junit.runner.shouldInstallTestSecurityManager=false", # fixes preferences not writable on mac "-Djava.util.prefs.PreferencesFactory=com.google.idea.blaze.clwb.base.InMemoryPreferencesFactory", + # suppressed plugin sets for classic, radler is currently disabled for tests + "-Didea.suppressed.plugins.set.classic=org.jetbrains.plugins.clion.radler,intellij.rider.cpp.debugger,intellij.rider.plugins.clion.radler.cwm", + "-Didea.suppressed.plugins.set.selector=classic", ], deps = deps + [ ":clwb_lib", diff --git a/intellij_platform_sdk/BUILD.clion243 b/intellij_platform_sdk/BUILD.clion243 index ad92f06dd35..bb7ad3cb60c 100644 --- a/intellij_platform_sdk/BUILD.clion243 +++ b/intellij_platform_sdk/BUILD.clion243 @@ -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", + "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