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

Add -strict to exit on build file and directive errors #1214

Merged
merged 7 commits into from Apr 18, 2022

Conversation

dr-dime
Copy link
Contributor

@dr-dime dr-dime commented Mar 24, 2022

Gazelle tolerates common errors, which is fine for daily uses.
However, when being used for scripting, we will need a way to
tell if such errors have occurred. This CL adds -strict flag
to exit with a non-zero value after seeing those errors.

Updates #1029

Gazelle tolerates common errors, which is fine for daily uses.
However when being used for scripting, we will need a way to
tell if such errors have occored. This CL adds -strict flag
to exit with non-zero value after seeing those errors.
@dr-dime dr-dime changed the title add -strict to exit on build file and directive errors Add -strict to exit on build file and directive errors Mar 24, 2022
@achew22
Copy link
Member

achew22 commented Mar 30, 2022

Hey @dr-dime, thanks so much for your contribution! We just merged in a way to create test cases that cover things like this pretty simply. Could I have you add a test for this before we merge it?

The high level overview of how to create a test using this is to:

  1. cp -r tests/diff_mode tests/strict_mode from the root of the repo
  2. Manipulate the arguments.txt file so that it contains -strict
  3. Put in a BUILD.in (note that it can't just be called BUILD because we want to be able to compare the before and after, which is called BUILD.out)
  4. bazel test //tests:strict_mode and confirm that it passes. If it doesn't pass because of a diff in the stdout/stderr it will print out a command you can run to generate expected{ExitCode,Stdout,Stderr}.txt as well as any BUILD.out files that were created.

@dr-dime
Copy link
Contributor Author

dr-dime commented Apr 6, 2022

Will do.

* upstream/master:
  fix: Remove gazelle_binary import collision (bazelbuild#1226)
  Update extend.md with a practical languages example (bazelbuild#1222)
  Add test of diff mode
  Add e2e test for normal operations
  Make `gazelle_generation_test`'s take a list
  Add instructions on regenerating `go_repository_tools_srcs.bzl`
  fix(tests): fix gazelle_generation_test expected stderr update (bazelbuild#1220)
@dr-dime
Copy link
Contributor Author

dr-dime commented Apr 6, 2022

@achew22 the error message gazelle generates includes the full path of the temp directory so it's very much impossible to match in the future. Now I have to fix generationtest first 🤣

gazelle: /private/var/folders/_9/15t9b0j51hz3fwb8v00mq44w0000gn/T/gazelle_test3489490209/fix_strict_mode/BUILD.bazel:3:13: syntax error near visibility
gazelle: Exit as strict mode is on

@dr-dime
Copy link
Contributor Author

dr-dime commented Apr 6, 2022

depends on #1231

@achew22
Copy link
Member

achew22 commented Apr 6, 2022

As a temporary hack, we could tag this test specifically as not to be run in windows?

- "-//internal:bazel_test"

* upstream/master:
  gazelle_generation_test: redact workspace path from output
  Broaden label name regex (bazelbuild#1229)
@@ -0,0 +1,4 @@
go_library(
name = "syntax_error_no_comma"
visibility = ["//visibility:public"],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if there are multiple errors (maybe even across multiple files)? Do they accumulate and all get printed out? I presume this is mostly going to be used in CI pipelines, should we try to get all of the errors printed out before quitting?

Copy link
Contributor Author

@dr-dime dr-dime Apr 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will exit at the first error. I give that a quick thought as well and decided not to do it.

The bzl parser bailed out at the first encountered error, so we can report at most one error per file. Also, the current interface/API doesn't return errors, so to collect all the errors, some serious refactor needs to take place first. See the discussion in #1029.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the question is, would it be better to "accumulate" to stderr and have a single boolean tracking success and os.Exiting essentially in the main function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to accumulate all errors, but there is no clean way to do so with the current API. I've tried this approach in master...dr-dime:cl/strict-mode-2, which doesn't LGTM as the error handling strategy is not clear at all.

I admit that those log.Fatals are not pretty, but it's following the comment on error handling in lang.Language interface. I can put some big TODOs next to them to make this more explicit as a refactor goal in the future.

* upstream/master:
  Add -print0 to print names of rewritten files (bazelbuild#1213)
@achew22
Copy link
Member

achew22 commented Apr 14, 2022

Yeah, let's drop in some TODOs and hopefully address them down the road. It really would be better to accumulate some errors but it looks very painful

@dr-dime
Copy link
Contributor Author

dr-dime commented Apr 18, 2022

@achew22 Done. PTAL

@achew22 achew22 merged commit ee5f680 into bazelbuild:master Apr 18, 2022
gcf-merge-on-green bot pushed a commit to googleapis/gapic-config-validator that referenced this pull request Jun 27, 2022
[![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [bazel_gazelle](https://togithub.com/bazelbuild/bazel-gazelle) | http_archive | minor | `v0.25.0` -> `v0.26.0` |

---

### Release Notes

<details>
<summary>bazelbuild/bazel-gazelle</summary>

### [`v0.26.0`](https://togithub.com/bazelbuild/bazel-gazelle/releases/tag/v0.26.0)

[Compare Source](https://togithub.com/bazelbuild/bazel-gazelle/compare/v0.25.0...v0.26.0)

#### What's Changed

-   fix(tests): fix gazelle_generation_test expected stderr update by [@&#8203;jbedard](https://togithub.com/jbedard) in [bazelbuild/bazel-gazelle#1220
-   Add an e2e test confirming no output on success by [@&#8203;achew22](https://togithub.com/achew22) in [bazelbuild/bazel-gazelle#1216
-   Update extend.md with a practical languages example by [@&#8203;Anthony-Bible](https://togithub.com/Anthony-Bible) in [bazelbuild/bazel-gazelle#1222
-   fix: Remove gazelle_binary import collision by [@&#8203;illicitonion](https://togithub.com/illicitonion) in [bazelbuild/bazel-gazelle#1226
-   Broaden label name regex by [@&#8203;illicitonion](https://togithub.com/illicitonion) in [bazelbuild/bazel-gazelle#1229
-   gazelle_generation_test: redact workspace path from output by [@&#8203;dr-dime](https://togithub.com/dr-dime) in [bazelbuild/bazel-gazelle#1231
-   Add -print0 to print names of rewritten files by [@&#8203;dr-dime](https://togithub.com/dr-dime) in [bazelbuild/bazel-gazelle#1213
-   Code Quality Improvements by [@&#8203;sluongng](https://togithub.com/sluongng) in [bazelbuild/bazel-gazelle#1197
-   Add -strict to exit on build file and directive errors by [@&#8203;dr-dime](https://togithub.com/dr-dime) in [bazelbuild/bazel-gazelle#1214
-   fix(lang/proto): include imports from different targets by [@&#8203;nickgooding](https://togithub.com/nickgooding) in [bazelbuild/bazel-gazelle#1237
-   Update rules example in README to v0.25.0 by [@&#8203;yujunz](https://togithub.com/yujunz) in [bazelbuild/bazel-gazelle#1240
-   Allow static dependency resolution for Gazelle rule by [@&#8203;uhthomas](https://togithub.com/uhthomas) in [bazelbuild/bazel-gazelle#1242
-   Handle wrapped errors by [@&#8203;illicitonion](https://togithub.com/illicitonion) in [bazelbuild/bazel-gazelle#1234
-   Go: Update tests to use cmp.Diff instead of reflect.DeepEqual by [@&#8203;thempatel](https://togithub.com/thempatel) in [bazelbuild/bazel-gazelle#1244
-   Fix startup script manifest resolution with --nolegacy_external_runfiles by [@&#8203;jvolkman](https://togithub.com/jvolkman) in [bazelbuild/bazel-gazelle#1247
-   Label's package may contain [@&#8203;s](https://togithub.com/s) by [@&#8203;illicitonion](https://togithub.com/illicitonion) in [bazelbuild/bazel-gazelle#1249
-   Trim runfiles prefix consistently by [@&#8203;uhthomas](https://togithub.com/uhthomas) in [bazelbuild/bazel-gazelle#1257
-   Respect .bazelignore by [@&#8203;Whoaa512](https://togithub.com/Whoaa512) in [bazelbuild/bazel-gazelle#1245
-   Implement very minimalistic support for go workspaces by [@&#8203;HakanSunay](https://togithub.com/HakanSunay) in [bazelbuild/bazel-gazelle#1250
-   Fix typo in comment by [@&#8203;yujunz](https://togithub.com/yujunz) in [bazelbuild/bazel-gazelle#1270
-   Use `patch` from `@bazel_tools//tools/build_defs/repo:utils.bzl` by [@&#8203;bozaro](https://togithub.com/bozaro) in [bazelbuild/bazel-gazelle#1269
-   Update rules_go to 0.33.0 by [@&#8203;fmeum](https://togithub.com/fmeum) in [bazelbuild/bazel-gazelle#1263
-   Add support for auth_patterns in go_repository by [@&#8203;dmivankov](https://togithub.com/dmivankov) in [bazelbuild/bazel-gazelle#1254
-   Sluongng/revert patch by [@&#8203;sluongng](https://togithub.com/sluongng) in [bazelbuild/bazel-gazelle#1277
-   Stop inferring import path for empty packages by [@&#8203;linzhp](https://togithub.com/linzhp) in [bazelbuild/bazel-gazelle#1280
-   Don't exclude spaces from the label name regex by [@&#8203;illicitonion](https://togithub.com/illicitonion) in [bazelbuild/bazel-gazelle#1271

#### New Contributors

-   [@&#8203;Anthony-Bible](https://togithub.com/Anthony-Bible) made their first contribution in [bazelbuild/bazel-gazelle#1222
-   [@&#8203;dr-dime](https://togithub.com/dr-dime) made their first contribution in [bazelbuild/bazel-gazelle#1231
-   [@&#8203;sluongng](https://togithub.com/sluongng) made their first contribution in [bazelbuild/bazel-gazelle#1197
-   [@&#8203;nickgooding](https://togithub.com/nickgooding) made their first contribution in [bazelbuild/bazel-gazelle#1237
-   [@&#8203;yujunz](https://togithub.com/yujunz) made their first contribution in [bazelbuild/bazel-gazelle#1240
-   [@&#8203;uhthomas](https://togithub.com/uhthomas) made their first contribution in [bazelbuild/bazel-gazelle#1242
-   [@&#8203;thempatel](https://togithub.com/thempatel) made their first contribution in [bazelbuild/bazel-gazelle#1244
-   [@&#8203;Whoaa512](https://togithub.com/Whoaa512) made their first contribution in [bazelbuild/bazel-gazelle#1245
-   [@&#8203;HakanSunay](https://togithub.com/HakanSunay) made their first contribution in [bazelbuild/bazel-gazelle#1250
-   [@&#8203;bozaro](https://togithub.com/bozaro) made their first contribution in [bazelbuild/bazel-gazelle#1269
-   [@&#8203;fmeum](https://togithub.com/fmeum) made their first contribution in [bazelbuild/bazel-gazelle#1263
-   [@&#8203;dmivankov](https://togithub.com/dmivankov) made their first contribution in [bazelbuild/bazel-gazelle#1254

**Full Changelog**: bazelbuild/bazel-gazelle@v0.25.0...v0.26.0

#### `WORKSPACE` code

    load("@&#8203;bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

    http_archive(
        name = "bazel_gazelle",
        sha256 = "501deb3d5695ab658e82f6f6f549ba681ea3ca2a5fb7911154b5aa45596183fa",
        urls = [
            "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.26.0/bazel-gazelle-v0.26.0.tar.gz",
            "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.26.0/bazel-gazelle-v0.26.0.tar.gz",
        ],
    )

    load("@&#8203;bazel_gazelle//:deps.bzl", "gazelle_dependencies", "go_repository")

    ############################################################

### Define your own dependencies here using go_repository.

### Else, dependencies declared by rules_go/gazelle will be used.

### The first declaration of an external repository "wins".

    ############################################################

    gazelle_dependencies()

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/gapic-config-validator).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants