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

Stardoc crashes when interacting with apple_common global #76

Closed
achew22 opened this issue Oct 22, 2020 · 10 comments · Fixed by #166
Closed

Stardoc crashes when interacting with apple_common global #76

achew22 opened this issue Oct 22, 2020 · 10 comments · Fixed by #166
Assignees

Comments

@achew22
Copy link
Member

achew22 commented Oct 22, 2020

When Stardoc encounters the following bit of code in rules_go,

_PLATFORMS = {
    "armv7-apple-ios": (apple_common.platform.ios_device, apple_common.platform_type.ios),
    "armv7-apple-tvos": (apple_common.platform.tvos_device, apple_common.platform_type.tvos),
    "armv7k-apple-watchos": (apple_common.platform.watchos_device, apple_common.platform_type.watchos),
    "arm64-apple-ios": (apple_common.platform.ios_device, apple_common.platform_type.ios),
    "arm64-apple-tvos": (apple_common.platform.tvos_device, apple_common.platform_type.tvos),
    "i386-apple-ios": (apple_common.platform.ios_simulator, apple_common.platform_type.ios),
    "i386-apple-tvos": (apple_common.platform.tvos_simulator, apple_common.platform_type.tvos),
    "i386-apple-watchos": (apple_common.platform.watchos_simulator, apple_common.platform_type.watchos),
    "x86_64-apple-ios": (apple_common.platform.ios_simulator, apple_common.platform_type.ios),
    "x86_64-apple-tvos": (apple_common.platform.ios_simulator, apple_common.platform_type.tvos),
    "x86_64-apple-watchos": (apple_common.platform.watchos_simulator, apple_common.platform_type.watchos),
}

it throws the following error:

SUBCOMMAND: # //go:def-docs [action 'Generating proto for Starlark doc for def-docs', configuration: faff19e6fd939f490ac11578d94024c6b7a032836cde039fd5edd28b838194e8, execution platform: @local_config_platform//:host]
(cd <snip> && \
  exec env - \
  bazel-out/host/bin/external/io_bazel_stardoc/stardoc/stardoc '--input=//go:def.bzl' '--workspace_name=io_bazel_rules_go' '--dep_roots=.' '--dep_roots=external/io_bazel_rules_go' '--output=bazel-out/k8-fastbuild/bin/go/def-docs.raw')
