diff --git a/.bazelrc.remote b/.bazelrc.remote new file mode 100644 index 00000000000..f45d7a6fd2f --- /dev/null +++ b/.bazelrc.remote @@ -0,0 +1,7 @@ +build --bes_results_url=https://app.buildbuddy.io/invocation/ +build --bes_backend=grpcs://cloud.buildbuddy.io +# build --remote_cache=grpcs://cloud.buildbuddy.io + +# build --remote_download_minimal +# build --remote_retries=0 +# build --remote_timeout=10 diff --git a/.bazelversion b/.bazelversion new file mode 100644 index 00000000000..09b254e90c6 --- /dev/null +++ b/.bazelversion @@ -0,0 +1 @@ +6.0.0 diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml new file mode 100644 index 00000000000..b7ea78e2a21 --- /dev/null +++ b/.github/workflows/continuous-integration-workflow.yml @@ -0,0 +1,28 @@ +name: Run all tests +on: [push] +jobs: + build: + name: test with ${{ matrix.ij_product }} + runs-on: ubuntu-20.04 + continue-on-error: ${{ matrix.experimental }} + strategy: + fail-fast: false + matrix: + ij_product: ['intellij-2022.1', 'intellij-2022.2', 'intellij-2022.3'] + experimental: [false] + steps: + - uses: actions/checkout@v2 + - name: bazel cache + uses: actions/cache@v2 + with: + path: ~/.bazel-repository-cache + key: ${{ github.ref }} + restore-keys: refs/heads/master + - name: run bazel + continue-on-error: ${{ matrix.experimental }} + run: > + bazel --bazelrc=.bazelrc.remote test //:ijwb_ce_tests + --repository_cache=~/.bazel-repository-cache + --define=ij_product=${{ matrix.ij_product }} + --keep_going + --test_output=errors diff --git a/WORKSPACE b/WORKSPACE index af1686b012a..4f6db321c24 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -641,3 +641,29 @@ jvm_maven_import_external( licenses = ["notice"], # Apache 2.0 server_urls = ["https://repo1.maven.org/maven2"], ) + +bazel_version = "31082327bdb64b7bf52dd55ae18d29e920e61025" + +bazel_repo_sha256 = "e8e1ac4bcab303f8f99c9b14ad3afbd059b84c516b7e76f6d9b89b8d5175594f" + +http_archive( + name = "bazel", + sha256 = bazel_repo_sha256, + strip_prefix = "bazel-" + bazel_version, + url = "https://github.com/bazelbuild/bazel/archive/%s.zip" % bazel_version, +) + +http_archive( + name = "io_buildbuddy_buildbuddy_toolchain", + sha256 = "9055a3e6f45773cd61931eba7b7cf35d6477ab6ad8fb2f18bf9815271fc682fe", + strip_prefix = "buildbuddy-toolchain-52aa5d2cc6c9ba7ee4063de35987be7d1b75f8e2", + urls = ["https://github.com/buildbuddy-io/buildbuddy-toolchain/archive/52aa5d2cc6c9ba7ee4063de35987be7d1b75f8e2.tar.gz"], +) + +load("@io_buildbuddy_buildbuddy_toolchain//:deps.bzl", "buildbuddy_deps") + +buildbuddy_deps() + +load("@io_buildbuddy_buildbuddy_toolchain//:rules.bzl", "buildbuddy") + +buildbuddy(name = "buildbuddy_toolchain") diff --git a/aspect/fast_build_info.bzl b/aspect/fast_build_info.bzl index db99e951c32..3dcba6fd2d0 100644 --- a/aspect/fast_build_info.bzl +++ b/aspect/fast_build_info.bzl @@ -23,6 +23,7 @@ def _fast_build_info_impl(target, ctx): "workspace_name": ctx.workspace_name, "label": stringify_label(target.label), "dependencies": [stringify_label(t.label) for t in dep_targets], + "build_file_path": ctx.build_file_path, } write_output = False @@ -43,6 +44,9 @@ def _fast_build_info_impl(target, ctx): elif java_common.JavaToolchainInfo != platform_common.ToolchainInfo and \ java_common.JavaToolchainInfo in target: toolchain = target[java_common.JavaToolchainInfo] + elif hasattr(ctx.rule.attr, "java_compile_toolchain") and ctx.rule.attr.java_compile_toolchain and \ + java_common.JavaToolchainInfo in ctx.rule.attr.java_compile_toolchain: + toolchain = ctx.rule.attr.java_compile_toolchain[java_common.JavaToolchainInfo] else: toolchain = None if toolchain: @@ -53,11 +57,17 @@ def _fast_build_info_impl(target, ctx): bootclasspath_jars = [] if hasattr(toolchain, "bootclasspath"): bootclasspath_jars = [artifact_location(f) for f in toolchain.bootclasspath.to_list()] + java_runtime = struct() + if hasattr(toolchain, "java_runtime"): + java_runtime = struct_omit_none( + java_executable_exec_path = toolchain.java_runtime.java_executable_exec_path, + ) info["java_toolchain_info"] = struct_omit_none( javac_jars = javac_jars, bootclasspath_jars = bootclasspath_jars, source_version = toolchain.source_version, target_version = toolchain.target_version, + java_runtime = java_runtime, ) if JavaInfo in target: write_output = True @@ -92,6 +102,13 @@ def _fast_build_info_impl(target, ctx): ) info["android_info"] = android_info + if ProtoInfo in target: + write_output = True + proto_info = { + "sources": sources_from_target(ctx), + } + info["proto_info"] = struct_omit_none(**proto_info) + if write_output: output_file = ctx.actions.declare_file(target.label.name + ".ide-fast-build-info.txt") ctx.actions.write(output_file, struct_omit_none(**info).to_proto()) diff --git a/aspect/intellij_info_impl.bzl b/aspect/intellij_info_impl.bzl index 39b8e601178..43d6019273c 100644 --- a/aspect/intellij_info_impl.bzl +++ b/aspect/intellij_info_impl.bzl @@ -156,13 +156,8 @@ def library_artifact(java_output, rule_kind = None): return None src_jars = get_source_jars(java_output) - if rule_kind != None and rule_kind.startswith("scala"): - interface_jar = None - else: - interface_jar = artifact_location(java_output.ijar) - return struct_omit_none( - interface_jar = interface_jar, + interface_jar = None, jar = artifact_location(java_output.class_jar), source_jar = artifact_location(src_jars[0]) if src_jars else None, source_jars = [artifact_location(f) for f in src_jars], @@ -328,6 +323,24 @@ def _do_starlark_string_expansion(ctx, name, strings, extra_targets = []): return strings ##### Builders for individual parts of the aspect output +def collect_proto_info(target, ctx, semantics, ide_info, ide_info_file, output_groups): + if not ProtoInfo in target: + return False + + proto_info = target[ProtoInfo] + proto_output = depset([proto_info.direct_descriptor_set]) + + ide_info["proto_ide_info"] = struct_omit_none( + sources = sources_from_target(ctx), + source_root = proto_info.proto_source_root, + strip_import_prefix = ctx.rule.attr.strip_import_prefix, + import_prefix = ctx.rule.attr.import_prefix, + ) + + update_sync_output_groups(output_groups, "intellij-info-proto", depset([ide_info_file])) + update_sync_output_groups(output_groups, "intellij-compile-proto", proto_output) + update_sync_output_groups(output_groups, "intellij-resolve-proto", proto_output) + return True def collect_py_info(target, ctx, semantics, ide_info, ide_info_file, output_groups): """Updates Python-specific output groups, returns false if not a Python target.""" @@ -1123,6 +1136,7 @@ def intellij_info_aspect_impl(target, ctx, semantics): ide_info["test_info"] = build_test_info(ctx) handled = False + handled = collect_proto_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled handled = collect_py_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled handled = collect_cpp_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled handled = collect_c_toolchain_info(target, ctx, semantics, ide_info, ide_info_file, output_groups) or handled diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/BUILD b/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/BUILD new file mode 100644 index 00000000000..0b932ae4122 --- /dev/null +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/BUILD @@ -0,0 +1,41 @@ +licenses(["notice"]) # Apache 2.0 + +load( + "//aspect/testing/rules:intellij_aspect_test_fixture.bzl", + "intellij_aspect_test_fixture", +) + +proto_library( + name = "a_proto", + srcs = ["a.proto"], + import_prefix = "test", + strip_import_prefix = "/" + package_name(), +) + +proto_library( + name = "b_proto", + srcs = ["b.proto"], + deps = [":a_proto"], +) + +intellij_aspect_test_fixture( + name = "fixture", + deps = [":b_proto"], +) + +java_test( + name = "ProtoLibraryTest", + srcs = ["ProtoLibraryTest.java"], + data = [ + ":fixture", + ], + deps = [ + "//aspect/testing:BazelIntellijAspectTest", + "//aspect/testing:guava", + "//aspect/testing/rules:IntellijAspectTest", + "//aspect/testing/rules:intellij_aspect_test_fixture_java_proto", + "//intellij_platform_sdk:test_libs", + "//proto:intellij_ide_info_java_proto", + "@junit//jar", + ], +) diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/ProtoLibraryTest.java b/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/ProtoLibraryTest.java new file mode 100644 index 00000000000..22984a8518b --- /dev/null +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/ProtoLibraryTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2017 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.aspect.proto.pl; + +import com.google.devtools.intellij.IntellijAspectTestFixtureOuterClass.IntellijAspectTestFixture; +import com.google.devtools.intellij.ideinfo.IntellijIdeInfo.TargetIdeInfo; +import com.google.idea.blaze.BazelIntellijAspectTest; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; + +import static com.google.common.truth.Truth.assertThat; + +/** Tests for proto_library. */ +@RunWith(JUnit4.class) +public class ProtoLibraryTest extends BazelIntellijAspectTest { + + @Test + public void testProtoLibrary() throws Exception { + IntellijAspectTestFixture fixture = loadTestFixture(":fixture"); + + TargetIdeInfo aProto = findTarget(fixture, ":a_proto"); + assertThat(aProto).isNotNull(); + assertThat(aProto.hasProtoIdeInfo()).isTrue(); + assertThat(relativePathsForArtifacts(aProto.getProtoIdeInfo().getSourcesList())) + .containsExactly(testRelative("a.proto")); + assertThat(aProto.getProtoIdeInfo().getSourceRoot()) + .isEqualTo( + "bazel-out/darwin-fastbuild/bin/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/_virtual_imports/a_proto"); + assertThat(aProto.getProtoIdeInfo().getImportPrefix()).isEqualTo("test"); + assertThat(aProto.getProtoIdeInfo().getStripImportPrefix()) + .isEqualTo("/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl"); + + TargetIdeInfo bProto = findTarget(fixture, ":b_proto"); + assertThat(bProto).isNotNull(); + assertThat(bProto.hasProtoIdeInfo()).isTrue(); + assertThat(relativePathsForArtifacts(bProto.getProtoIdeInfo().getSourcesList())) + .containsExactly(testRelative("b.proto")); + assertThat(bProto.getProtoIdeInfo().getSourceRoot()).isEqualTo("."); + assertThat(bProto.getProtoIdeInfo().getImportPrefix()).isEmpty(); + assertThat(bProto.getProtoIdeInfo().getStripImportPrefix()).isEmpty(); + assertThat(dependenciesForTarget(bProto)).contains(dep(aProto)); + + assertThat(getOutputGroupFiles(fixture, "intellij-info-proto")) + .containsExactly( + testRelative(intellijInfoFileName(aProto.getKey())), + testRelative(intellijInfoFileName(bProto.getKey()))); + + assertThat(getOutputGroupFiles(fixture, "intellij-compile-proto")) + .containsExactly( + testRelative("a_proto-descriptor-set.proto.bin"), + testRelative("b_proto-descriptor-set.proto.bin")); + + assertThat(getOutputGroupFiles(fixture, "intellij-resolve-proto")) + .containsExactly( + testRelative("a_proto-descriptor-set.proto.bin"), + testRelative("b_proto-descriptor-set.proto.bin")); + } +} diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/a.proto b/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/a.proto new file mode 100644 index 00000000000..972e1e98051 --- /dev/null +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/a.proto @@ -0,0 +1,3 @@ +syntax = "proto2"; +package a; +message A {} diff --git a/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/b.proto b/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/b.proto new file mode 100644 index 00000000000..43e87d26fa4 --- /dev/null +++ b/aspect/testing/tests/src/com/google/idea/blaze/aspect/proto/pl/b.proto @@ -0,0 +1,4 @@ +syntax = "proto3"; +import "test/a.proto"; +package b; +message B {a.A a = 1;} diff --git a/base/src/META-INF/blaze-base.xml b/base/src/META-INF/blaze-base.xml index fa9a7799bfb..ededbd3c010 100644 --- a/base/src/META-INF/blaze-base.xml +++ b/base/src/META-INF/blaze-base.xml @@ -226,6 +226,8 @@ serviceImplementation="com.google.idea.blaze.base.projectview.ProjectViewStorageManagerImpl"/> + targetLabels = SourceToTargetMap.getInstance(project) + .getTargetsToBuildForSourceFile(file).stream(); + Label label = - SourceToTargetMap.getInstance(project).getTargetsToBuildForSourceFile(file).stream() - .filter(l -> l.blazePackage().equals(packagePath)) + filterCRelatedLabelsWhichBelongToOtherPackages(file,packagePath, targetLabels) .findFirst() .orElse(null); if (label == null) { @@ -98,6 +103,28 @@ static PsiElement findBuildTarget(Project project, BlazePackage parentPackage, F return null; } + private static Stream