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 #596

Merged
merged 5 commits into from
Jan 4, 2024
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: 0 additions & 1 deletion cmd/aspect/help/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/aspect/root/flags",
"//pkg/aspecterrors",
"//pkg/bazel",
"//pkg/interceptors",
"//pkg/ioutils",
Expand Down
12 changes: 1 addition & 11 deletions cmd/aspect/help/flags_as_proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"aspect.build/cli/pkg/aspect/root/flags"
"aspect.build/cli/pkg/aspecterrors"
"aspect.build/cli/pkg/bazel"
"aspect.build/cli/pkg/interceptors"
"aspect.build/cli/pkg/ioutils"
Expand All @@ -27,16 +26,7 @@ func NewFlagsAsProtoCmd(streams ioutils.Streams, bzl bazel.Bazel) *cobra.Command
flags.FlagsInterceptor(streams),
}, func(ctx context.Context, cmd *cobra.Command, args []string) error {
bazelCmd := []string{"help", "flags-as-proto"}

if exitCode, err := bzl.RunCommand(streams, nil, bazelCmd...); exitCode != 0 {
err = &aspecterrors.ExitError{
Err: err,
ExitCode: exitCode,
}
return err
}

return nil
return bzl.RunCommand(streams, nil, bazelCmd...)
}),
}
return &cmd
Expand Down
8 changes: 7 additions & 1 deletion cmd/aspect/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func NewDefaultCmd(pluginSystem system.PluginSystem) *cobra.Command {
}