ERROR: <snip>/rules_go/go/BUILD.bazel:61:8: Generating proto for Starlark doc for def-docs failed (Exit 1) stardoc failed: error executing command bazel-out/host/bin/external/io_bazel_stardoc/stardoc/stardoc '--input=//go:def.bzl' '--workspace_name=io_bazel_rules_go' '--dep_roots=.' '--dep_roots=external/io_bazel_rules_go' ... (remaining 1 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
com.google.devtools.build.skydoc.SkydocMain$StarlarkEvaluationException: Starlark evaluation error
        at com.google.devtools.build.skydoc.SkydocMain.recursiveEval(SkydocMain.java:423)
        at com.google.devtools.build.skydoc.SkydocMain.recursiveEval(SkydocMain.java:397)
        at com.google.devtools.build.skydoc.SkydocMain.recursiveEval(SkydocMain.java:397)
        at com.google.devtools.build.skydoc.SkydocMain.eval(SkydocMain.java:255)
        at com.google.devtools.build.skydoc.SkydocMain.main(SkydocMain.java:158)
Caused by: Traceback (most recent call last):
        File "./go/platform/apple.bzl", line 16, column 46, in <toplevel>
                "armv7-apple-ios": (apple_common.platform.ios_device, apple_common.platform_type.ios),
Error:
        at net.starlark.java.eval.Starlark.errorf(Starlark.java:555)
        at net.starlark.java.eval.Starlark.getattr(Starlark.java:606)
        at net.starlark.java.eval.Eval.evalDot(Eval.java:530)
        at net.starlark.java.eval.Eval.eval(Eval.java:446)
        at net.starlark.java.eval.Eval.evalList(Eval.java:704)
        at net.starlark.java.eval.Eval.eval(Eval.java:466)
        at net.starlark.java.eval.Eval.evalDict(Eval.java:509)
        at net.starlark.java.eval.Eval.eval(Eval.java:444)
        at net.starlark.java.eval.Eval.execAssignment(Eval.java:108)
        at net.starlark.java.eval.Eval.exec(Eval.java:260)
        at net.starlark.java.eval.Eval.execStatements(Eval.java:80)
        at net.starlark.java.eval.Eval.execFunctionBody(Eval.java:64)
        at net.starlark.java.eval.StarlarkFunction.fastcall(StarlarkFunction.java:155)
        at net.starlark.java.eval.Starlark.fastcall(Starlark.java:509)
        at net.starlark.java.eval.Starlark.execFileProgram(Starlark.java:779)
        at com.google.devtools.build.skydoc.SkydocMain.recursiveEval(SkydocMain.java:420)
        ... 4 more

To view, clone, and test this change, please see my CL to be: https://github.com/achew22/rules_go/pull/new/stardoc
and bazel build //go:def-docs

@alandonovan
Copy link

There are two bugs here. The first is that the error message is terrible: instead of showing you the names of various Java functions inside Skydoc, it should report the Starlark stack and (crucially) the error message. The second bug is that the failure, of the .ios_device operator, is spurious: it is caused by a mismatch between the fake environment used by skydoc and the reality of bazel. Compare:

https://github.com/bazelbuild/bazel/blob/750c938ad180d69cce95af704738360677269d85/src/main/java/com/google/devtools/build/skydoc/fakebuildapi/apple/FakeAppleCommon.java#L62
https://github.com/bazelbuild/bazel/blob/450c7ad65bfcffebf753159ee2b617e557ffb4fd/src/main/java/com/google/devtools/build/lib/rules/apple/ApplePlatform.java#L194

The solution to the first bug is to change the exception handling in skydoc. The solution to the second is to reimplement skydoc as a client of bazel query, which would load .bzl files and print information about them so that skydoc doesn't need all this fakery. As a short-term hack, one could modify the fake environment, but this is only postponing the inevitable.

@c-parsons
Copy link
Collaborator

c-parsons commented Oct 22, 2020

Is the plan to reimplement stardoc as a client of bazel query something that's being actively worked on? Or, is it on a roadmap? If not, we may want to modify the fake environment regardless. It's a quick change.

@achew22
Copy link
Member Author

achew22 commented Oct 22, 2020

@c-parsons I'm not sure exactly how one would go about doing that. I presume this is the fake that would need to be modified. More specifically, I'm not sure why this line is insufficient?

@achew22
Copy link
Member Author

achew22 commented Oct 27, 2020

Friendly ping

@achew22
Copy link
Member Author

achew22 commented Oct 28, 2020

Even friendlier ping

@alandonovan
Copy link

Is the plan to reimplement stardoc as a client of bazel query something that's being actively worked on?

It's on the roadmap, but it's blocked behind several other changes, so it won't happen for a while.

Modifying the fake environment is the expedient move.

@c-parsons
Copy link
Collaborator

@c-parsons I'm not sure exactly how one would go about doing that. I presume this is the fake that would need to be modified.

Yes, particularly this demonstrates how one should return a non-empty struct for getPlatformStruct.

More specifically, I'm not sure why this line is insufficient?

Lets consider the evaluation of (apple_common.platform.ios_device, apple_common.platform_type.ios).
The latter is fine, because, in the fake environment, apple_common.platform_type does have a field "ios". However, apple_common.platform is equivalent to struct(), thus an error is thrown.

achew22 added a commit to achew22/bazel that referenced this issue Oct 29, 2020
achew22 added a commit to achew22/bazel that referenced this issue Oct 29, 2020
@achew22
Copy link
Member Author

achew22 commented Oct 29, 2020

@c-parsons is this what you were expecting bazelbuild/bazel#12383?

@achew22
Copy link
Member Author

achew22 commented Nov 8, 2020

Friendly ping @c-parsons

bazel-io pushed a commit to bazelbuild/bazel that referenced this issue Nov 10, 2020
See bazelbuild/stardoc#76 for more
information.

Closes #12383.

PiperOrigin-RevId: 341621899
@c-parsons
Copy link
Collaborator

Related issue: #83

Apologies that response has been so slow on this issue.
Maintenance of this repository is changing hands, and thus some issues have fallen through the cracks.

@brandjon brandjon self-assigned this Jan 12, 2021
tetromino added a commit that referenced this issue Jul 25, 2023
…lable

* When available (i.e. in Bazel 7, or in current development Bazel at HEAD), try use the `starlark_doc_extract` native rule for doc extraction instead of the legacy pre-built extraction jar. This behavior can be disabled by passing `use_starlark_doc_extract = False` to the `stardoc` macro.
* Add templates and markdown rendering functionality for repository rule and module extension info protos (which are output by `starlark_doc_extract`).
    * Temporary wart: for module extensions, by default we would want the summary blurb to look something like
```
my_ext = use_extension("@my_local_repo//some:file.bzl", "my_ext")
my_ext.tag(foo, bar)
```
but alas, we don't have a good way to get the name of the local repo from Starlark when bzlmod is enabled.
* ... and of course, update tests. Which means in some cases, we have to fork the golden files into current (i.e. `starlark_doc_extract`-enabled) and legacy flavors.

Fixes #69
Fixes #76
Fixes #81
Fixes #123
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants