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

(rebase) Support embedded go_proto_library #6030

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 34 additions & 14 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
Expand Up @@ -391,20 +391,6 @@ http_archive(
url = PYTHON_PLUGIN_233_URL,
)

http_archive(
name = "python_2023_1",
build_file_content = _PYTHON_CE_BUILD_FILE,
sha256 = "825c30d2cbcce405fd18fddf356eb1f425607e9c780f8eff95d21ac23f8d90fd",
url = "https://plugins.jetbrains.com/maven/com/jetbrains/plugins/PythonCore/231.8770.65/PythonCore-231.8770.65.zip",
)

http_archive(
name = "python_2023_2",
build_file_content = _PYTHON_CE_BUILD_FILE,
sha256 = "e744349f353568c18a9e11ec5e3a205f62bbdc1b65c9abc96783c479fe2aa51b",
url = "https://plugins.jetbrains.com/maven/com/jetbrains/plugins/PythonCore/232.9921.47/PythonCore-232.9921.47.zip",
)

PYTHON_PLUGIN_241_URL = "https://plugins.jetbrains.com/maven/com/jetbrains/plugins/PythonCore/241.14494.127/PythonCore-241.14494.127.zip"

PYTHON_PLUGIN_241_SHA = "41d941d9198078df72583297ca643c2c465a58fa478beda595e18f79fccb7dca"
Expand Down Expand Up @@ -774,3 +760,37 @@ grpc_java_repositories()

# Register custom java 17 toolchain
register_toolchains("//:custom_java_17_toolchain_definition")

# Dependency needed for Go test library
http_archive(
name = "bazel_gazelle",
sha256 = "29218f8e0cebe583643cbf93cae6f971be8a2484cdcfa1e45057658df8d54002",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.32.0/bazel-gazelle-v0.32.0.tar.gz",
"https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.32.0/bazel-gazelle-v0.32.0.tar.gz",
],
)

load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

# gRPC is used to generate Go from proto in the aspect tests, in
# //aspect/testing/tests/src/com/google/idea/blaze/aspect/go/...
go_repository(
name = "org_golang_google_grpc",
build_file_proto_mode = "disable",
importpath = "google.golang.org/grpc",
sum = "h1:zvIju4sqAGvwKspUQOhwnpcqSbzi7/H6QomNNjTL4sk=",
version = "v1.27.1",
)

load("@io_bazel_rules_go//tests:grpc_repos.bzl", "grpc_dependencies")

grpc_dependencies()

load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies")

go_rules_dependencies()

go_register_toolchains(version = "1.19.3")

gazelle_dependencies(go_repository_default_config = "//:WORKSPACE.bzlmod")
2 changes: 1 addition & 1 deletion aspect/intellij_info_impl.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ def collect_go_info(target, ctx, semantics, ide_info, ide_info_file, output_grou
library_labels = [stringify_label(ctx.rule.attr.library.label)]
elif getattr(ctx.rule.attr, "embed", None) != None:
for library in ctx.rule.attr.embed:
if library.intellij_info.kind == "go_source":
if library.intellij_info.kind == "go_source" or library.intellij_info.kind == "go_proto_library":
l = library.intellij_info.output_groups["intellij-sources-go-outputs"].to_list()
sources += l
generated += [f for f in l if not f.is_source]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load(
"//aspect/testing/rules:intellij_aspect_test_fixture.bzl",
"intellij_aspect_test_fixture",
)

proto_library(
name = "fooproto_proto",
srcs = ["fooserver.proto"],
visibility = ["//visibility:public"],
deps = ["@com_google_protobuf//:empty_proto"],
)

go_proto_library(
name = "fooproto_go_proto",
compilers = ["@io_bazel_rules_go//proto:go_grpc"],
importpath = "github.com/bazelbuild/intellij/examples/go/with_proto/proto",
proto = ":fooproto_proto",
visibility = ["//visibility:public"],
)

go_library(
name = "proto",
srcs = ["translators.go"],
embed = [":fooproto_go_proto"],
importpath = "github.com/bazelbuild/intellij/examples/go/with_proto/proto",
visibility = ["//visibility:public"],
)

intellij_aspect_test_fixture(
name = "simple_fixture",
deps = [":proto"],
)

java_test(
name = "GoTest",
srcs = ["GoTest.java"],
data = [":simple_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",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* 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.aspect.go.go_proto_library;

import static com.google.common.truth.Truth.assertThat;

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 java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


/** Tests go_proto_library */
@RunWith(JUnit4.class)
public class GoTest extends BazelIntellijAspectTest {
@Test
public void testGoTest() throws Exception {
IntellijAspectTestFixture testFixture = loadTestFixture(":simple_fixture");
TargetIdeInfo target = findTarget(testFixture, ":proto");
assertThat(target.getKindString()).isEqualTo("go_library");
assertThat(relativePathsForArtifacts(target.getGoIdeInfo().getSourcesList()))
.contains(testRelative("translators.go"));
assertThat(relativePathsForArtifacts(target.getGoIdeInfo().getSourcesList()))
.contains(testRelative("fooproto_go_proto_/github.com/bazelbuild/intellij/examples/go/with_proto/proto/fooserver.pb.go"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
syntax = "proto3";

package fooproto;

import "google/protobuf/empty.proto";

service FooService {
rpc SayHello (HelloRequest) returns (HelloReply) {}
// This function exists to validate that the well known types (such as google.protobuf.Empty)
// are picked up by the plugin.
// To validate that they are working, navigate to "External Libraries" > "Go Libraries" >
// "github.com/bazelbuild/intellij/examples/go/with_proto/proto/fooserver.pb.go",
// and validate that "google.golang.org/protobuf/types/known/emptypb" is resolved correctly.
rpc EmptyFunction (google.protobuf.Empty) returns (google.protobuf.Empty);
}

message HelloRequest {
optional string name = 1;
}

message HelloReply {
optional string message = 1;
}

message Time {
string value = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package proto

import (
"time"
)

// Time translation functions.

func ToProtoTime(t time.Time) Time {
return Time{Value: t.Format(time.RFC3339Nano)}
}
1 change: 1 addition & 0 deletions examples/go/with_proto/proto/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ go_proto_library(

go_library(
name = "proto",
srcs = ["translators.go"],
embed = [":fooproto_go_proto"],
importpath = "github.com/bazelbuild/intellij/examples/go/with_proto/proto",
visibility = ["//visibility:public"],
Expand Down
4 changes: 4 additions & 0 deletions examples/go/with_proto/proto/fooserver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ message HelloRequest {
message HelloReply {
optional string message = 1;
}

message Time {
string value = 1;
}
12 changes: 12 additions & 0 deletions examples/go/with_proto/proto/translators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package proto

import (
"time"
)

// Time translation functions.
// If all symbols resolve correctly (i.e. there are no red squigglies after a sync)
// then this target is working.
func ToProtoTime(t time.Time) Time {
blorente marked this conversation as resolved.
Show resolved Hide resolved
return Time{Value: t.Format(time.RFC3339Nano)}
}
Loading