Skip to content

Commit

Permalink
fix gazelle_test
Browse files Browse the repository at this point in the history
  • Loading branch information
tyler-french committed Dec 14, 2023
1 parent 49a501e commit a021da3
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 71 deletions.
63 changes: 62 additions & 1 deletion .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ matrix:

tasks:
ubuntu2204:
name: Ubuntu 22.04 with WORKSPACE
platform: ubuntu2204
build_flags:
- "--noexperimental_enable_bzlmod"
build_targets:
- "..."
run_targets:
# Run Gazelle on repo to verify BUILD files are up-to-date. The output shouldn't differ
# between platforms, so we only run it from one.
- "//:gazelle_ci"
test_targets:
- "..."
ubuntu2204_bzlmod:
name: Ubuntu 22.04 with Bzlmod
platform: ubuntu2204
build_targets:
- "..."
Expand All @@ -15,6 +29,7 @@ tasks:
- "//:gazelle_ci"
test_targets:
- "..."
- "-//internal:bazel_test"
bcr_tests:
name: BCR test module
platform: ${{ platform }}
Expand Down Expand Up @@ -58,20 +73,66 @@ tasks:
- "//pkg:pkg_test"
- "//..."
- "@test_dep//..."
macos_arm64_bzlmod:
name: Mac OS Arm 64 with Bzlmod
platform: macos_arm64
build_targets:
- "..."
test_targets:
- "..."
- "-//internal:bazel_test"
macos_arm64:
name: Mac OS Arm 64 with WORKSPACE
platform: macos_arm64
build_flags:
- "--noexperimental_enable_bzlmod"
build_targets:
- "..."
test_targets:
- "..."
macos:
macos_bzlmod:
name: Mac OS with Bzlmod
platform: macos
build_targets:
- "..."
test_targets:
- "..."
- "-//internal:bazel_test"
macos:
name: Mac OS with WORKSPACE
build_flags:
- "--noexperimental_enable_bzlmod"
build_targets:
- "..."
test_targets:
- "..."
windows_bzlmod:
name: Windows with Bzlmod
platform: windows
build_targets:
- "--"
- "..."
- "-//cmd/autogazelle/..."
test_targets:
- "--"
- "..."
# autogazelle is only supported on UNIX-like platforms.
# It requires UNIX domain sockets.
- "-//cmd/autogazelle/..."
# Stardoc produces different line-endings on windows,
# so the documentation it generates doesn't match the checked in files
- "-//docs:all"
# Fails to execute, apparently due to command-line length limit.
- "-//internal:bazel_test"
# gazelle prints file paths with backward slashes on windows,
# which doesn't match the golden files generated on *nix.
- "-//tests:fix_mode_print0"
- "-//tests:fix_mode_strict"
windows:
name: Windows with WORKSPACE
platform: windows
build_flags:
- "--noexperimental_enable_bzlmod"
build_targets:
- "--"
- "..."
Expand Down
13 changes: 11 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module(
repo_name = "bazel_gazelle",
)

bazel_dep(name = "bazel_skylib", version = "1.3.0")
bazel_dep(name = "bazel_skylib", version = "1.5.0")
bazel_dep(name = "protobuf", version = "3.19.6", repo_name = "com_google_protobuf")
bazel_dep(name = "rules_go", version = "0.42.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_proto", version = "4.0.0")
Expand Down Expand Up @@ -54,4 +54,13 @@ use_repo(
)

bazel_dep(name = "bazel_skylib_gazelle_plugin", version = "1.4.1", dev_dependency = True)
bazel_dep(name = "stardoc", version = "0.5.1", dev_dependency = True, repo_name = "io_bazel_stardoc")
bazel_dep(name = "stardoc", version = "0.6.2", dev_dependency = True, repo_name = "io_bazel_stardoc")


go_sdk_dev = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk", dev_dependency = True)

# Known to exist since it is instantiated by rules_go itself.
use_repo(
go_sdk_dev,
go_sdk = "go_default_sdk",
)
29 changes: 26 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,38 @@ gazelle_dependencies()
# For API doc generation
# This is a dev dependency, users should not need to install it
# so we declare it in the WORKSPACE
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "io_bazel_stardoc",
sha256 = "3fd8fec4ddec3c670bd810904e2e33170bedfe12f90adf943508184be458c8bb",
sha256 = "62bd2e60216b7a6fec3ac79341aa201e0956477e7c8f6ccc286f279ad1d96432",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz",
"https://github.com/bazelbuild/stardoc/releases/download/0.5.3/stardoc-0.5.3.tar.gz",
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz",
"https://github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz",
],
)

# Stardoc pulls in a lot of deps, which we need to declare here.
load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@io_bazel_stardoc//:deps.bzl", "stardoc_external_deps")

stardoc_external_deps()

load("@stardoc_maven//:defs.bzl", stardoc_pinned_maven_install = "pinned_maven_install")

stardoc_pinned_maven_install()

load("@bazel_skylib//lib:unittest.bzl", "register_unittest_toolchains")

register_unittest_toolchains()
Expand Down
31 changes: 14 additions & 17 deletions extend.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<!-- Generated with Stardoc: http://skydoc.bazel.build -->


Extending Gazelle
=================

Expand Down Expand Up @@ -108,7 +107,6 @@ includes the proto package name, as well as source names, imports, and options.
[proto.GetProtoConfig]: https://godoc.org/github.com/bazelbuild/bazel-gazelle/language/proto#GetProtoConfig
[proto.Package]: https://godoc.org/github.com/bazelbuild/bazel-gazelle/language/proto#Package


<a id="gazelle_binary"></a>

## gazelle_binary
Expand All @@ -129,14 +127,13 @@ proto extension stores metadata in hidden attributes of generated
`proto_library` rules. The Go extension uses this metadata to generate
`go_proto_library` rules.


**ATTRIBUTES**


| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| <a id="gazelle_binary-name"></a>name | A unique name for this target. | <a href="https://bazel.build/concepts/labels#target-names">Name</a> | required | |
| <a id="gazelle_binary-languages"></a>languages | A list of language extensions the Gazelle binary will use.<br><br> Each extension must be a [go_library] or something compatible. Each extension must export a function named <code>NewLanguage</code> with no parameters that returns a value assignable to [Language]. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |
| <a id="gazelle_binary-languages"></a>languages | A list of language extensions the Gazelle binary will use.<br><br>Each extension must be a [go_library] or something compatible. Each extension must export a function named `NewLanguage` with no parameters that returns a value assignable to [Language]. | <a href="https://bazel.build/concepts/labels">List of labels</a> | required | |


<a id="gazelle_generation_test"></a>
Expand All @@ -148,23 +145,23 @@ gazelle_generation_test(<a href="#gazelle_generation_test-name">name</a>, <a hre
<a href="#gazelle_generation_test-gazelle_timeout_seconds">gazelle_timeout_seconds</a>, <a href="#gazelle_generation_test-size">size</a>, <a href="#gazelle_generation_test-kwargs">kwargs</a>)
</pre>

gazelle_generation_test is a macro for testing gazelle against workspaces.
gazelle_generation_test is a macro for testing gazelle against workspaces.

The generation test expects a file structure like the following:

```
|-- &lt;testDataPath&gt;
|-- <testDataPath>
|-- some_test
|-- WORKSPACE
|-- README.md --&gt; README describing what the test does.
|-- arguments.txt --&gt; newline delimited list of arguments to pass in (ignored if empty).
|-- expectedStdout.txt --&gt; Expected stdout for this test.
|-- expectedStderr.txt --&gt; Expected stderr for this test.
|-- expectedExitCode.txt --&gt; Expected exit code for this test.
|-- README.md --> README describing what the test does.
|-- arguments.txt --> newline delimited list of arguments to pass in (ignored if empty).
|-- expectedStdout.txt --> Expected stdout for this test.
|-- expectedStderr.txt --> Expected stderr for this test.
|-- expectedExitCode.txt --> Expected exit code for this test.
|-- app
|-- sourceFile.foo
|-- BUILD.in --&gt; BUILD file prior to running gazelle.
|-- BUILD.out --&gt; BUILD file expected after running gazelle.
|-- BUILD.in --> BUILD file prior to running gazelle.
|-- BUILD.out --> BUILD file expected after running gazelle.
```

To update the expected files, run `UPDATE_SNAPSHOTS=true bazel run //path/to:the_test_target`.
Expand All @@ -178,10 +175,10 @@ To update the expected files, run `UPDATE_SNAPSHOTS=true bazel run //path/to:the
| <a id="gazelle_generation_test-name"></a>name | The name of the test. | none |
| <a id="gazelle_generation_test-gazelle_binary"></a>gazelle_binary | The name of the gazelle binary target. For example, //path/to:my_gazelle. | none |
| <a id="gazelle_generation_test-test_data"></a>test_data | A list of target of the test data files you will pass to the test. This can be a https://bazel.build/reference/be/general#filegroup. | none |
| <a id="gazelle_generation_test-build_in_suffix"></a>build_in_suffix | The suffix for the input BUILD.bazel files. Defaults to .in. By default, will use files named BUILD.in as the BUILD files before running gazelle. | <code>".in"</code> |
| <a id="gazelle_generation_test-build_out_suffix"></a>build_out_suffix | The suffix for the expected BUILD.bazel files after running gazelle. Defaults to .out. By default, will use files named check the results of the gazelle run against files named BUILD.out. | <code>".out"</code> |
| <a id="gazelle_generation_test-gazelle_timeout_seconds"></a>gazelle_timeout_seconds | <p align="center"> - </p> | <code>2</code> |
| <a id="gazelle_generation_test-size"></a>size | Specifies a test target's "heaviness": how much time/resources it needs to run. | <code>None</code> |
| <a id="gazelle_generation_test-build_in_suffix"></a>build_in_suffix | The suffix for the input BUILD.bazel files. Defaults to .in. By default, will use files named BUILD.in as the BUILD files before running gazelle. | `".in"` |
| <a id="gazelle_generation_test-build_out_suffix"></a>build_out_suffix | The suffix for the expected BUILD.bazel files after running gazelle. Defaults to .out. By default, will use files named check the results of the gazelle run against files named BUILD.out. | `".out"` |
| <a id="gazelle_generation_test-gazelle_timeout_seconds"></a>gazelle_timeout_seconds | <p align="center"> - </p> | `2` |
| <a id="gazelle_generation_test-size"></a>size | Specifies a test target's "heaviness": how much time/resources it needs to run. | `None` |
| <a id="gazelle_generation_test-kwargs"></a>kwargs | Attributes that are passed directly to the test declaration. | none |


Loading

0 comments on commit a021da3

Please sign in to comment.