bazelstarlark

Is there a way to directly access the built-in types of starlark language in Bazel?


For example, is there a way to call the constructor of File class to create an instance of it?


Solution

  • Generally it just depends on the thing you want. Some things like File you have to go through an API, for example to create a file object in a rule function, you would use ctx.actions.declare_file(filename)

    See this for examples: https://docs.bazel.build/versions/master/skylark/lib/actions.html#declare_file

    Other things you can create directly, like depset has depset(). See global functions here https://docs.bazel.build/versions/master/skylark/lib/skylark-overview.html