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

Accommodate Starlark reserved keywords as Protobuf message field names #119

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

LINKIWI
Copy link

@LINKIWI LINKIWI commented Jun 12, 2024

The Protobuf language permits identifiers that are reserved in Starlark, like pass. Consider, for example:

package foo;

message Foo {
    bool pass = 1;
}

There is currently no way to express this in Skycfg, since this is (correctly) flagged as a Starlark syntax error. For example:

foopb = proto.package("foo");

def main(ctx):
    return [
        foopb.Foo(pass = True),
    ]
got pass, want primary expression

Language-specific Protobuf code generation plugins typically work around such collisions by suffixing identifiers with an underscore. This PR proposes using the same convention to enable use of such reserved keywords as attribute names when creating Protobuf messages in Skycfg.

This enables the above example to be expressed as:

foopb = proto.package("foo");

def main(ctx):
    return [
        foopb.Foo(pass_ = True),
    ]

Verification

I updated the unit tests.

$ bazelisk test //...
INFO: Invocation ID: 2aa156b0-26c2-4577-a35e-51ba751a7d18
Analyzing: 14 targets (15 packages loaded, 2996 targets configured)
INFO: Analyzed 14 targets (93 packages loaded, 7937 targets configured).
INFO: Found 8 targets and 6 test targets...
INFO: Elapsed time: 148.927s, Critical Path: 26.24s
INFO: 358 processes: 25 internal, 333 linux-sandbox.
INFO: Build completed successfully, 358 total actions
//:skycfg_test                                                           PASSED in 0.1s
//go/assertmodule:assertmodule_test                                      PASSED in 0.1s
//go/hashmodule:hashmodule_test                                          PASSED in 0.3s
//go/protomodule:protomodule_test                                        PASSED in 0.1s
//go/urlmodule:urlmodule_test                                            PASSED in 0.3s
//go/yamlmodule:yamlmodule_test                                          PASSED in 0.4s

Executed 6 out of 6 tests: 6 tests pass.

@CLAassistant
Copy link

CLAassistant commented Jun 12, 2024

CLA assistant check
All committers have signed the CLA.

@LINKIWI
Copy link
Author

LINKIWI commented Jun 13, 2024

@seena-stripe @dl-stripe Apologies for the direct tag; would one of you be the right person to review this change? Thanks.

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.

2 participants