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

chore(copybara): sync commits from Aspect-internal silo #452

Merged
merged 3 commits into from
Jun 1, 2023
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
1 change: 1 addition & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ write_source_files(
"//pkg/plugin/sdk/v1alpha1/proto:proto_go_proto.update_go_pb",
"//pkg/plugin/sdk/v1alpha2/proto:proto_go_proto.update_go_pb",
"//pkg/plugin/sdk/v1alpha3/proto:proto_go_proto.update_go_pb",
"//pkg/plugin/sdk/v1alpha4/proto:proto_go_proto.update_go_pb",
],
)

Expand Down
13 changes: 8 additions & 5 deletions cmd/aspect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,19 @@ func main() {
aspecterrors.HandleError(err)
}

argsWithoutStartupFlags, err := bazel.InitializeStartupFlags(os.Args[1:])
restArgs, startupFlags, err := bazel.InitializeStartupFlags(os.Args[1:])

if err != nil {
aspecterrors.HandleError(err)
}
os.Args = append(os.Args[0:1], argsWithoutStartupFlags...)

if err = command(bzl, streams); err != nil {
if err = command(bzl, streams, restArgs, startupFlags); err != nil {
aspecterrors.HandleError(err)
}
}

func command(bzl bazel.Bazel, streams ioutils.Streams) error {
func command(bzl bazel.Bazel, streams ioutils.Streams, restArgs, startupFlags []string) error {

pluginsConfig := viper.Get("plugins")
pluginSystem := system.NewPluginSystem()
if err := pluginSystem.Configure(streams, pluginsConfig); err != nil {
Expand All @@ -89,10 +90,12 @@ func command(bzl bazel.Bazel, streams ioutils.Streams) error {
return err
}

if err := pluginSystem.RegisterCustomCommands(cmd); err != nil {
if err := pluginSystem.RegisterCustomCommands(cmd, startupFlags); err != nil {
return err
}

os.Args = append(os.Args[0:1], restArgs...)

if err := cmd.ExecuteContext(context.Background()); err != nil {
return err
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/docgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ func main() {
log.Fatal(err)
}

argsWithoutStartupFlags, err := bazel.InitializeStartupFlags(os.Args[1:])
restArgs, startupFlags, err := bazel.InitializeStartupFlags(os.Args[1:])

if err != nil {
log.Fatal(err)
}
os.Args = append(os.Args[0:1], argsWithoutStartupFlags...)

if err = command(bzl); err != nil {
if err = command(bzl, restArgs, startupFlags); err != nil {
log.Fatal(err)
}
}

func command(bzl bazel.Bazel) error {
func command(bzl bazel.Bazel, restArgs, startupFlags []string) error {
cmd := &cobra.Command{Use: "docgen"}

pluginSystem := system.NewPluginSystem()
Expand All @@ -68,7 +68,7 @@ func command(bzl bazel.Bazel) error {
return err
}

if err := pluginSystem.RegisterCustomCommands(cmd); err != nil {
if err := pluginSystem.RegisterCustomCommands(cmd, startupFlags); err != nil {
return err
}

Expand Down
5 changes: 3 additions & 2 deletions gazelle/js/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@ func (ts *TypeScript) addProjectRule(cfg *JsGazelleConfig, args language.Generat

for result := range ts.collectAllImports(cfg, args, sourceFiles) {
if len(result.Errors) > 0 {
fmt.Println(result.SourcePath, "parse error(s):")
fmt.Printf("%s:\n", result.SourcePath)
for _, err := range result.Errors {
fmt.Println(err)
fmt.Printf("\t%s\n", err)
}
fmt.Println()
}

for _, sourceImport := range result.Imports {
Expand Down
15 changes: 9 additions & 6 deletions gazelle/js/tests/parse_errors/expectedStdout.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
subbuild/subbuild-bad.ts parse error(s):
4: Expected ";" but found "1"
subdir/subdir-bad.ts parse error(s):
3: Expected "}" but found "SyntaxError"
bad.ts parse error(s):
2: Expected ";" but found "like"
subbuild/subbuild-bad.ts:
4: Expected ";" but found "1"

subdir/subdir-bad.ts:
3: Expected "}" but found "SyntaxError"

bad.ts:
2: Expected ";" but found "like"

6 changes: 3 additions & 3 deletions pkg/bazel/bazel.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ func (b *bazel) RunCommand(streams ioutils.Streams, wd *string, command ...strin
}

// Initializes start-up flags from args and returns args without start-up flags
func InitializeStartupFlags(args []string) ([]string, error) {
func InitializeStartupFlags(args []string) ([]string, []string, error) {
nonFlags, flags, err := ParseOutBazelFlags("startup", args)
if err != nil {
return nil, err
return nil, nil, err
}

startupFlags = flags
return nonFlags, nil
return nonFlags, flags, nil
}

// Flags fetches the metadata for Bazel's command line flag via `bazel help flags-as-proto`
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/client/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/ioutils",
"//pkg/plugin/sdk/v1alpha3/config",
"//pkg/plugin/sdk/v1alpha3/plugin",
"//pkg/plugin/sdk/v1alpha4/config",
"//pkg/plugin/sdk/v1alpha4/plugin",
"//pkg/plugin/types",
"@com_github_fatih_color//:color",
"@com_github_hashicorp_go_hclog//:go-hclog",
Expand Down
6 changes: 3 additions & 3 deletions pkg/plugin/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import (
goplugin "github.com/hashicorp/go-plugin"

"aspect.build/cli/pkg/ioutils"
"aspect.build/cli/pkg/plugin/sdk/v1alpha3/config"
"aspect.build/cli/pkg/plugin/sdk/v1alpha3/plugin"
"aspect.build/cli/pkg/plugin/sdk/v1alpha4/config"
"aspect.build/cli/pkg/plugin/sdk/v1alpha4/plugin"
"aspect.build/cli/pkg/plugin/types"
)

Expand All @@ -48,7 +48,7 @@ func NewFactory() Factory {
// ExecuteCustomCommand method so that the Core can ask over gRPC for a specific command to
// be executed. `cmdName` is the name of the custom command the plugin created.
type CustomCommandExecutor interface {
ExecuteCustomCommand(cmdName string, ctx context.Context, args []string) error
ExecuteCustomCommand(cmdName string, ctx context.Context, args []string, bazelStartupArgs []string) error
}

type clientFactory struct {
Expand Down
5 changes: 5 additions & 0 deletions pkg/plugin/sdk/v1alpha4/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Plugin SDK v1alpha4

This is the SDK for creating plugins for the Aspect CLI using the Go language.

See https://aspect-build.github.io/aspect-cli/help/topics/plugins
13 changes: 13 additions & 0 deletions pkg/plugin/sdk/v1alpha4/config/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "config",
srcs = ["config.go"],
importpath = "aspect.build/cli/pkg/plugin/sdk/v1alpha4/config",
visibility = ["//visibility:public"],
deps = [
"//pkg/plugin/sdk/v1alpha4/plugin",
"@com_github_hashicorp_go_plugin//:go-plugin",
"@org_golang_google_grpc//:go_default_library",
],
)
65 changes: 65 additions & 0 deletions pkg/plugin/sdk/v1alpha4/config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2022 Aspect Build Systems, Inc.
*
* 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 config

import (
"math"

goplugin "github.com/hashicorp/go-plugin"
"google.golang.org/grpc"

"aspect.build/cli/pkg/plugin/sdk/v1alpha4/plugin"
)

// DefaultPluginName is the name each aspect plugin must provide.
const DefaultPluginName = "aspectplugin"

// Handshake is the shared handshake config for the v1alpha4 protocol.
var Handshake = goplugin.HandshakeConfig{
ProtocolVersion: 3,
MagicCookieKey: "PLUGIN",
MagicCookieValue: "ASPECT",
}

// PluginMap represents the plugin interfaces allowed to be implemented by a
// plugin executable.
var PluginMap = map[string]goplugin.Plugin{
DefaultPluginName: &plugin.GRPCPlugin{},
}

// NewConfigFor returns the default configuration for the passed Plugin
// implementation.
func NewConfigFor(p plugin.Plugin) *goplugin.ServeConfig {
return &goplugin.ServeConfig{
HandshakeConfig: Handshake,
Plugins: map[string]goplugin.Plugin{
DefaultPluginName: &plugin.GRPCPlugin{Impl: p},
},
GRPCServer: func(opts []grpc.ServerOption) *grpc.Server {
return grpc.NewServer(append(
opts,
// Bazel doesn't seem to set a maximum send message size, therefore
// we match the default send message for Go, which should be enough
// for all messages sent by Bazel (roughly 2.14GB).
grpc.MaxRecvMsgSize(math.MaxInt32),
// Here we are just being explicit with the default value since we
// also set the receive message size.
grpc.MaxSendMsgSize(math.MaxInt32),
)...)
},
}
}
19 changes: 19 additions & 0 deletions pkg/plugin/sdk/v1alpha4/plugin/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "plugin",
srcs = [
"grpc.go",
"interface.go",
],
importpath = "aspect.build/cli/pkg/plugin/sdk/v1alpha4/plugin",
visibility = ["//visibility:public"],
deps = [
"//bazel/buildeventstream",
"//pkg/ioutils",
"//pkg/plugin/sdk/v1alpha4/proto",
"@com_github_hashicorp_go_plugin//:go-plugin",
"@com_github_manifoldco_promptui//:promptui",
"@org_golang_google_grpc//:go_default_library",
],
)
Loading