Rename a number of instances of 'skylark' to 'starlark' or 'bzl'

Most notably, this renames/moves a few important identifiers:

//:skylark_library.bzl -> //:bzl_library.bzl
skylark_library -> bzl_library
SkylarkLibraryInfo -> StarlarkLibraryInfo
This commit is contained in:
c-parsons 2018-09-28 09:09:18 -04:00 committed by GitHub
parent 1099dd2d0a
commit 6e2d7e4a75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 142 additions and 130 deletions

10
BUILD
View File

@ -2,7 +2,7 @@ licenses(["notice"]) # Apache 2.0
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
load("//:skylark_library.bzl", "skylark_library") load("//:bzl_library.bzl", "bzl_library")
exports_files([ exports_files([
"LICENSE", "LICENSE",
@ -18,7 +18,7 @@ filegroup(
] + glob(["*.bzl"]), ] + glob(["*.bzl"]),
) )
skylark_library( bzl_library(
name = "lib", name = "lib",
srcs = ["lib.bzl"], srcs = ["lib.bzl"],
deprecation = ( deprecation = (
@ -41,7 +41,7 @@ skylark_library(
], ],
) )
skylark_library( bzl_library(
name = "skylark_library", name = "bzl_library",
srcs = ["skylark_library.bzl"], srcs = ["bzl_library.bzl"],
) )

View File

@ -80,8 +80,8 @@ Steps to add a module to Skylib:
1. Add unit tests for your module in the `tests` directory. 1. Add unit tests for your module in the `tests` directory.
## `skylark_library` ## `bzl_library`
The `skylark_library.bzl` rule can be used to aggregate a set of The `bzl_library.bzl` rule can be used to aggregate a set of
Skylark files and its dependencies for use in test targets and Starlark files and its dependencies for use in test targets and
documentation generation. documentation generation.

109
bzl_library.bzl Normal file
View File

@ -0,0 +1,109 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Skylib module containing a library rule for aggregating rules files."""
StarlarkLibraryInfo = provider(
"Information on contained Starlark rules.",
fields = {
"srcs": "Top level rules files.",
"transitive_srcs": "Transitive closure of rules files required for " +
"interpretation of the srcs",
},
)
def _bzl_library_impl(ctx):
deps_files = [depset(x.files, order = "postorder") for x in ctx.attr.deps]
all_files = depset(ctx.files.srcs, order = "postorder", transitive = deps_files)
return [
# All dependent files should be listed in both `files` and in `runfiles`;
# this ensures that a `bzl_library` can be referenced as `data` from
# a separate program, or from `tools` of a genrule().
DefaultInfo(
files = all_files,
runfiles = ctx.runfiles(files = list(all_files)),
),
# We also define our own provider struct, for aggregation and testing.
StarlarkLibraryInfo(
srcs = ctx.files.srcs,
transitive_srcs = all_files,
),
]
bzl_library = rule(
implementation = _bzl_library_impl,
attrs = {
"srcs": attr.label_list(
allow_files = [".bzl"],
),
"deps": attr.label_list(
allow_files = [".bzl"],
providers = [
[StarlarkLibraryInfo],
],
),
},
)
"""Creates a logical collection of Starlark .bzl files.
Args:
srcs: List of `.bzl` files that are processed to create this target.
deps: List of other `bzl_library` targets that are required by the
Starlark files listed in `srcs`.
Example:
Suppose your project has the following structure:
```
[workspace]/
WORKSPACE
BUILD
checkstyle/
BUILD
checkstyle.bzl
lua/
BUILD
lua.bzl
luarocks.bzl
```
In this case, you can have `bzl_library` targets in `checkstyle/BUILD` and
`lua/BUILD`:
`checkstyle/BUILD`:
```python
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
bzl_library(
name = "checkstyle-rules",
srcs = ["checkstyle.bzl"],
)
```
`lua/BUILD`:
```python
load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
bzl_library(
name = "lua-rules",
srcs = [
"lua.bzl",
"luarocks.bzl",
],
)
```
"""

View File

@ -2,7 +2,7 @@ licenses(["notice"])
package(default_visibility = ["//visibility:public"]) package(default_visibility = ["//visibility:public"])
load("//:skylark_library.bzl", "skylark_library") load("//:bzl_library.bzl", "bzl_library")
filegroup( filegroup(
name = "test_deps", name = "test_deps",
@ -10,63 +10,63 @@ filegroup(
srcs = ["BUILD"] + glob(["*.bzl"]), srcs = ["BUILD"] + glob(["*.bzl"]),
) )
skylark_library( bzl_library(
name = "collections", name = "collections",
srcs = ["collections.bzl"], srcs = ["collections.bzl"],
) )
skylark_library( bzl_library(
name = "dicts", name = "dicts",
srcs = ["dicts.bzl"], srcs = ["dicts.bzl"],
) )
skylark_library( bzl_library(
name = "partial", name = "partial",
srcs = ["partial.bzl"], srcs = ["partial.bzl"],
) )
skylark_library( bzl_library(
name = "paths", name = "paths",
srcs = ["paths.bzl"], srcs = ["paths.bzl"],
) )
skylark_library( bzl_library(
name = "selects", name = "selects",
srcs = ["selects.bzl"], srcs = ["selects.bzl"],
) )
skylark_library( bzl_library(
name = "sets", name = "sets",
srcs = ["sets.bzl"], srcs = ["sets.bzl"],
) )
skylark_library( bzl_library(
name = "new_sets", name = "new_sets",
srcs = ["new_sets.bzl"], srcs = ["new_sets.bzl"],
) )
skylark_library( bzl_library(
name = "shell", name = "shell",
srcs = ["shell.bzl"], srcs = ["shell.bzl"],
) )
skylark_library( bzl_library(
name = "structs", name = "structs",
srcs = ["structs.bzl"], srcs = ["structs.bzl"],
) )
skylark_library( bzl_library(
name = "types", name = "types",
srcs = ["types.bzl"], srcs = ["types.bzl"],
) )
skylark_library( bzl_library(
name = "unittest", name = "unittest",
srcs = ["unittest.bzl"], srcs = ["unittest.bzl"],
deps = [":sets"], deps = [":sets"],
) )
skylark_library( bzl_library(
name = "versions", name = "versions",
srcs = ["versions.bzl"], srcs = ["versions.bzl"],
) )

View File

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
"""Skylark module for working with partial function objects. """Starlark module for working with partial function objects.
Partial function objects allow some parameters are bound before the call. Partial function objects allow some parameters are bound before the call.

View File

@ -54,7 +54,7 @@ def _with_or(input_dict, no_match_error = ""):
def _with_or_dict(input_dict): def _with_or_dict(input_dict):
"""Variation of `with_or` that returns the dict of the `select()`. """Variation of `with_or` that returns the dict of the `select()`.
Unlike `select()`, the contents of the dict can be inspected by Skylark Unlike `select()`, the contents of the dict can be inspected by Starlark
macros. macros.
Args: Args:

View File

@ -59,7 +59,7 @@ def _make(impl, attrs = None):
""" """
# Derive the name of the implementation function for better test feedback. # Derive the name of the implementation function for better test feedback.
# Skylark currently stringifies a function as "<function NAME>", so we use # Starlark currently stringifies a function as "<function NAME>", so we use
# that knowledge to parse the "NAME" portion out. If this behavior ever # that knowledge to parse the "NAME" portion out. If this behavior ever
# changes, we'll need to update this. # changes, we'll need to update this.
# TODO(bazel-team): Expose a ._name field on functions to avoid this. # TODO(bazel-team): Expose a ._name field on functions to avoid this.

View File

@ -1,109 +1,12 @@
# Copyright 2017 The Bazel Authors. All rights reserved. print(
# "WARNING: skylark_library.bzl is deprecated and will go away in the future, please" +
# Licensed under the Apache License, Version 2.0 (the "License"); " use bzl_library.bzl instead.",
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Skylib module containing a library rule for aggregating rules files."""
SkylarkLibraryInfo = provider(
"Information on contained Skylark rules.",
fields = {
"srcs": "Top level rules files.",
"transitive_srcs": "Transitive closure of rules files required for " +
"interpretation of the srcs",
},
) )
def _skylark_library_impl(ctx): load("//:bzl_library.bzl", "StarlarkLibraryInfo", "bzl_library")
deps_files = [depset(x.files, order = "postorder") for x in ctx.attr.deps]
all_files = depset(ctx.files.srcs, order = "postorder", transitive = deps_files)
return [
# All dependent files should be listed in both `files` and in `runfiles`;
# this ensures that a `skylark_library` can be referenced as `data` from
# a separate program, or from `tools` of a genrule().
DefaultInfo(
files = all_files,
runfiles = ctx.runfiles(files = list(all_files)),
),
# We also define our own provider struct, for aggregation and testing. # These are temporary forwarding macros to facilitate migration to
SkylarkLibraryInfo( # the new names for these objects.
srcs = ctx.files.srcs, SkylarkLibraryInfo = StarlarkLibraryInfo
transitive_srcs = all_files,
),
]
skylark_library = rule( skylark_library = bzl_library
implementation = _skylark_library_impl,
attrs = {
"srcs": attr.label_list(
allow_files = [".bzl"],
),
"deps": attr.label_list(
allow_files = [".bzl"],
providers = [
[SkylarkLibraryInfo],
],
),
},
)
"""Creates a logical collection of Skylark .bzl files.
Args:
srcs: List of `.bzl` files that are processed to create this target.
deps: List of other `skylark_library` targets that are required by the
Skylark files listed in `srcs`.
Example:
Suppose your project has the following structure:
```
[workspace]/
WORKSPACE
BUILD
checkstyle/
BUILD
checkstyle.bzl
lua/
BUILD
lua.bzl
luarocks.bzl
```
In this case, you can have `skylark_library` targets in `checkstyle/BUILD` and
`lua/BUILD`:
`checkstyle/BUILD`:
```python
load("@bazel_skylib//:skylark_library.bzl", "skylark_library")
skylark_library(
name = "checkstyle-rules",
srcs = ["checkstyle.bzl"],
)
```
`lua/BUILD`:
```python
load("@bazel_skylib//:skylark_library.bzl", "skylark_library")
skylark_library(
name = "lua-rules",
srcs = [
"lua.bzl",
"luarocks.bzl",
],
)
```
"""

View File

@ -21,7 +21,7 @@ def _with_or_test(ctx):
"""Unit tests for with_or.""" """Unit tests for with_or."""
env = unittest.begin(ctx) env = unittest.begin(ctx)
# We actually test on with_or_dict because Skylark can't get the # We actually test on with_or_dict because Starlark can't get the
# dictionary from a select(). # dictionary from a select().
# Test select()-compatible input syntax. # Test select()-compatible input syntax.