func NewCmd(streams ioutils.Streams, pluginSystem system.PluginSystem, bzl bazel.Bazel) *cobra.Command {
return &cobra.Command{
cmd := &cobra.Command{
Use: "lint <target patterns>",
Args: cobra.MinimumNArgs(1),
Short: "Run configured linters over the dependency graph.",
Expand All @@ -46,4 +46,10 @@ func NewCmd(streams ioutils.Streams, pluginSystem system.PluginSystem, bzl bazel
lint.New(streams, bzl).Run,
),
}

cmd.Flags().Bool("fix", false, "Apply patch fixes for lint errors")
cmd.Flags().Bool("diff", false, "Output patch fixes for lint errors")
cmd.Flags().Bool("report", true, "Output lint reports")

return cmd
}
4 changes: 2 additions & 2 deletions cmd/aspect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ func main() {
streams := ioutils.DefaultStreams

// Re-enter another aspect if version running is not the configured version
reentered, exitCode, err := bzl.MaybeReenterAspect(streams, os.Args[1:], root.CheckAspectLockVersionFlag(os.Args[1:]))
reentered, err := bzl.MaybeReenterAspect(streams, os.Args[1:], root.CheckAspectLockVersionFlag(os.Args[1:]))
if reentered {
if err != nil {
aspecterrors.HandleError(err)
}
os.Exit(exitCode)
os.Exit(0)
}

// Handle --version and -v before initializing the plugin system so these special
Expand Down
5 changes: 4 additions & 1 deletion docs/aspect_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ aspect lint <target patterns> [flags]
### Options

```
-h, --help help for lint
--diff Output patch fixes for lint errors
--fix Apply patch fixes for lint errors
-h, --help help for lint
--report Output lint reports (default true)
```

### Options inherited from parent commands
Expand Down
16 changes: 2 additions & 14 deletions docs/bazelrc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
load("@aspect_bazel_lib//lib:bazelrc_presets.bzl", "write_aspect_bazelrc_presets")
load("@io_bazel_rules_go//go:def.bzl", "go_library")

write_aspect_bazelrc_presets(
name = "update_aspect_bazelrc_presets",
presets = [
"bazel6",
"bazel7",
"ci",
"convenience",
"correctness",
"debug",
"javascript",
"performance",
],
)
write_aspect_bazelrc_presets(name = "update_aspect_bazelrc_presets")

go_library(
name = "bazelrc",
Expand All @@ -23,8 +11,8 @@ go_library(
],
embedsrcs = [
".gitignore",
"bazel5.bazelrc",
"bazel6.bazelrc",
"bazel7.bazelrc",
"ci.bazelrc",
"convenience.bazelrc",
"correctness.bazelrc",
Expand Down
5 changes: 5 additions & 0 deletions docs/bazelrc/bazel5.bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Performance improvement for WORKSPACE evaluation
# of slow rulesets, for example rules_k8s has been
# observed to take 10 seconds without this flag.
# See https://github.com/bazelbuild/bazel/issues/13907
common --incompatible_existing_rules_immutable_view
15 changes: 0 additions & 15 deletions docs/bazelrc/bazel7.bazelrc

This file was deleted.

2 changes: 1 addition & 1 deletion gazelle/js/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ func (ts *Resolver) resolveModuleDep(

match := filteredMatches[0]

BazelLog.Tracef("resolve %q import %q as %q", mod.Imp, match)
BazelLog.Tracef("resolve %q import %q as %q", from, mod.Imp, match)

return Resolution_Override, &match, nil
}
Expand Down
7 changes: 7 additions & 0 deletions go.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def deps():
sum = "h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=",
version = "v0.0.0-20140422174119-9fd32a8b3d3d",
)
go_repository(
name = "com_github_bluekeyes_go_gitdiff",
build_file_proto_mode = "disable_global",
importpath = "github.com/bluekeyes/go-gitdiff",
sum = "h1:graP4ElLRshr8ecu0UtqfNTCHrtSyZd3DABQm/DWesQ=",
version = "v0.7.1",
)
go_repository(
name = "com_github_bmatcuk_doublestar_v4",
build_file_proto_mode = "disable_global",
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/bazelbuild/bazel-gazelle v0.34.0
github.com/bazelbuild/bazelisk v1.17.0
github.com/bazelbuild/buildtools v0.0.0-20231017121127-23aa65d4e117
github.com/bluekeyes/go-gitdiff v0.7.1
github.com/bmatcuk/doublestar/v4 v4.6.1
github.com/emirpasic/gods v1.18.1
github.com/fatih/color v1.16.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/bazelbuild/rules_go v0.42.0 h1:aY2smc3JWyUKOjGYmOKVLX70fPK9ON0rtwQoju
github.com/bazelbuild/rules_go v0.42.0/go.mod h1:TMHmtfpvyfsxaqfL9WnahCsXMWDMICTw7XeK9yVb+YU=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d h1:xDfNPAt8lFiC1UJrqV3uuy861HCTo708pDMbjHHdCas=
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d/go.mod h1:6QX/PXZ00z/TKoufEY6K/a0k6AhaJrQKdFe6OfVXsa4=
github.com/bluekeyes/go-gitdiff v0.7.1 h1:graP4ElLRshr8ecu0UtqfNTCHrtSyZd3DABQm/DWesQ=
github.com/bluekeyes/go-gitdiff v0.7.1/go.mod h1:QpfYYO1E0fTVHVZAZKiRjtSGY9823iCdvGXBcEzHGbM=
github.com/bmatcuk/doublestar/v4 v4.6.1 h1:FH9SifrbvJhnlQpztAx++wlkk70QBf0iBWDwNy7PA4I=
github.com/bmatcuk/doublestar/v4 v4.6.1/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
Expand Down
9 changes: 9 additions & 0 deletions integration_tests/aspect/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ bats_test(
env = env,
)

bats_test(
name = "reenter_test",
srcs = ["reenter_test.bats"],
data = data,
env = env,
# Bazel-in-bazel requires network
tags = ["requires-network"],
)

bats_test(
name = "version_test",
srcs = ["version_test.bats"],
Expand Down
41 changes: 41 additions & 0 deletions integration_tests/aspect/reenter_test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
load "common.bats"

setup() {
touch WORKSPACE
}

@test 'should download and reenter aspect cli version specified in bazeliskrc' {
cat > .bazeliskrc << 'EOF'
BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download
USE_BAZEL_VERSION=aspect/5.8.19
EOF
run aspect --version
assert_success
assert_output --partial "aspect 5.8.19"

rm .bazeliskrc
}

@test 'exit code from reentrant aspect cli should be progated to parent' {
cat > .bazeliskrc << 'EOF'
BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download
USE_BAZEL_VERSION=aspect/5.8.19
EOF
run aspect --versio
assert_failure
assert_output --partial "unknown startup flag: --versio"

rm .bazeliskrc
}

@test 'non-one exit code from reentrant aspect cli should be progated to parent' {
cat > .bazeliskrc << 'EOF'
BAZELISK_BASE_URL=https://github.com/aspect-build/aspect-cli/releases/download
USE_BAZEL_VERSION=aspect/5.8.19
EOF
run aspect configure --mode=diff
assert_failure 112
assert_output --partial "No languages enabled for BUILD file generation."

rm .bazeliskrc
}
10 changes: 5 additions & 5 deletions integration_tests/runner.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash
IFS=':' read -ra LIBS <<<"$BATS_LIB_PATH"
IFS=':' read -ra LIBS <<< "$BATS_LIB_PATH"

NEW_LIBS=()
for RAW_LIB_PATH in "${LIBS[@]}"; do
NEW_PATH=$(cd "${RAW_LIB_PATH}" && pwd)
NEW_LIBS+=("$NEW_PATH")
NEW_PATH=$(cd "${RAW_LIB_PATH}" && pwd)
NEW_LIBS+=("$NEW_PATH")
done

BATS_LIB_PATH=$(
IFS=:
echo "${NEW_LIBS[*]}"
IFS=:
echo "${NEW_LIBS[*]}"
)
export BATS_LIB_PATH
export BATS_TEST_TIMEOUT="$TEST_TIMEOUT"
Expand Down
1 change: 0 additions & 1 deletion pkg/aspect/analyzeprofile/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ go_library(
importpath = "aspect.build/cli/pkg/aspect/analyzeprofile",
visibility = ["//visibility:public"],
deps = [
"//pkg/aspecterrors",
"//pkg/bazel",
"//pkg/ioutils",
"@com_github_spf13_cobra//:cobra",
Expand Down
13 changes: 1 addition & 12 deletions pkg/aspect/analyzeprofile/analyzeprofile.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"aspect.build/cli/pkg/bazel"
"aspect.build/cli/pkg/ioutils"
"github.com/spf13/cobra"

"aspect.build/cli/pkg/aspecterrors"
)

type AnalyzeProfile struct {
Expand All @@ -41,14 +39,5 @@ func New(streams ioutils.Streams, bzl bazel.Bazel) *AnalyzeProfile {
func (runner *AnalyzeProfile) Run(ctx context.Context, _ *cobra.Command, args []string) error {
bazelCmd := []string{"analyze-profile"}
bazelCmd = append(bazelCmd, args...)

if exitCode, err := runner.bzl.RunCommand(runner.Streams, nil, bazelCmd...); exitCode != 0 {
err = &aspecterrors.ExitError{
Err: err,
ExitCode: exitCode,
}
return err
}

return nil
return runner.bzl.RunCommand(runner.Streams, nil, bazelCmd...)
}
6 changes: 3 additions & 3 deletions pkg/aspect/aquery/aquery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestQuery(t *testing.T) {
spawner.
EXPECT().
RunCommand(streams, nil, "aquery", "somepath(//cmd/aspect/query:query, @com_github_bazelbuild_bazelisk//core:go_default_library)").
Return(0, nil)
Return(nil)

q := aquery.New(streams, spawner, true)
q.Presets = []*shared.PresetQuery{
Expand Down Expand Up @@ -73,7 +73,7 @@ func TestQuery(t *testing.T) {
spawner.
EXPECT().
RunCommand(streams, nil, "aquery", "somepath(//cmd/aspect/query:query, @com_github_bazelbuild_bazelisk//core:go_default_library)").
Return(0, nil)
Return(nil)

promptRunner := query_mock.NewMockPromptRunner(ctrl)
gomock.InOrder(
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestQuery(t *testing.T) {
spawner.
EXPECT().
RunCommand(streams, nil, "aquery", "somepath(//cmd/aspect/query:query, @com_github_bazelbuild_bazelisk//core:go_default_library)").
Return(0, nil)
Return(nil)

promptRunner := query_mock.NewMockPromptRunner(ctrl)
gomock.InOrder(
Expand Down
1 change: 0 additions & 1 deletion pkg/aspect/build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/aspect/root/flags",
"//pkg/aspecterrors",
"//pkg/bazel",
"//pkg/ioutils",
"//pkg/plugin/system/bep",
Expand Down
19 changes: 6 additions & 13 deletions pkg/aspect/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"

"aspect.build/cli/pkg/aspect/root/flags"
"aspect.build/cli/pkg/aspecterrors"
"aspect.build/cli/pkg/bazel"
"aspect.build/cli/pkg/ioutils"
"aspect.build/cli/pkg/plugin/system/bep"
Expand All @@ -47,7 +46,7 @@ func New(

// Run runs the aspect build command, calling `bazel build` with a local Build
// Event Protocol backend used by Aspect plugins to subscribe to build events.
func (runner *Build) Run(ctx context.Context, _ *cobra.Command, args []string) (exitErr error) {
func (runner *Build) Run(ctx context.Context, _ *cobra.Command, args []string) error {
bazelCmd := []string{"build"}
bazelCmd = append(bazelCmd, args...)

Expand All @@ -63,24 +62,18 @@ func (runner *Build) Run(ctx context.Context, _ *cobra.Command, args []string) (
bazelCmd = flags.AddFlagToCommand(bazelCmd, besBackendFlag)
}

exitCode, bazelErr := runner.bzl.RunCommand(runner.Streams, nil, bazelCmd...)
err := runner.bzl.RunCommand(runner.Streams, nil, bazelCmd...)

// Process the subscribers errors before the Bazel one.
// Check for subscriber errors
subscriberErrors := bep.BESErrors(ctx)
if len(subscriberErrors) > 0 {
for _, err := range subscriberErrors {
fmt.Fprintf(runner.Streams.Stderr, "Error: failed to run build command: %v\n", err)
}
exitCode = 1
}

if exitCode != 0 {
err := &aspecterrors.ExitError{ExitCode: exitCode}
if bazelErr != nil {
err.Err = bazelErr
if err == nil {
err = fmt.Errorf("%v BES subscriber error(s)", len(subscriberErrors))
}
return err
}

return nil
return err
}
Loading
Loading