Skip to content

Commit

Permalink
Integration tests for CLion (#6581)
Browse files Browse the repository at this point in the history
Adds a test suite which runs CLion headless and imports a simple project.
  • Loading branch information
LeFrosch committed Aug 8, 2024
1 parent c5cad51 commit 6aa0ee4
Show file tree
Hide file tree
Showing 36 changed files with 663 additions and 100 deletions.
5 changes: 5 additions & 0 deletions .bazelci/clion.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,10 @@ tasks:
- --define=ij_product=clion-oss-under-dev
build_targets:
- //clwb/...
test_flags:
- --define=ij_product=clion-oss-under-dev
- --test_output=errors
test_targets:
- //clwb:integration_tests
soft_fail:
- exit_status: 1
11 changes: 8 additions & 3 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
build --java_language_version=17 --java_runtime_version=17

# delete testdata package needed for bazel integration tests
build --deleted_packages=//aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata
query --deleted_packages=//aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata
# Delete test data packages, needed for bazel integration tests. Update by running the following command:
# bazel run @rules_bazel_integration_test//tools:update_deleted_packages
build --deleted_packages=aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata,clwb/tests/projects/simple/main
query --deleted_packages=aspect/testing/tests/src/com/google/idea/blaze/aspect/integration/testdata,clwb/tests/projects/simple/main

common --enable_bzlmod

# Required for CLion integration tests on windows
startup --windows_enable_symlinks
build --enable_runfiles
1 change: 1 addition & 0 deletions BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ test_suite(
tests = [
"//base:unit_tests",
"//clwb:unit_tests",
"//clwb:integration_tests",
"//cpp:unit_tests",
"//dart:unit_tests",
"//python:unit_tests",
Expand Down
4 changes: 2 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ bazel_binaries = use_extension(
)
bazel_binaries.download(version = "5.4.1")
bazel_binaries.download(version = "6.5.0")
bazel_binaries.download(version = "7.0.2")
bazel_binaries.download(version = "7.2.1", current = True)
use_repo(
bazel_binaries,
"bazel_binaries",
"bazel_binaries_bazelisk",
"build_bazel_bazel_5_4_1",
"build_bazel_bazel_6_5_0",
"build_bazel_bazel_7_0_2",
"build_bazel_bazel_7_2_1",
)

bazel_dep(name = "rules_jvm_external", version = "6.2")
Expand Down
24 changes: 12 additions & 12 deletions MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions aspect/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,11 @@ genrule(
"sed -i -e 's,:intellij_info_impl.bzl,:intellij_info_impl_bundled.bzl,g' $@",
)

genrule(
name = "create_workspace_file",
outs = ["WORKSPACE"],
srcs = [],
cmd = r"""echo 'workspace(name = "intellij_aspect")' > $@"""
)

define_flag_hack()
1 change: 0 additions & 1 deletion aspect/WORKSPACE

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy;
import com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategy.OutputGroup;
import com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategyBazel;
import com.google.idea.blaze.base.sync.aspects.strategy.AspectRepositoryProvider;
import java.io.File;
import java.nio.file.Paths;
import java.util.Collection;
Expand Down Expand Up @@ -54,7 +55,7 @@ public static void main(String[] a) throws Exception {
aspectStrategyBazel.getAspectFlag().get(),
String.format(
"%s=%s/%s/aspect",
AspectStrategyBazel.OVERRIDE_REPOSITORY_FLAG,
AspectRepositoryProvider.OVERRIDE_REPOSITORY_FLAG,
System.getenv("TEST_SRCDIR"),
System.getenv("TEST_WORKSPACE")));

Expand Down
2 changes: 2 additions & 0 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@
<extensionPoint qualifiedName="com.google.idea.blaze.TestTargetHeuristic" interface="com.google.idea.blaze.base.run.TestTargetHeuristic"/>
<extensionPoint qualifiedName="com.google.idea.blaze.ProjectDataDirectoryValidator" interface="com.google.idea.blaze.base.wizard2.ProjectDataDirectoryValidator"/>
<extensionPoint qualifiedName="com.google.idea.blaze.AspectStrategyProvider" interface="com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategyProvider"/>
<extensionPoint qualifiedName="com.google.idea.blaze.AspectRepositoryProvider" interface="com.google.idea.blaze.base.sync.aspects.strategy.AspectRepositoryProvider"/>
<extensionPoint qualifiedName="com.google.idea.blaze.FileStringParser" interface="com.google.idea.blaze.base.run.filter.FileResolver"/>
<extensionPoint qualifiedName="com.google.idea.blaze.BlazeGuard" interface="com.google.idea.blaze.base.execution.BazelGuard"/>
<extensionPoint qualifiedName="com.google.idea.blaze.BlazeTestEventsHandler" interface="com.google.idea.blaze.base.run.smrunner.BlazeTestEventsHandler"/>
Expand Down Expand Up @@ -611,6 +612,7 @@
<TestTargetHeuristic implementation="com.google.idea.blaze.base.run.TestSizeFromRoughTargetNameHeuristic" order="last, after TestSizeHeuristic"/>
<RunConfigurationFactory implementation="com.google.idea.blaze.base.run.BlazeBuildTargetRunConfigurationFactory" order="last"/>
<AspectStrategyProvider implementation="com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategyBazel$Provider"/>
<AspectRepositoryProvider implementation="com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategyBazel$RepositoryProvider"/>
<FileStringParser implementation="com.google.idea.blaze.base.run.filter.StandardFileResolver" order="last"/>
<BlazeTestEventsHandler implementation="com.google.idea.blaze.base.run.smrunner.BlazeWebTestEventsHandler"/>
<BlazeTestEventsHandler implementation="com.google.idea.blaze.base.run.smrunner.BlazeGenericTestEventsHandler" order="last"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.google.idea.blaze.base.scope.output.IssueOutput;
import com.google.idea.blaze.common.PrintOutput;
import com.intellij.execution.configurations.PathEnvironmentVariableUtil;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.execution.ParametersListUtil;
import java.io.File;
Expand All @@ -41,6 +42,8 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.concurrent.TimeoutException;
import java.util.stream.Stream;
import javax.annotation.Nullable;
Expand All @@ -51,6 +54,11 @@ public interface ExternalTask {
/** Run the task, attaching the given scopes to the task's {@link BlazeContext}. */
int run(BlazeScope... scopes);

/** Run the task async on thread pool */
default Future<Integer> runAsync(BlazeScope... scopes) {
return CompletableFuture.supplyAsync(() -> run(scopes), ApplicationManager.getApplication()::executeOnPooledThread);
}

/** A builder for an external task */
class Builder {
@VisibleForTesting public final ImmutableList.Builder<String> command = ImmutableList.builder();
Expand Down
7 changes: 3 additions & 4 deletions base/src/com/google/idea/blaze/base/command/BlazeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.errorprone.annotations.CanIgnoreReturnValue;
import com.google.idea.blaze.base.bazel.BuildSystem.BuildInvoker;
import com.google.idea.blaze.base.model.primitives.TargetExpression;
import com.google.idea.blaze.base.sync.aspects.strategy.AspectStrategyBazel;
import com.google.idea.blaze.base.sync.aspects.strategy.AspectRepositoryProvider;

import java.nio.file.Path;
import java.util.Arrays;
Expand Down Expand Up @@ -110,9 +110,8 @@ public Builder(String binaryPath, BlazeCommandName name) {
this.invokeParallel = false;
// Tell forge what tool we used to call blaze so we can track usage.
addBlazeFlags(BlazeFlags.getToolTagFlag());
AspectStrategyBazel.getAspectRepositoryOverrideFlag().ifPresent(it ->
addBlazeFlags(it)
);

AspectRepositoryProvider.getOverrideFlag().ifPresent(this::addBlazeFlags);
}

private ImmutableList<String> getArguments() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@
import javax.annotation.concurrent.GuardedBy;

/** Manages sync execution, coordinating the possibly-separate build/update phases. */
final class SyncPhaseCoordinator {
public final class SyncPhaseCoordinator {

private static final Logger logger = Logger.getInstance(SyncPhaseCoordinator.class);

static SyncPhaseCoordinator getInstance(Project project) {
public static SyncPhaseCoordinator getInstance(Project project) {
return project.getService(SyncPhaseCoordinator.class);
}

Expand Down Expand Up @@ -410,7 +410,7 @@ private void doFilterProjectTargets(
* Otherwise runs the build phase then passes the result to the project update queue.
*/
@VisibleForTesting
void runSync(BlazeSyncParams params, boolean singleThreaded, BlazeContext context) {
public void runSync(BlazeSyncParams params, boolean singleThreaded, BlazeContext context) {
Instant startTime = Instant.now();
int buildId = nextBuildId.getAndIncrement();
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.google.idea.blaze.base.sync.aspects.strategy;

import com.intellij.openapi.extensions.ExtensionPointName;
import java.io.File;
import java.util.Optional;

public interface AspectRepositoryProvider {
ExtensionPointName<AspectRepositoryProvider> EP_NAME =
ExtensionPointName.create("com.google.idea.blaze.AspectRepositoryProvider");

String OVERRIDE_REPOSITORY_FLAG = "--override_repository=intellij_aspect";

Optional<File> aspectDirectory();

static Optional<File> findAspectDirectory() {
return EP_NAME.getExtensionsIfPointIsRegistered().stream()
.map(AspectRepositoryProvider::aspectDirectory)
.filter(Optional::isPresent)
.findFirst()
.orElse(Optional.empty());
}

static Optional<String> getOverrideFlag() {
return findAspectDirectory().map(it -> OVERRIDE_REPOSITORY_FLAG + "=" + it.getPath());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.idea.blaze.base.model.BlazeVersionData;
import com.google.idea.blaze.base.settings.BuildSystemName;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.extensions.PluginDescriptor;
import java.io.File;
import java.util.Optional;
import javax.annotation.Nullable;
Expand All @@ -38,6 +38,14 @@ public AspectStrategy getStrategy(BlazeVersionData versionData) {
}
}

static final class RepositoryProvider implements AspectRepositoryProvider {
@Override
public Optional<File> aspectDirectory() {
return Optional.ofNullable(PluginManager.getPluginByClass(AspectStrategy.class))
.map((it) -> new File(it.getPath(), "aspect"));
}
}

@VisibleForTesting
public AspectStrategyBazel(BlazeVersionData versionData) {
super(/* aspectSupportsDirectDepsTrimming= */ true);
Expand All @@ -54,24 +62,8 @@ public Optional<String> getAspectFlag() {
return Optional.of(aspectFlag);
}

// In tests, the location of @intellij_aspect is not known at compile time.
public static final String OVERRIDE_REPOSITORY_FLAG = "--override_repository=intellij_aspect";

@Override
public String getName() {
return "AspectStrategySkylarkBazel";
}

private static Optional<File> findAspectDirectory() {
IdeaPluginDescriptor plugin =
PluginManager.getPlugin(PluginManager.getPluginByClassName(AspectStrategy.class.getName()));
if (plugin == null) {
return Optional.empty();
}
return Optional.of(new File(plugin.getPath(), "aspect"));
}

public static Optional<String> getAspectRepositoryOverrideFlag() {
return findAspectDirectory().map(it -> OVERRIDE_REPOSITORY_FLAG + "=" + it.getPath());
}
}
12 changes: 12 additions & 0 deletions clwb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ load(
"//testing:test_defs.bzl",
"intellij_unit_test_suite",
)
load(":test_defs.bzl", "clwb_integration_test")

licenses(["notice"])

Expand Down Expand Up @@ -148,3 +149,14 @@ filegroup(
srcs = ["gdbserver"],
visibility = ["//visibility:public"],
)

clwb_integration_test(
name = "simple_integration_test",
project = "simple",
srcs = ["tests/integrationtests/com/google/idea/blaze/clwb/SimpleTest.java"],
)

test_suite(
name = "integration_tests",
tests = [":simple_integration_test"],
)
3 changes: 1 addition & 2 deletions clwb/clwb.bazelproject
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ directories:
-examples

targets:
//clwb:clwb_bazel_dev
//:clwb_tests
//clwb:all

workspace_type: intellij_plugin

Expand Down
Loading

0 comments on commit 6aa0ee4

Please sign in to comment.