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

Merged
merged 5 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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,948 changes: 973 additions & 975 deletions bazel/buildeventstream/build_event_stream.pb.go

Large diffs are not rendered by default.

20 changes: 8 additions & 12 deletions bazel/buildeventstream/build_event_stream.proto
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ syntax = "proto3";

package build_event_stream;

import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

import "bazel/action_cache/action_cache.proto";
import "bazel/packages_metrics/package_load_metrics.proto";
import "bazel/command_line/command_line.proto";
import "bazel/failure_details/failure_details.proto";
import "bazel/invocation_policy/invocation_policy.proto";
import "bazel/packages_metrics/package_load_metrics.proto";
import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";

option go_package = "aspect.build/cli/bazel/buildeventstream";

Expand Down Expand Up @@ -407,7 +406,7 @@ message OptionsParsed {
repeated string explicit_startup_options = 2;
repeated string cmd_line = 3;
repeated string explicit_cmd_line = 4;
blaze.invocation_policy.InvocationPolicy invocation_policy = 5;
invocation_policy.InvocationPolicy invocation_policy = 5;
string tool_tag = 6;
}

Expand All @@ -434,17 +433,15 @@ message WorkspaceStatus {
// build.
message BuildMetadata {
// Custom metadata for the build.
map<string, string> metadata = 1
;
map<string, string> metadata = 1;
}

// Payload of an event reporting details of a given configuration.
message Configuration {
string mnemonic = 1;
string platform_name = 2;
string cpu = 3;
map<string, string> make_variable = 4
;
map<string, string> make_variable = 4;
// Whether this configuration is used for building tools.
bool is_tool = 5;
}
Expand Down Expand Up @@ -1008,8 +1005,7 @@ message BuildMetrics {
int64 packages_loaded = 1;

// Loading time metrics per package.
repeated devtools.build.lib.packages.metrics.PackageLoadMetrics
package_load_metrics = 2;
repeated metrics.PackageLoadMetrics package_load_metrics = 2;
}
PackageMetrics package_metrics = 4;

Expand Down
149 changes: 73 additions & 76 deletions bazel/invocation_policy/invocation_policy.pb.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bazel/invocation_policy/invocation_policy.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

syntax = "proto2";
package blaze.invocation_policy;
package invocation_policy;

// The --invocation_policy flag takes a base64-encoded binary-serialized or text
// formatted InvocationPolicy message.
Expand Down Expand Up @@ -196,4 +196,4 @@ message AllowValues {
// default value is always the empty list.
UseDefault use_default = 4;
}
}
}
47 changes: 23 additions & 24 deletions bazel/packages_metrics/package_load_metrics.pb.go

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

2 changes: 1 addition & 1 deletion bazel/packages_metrics/package_load_metrics.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.
syntax = "proto2";

package devtools.build.lib.packages.metrics;
package metrics;

import "google/protobuf/duration.proto";

Expand Down
2 changes: 2 additions & 0 deletions docs/help/topics/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ enable other projects to declare dependencies on the package.
| The format used to generate the name of the `npm_package` rule. |
| `# gazelle:js_tsconfig _filename_` | `tsconfig.json` |
| Path to a `tsconfig.json` file used to help generate TypeScript rules.<br />This value is inherited by sub-directories and applied relative to each BUILD.<br />The `ts_project(tsconfig)` attribute is *NOT* set and must be done manually if necessary |
| `# gazelle:js_custom_files _name_ _glob_` | | Generate additional custom `ts_project` targets |
| `# gazelle:js_custom_test_files _name_ _glob_` | | Generate additional custom `ts_project` testonly targets |
<!-- prettier-ignore-end -->

[gazelle directives]: https://github.com/bazelbuild/bazel-gazelle#directives
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
name = "default",
name = "src",
srcs = ["lib1.ts"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
name = "now-empty-sub",
srcs = ["src/a.ts"],
deps = [
"//directory/a",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
name = "src",
srcs = ["a.ts"],
deps = ["//directory/a"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from '../../a/lib-a';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# TEST

load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
name = "now-empty",
srcs = ["old.ts"],
deps = [
"//directory/a",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TEST
3 changes: 1 addition & 2 deletions integration_tests/aspect/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ data = [
)
for test in [
"flags",
# FIXME(alex)
#"init",
"init",
"lint",
"reenter",
]
Expand Down
1 change: 1 addition & 0 deletions pkg/aspect/lint/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
deps = [
"//bazel/buildeventstream",
"//pkg/aspect/root/flags",
"//pkg/aspecterrors",
"//pkg/bazel",
"//pkg/bazel/workspace",
"//pkg/ioutils",
Expand Down
28 changes: 23 additions & 5 deletions pkg/aspect/lint/bep.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2023 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 lint

import (
Expand All @@ -16,9 +32,10 @@ import (

// ResultForLabel aggregates the relevant files we find in the BEP for
type ResultForLabel struct {
reportFile *buildeventstream.File
patchFile *buildeventstream.File
linter string
exitCodeFile *buildeventstream.File
reportFile *buildeventstream.File
patchFile *buildeventstream.File
linter string
}

type LintBEPHandler struct {
Expand Down Expand Up @@ -129,9 +146,10 @@ func (runner *LintBEPHandler) BEPEventCallback(event *buildeventstream.BuildEven
// Parse the filename convention that rules_lint has for report files.
// path/to/linter.target_name.aspect_rules_lint.report -> linter
result.linter = strings.SplitN(filepath.Base(file.Name), ".", 2)[0]
} else if outputGroup.Name == LINT_REPORT_GROUP {
} else if outputGroup.Name == LINT_REPORT_GROUP && strings.HasSuffix(file.Name, ".report") {
result.reportFile = file

} else if outputGroup.Name == LINT_REPORT_GROUP && strings.HasSuffix(file.Name, ".exit_code") {
result.exitCodeFile = file
}
}
}
Expand Down
41 changes: 37 additions & 4 deletions pkg/aspect/lint/lint.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2023 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.
*/

/*
* Copyright 2022 Aspect Build Systems, Inc.
*
Expand All @@ -21,9 +37,11 @@ import (
"context"
"fmt"
"os"
"strconv"
"strings"

"aspect.build/cli/pkg/aspect/root/flags"
"aspect.build/cli/pkg/aspecterrors"
"aspect.build/cli/pkg/bazel"
"aspect.build/cli/pkg/bazel/workspace"
"aspect.build/cli/pkg/ioutils"
Expand Down Expand Up @@ -153,6 +171,7 @@ lint:
// optimization: don't request report files in a mode where we don't print them
outputGroups := []string{}
if applyFix || printDiff || isInteractiveMode {
bazelCmd = append(bazelCmd, "--@aspect_rules_lint//lint:fix")
outputGroups = append(outputGroups, LINT_PATCH_GROUP)
}
if printReport {
Expand Down Expand Up @@ -203,7 +222,7 @@ lint:
// Wait for completion and return the first error (if any)
wgErr := handleResultsErrgroup.Wait()
if wgErr != nil && err == nil {
err = wgErr
return wgErr
}

// Check for subscriber errors
Expand All @@ -213,15 +232,29 @@ lint:
fmt.Fprintf(runner.Streams.Stderr, "Error: failed to run lint command: %v\n", err)
}
if err == nil {
err = fmt.Errorf("%v BES subscriber error(s)", len(subscriberErrors))
return fmt.Errorf("%v BES subscriber error(s)", len(subscriberErrors))
}
}

// Bazel is done running, so stdout is now safe for us to print the results
applyAll := false
applyNone := false
exitCode := 0
for label, result := range lintBEPHandler.resultsByLabel {
l := label
if result.exitCodeFile != nil {
exitCodeStr, err := lintBEPHandler.readBEPFile(result.exitCodeFile)
if err != nil {
return err
}
targetExitCode, err := strconv.Atoi(strings.TrimSpace(exitCodeStr))
if err != nil {
return fmt.Errorf("failed parse read exit code as integer: %v", err)
}
if targetExitCode > 0 {
exitCode = 1
}
}
f := result.reportFile
content, err := lintBEPHandler.readBEPFile(f)
if err != nil {
Expand All @@ -244,7 +277,7 @@ lint:
}
choice, err = applyFixPrompt.Run()
if err != nil {
return fmt.Errorf("prompt failed: %v\n", err)
return fmt.Errorf("prompt failed: %v", err)
}
}
if strings.HasPrefix(choice, "A") {
Expand All @@ -264,7 +297,7 @@ lint:
}
}

return err
return &aspecterrors.ExitError{ExitCode: exitCode}
}

func (runner *Linter) patchLintResult(label string, lintPatch string, applyDiff, printDiff bool) error {
Expand Down