Skip to content
Snippets Groups Projects
Commit a0cd3553 authored by Googler's avatar Googler Committed by Copybara-Service
Browse files

Add support for loading .scl files

The Starlark Configuration Language (SCL) is a dialect of Starlark that resembles pure Starlark with just a few Bazel symbols (namely `visibility()` and `struct`), and a few restrictions on `load()` syntax and non-ASCII string data.

This CL adds support for loading .scl files anywhere a .bzl could be used. The restrictions on `load()` are implemented in this CL, but follow-up CLs will handle differentiating the top-level environment from .bzl, restricting non-ASCII data, and adding user documentation.

The dialect is gated on the flag `--experimental_enable_scl_dialect`.

- `BzlLoadValue` gains a new bool field on its abstract Key type to indicate whether it is for .scl. This was chosen instead of creating a new Key subclass so that .scl can work equally well in different contexts (loaded by BUILD, WORKSPACE, MODULE.bazel, or even @_builtins).

- `BzlLoadFunction.checkValidLoadLabel` and `.getLoadLabels` are both split into a public and private method. The public methods assume the load is coming from a .bzl file for validation purposes, and take a `StarlarkSemantics` to check whether the experimental flag is enabled.

- Eliminate `BzlLoadFunction.getBUILDLabel()` helper, which is obsolete.

- Modify existing tests to incidentally check that bzlmod .bzls can load .scl files and that .scl files can appear in transitive loads as reported by the Package (for `loadfiles()`).

RELNOTES: None
PiperOrigin-RevId: 528563228
Change-Id: I8493d1f33d35e1af8003dc61e5fdb626676d7e53
parent 51249ecc
Showing
with 274 additions and 38 deletions
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment