-
-
Notifications
You must be signed in to change notification settings - Fork 760
Stardoc generates extras.md #2992
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
Changes from 5 commits
070b8dd
5a586ff
3fb42b1
2cb268a
153aa82
ac60362
fd820da
f670ebb
82c60b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| load("@bazel_skylib//rules:write_file.bzl", "write_file") | ||
| load("@bazel_skylib//rules:diff_test.bzl", "diff_test") | ||
| load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc") | ||
|
|
||
| _NAV_HEADER = """# Extra rules | ||
|
|
||
| This is a collection of helper rules. These are not core to building a go binary, but are supplied | ||
| to make life a little easier. | ||
|
|
||
| Contents | ||
| - [gazelle](#gazelle) | ||
| - [gomock](#gomock) | ||
| - [go_embed_data](#go_embed_data) | ||
|
|
||
| ------------------------------------------------------------------------ | ||
| """ | ||
|
|
||
| _NAV_FOOTER = """ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The purpose of these in I think that would give us all the content we need on the page and simplify the BUILD file a great deal since we wouldn't need to generate a template at all. What do you think?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, after a bit of finagling I was able to get it to work without the template and by transferring over the consts to docstring comments. |
||
| [gazelle rule]: https://github.com/bazelbuild/bazel-gazelle#bazel-rule | ||
| [golang/mock]: https://github.com/golang/mock | ||
| [gomock_rule]: https://github.com/jmhodges/bazel_gomock | ||
| [core go rules]: core.rst | ||
| """ | ||
|
|
||
| # Workaround https://github.com/bazelbuild/stardoc/issues/25 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hrm... looking at the linked issue, it's possible that it is actually resolved and the workaround isn't necessary. See alexeagle/stardoc@586650b. If you are 100% sure that this is necessary, what would you think about writing the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are totally right about this, thank you for pointing it out! |
||
| write_file( | ||
| name = "gen_header", | ||
| out = "header.vm", | ||
| content = [ | ||
| _NAV_HEADER, | ||
| "${moduleDocstring}", | ||
| _NAV_FOOTER, | ||
| ], | ||
| ) | ||
|
|
||
| _DOC_SRCS = { | ||
| "extras:embed_data": "//go:extras.rst", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you're right, updating this. |
||
| } | ||
|
|
||
| [ | ||
| stardoc( | ||
| name = file.replace(":", "_") + "_doc", | ||
| out = file.replace(":", "_") + ".md_", | ||
| header_template = ":header.vm", | ||
| input = "//%s.bzl" % file, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move the |
||
| deps = ["//" + file], | ||
| ) | ||
| for file in _DOC_SRCS.keys() | ||
| ] | ||
|
|
||
| [ | ||
| diff_test( | ||
| name = "check_" + k.replace(":", "/"), | ||
| failure_message = "Please run \"bazel run //docs:update\"", | ||
| # Source file | ||
| file1 = v.replace(".rst", ".md"), | ||
| # Output from stardoc rule above | ||
| file2 = k.replace(":", "_") + ".md_", | ||
| ) | ||
| for [ | ||
| k, | ||
| v, | ||
| ] in _DOC_SRCS.items() | ||
| ] | ||
|
|
||
| write_file( | ||
| name = "gen_update", | ||
| out = "update.sh", | ||
| content = [ | ||
| "#!/bin/sh", | ||
| "cd $BUILD_WORKSPACE_DIRECTORY", | ||
| ] + [ | ||
| "cp -fv bazel-bin/docs/{0} {1}".format( | ||
| k.replace(":", "_") + ".md_", | ||
| v[2:].replace(":", "/").replace(".rst", ".md"), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here and above. This feels like a lot of work to avoid writing |
||
| ) | ||
| for [ | ||
| k, | ||
| v, | ||
| ] in _DOC_SRCS.items() | ||
| ], | ||
| ) | ||
|
|
||
| sh_binary( | ||
| name = "update", | ||
| srcs = ["update.sh"], | ||
| data = [k.replace(":", "_") + ".md_" for k in _DOC_SRCS.keys()], | ||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # Extra rules | ||
|
|
||
| This is a collection of helper rules. These are not core to building a go binary, but are supplied | ||
| to make life a little easier. | ||
|
|
||
| Contents | ||
| - [gazelle](#gazelle) | ||
| - [gomock](#gomock) | ||
| - [go_embed_data](#go_embed_data) | ||
|
|
||
| ------------------------------------------------------------------------ | ||
|
|
||
|
|
||
| gazelle | ||
| ------- | ||
|
|
||
| This rule has moved. See [gazelle rule] in the Gazelle repository. | ||
|
|
||
| gomock | ||
| ------ | ||
|
|
||
| This rule allows you to generate mock interfaces with mockgen (from [golang/mock]) which can be useful for certain testing scenarios. See [gomock_rule] in the gomock repository. | ||
|
|
||
|
|
||
|
|
||
| [gazelle rule]: https://github.com/bazelbuild/bazel-gazelle#bazel-rule | ||
| [golang/mock]: https://github.com/golang/mock | ||
| [gomock_rule]: https://github.com/jmhodges/bazel_gomock | ||
| [core go rules]: core.rst | ||
|
|
||
| <a id="#go_embed_data"></a> | ||
|
|
||
| ## go_embed_data | ||
|
|
||
| <pre> | ||
| go_embed_data(<a href="#go_embed_data-name">name</a>, <a href="#go_embed_data-flatten">flatten</a>, <a href="#go_embed_data-package">package</a>, <a href="#go_embed_data-src">src</a>, <a href="#go_embed_data-srcs">srcs</a>, <a href="#go_embed_data-string">string</a>, <a href="#go_embed_data-unpack">unpack</a>, <a href="#go_embed_data-var">var</a>) | ||
| </pre> | ||
|
|
||
| `go_embed_data` generates a .go file that contains data from a file or a | ||
| list of files. It should be consumed in the srcs list of one of the | ||
| [core go rules]. | ||
|
|
||
| Before using `go_embed_data`, you must add the following snippet to your | ||
| WORKSPACE: | ||
|
|
||
| ``` bzl | ||
| load("@io_bazel_rules_go//extras:embed_data_deps.bzl", "go_embed_data_dependencies") | ||
|
|
||
| go_embed_data_dependencies() | ||
| ``` | ||
|
|
||
| `go_embed_data` accepts the attributes listed below. | ||
|
|
||
|
|
||
| **ATTRIBUTES** | ||
|
|
||
|
|
||
| | Name | Description | Type | Mandatory | Default | | ||
| | :------------- | :------------- | :------------- | :------------- | :------------- | | ||
| | <a id="go_embed_data-name"></a>name | A unique name for this target. | <a href="https://bazel.build/docs/build-ref.html#name">Name</a> | required | | | ||
| | <a id="go_embed_data-flatten"></a>flatten | If <code>True</code> and <code>srcs</code> is used, map keys are file base names instead of relative paths. | Boolean | optional | False | | ||
| | <a id="go_embed_data-package"></a>package | Go package name for the generated .go file. | String | optional | "" | | ||
| | <a id="go_embed_data-src"></a>src | A single file to embed. This cannot be used at the same time as <code>srcs</code>. The generated file will have a variable of type <code>[]byte</code> or <code>string</code> with the contents of this file. | <a href="https://bazel.build/docs/build-ref.html#labels">Label</a> | optional | None | | ||
| | <a id="go_embed_data-srcs"></a>srcs | A list of files to embed. This cannot be used at the same time as <code>src</code>. The generated file will have a variable of type <code>map[string][]byte</code> or <code>map[string]string</code> with the contents of each file. The map keys are relative paths of the files from the repository root. Keys for files in external repositories will be prefixed with <code>"external/repo/"</code> where "repo" is the name of the external repository. | <a href="https://bazel.build/docs/build-ref.html#labels">List of labels</a> | optional | [] | | ||
| | <a id="go_embed_data-string"></a>string | If <code>True</code>, the embedded data will be stored as <code>string</code> instead of <code>[]byte</code>. | Boolean | optional | False | | ||
| | <a id="go_embed_data-unpack"></a>unpack | If <code>True</code>, sources are treated as archives and their contents will be stored. Supported formats are <code>.zip</code> and <code>.tar</code> | Boolean | optional | False | | ||
| | <a id="go_embed_data-var"></a>var | Name of the variable that will contain the embedded data. | String | optional | "Data" | | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, one more thing. Can you add a comment here identifying the issue tracking this so we can recover it when that's resolved