From 6e30a77347071ab22ce346b6d20cf8912919f644 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Wed, 27 Oct 2021 09:13:59 -0400 Subject: [PATCH] Update internal dependencies to modern versions. Bazel Federation repo is deprecated. (#327) See https://github.com/bazelbuild/bazel-federation/pull/127 In particular, this allows us to use a modern Stardoc release to fix generated md docs. And we can remove internal_deps.bzl/internal_setup.bzl - it's unnecessary complexity needed only for deprecated Federation setup. --- BUILD | 2 - WORKSPACE | 95 +++++++-------- docs/BUILD | 2 +- docs/analysis_test_doc.md | 10 +- docs/build_test_doc.md | 12 +- docs/collections_doc.md | 36 ++++-- docs/common_settings_doc.md | 67 ++++++----- docs/copy_file_doc.md | 25 ++-- docs/dicts_doc.md | 14 ++- docs/diff_test_doc.md | 18 ++- docs/native_binary_doc.md | 36 +++--- docs/new_sets_doc.md | 177 +++++++++++++++++++--------- docs/partial_doc.md | 45 +++++--- docs/paths_doc.md | 96 ++++++++++----- docs/run_binary_doc.md | 22 ++-- docs/selects_doc.md | 45 +++++--- docs/shell_doc.md | 23 +++- docs/structs_doc.md | 14 ++- docs/types_doc.md | 102 +++++++++++----- docs/unittest_doc.md | 225 ++++++++++++++++++++++-------------- docs/versions_doc.md | 50 +++++--- docs/write_file_doc.md | 26 +++-- internal_deps.bzl | 27 ----- internal_setup.bzl | 18 --- 24 files changed, 744 insertions(+), 443 deletions(-) delete mode 100644 internal_deps.bzl delete mode 100644 internal_setup.bzl diff --git a/BUILD b/BUILD index bec32f5..d61528f 100644 --- a/BUILD +++ b/BUILD @@ -4,8 +4,6 @@ licenses(["notice"]) package(default_visibility = ["//visibility:public"]) -# gazelle:exclude internal_deps.bzl -# gazelle:exclude internal_setup.bzl # buildifier: disable=skylark-comment # gazelle:exclude skylark_library.bzl diff --git a/WORKSPACE b/WORKSPACE index e8e042e..00f86ab 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -3,12 +3,47 @@ workspace(name = "bazel_skylib") load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") -http_archive( - name = "rules_pkg", - sha256 = "352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a", +maybe( + name = "io_bazel_rules_go", + repo_rule = http_archive, + sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f", urls = [ - "https://github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz", - "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.2.5/rules_pkg-0.2.5.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip", + "https://github.com/bazelbuild/rules_go/releases/download/v0.29.0/rules_go-v0.29.0.zip", + ], +) + +load("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") + +go_rules_dependencies() + +go_register_toolchains(version = "1.17.1") + +# Below this line is for documentation generation only, +# and should thus not be included by dependencies on +# bazel-skylib. + +maybe( + http_archive, + name = "io_bazel_stardoc", + sha256 = "c9794dcc8026a30ff67cf7cf91ebe245ca294b20b071845d12c192afe243ad72", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.5.0/stardoc-0.5.0.tar.gz", + "https://github.com/bazelbuild/stardoc/releases/download/0.5.0/stardoc-0.5.0.tar.gz", + ], +) + +load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories") + +stardoc_repositories() + +maybe( + http_archive, + name = "rules_pkg", + sha256 = "a89e203d3cf264e564fcb96b6e06dd70bc0557356eb48400ce4b5d97c2c3720d", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz", + "https://github.com/bazelbuild/rules_pkg/releases/download/0.5.1/rules_pkg-0.5.1.tar.gz", ], ) @@ -16,60 +51,30 @@ load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") rules_pkg_dependencies() -maybe( - name = "bazel_federation", - repo_rule = http_archive, - sha256 = "b10529fcf8a464591e845588348533981e948315b706183481e0d076afe2fa3c", - url = "https://github.com/bazelbuild/bazel-federation/releases/download/0.0.2/bazel_federation-0.0.2.tar.gz", -) - -load("@bazel_federation//:repositories.bzl", "bazel_skylib_deps", "rules_go") - -bazel_skylib_deps() - -rules_go() - -load("@bazel_federation//setup:bazel_skylib.bzl", "bazel_skylib_setup") - -bazel_skylib_setup() - -load("@bazel_federation//setup:rules_go.bzl", "rules_go_setup") - -rules_go_setup() - -# Below this line is for documentation generation only, -# and should thus not be included by dependencies on -# bazel-skylib. - -load("//:internal_deps.bzl", "bazel_skylib_internal_deps") - -bazel_skylib_internal_deps() - -load("//:internal_setup.bzl", "bazel_skylib_internal_setup") - -bazel_skylib_internal_setup() - maybe( name = "rules_cc", repo_rule = http_archive, - sha256 = "b4b2a2078bdb7b8328d843e8de07d7c13c80e6c89e86a09d6c4b424cfd1aaa19", - strip_prefix = "rules_cc-cb2dfba6746bfa3c3705185981f3109f0ae1b893", + sha256 = "4dccbfd22c0def164c8f47458bd50e0c7148f3d92002cdb459c2a96a68498241", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/rules_cc/archive/cb2dfba6746bfa3c3705185981f3109f0ae1b893.zip", - "https://github.com/bazelbuild/rules_cc/archive/cb2dfba6746bfa3c3705185981f3109f0ae1b893.zip", + "https://mirror.bazel.build/github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz", + "https://github.com/bazelbuild/rules_cc/releases/download/0.0.1/rules_cc-0.0.1.tar.gz", ], ) +load("//lib:unittest.bzl", "register_unittest_toolchains") + +register_unittest_toolchains() + # Provide a repository hint for Gazelle to inform it that the go package # github.com/bazelbuild/rules_go is available from io_bazel_rules_go and it # doesn't need to duplicatively fetch it. # gazelle:repository go_repository name=io_bazel_rules_go importpath=github.com/bazelbuild/rules_go http_archive( name = "bazel_gazelle", - sha256 = "bfd86b3cbe855d6c16c6fce60d76bd51f5c8dbc9cfcaef7a2bb5c1aafd0710e8", + sha256 = "de69a09dc70417580aabf20a28619bb3ef60d038470c7cf8442fafcf627c21cb", urls = [ - "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.21.0/bazel-gazelle-v0.21.0.tar.gz", - "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.21.0/bazel-gazelle-v0.21.0.tar.gz", + "https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", + "https://github.com/bazelbuild/bazel-gazelle/releases/download/v0.24.0/bazel-gazelle-v0.24.0.tar.gz", ], ) # Another Gazelle repository hint. diff --git a/docs/BUILD b/docs/BUILD index 1d5d0d8..2ccd60e 100644 --- a/docs/BUILD +++ b/docs/BUILD @@ -1,4 +1,4 @@ -load("@io_bazel_skydoc//stardoc:stardoc.bzl", "stardoc") +load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc") licenses(["notice"]) diff --git a/docs/analysis_test_doc.md b/docs/analysis_test_doc.md index 6585e29..1a564ae 100755 --- a/docs/analysis_test_doc.md +++ b/docs/analysis_test_doc.md @@ -1,6 +1,8 @@ - +A test verifying other targets can be successfully analyzed as part of a `bazel test` + + ## analysis_test @@ -39,8 +41,8 @@ Test rule checking that other targets can be successfully analyzed. | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | -| targets | - | List of labels | required | | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| targets | - | List of labels | required | | diff --git a/docs/build_test_doc.md b/docs/build_test_doc.md index 5974bc3..332dc58 100755 --- a/docs/build_test_doc.md +++ b/docs/build_test_doc.md @@ -1,6 +1,8 @@ - +A test verifying other targets build as part of a `bazel test` + + ## build_test @@ -31,9 +33,9 @@ Typical usage: | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name | The name of the test rule. | none | -| targets | A list of targets to ensure build. | none | -| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. | none | +| :------------- | :------------- | :------------- | +| name | The name of the test rule. | none | +| targets | A list of targets to ensure build. | none | +| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. | none | diff --git a/docs/collections_doc.md b/docs/collections_doc.md index 1b54e34..1138850 100755 --- a/docs/collections_doc.md +++ b/docs/collections_doc.md @@ -1,6 +1,8 @@ - +Skylib module containing functions that operate on collections. + + ## collections.after_each @@ -14,12 +16,16 @@ Inserts `separator` after each item in `iterable`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| separator | The value to insert after each item in iterable. | none | -| iterable | The list into which to intersperse the separator. | none | +| :------------- | :------------- | :------------- | +| separator | The value to insert after each item in iterable. | none | +| iterable | The list into which to intersperse the separator. | none | + +**RETURNS** + +A new list with `separator` after each item in `iterable`. - + ## collections.before_each @@ -33,12 +39,16 @@ Inserts `separator` before each item in `iterable`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| separator | The value to insert before each item in iterable. | none | -| iterable | The list into which to intersperse the separator. | none | +| :------------- | :------------- | :------------- | +| separator | The value to insert before each item in iterable. | none | +| iterable | The list into which to intersperse the separator. | none | + +**RETURNS** + +A new list with `separator` before each item in `iterable`. - + ## collections.uniq @@ -55,7 +65,11 @@ Requires all the elements to be hashable. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| iterable | An iterable to filter. | none | +| :------------- | :------------- | :------------- | +| iterable | An iterable to filter. | none | + +**RETURNS** + +A new list with all unique elements from `iterable`. diff --git a/docs/common_settings_doc.md b/docs/common_settings_doc.md index 41271c7..736e48c 100755 --- a/docs/common_settings_doc.md +++ b/docs/common_settings_doc.md @@ -1,6 +1,15 @@ - +Common build setting rules + +These rules return a BuildSettingInfo with the value of the build setting. +For label-typed settings, use the native label_flag and label_setting rules. + +More documentation on how to use build settings at +https://docs.bazel.build/versions/main/skylark/config.html#user-defined-build-settings + + + ## bool_flag @@ -14,11 +23,11 @@ A bool-typed build setting that can be set on the command line | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | - + ## bool_setting @@ -32,11 +41,11 @@ A bool-typed build setting that cannot be set on the command line | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | - + ## int_flag @@ -50,11 +59,11 @@ An int-typed build setting that can be set on the command line | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | - + ## int_setting @@ -68,11 +77,11 @@ An int-typed build setting that cannot be set on the command line | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | - + ## string_flag @@ -86,12 +95,12 @@ A string-typed build setting that can be set on the command line | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | -| values | The list of allowed values for this setting. An error is raised if any other value is given. | List of strings | optional | [] | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| values | The list of allowed values for this setting. An error is raised if any other value is given. | List of strings | optional | [] | - + ## string_list_flag @@ -105,11 +114,11 @@ A string list-typed build setting that can be set on the command line | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | - + ## string_list_setting @@ -123,11 +132,11 @@ A string list-typed build setting that cannot be set on the command line | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | - + ## string_setting @@ -141,12 +150,12 @@ A string-typed build setting that cannot be set on the command line | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | -| values | The list of allowed values for this setting. An error is raised if any other value is given. | List of strings | optional | [] | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| values | The list of allowed values for this setting. An error is raised if any other value is given. | List of strings | optional | [] | - + ## BuildSettingInfo @@ -160,7 +169,7 @@ A singleton provider that contains the raw value of a build setting | Name | Description | -| :-------------: | :-------------: | -| value | The value of the build setting in the current configuration. This value may come from the command line or an upstream transition, or else it will be the build setting's default. | +| :------------- | :------------- | +| value | The value of the build setting in the current configuration. This value may come from the command line or an upstream transition, or else it will be the build setting's default. | diff --git a/docs/copy_file_doc.md b/docs/copy_file_doc.md index 52f10a5..47a1244 100755 --- a/docs/copy_file_doc.md +++ b/docs/copy_file_doc.md @@ -1,6 +1,15 @@ - +A rule that copies a file to another place. + +native.genrule() is sometimes used to copy files (often wishing to rename them). +The 'copy_file' rule does this with a simpler interface than genrule. + +The rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command +on Windows (no Bash is required). + + + ## copy_file @@ -19,12 +28,12 @@ This rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name | Name of the rule. | none | -| src | A Label. The file to make a copy of. (Can also be the label of a rule that generates a file.) | none | -| out | Path of the output file, relative to this package. | none | -| is_executable | A boolean. Whether to make the output file executable. When True, the rule's output can be executed using bazel run and can be in the srcs of binary and test rules that require executable sources. WARNING: If allow_symlink is True, src must also be executable. | False | -| allow_symlink | A boolean. Whether to allow symlinking instead of copying. When False, the output is always a hard copy. When True, the output *can* be a symlink, but there is no guarantee that a symlink is created (i.e., at the time of writing, we don't create symlinks on Windows). Set this to True if you need fast copying and your tools can handle symlinks (which most UNIX tools can). | False | -| kwargs | further keyword arguments, e.g. visibility | none | +| :------------- | :------------- | :------------- | +| name | Name of the rule. | none | +| src | A Label. The file to make a copy of. (Can also be the label of a rule that generates a file.) | none | +| out | Path of the output file, relative to this package. | none | +| is_executable | A boolean. Whether to make the output file executable. When True, the rule's output can be executed using bazel run and can be in the srcs of binary and test rules that require executable sources. WARNING: If allow_symlink is True, src must also be executable. | False | +| allow_symlink | A boolean. Whether to allow symlinking instead of copying. When False, the output is always a hard copy. When True, the output *can* be a symlink, but there is no guarantee that a symlink is created (i.e., at the time of writing, we don't create symlinks on Windows). Set this to True if you need fast copying and your tools can handle symlinks (which most UNIX tools can). | False | +| kwargs | further keyword arguments, e.g. visibility | none | diff --git a/docs/dicts_doc.md b/docs/dicts_doc.md index 0b54243..5e8bce6 100755 --- a/docs/dicts_doc.md +++ b/docs/dicts_doc.md @@ -1,6 +1,8 @@ - +Skylib module containing functions that operate on dictionaries. + + ## dicts.add @@ -23,8 +25,12 @@ dictionary, and the sum of a single dictionary is a copy of itself. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| dictionaries | Zero or more dictionaries to be added. | none | -| kwargs | Additional dictionary passed as keyword args. | none | +| :------------- | :------------- | :------------- | +| dictionaries | Zero or more dictionaries to be added. | none | +| kwargs | Additional dictionary passed as keyword args. | none | + +**RETURNS** + +A new `dict` that has all the entries of the given dictionaries. diff --git a/docs/diff_test_doc.md b/docs/diff_test_doc.md index fc66934..fd62a38 100755 --- a/docs/diff_test_doc.md +++ b/docs/diff_test_doc.md @@ -1,6 +1,12 @@ - +A test rule that compares two binary files. + +The rule uses a Bash command (diff) on Linux/macOS/non-Windows, and a cmd.exe +command (fc.exe) on Windows (no Bash is required). + + + ## diff_test @@ -17,10 +23,10 @@ The test succeeds if the files' contents match. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name | The name of the test rule. | none | -| file1 | Label of the file to compare to <code>file2</code>. | none | -| file2 | Label of the file to compare to <code>file1</code>. | none | -| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. | none | +| :------------- | :------------- | :------------- | +| name | The name of the test rule. | none | +| file1 | Label of the file to compare to <code>file2</code>. | none | +| file2 | Label of the file to compare to <code>file1</code>. | none | +| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. | none | diff --git a/docs/native_binary_doc.md b/docs/native_binary_doc.md index 9979dd2..cb69179 100755 --- a/docs/native_binary_doc.md +++ b/docs/native_binary_doc.md @@ -1,6 +1,14 @@ - +native_binary() and native_test() rule implementations. + +These rules let you wrap a pre-built binary or script in a conventional binary +and test rule respectively. They fulfill the same goal as sh_binary and sh_test +do, but they run the wrapped binary directly, instead of through Bash, so they +don't depend on Bash and work with --shell_exectuable="". + + + ## native_binary @@ -17,15 +25,15 @@ You can "bazel run" this rule like any other binary rule, and use it as a tool i | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name | The name of the test rule. | none | -| src | label; path of the pre-built executable | none | -| out | output; an output name for the copy of the binary. (Bazel requires that this rule make a copy of 'src'.) | none | -| data | list of labels; data dependencies | None | -| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-binaries">common attributes for binaries</a>. | none | +| :------------- | :------------- | :------------- | +| name | The name of the test rule. | none | +| src | label; path of the pre-built executable | none | +| out | output; an output name for the copy of the binary. (Bazel requires that this rule make a copy of 'src'.) | none | +| data | list of labels; data dependencies | None | +| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-binaries">common attributes for binaries</a>. | none | - + ## native_test @@ -43,11 +51,11 @@ runfiles. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name | The name of the test rule. | none | -| src | label; path of the pre-built executable | none | -| out | output; an output name for the copy of the binary. (Bazel requires that this rule make a copy of 'src'.) | none | -| data | list of labels; data dependencies | None | -| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. | none | +| :------------- | :------------- | :------------- | +| name | The name of the test rule. | none | +| src | label; path of the pre-built executable | none | +| out | output; an output name for the copy of the binary. (Bazel requires that this rule make a copy of 'src'.) | none | +| data | list of labels; data dependencies | None | +| kwargs | The <a href="https://docs.bazel.build/versions/main/be/common-definitions.html#common-attributes-tests">common attributes for tests</a>. | none | diff --git a/docs/new_sets_doc.md b/docs/new_sets_doc.md index b25d92f..e34107f 100755 --- a/docs/new_sets_doc.md +++ b/docs/new_sets_doc.md @@ -1,6 +1,17 @@ - +Skylib module containing common hash-set algorithms. + + An empty set can be created using: `sets.make()`, or it can be created with some starting values + if you pass it an sequence: `sets.make([1, 2, 3])`. This returns a struct containing all of the + values as keys in a dictionary - this means that all passed in values must be hashable. The + values in the set can be retrieved using `sets.to_list(my_set)`. + + An arbitrary object can be tested whether it is a set generated by `sets.make()` or not with the + `types.is_set()` method in types.bzl. + + + ## sets.make @@ -17,11 +28,15 @@ All elements must be hashable. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| elements | Optional sequence to construct the set out of. | None | +| :------------- | :------------- | :------------- | +| elements | Optional sequence to construct the set out of. | None | + +**RETURNS** + +A set containing the passed in values. - + ## sets.copy @@ -35,11 +50,15 @@ Creates a new set from another set. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| s | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| s | A set, as returned by sets.make(). | none | + +**RETURNS** + +A new set containing the same elements as `s`. - + ## sets.to_list @@ -53,11 +72,15 @@ Creates a list from the values in the set. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| s | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| s | A set, as returned by sets.make(). | none | + +**RETURNS** + +A list of values inserted into the set. - + ## sets.insert @@ -74,12 +97,16 @@ Element must be hashable. This mutates the original set. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| s | A set, as returned by sets.make(). | none | -| e | The element to be inserted. | none | +| :------------- | :------------- | :------------- | +| s | A set, as returned by sets.make(). | none | +| e | The element to be inserted. | none | + +**RETURNS** + +The set `s` with `e` included. - + ## sets.contains @@ -93,12 +120,16 @@ Checks for the existence of an element in a set. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| a | A set, as returned by sets.make(). | none | -| e | The element to look for. | none | +| :------------- | :------------- | :------------- | +| a | A set, as returned by sets.make(). | none | +| e | The element to look for. | none | + +**RETURNS** + +True if the element exists in the set, False if the element does not. - + ## sets.is_equal @@ -112,12 +143,16 @@ Returns whether two sets are equal. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| a | A set, as returned by sets.make(). | none | -| b | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | + +**RETURNS** + +True if `a` is equal to `b`, False otherwise. - + ## sets.is_subset @@ -131,12 +166,16 @@ Returns whether `a` is a subset of `b`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| a | A set, as returned by sets.make(). | none | -| b | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | + +**RETURNS** + +True if `a` is a subset of `b`, False otherwise. - + ## sets.disjoint @@ -153,12 +192,16 @@ Two sets are disjoint if they have no elements in common. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| a | A set, as returned by sets.make(). | none | -| b | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | + +**RETURNS** + +True if `a` and `b` are disjoint, False otherwise. - + ## sets.intersection @@ -172,12 +215,16 @@ Returns the intersection of two sets. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| a | A set, as returned by sets.make(). | none | -| b | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | + +**RETURNS** + +A set containing the elements that are in both `a` and `b`. - + ## sets.union @@ -191,11 +238,15 @@ Returns the union of several sets. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| args | An arbitrary number of sets. | none | +| :------------- | :------------- | :------------- | +| args | An arbitrary number of sets. | none | + +**RETURNS** + +The set union of all sets in `*args`. - + ## sets.difference @@ -209,12 +260,16 @@ Returns the elements in `a` that are not in `b`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| a | A set, as returned by sets.make(). | none | -| b | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | + +**RETURNS** + +A set containing the elements that are in `a` but not in `b`. - + ## sets.length @@ -228,11 +283,15 @@ Returns the number of elements in a set. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| s | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| s | A set, as returned by sets.make(). | none | + +**RETURNS** + +An integer representing the number of elements in the set. - + ## sets.remove @@ -249,12 +308,16 @@ Element must be hashable. This mutates the original set. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| s | A set, as returned by sets.make(). | none | -| e | The element to be removed. | none | +| :------------- | :------------- | :------------- | +| s | A set, as returned by sets.make(). | none | +| e | The element to be removed. | none | + +**RETURNS** + +The set `s` with `e` removed. - + ## sets.repr @@ -268,11 +331,15 @@ Returns a string value representing the set. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| s | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| s | A set, as returned by sets.make(). | none | + +**RETURNS** + +A string representing the set. - + ## sets.str @@ -286,7 +353,11 @@ Returns a string value representing the set. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| s | A set, as returned by sets.make(). | none | +| :------------- | :------------- | :------------- | +| s | A set, as returned by sets.make(). | none | + +**RETURNS** + +A string representing the set. diff --git a/docs/partial_doc.md b/docs/partial_doc.md index ae2046a..d772ec8 100755 --- a/docs/partial_doc.md +++ b/docs/partial_doc.md @@ -1,6 +1,13 @@ - +Starlark module for working with partial function objects. + +Partial function objects allow some parameters are bound before the call. + +Similar to https://docs.python.org/3/library/functools.html#functools.partial. + + + ## partial.make @@ -106,13 +113,17 @@ partial.call(func, x=2) | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| func | The function to be called. | none | -| args | Positional arguments to be passed to function. | none | -| kwargs | Keyword arguments to be passed to function. Note that these can be overridden at the call sites. | none | +| :------------- | :------------- | :------------- | +| func | The function to be called. | none | +| args | Positional arguments to be passed to function. | none | +| kwargs | Keyword arguments to be passed to function. Note that these can be overridden at the call sites. | none | + +**RETURNS** + +A new `partial` that can be called using `call` - + ## partial.call @@ -126,13 +137,17 @@ Calls a partial created using `make`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| partial | The partial to be called. | none | -| args | Additional positional arguments to be appended to the ones given to make. | none | -| kwargs | Additional keyword arguments to augment and override the ones given to make. | none | +| :------------- | :------------- | :------------- | +| partial | The partial to be called. | none | +| args | Additional positional arguments to be appended to the ones given to make. | none | +| kwargs | Additional keyword arguments to augment and override the ones given to make. | none | + +**RETURNS** + +Whatever the function in the partial returns. - + ## partial.is_instance @@ -146,7 +161,11 @@ Returns True if v is a partial created using `make`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value to check. | none | +| :------------- | :------------- | :------------- | +| v | The value to check. | none | + +**RETURNS** + +True if v was created by `make`, False otherwise. diff --git a/docs/paths_doc.md b/docs/paths_doc.md index cd19358..e0d8116 100755 --- a/docs/paths_doc.md +++ b/docs/paths_doc.md @@ -1,6 +1,13 @@ - +Skylib module containing file path manipulation functions. + +NOTE: The functions in this module currently only support paths with Unix-style +path separators (forward slash, "/"); they do not handle Windows-style paths +with backslash separators or drive letters. + + + ## paths.basename @@ -20,11 +27,15 @@ the final slash). | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| p | The path whose basename should be returned. | none | +| :------------- | :------------- | :------------- | +| p | The path whose basename should be returned. | none | + +**RETURNS** + +The basename of the path, which includes the extension. - + ## paths.dirname @@ -43,11 +54,15 @@ included, unless omitting them would make the dirname empty. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| p | The path whose dirname should be returned. | none | +| :------------- | :------------- | :------------- | +| p | The path whose dirname should be returned. | none | + +**RETURNS** + +The dirname of the path. - + ## paths.is_absolute @@ -61,11 +76,15 @@ Returns `True` if `path` is an absolute path. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| path | A path (which is a string). | none | +| :------------- | :------------- | :------------- | +| path | A path (which is a string). | none | + +**RETURNS** + +`True` if `path` is an absolute path. - + ## paths.join @@ -88,12 +107,16 @@ If any component is an absolute path, all previous components are discarded. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| path | A path segment. | none | -| others | Additional path segments. | none | +| :------------- | :------------- | :------------- | +| path | A path segment. | none | +| others | Additional path segments. | none | + +**RETURNS** + +A string containing the joined paths. - + ## paths.normalize @@ -122,11 +145,15 @@ POSIX platforms; specifically: | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| path | A path. | none | +| :------------- | :------------- | :------------- | +| path | A path. | none | + +**RETURNS** + +The normalized path. - + ## paths.relativize @@ -149,12 +176,16 @@ the path both start with the same initial parent references. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| path | The path to relativize. | none | -| start | The ancestor path against which to relativize. | none | +| :------------- | :------------- | :------------- | +| path | The path to relativize. | none | +| start | The ancestor path against which to relativize. | none | + +**RETURNS** + +The portion of `path` that is relative to `start`. - + ## paths.replace_extension @@ -171,12 +202,16 @@ If the path has no extension, the new extension is added to it. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| p | The path whose extension should be replaced. | none | -| new_extension | The new extension for the file. The new extension should begin with a dot if you want the new filename to have one. | none | +| :------------- | :------------- | :------------- | +| p | The path whose extension should be replaced. | none | +| new_extension | The new extension for the file. The new extension should begin with a dot if you want the new filename to have one. | none | + +**RETURNS** + +The path with the extension replaced (or added, if it did not have one). - + ## paths.split_extension @@ -194,7 +229,14 @@ Leading periods on the basename are ignored, so | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| p | The path whose root and extension should be split. | none | +| :------------- | :------------- | :------------- | +| p | The path whose root and extension should be split. | none | + +**RETURNS** + +A tuple `(root, ext)` such that the root is the path without the file +extension, and `ext` is the file extension (which, if non-empty, contains +the leading dot). The returned tuple always satisfies the relationship +`root + ext == p`. diff --git a/docs/run_binary_doc.md b/docs/run_binary_doc.md index 0f94f65..96bada5 100755 --- a/docs/run_binary_doc.md +++ b/docs/run_binary_doc.md @@ -1,6 +1,12 @@ - + +run_binary() build rule implementation. + +Runs a binary as a build action. This rule does not require Bash (unlike native.genrule()). + + + ## run_binary @@ -14,12 +20,12 @@ Runs a binary as a build action.

This rule does not require Bash (unlik | Name | Description | Type | Mandatory | Default | -| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | -| name | A unique name for this target. | Name | required | | -| args | Command line arguments of the binary.<br/><br/>Subject to<code><a href="https://docs.bazel.build/versions/main/be/make-variables.html#location">$(location)</a></code> expansion. | List of strings | optional | [] | -| env | Environment variables of the action.<br/><br/>Subject to <code><a href="https://docs.bazel.build/versions/main/be/make-variables.html#location">$(location)</a></code> expansion. | Dictionary: String -> String | optional | {} | -| outs | Output files generated by the action.<br/><br/>These labels are available for <code>$(location)</code> expansion in <code>args</code> and <code>env</code>. | List of labels | required | | -| srcs | Additional inputs of the action.<br/><br/>These labels are available for <code>$(location)</code> expansion in <code>args</code> and <code>env</code>. | List of labels | optional | [] | -| tool | The tool to run in the action.<br/><br/>Must be the label of a *_binary rule, of a rule that generates an executable file, or of a file that can be executed as a subprocess (e.g. an .exe or .bat file on Windows or a binary with executable permission on Linux). This label is available for <code>$(location)</code> expansion in <code>args</code> and <code>env</code>. | Label | required | | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| args | Command line arguments of the binary.<br/><br/>Subject to<code><a href="https://docs.bazel.build/versions/main/be/make-variables.html#location">$(location)</a></code> expansion. | List of strings | optional | [] | +| env | Environment variables of the action.<br/><br/>Subject to <code><a href="https://docs.bazel.build/versions/main/be/make-variables.html#location">$(location)</a></code> expansion. | Dictionary: String -> String | optional | {} | +| outs | Output files generated by the action.<br/><br/>These labels are available for <code>$(location)</code> expansion in <code>args</code> and <code>env</code>. | List of labels | required | | +| srcs | Additional inputs of the action.<br/><br/>These labels are available for <code>$(location)</code> expansion in <code>args</code> and <code>env</code>. | List of labels | optional | [] | +| tool | The tool to run in the action.<br/><br/>Must be the label of a *_binary rule, of a rule that generates an executable file, or of a file that can be executed as a subprocess (e.g. an .exe or .bat file on Windows or a binary with executable permission on Linux). This label is available for <code>$(location)</code> expansion in <code>args</code> and <code>env</code>. | Label | required | | diff --git a/docs/selects_doc.md b/docs/selects_doc.md index 6bc1bda..8bfd964 100755 --- a/docs/selects_doc.md +++ b/docs/selects_doc.md @@ -1,6 +1,8 @@ - +Skylib module containing convenience interfaces for select(). + + ## selects.with_or @@ -28,12 +30,25 @@ Example: | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| input_dict | The same dictionary select() takes, except keys may take either the usual form "//foo:config1" or ("//foo:config1", "//foo:config2", ...) to signify //foo:config1 OR //foo:config2 OR .... | none | -| no_match_error | Optional custom error to report if no condition matches. | "" | +| :------------- | :------------- | :------------- | +| input_dict | The same dictionary select() takes, except keys may take either the usual form "//foo:config1" or ("//foo:config1", "//foo:config2", ...) to signify //foo:config1 OR //foo:config2 OR .... | none | +| no_match_error | Optional custom error to report if no condition matches. | "" | + +**RETURNS** + +A native `select()` that expands + +`("//configs:two", "//configs:three"): [":dep2or3"]` + +to + +```build +"//configs:two": [":dep2or3"], +"//configs:three": [":dep2or3"], +``` - + ## selects.with_or_dict @@ -51,11 +66,15 @@ macros. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| input_dict | Same as with_or. | none | +| :------------- | :------------- | :------------- | +| input_dict | Same as with_or. | none | + +**RETURNS** + +A dictionary usable by a native `select()`. - + ## selects.config_setting_group @@ -91,10 +110,10 @@ Example: | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name | The group's name. This is how select()s reference it. | none | -| match_any | A list of config_settings. This group matches if *any* member in the list matches. If this is set, match_all must not be set. | [] | -| match_all | A list of config_settings. This group matches if *every* member in the list matches. If this is set, match_any must be not set. | [] | -| visibility | Visibility of the config_setting_group. | None | +| :------------- | :------------- | :------------- | +| name | The group's name. This is how select()s reference it. | none | +| match_any | A list of config_settings. This group matches if *any* member in the list matches. If this is set, match_all must not be set. | [] | +| match_all | A list of config_settings. This group matches if *every* member in the list matches. If this is set, match_any must be not set. | [] | +| visibility | Visibility of the config_setting_group. | None | diff --git a/docs/shell_doc.md b/docs/shell_doc.md index a414926..0759434 100755 --- a/docs/shell_doc.md +++ b/docs/shell_doc.md @@ -1,6 +1,8 @@ - +Skylib module containing shell utility functions. + + ## shell.array_literal @@ -22,11 +24,16 @@ safety, even if they do not need to be. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| iterable | A sequence of elements. Elements that are not strings will be converted to strings first, by calling str(). | none | +| :------------- | :------------- | :------------- | +| iterable | A sequence of elements. Elements that are not strings will be converted to strings first, by calling str(). | none | + +**RETURNS** + +A string that represents the sequence as a shell array; that is, +parentheses containing the quoted elements. - + ## shell.quote @@ -44,7 +51,11 @@ shell metacharacters.) | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| s | The string to quote. | none | +| :------------- | :------------- | :------------- | +| s | The string to quote. | none | + +**RETURNS** + +A quoted version of the string that can be passed to a shell command. diff --git a/docs/structs_doc.md b/docs/structs_doc.md index c2f1337..a409d86 100755 --- a/docs/structs_doc.md +++ b/docs/structs_doc.md @@ -1,6 +1,8 @@ - +Skylib module containing functions that operate on structs. + + ## structs.to_dict @@ -14,7 +16,13 @@ Converts a `struct` to a `dict`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| s | A struct. | none | +| :------------- | :------------- | :------------- | +| s | A struct. | none | + +**RETURNS** + +A `dict` whose keys and values are the same as the fields in `s`. The +transformation is only applied to the struct's fields and not to any +nested values. diff --git a/docs/types_doc.md b/docs/types_doc.md index f18c561..7ab0a6c 100755 --- a/docs/types_doc.md +++ b/docs/types_doc.md @@ -1,6 +1,8 @@ - +Skylib module containing functions checking types. + + ## types.is_list @@ -14,11 +16,15 @@ Returns True if v is an instance of a list. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v is an instance of a list, False otherwise. - + ## types.is_string @@ -32,11 +38,15 @@ Returns True if v is an instance of a string. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v is an instance of a string, False otherwise. - + ## types.is_bool @@ -50,11 +60,15 @@ Returns True if v is an instance of a bool. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v is an instance of a bool, False otherwise. - + ## types.is_none @@ -68,11 +82,15 @@ Returns True if v has the type of None. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v is None, False otherwise. - + ## types.is_int @@ -86,11 +104,15 @@ Returns True if v is an instance of a signed integer. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v is an instance of a signed integer, False otherwise. - + ## types.is_tuple @@ -104,11 +126,15 @@ Returns True if v is an instance of a tuple. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v is an instance of a tuple, False otherwise. - + ## types.is_dict @@ -122,11 +148,15 @@ Returns True if v is an instance of a dict. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v is an instance of a dict, False otherwise. - + ## types.is_function @@ -140,11 +170,15 @@ Returns True if v is an instance of a function. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v is an instance of a function, False otherwise. - + ## types.is_depset @@ -158,11 +192,15 @@ Returns True if v is an instance of a `depset`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v is an instance of a `depset`, False otherwise. - + ## types.is_set @@ -176,7 +214,11 @@ Returns True if v is a set created by sets.make(). | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| v | The value whose type should be checked. | none | +| :------------- | :------------- | :------------- | +| v | The value whose type should be checked. | none | + +**RETURNS** + +True if v was created by sets.make(), False otherwise. diff --git a/docs/unittest_doc.md b/docs/unittest_doc.md index db9a839..4384438 100755 --- a/docs/unittest_doc.md +++ b/docs/unittest_doc.md @@ -1,6 +1,13 @@ - +Unit testing support. + +Unlike most Skylib files, this exports two modules: `unittest` which contains +functions to declare and define unit tests, and `asserts` which contains the +assertions used to within tests. + + + ## unittest_toolchain @@ -15,17 +22,17 @@ unittest_toolchain(name, Name | required | | -| escape_chars_with | Dictionary of characters that need escaping in test failure message to prefix appended to escape those characters. For example, {"%": "%", ">": "^"} would replace % with %% and > with ^> in the failure message before that is included in success_templ. | Dictionary: String -> String | optional | {} | -| escape_other_chars_with | String to prefix every character in test failure message which is not a key in escape_chars_with before including that in success_templ. For example, "" would prefix every character in the failure message (except those in the keys of escape_chars_with) with \. | String | optional | "" | -| failure_templ | Test script template with a single %s. That placeholder is replaced with the lines in the failure message joined with the string specified in join_with. The resulting script should print the failure message and exit with non-zero status. | String | required | | -| file_ext | File extension for test script, including leading dot. | String | required | | -| join_on | String used to join the lines in the failure message before including the resulting string in the script specified in failure_templ. | String | required | | -| success_templ | Test script generated when the test passes. Should exit with status 0. | String | required | | +| :------------- | :------------- | :------------- | :------------- | :------------- | +| name | A unique name for this target. | Name | required | | +| escape_chars_with | Dictionary of characters that need escaping in test failure message to prefix appended to escape those characters. For example, {"%": "%", ">": "^"} would replace % with %% and > with ^> in the failure message before that is included in success_templ. | Dictionary: String -> String | optional | {} | +| escape_other_chars_with | String to prefix every character in test failure message which is not a key in escape_chars_with before including that in success_templ. For example, "" would prefix every character in the failure message (except those in the keys of escape_chars_with) with \. | String | optional | "" | +| failure_templ | Test script template with a single %s. That placeholder is replaced with the lines in the failure message joined with the string specified in join_with. The resulting script should print the failure message and exit with non-zero status. | String | required | | +| file_ext | File extension for test script, including leading dot. | String | required | | +| join_on | String used to join the lines in the failure message before including the resulting string in the script specified in failure_templ. | String | required | | +| success_templ | Test script generated when the test passes. Should exit with status 0. | String | required | | - + ## analysistest.make @@ -64,16 +71,21 @@ Recall that names of test rules must end in `_test`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| impl | The implementation function of the unit test. | none | -| expect_failure | If true, the analysis test will expect the target_under_test to fail. Assertions can be made on the underlying failure using asserts.expect_failure | False | -| attrs | An optional dictionary to supplement the attrs passed to the unit test's rule() constructor. | {} | -| fragments | An optional list of fragment names that can be used to give rules access to language-specific parts of configuration. | [] | -| config_settings | A dictionary of configuration settings to change for the target under test and its dependencies. This may be used to essentially change 'build flags' for the target under test, and may thus be utilized to test multiple targets with different flags in a single build | {} | -| extra_target_under_test_aspects | An optional list of aspects to apply to the target_under_test in addition to those set up by default for the test harness itself. | [] | +| :------------- | :------------- | :------------- | +| impl | The implementation function of the unit test. | none | +| expect_failure | If true, the analysis test will expect the target_under_test to fail. Assertions can be made on the underlying failure using asserts.expect_failure | False | +| attrs | An optional dictionary to supplement the attrs passed to the unit test's rule() constructor. | {} | +| fragments | An optional list of fragment names that can be used to give rules access to language-specific parts of configuration. | [] | +| config_settings | A dictionary of configuration settings to change for the target under test and its dependencies. This may be used to essentially change 'build flags' for the target under test, and may thus be utilized to test multiple targets with different flags in a single build | {} | +| extra_target_under_test_aspects | An optional list of aspects to apply to the target_under_test in addition to those set up by default for the test harness itself. | [] | + +**RETURNS** + +A rule definition that should be stored in a global whose name ends in +`_test`. - + ## analysistest.begin @@ -93,11 +105,17 @@ test. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| ctx | The Starlark context. Pass the implementation function's ctx argument in verbatim. | none | +| :------------- | :------------- | :------------- | +| ctx | The Starlark context. Pass the implementation function's ctx argument in verbatim. | none | + +**RETURNS** + +A test environment struct that must be passed to assertions and finally to +`unittest.end`. Do not rely on internal details about the fields in this +struct as it may change. - + ## analysistest.end @@ -115,11 +133,15 @@ that the results are reported. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by analysistest.begin. | none | +| :------------- | :------------- | :------------- | +| env | The test environment returned by analysistest.begin. | none | + +**RETURNS** + +A list of providers needed to automatically register the analysis test result. - + ## analysistest.fail @@ -133,12 +155,12 @@ Unconditionally causes the current test to fail. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by unittest.begin. | none | -| msg | The message to log describing the failure. | none | +| :------------- | :------------- | :------------- | +| env | The test environment returned by unittest.begin. | none | +| msg | The message to log describing the failure. | none | - + ## analysistest.target_actions @@ -152,11 +174,15 @@ Returns a list of actions registered by the target under test. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by analysistest.begin. | none | +| :------------- | :------------- | :------------- | +| env | The test environment returned by analysistest.begin. | none | + +**RETURNS** + +A list of actions registered by the target under test - + ## analysistest.target_bin_dir_path @@ -170,11 +196,15 @@ Returns ctx.bin_dir.path for the target under test. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by analysistest.begin. | none | +| :------------- | :------------- | :------------- | +| env | The test environment returned by analysistest.begin. | none | + +**RETURNS** + +Output bin dir path string. - + ## analysistest.target_under_test @@ -188,11 +218,15 @@ Returns the target under test. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by analysistest.begin. | none | +| :------------- | :------------- | :------------- | +| env | The test environment returned by analysistest.begin. | none | + +**RETURNS** + +The target under test. - + ## asserts.expect_failure @@ -210,12 +244,12 @@ This requires that the analysis test is created with `analysistest.make()` and | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by analysistest.begin. | none | -| expected_failure_msg | The error message to expect as a result of analysis failures. | "" | +| :------------- | :------------- | :------------- | +| env | The test environment returned by analysistest.begin. | none | +| expected_failure_msg | The error message to expect as a result of analysis failures. | "" | - + ## asserts.equals @@ -229,14 +263,14 @@ Asserts that the given `expected` and `actual` values are equal. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by unittest.begin. | none | -| expected | The expected value of some computation. | none | -| actual | The actual value returned by some computation. | none | -| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | None | +| :------------- | :------------- | :------------- | +| env | The test environment returned by unittest.begin. | none | +| expected | The expected value of some computation. | none | +| actual | The actual value returned by some computation. | none | +| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | None | - + ## asserts.false @@ -250,13 +284,13 @@ Asserts that the given `condition` is false. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by unittest.begin. | none | -| condition | A value that will be evaluated in a Boolean context. | none | -| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | "Expected condition to be false, but was true." | +| :------------- | :------------- | :------------- | +| env | The test environment returned by unittest.begin. | none | +| condition | A value that will be evaluated in a Boolean context. | none | +| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | "Expected condition to be false, but was true." | - + ## asserts.set_equals @@ -270,14 +304,14 @@ Asserts that the given `expected` and `actual` sets are equal. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by unittest.begin. | none | -| expected | The expected set resulting from some computation. | none | -| actual | The actual set returned by some computation. | none | -| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | None | +| :------------- | :------------- | :------------- | +| env | The test environment returned by unittest.begin. | none | +| expected | The expected set resulting from some computation. | none | +| actual | The actual set returned by some computation. | none | +| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | None | - + ## asserts.new_set_equals @@ -291,14 +325,14 @@ Asserts that the given `expected` and `actual` sets are equal. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by unittest.begin. | none | -| expected | The expected set resulting from some computation. | none | -| actual | The actual set returned by some computation. | none | -| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | None | +| :------------- | :------------- | :------------- | +| env | The test environment returned by unittest.begin. | none | +| expected | The expected set resulting from some computation. | none | +| actual | The actual set returned by some computation. | none | +| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | None | - + ## asserts.true @@ -312,13 +346,13 @@ Asserts that the given `condition` is true. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by unittest.begin. | none | -| condition | A value that will be evaluated in a Boolean context. | none | -| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | "Expected condition to be true, but was false." | +| :------------- | :------------- | :------------- | +| env | The test environment returned by unittest.begin. | none | +| condition | A value that will be evaluated in a Boolean context. | none | +| msg | An optional message that will be printed that describes the failure. If omitted, a default will be used. | "Expected condition to be true, but was false." | - + ## register_unittest_toolchains @@ -328,11 +362,9 @@ register_unittest_toolchains() Registers the toolchains for unittest users. -**PARAMETERS** - - + ## unittest.make @@ -370,12 +402,17 @@ Recall that names of test rules must end in `_test`. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| impl | The implementation function of the unit test. | none | -| attrs | An optional dictionary to supplement the attrs passed to the unit test's rule() constructor. | {} | +| :------------- | :------------- | :------------- | +| impl | The implementation function of the unit test. | none | +| attrs | An optional dictionary to supplement the attrs passed to the unit test's rule() constructor. | {} | + +**RETURNS** + +A rule definition that should be stored in a global whose name ends in +`_test`. - + ## unittest.suite @@ -426,12 +463,12 @@ name each target. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name | The name of the test_suite target, and the prefix of all the test target names. | none | -| test_rules | A list of test rules defines by unittest.test. | none | +| :------------- | :------------- | :------------- | +| name | The name of the test_suite target, and the prefix of all the test target names. | none | +| test_rules | A list of test rules defines by unittest.test. | none | - + ## unittest.begin @@ -451,11 +488,17 @@ test. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| ctx | The Starlark context. Pass the implementation function's ctx argument in verbatim. | none | +| :------------- | :------------- | :------------- | +| ctx | The Starlark context. Pass the implementation function's ctx argument in verbatim. | none | + +**RETURNS** + +A test environment struct that must be passed to assertions and finally to +`unittest.end`. Do not rely on internal details about the fields in this +struct as it may change. - + ## unittest.end @@ -473,11 +516,15 @@ that the results are reported. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by unittest.begin. | none | +| :------------- | :------------- | :------------- | +| env | The test environment returned by unittest.begin. | none | + +**RETURNS** + +A list of providers needed to automatically register the test result. - + ## unittest.fail @@ -491,8 +538,8 @@ Unconditionally causes the current test to fail. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| env | The test environment returned by unittest.begin. | none | -| msg | The message to log describing the failure. | none | +| :------------- | :------------- | :------------- | +| env | The test environment returned by unittest.begin. | none | +| msg | The message to log describing the failure. | none | diff --git a/docs/versions_doc.md b/docs/versions_doc.md index b39f5d0..83ee7a7 100755 --- a/docs/versions_doc.md +++ b/docs/versions_doc.md @@ -1,6 +1,8 @@ - +Skylib module containing functions for checking Bazel versions. + + ## versions.get @@ -10,11 +12,9 @@ versions.get() Returns the current Bazel version -**PARAMETERS** - - + ## versions.parse @@ -31,11 +31,15 @@ int tuples can be compared directly using binary operators (<, >). | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| bazel_version | the Bazel version string | none | +| :------------- | :------------- | :------------- | +| bazel_version | the Bazel version string | none | + +**RETURNS** + +An int 3-tuple of a (major, minor, patch) version. - + ## versions.check @@ -49,13 +53,13 @@ Check that the version of Bazel is valid within the specified range. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| minimum_bazel_version | minimum version of Bazel expected | none | -| maximum_bazel_version | maximum version of Bazel expected | None | -| bazel_version | the version of Bazel to check. Used for testing, defaults to native.bazel_version | None | +| :------------- | :------------- | :------------- | +| minimum_bazel_version | minimum version of Bazel expected | none | +| maximum_bazel_version | maximum version of Bazel expected | None | +| bazel_version | the version of Bazel to check. Used for testing, defaults to native.bazel_version | None | - + ## versions.is_at_most @@ -69,12 +73,16 @@ Check that a version is lower or equals to a threshold. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| threshold | the maximum version string | none | -| version | the version string to be compared to the threshold | none | +| :------------- | :------------- | :------------- | +| threshold | the maximum version string | none | +| version | the version string to be compared to the threshold | none | + +**RETURNS** + +True if version <= threshold. - + ## versions.is_at_least @@ -88,8 +96,12 @@ Check that a version is higher or equals to a threshold. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| threshold | the minimum version string | none | -| version | the version string to be compared to the threshold | none | +| :------------- | :------------- | :------------- | +| threshold | the minimum version string | none | +| version | the version string to be compared to the threshold | none | + +**RETURNS** + +True if version >= threshold. diff --git a/docs/write_file_doc.md b/docs/write_file_doc.md index 74f6327..8f39376 100755 --- a/docs/write_file_doc.md +++ b/docs/write_file_doc.md @@ -1,6 +1,16 @@ - +A rule that writes a UTF-8 encoded text file from user-specified contents. + +native.genrule() is sometimes used to create a text file. The 'write_file' and +macro does this with a simpler interface than genrule. + +The rules generated by the macro do not use Bash or any other shell to write the +file. Instead they use Starlark's built-in file writing action +(ctx.actions.write). + + + ## write_file @@ -14,12 +24,12 @@ Creates a UTF-8 encoded text file. | Name | Description | Default Value | -| :-------------: | :-------------: | :-------------: | -| name | Name of the rule. | none | -| out | Path of the output file, relative to this package. | none | -| content | A list of strings. Lines of text, the contents of the file. Newlines are added automatically after every line except the last one. | [] | -| is_executable | A boolean. Whether to make the output file executable. When True, the rule's output can be executed using bazel run and can be in the srcs of binary and test rules that require executable sources. | False | -| newline | one of ["auto", "unix", "windows"]: line endings to use. "auto" for platform-determined, "unix" for LF, and "windows" for CRLF. | "auto" | -| kwargs | further keyword arguments, e.g. <code>visibility</code> | none | +| :------------- | :------------- | :------------- | +| name | Name of the rule. | none | +| out | Path of the output file, relative to this package. | none | +| content | A list of strings. Lines of text, the contents of the file. Newlines are added automatically after every line except the last one. | [] | +| is_executable | A boolean. Whether to make the output file executable. When True, the rule's output can be executed using bazel run and can be in the srcs of binary and test rules that require executable sources. | False | +| newline | one of ["auto", "unix", "windows"]: line endings to use. "auto" for platform-determined, "unix" for LF, and "windows" for CRLF. | "auto" | +| kwargs | further keyword arguments, e.g. <code>visibility</code> | none | diff --git a/internal_deps.bzl b/internal_deps.bzl deleted file mode 100644 index c7dacd8..0000000 --- a/internal_deps.bzl +++ /dev/null @@ -1,27 +0,0 @@ -# Copyright 2019 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. - -"""Dependencies that are needed for running skylib tests.""" - -load( - "@bazel_federation//:repositories.bzl", - "bazel", - "bazel_stardoc", - "rules_pkg", -) - -def bazel_skylib_internal_deps(): - bazel() - bazel_stardoc() - rules_pkg() diff --git a/internal_setup.bzl b/internal_setup.bzl deleted file mode 100644 index e3189ed..0000000 --- a/internal_setup.bzl +++ /dev/null @@ -1,18 +0,0 @@ -# Copyright 2019 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. - -"""Setup function that must be invoked before running skylib tests.""" - -def bazel_skylib_internal_setup(): - pass # placeholder function for the federation