diff --git a/BUILD b/BUILD index 6f932f5..cabe9f4 100644 --- a/BUILD +++ b/BUILD @@ -2,7 +2,7 @@ licenses(["notice"]) # Apache 2.0 package(default_visibility = ["//visibility:public"]) -load("//:skylark_library.bzl", "skylark_library") +load("//:bzl_library.bzl", "bzl_library") exports_files([ "LICENSE", @@ -18,7 +18,7 @@ filegroup( ] + glob(["*.bzl"]), ) -skylark_library( +bzl_library( name = "lib", srcs = ["lib.bzl"], deprecation = ( @@ -41,7 +41,7 @@ skylark_library( ], ) -skylark_library( - name = "skylark_library", - srcs = ["skylark_library.bzl"], +bzl_library( + name = "bzl_library", + srcs = ["bzl_library.bzl"], ) diff --git a/README.md b/README.md index 6b80e43..e06c0f5 100644 --- a/README.md +++ b/README.md @@ -80,8 +80,8 @@ Steps to add a module to Skylib: 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 -Skylark files and its dependencies for use in test targets and +The `bzl_library.bzl` rule can be used to aggregate a set of +Starlark files and its dependencies for use in test targets and documentation generation. diff --git a/bzl_library.bzl b/bzl_library.bzl new file mode 100644 index 0000000..8f1a6c9 --- /dev/null +++ b/bzl_library.bzl @@ -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", + ], + ) + ``` +""" diff --git a/lib/BUILD b/lib/BUILD index d9576d9..4435d67 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -2,7 +2,7 @@ licenses(["notice"]) package(default_visibility = ["//visibility:public"]) -load("//:skylark_library.bzl", "skylark_library") +load("//:bzl_library.bzl", "bzl_library") filegroup( name = "test_deps", @@ -10,63 +10,63 @@ filegroup( srcs = ["BUILD"] + glob(["*.bzl"]), ) -skylark_library( +bzl_library( name = "collections", srcs = ["collections.bzl"], ) -skylark_library( +bzl_library( name = "dicts", srcs = ["dicts.bzl"], ) -skylark_library( +bzl_library( name = "partial", srcs = ["partial.bzl"], ) -skylark_library( +bzl_library( name = "paths", srcs = ["paths.bzl"], ) -skylark_library( +bzl_library( name = "selects", srcs = ["selects.bzl"], ) -skylark_library( +bzl_library( name = "sets", srcs = ["sets.bzl"], ) -skylark_library( +bzl_library( name = "new_sets", srcs = ["new_sets.bzl"], ) -skylark_library( +bzl_library( name = "shell", srcs = ["shell.bzl"], ) -skylark_library( +bzl_library( name = "structs", srcs = ["structs.bzl"], ) -skylark_library( +bzl_library( name = "types", srcs = ["types.bzl"], ) -skylark_library( +bzl_library( name = "unittest", srcs = ["unittest.bzl"], deps = [":sets"], ) -skylark_library( +bzl_library( name = "versions", srcs = ["versions.bzl"], ) diff --git a/lib/partial.bzl b/lib/partial.bzl index d70aa0f..e2f24b7 100644 --- a/lib/partial.bzl +++ b/lib/partial.bzl @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # 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. diff --git a/lib/selects.bzl b/lib/selects.bzl index 4f9fea4..1c589d3 100644 --- a/lib/selects.bzl +++ b/lib/selects.bzl @@ -54,7 +54,7 @@ def _with_or(input_dict, no_match_error = ""): def _with_or_dict(input_dict): """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. Args: diff --git a/lib/unittest.bzl b/lib/unittest.bzl index 11af89f..b9763fc 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -59,7 +59,7 @@ def _make(impl, attrs = None): """ # Derive the name of the implementation function for better test feedback. - # Skylark currently stringifies a function as "", so we use + # Starlark currently stringifies a function as "", so we use # that knowledge to parse the "NAME" portion out. If this behavior ever # changes, we'll need to update this. # TODO(bazel-team): Expose a ._name field on functions to avoid this. diff --git a/skylark_library.bzl b/skylark_library.bzl index a91639d..499cd5a 100644 --- a/skylark_library.bzl +++ b/skylark_library.bzl @@ -1,109 +1,12 @@ -# 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.""" - -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", - }, +print( + "WARNING: skylark_library.bzl is deprecated and will go away in the future, please" + + " use bzl_library.bzl instead.", ) -def _skylark_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 `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)), - ), +load("//:bzl_library.bzl", "StarlarkLibraryInfo", "bzl_library") - # We also define our own provider struct, for aggregation and testing. - SkylarkLibraryInfo( - srcs = ctx.files.srcs, - transitive_srcs = all_files, - ), - ] +# These are temporary forwarding macros to facilitate migration to +# the new names for these objects. +SkylarkLibraryInfo = StarlarkLibraryInfo -skylark_library = rule( - 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", - ], - ) - ``` -""" +skylark_library = bzl_library diff --git a/tests/selects_tests.bzl b/tests/selects_tests.bzl index f7b19f9..94987cb 100644 --- a/tests/selects_tests.bzl +++ b/tests/selects_tests.bzl @@ -21,7 +21,7 @@ def _with_or_test(ctx): """Unit tests for with_or.""" 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(). # Test select()-compatible input syntax.