From 836f1b2f564e8952a9b1ae72f66fc9fad8c8e6f1 Mon Sep 17 00:00:00 2001 From: Samuel Giddins Date: Mon, 7 Sep 2020 14:29:39 -0700 Subject: Add support for gazelle handling relative imports (#271) --- gazelle/bzl/BUILD | 2 +- gazelle/bzl/gazelle.go | 19 +++++++++++++++---- gazelle/bzl/testdata/import/BUILD.out | 2 +- gazelle/bzl/testdata/relative_import/BUILD.in | 0 gazelle/bzl/testdata/relative_import/BUILD.out | 14 ++++++++++++++ gazelle/bzl/testdata/relative_import/WORKSPACE | 0 gazelle/bzl/testdata/relative_import/bar.bzl | 6 ++++++ gazelle/bzl/testdata/relative_import/foo.bzl | 7 +++++++ .../bzl/testdata/relative_import/nested/dir/BUILD.in | 0 .../bzl/testdata/relative_import/nested/dir/BUILD.out | 14 ++++++++++++++ .../bzl/testdata/relative_import/nested/dir/bar.bzl | 6 ++++++ .../bzl/testdata/relative_import/nested/dir/foo.bzl | 7 +++++++ gazelle/bzl/testdata/workspace_name/BUILD.in | 0 gazelle/bzl/testdata/workspace_name/BUILD.out | 14 ++++++++++++++ gazelle/bzl/testdata/workspace_name/WORKSPACE | 1 + gazelle/bzl/testdata/workspace_name/bar.bzl | 6 ++++++ gazelle/bzl/testdata/workspace_name/foo.bzl | 7 +++++++ 17 files changed, 99 insertions(+), 6 deletions(-) create mode 100644 gazelle/bzl/testdata/relative_import/BUILD.in create mode 100644 gazelle/bzl/testdata/relative_import/BUILD.out create mode 100644 gazelle/bzl/testdata/relative_import/WORKSPACE create mode 100644 gazelle/bzl/testdata/relative_import/bar.bzl create mode 100644 gazelle/bzl/testdata/relative_import/foo.bzl create mode 100644 gazelle/bzl/testdata/relative_import/nested/dir/BUILD.in create mode 100644 gazelle/bzl/testdata/relative_import/nested/dir/BUILD.out create mode 100644 gazelle/bzl/testdata/relative_import/nested/dir/bar.bzl create mode 100644 gazelle/bzl/testdata/relative_import/nested/dir/foo.bzl create mode 100644 gazelle/bzl/testdata/workspace_name/BUILD.in create mode 100644 gazelle/bzl/testdata/workspace_name/BUILD.out create mode 100644 gazelle/bzl/testdata/workspace_name/WORKSPACE create mode 100644 gazelle/bzl/testdata/workspace_name/bar.bzl create mode 100644 gazelle/bzl/testdata/workspace_name/foo.bzl diff --git a/gazelle/bzl/BUILD b/gazelle/bzl/BUILD index fea1d51..29caeb0 100644 --- a/gazelle/bzl/BUILD +++ b/gazelle/bzl/BUILD @@ -49,5 +49,5 @@ gazelle_binary( gazelle( name = "gazelle", - gazelle = "//gazelle:gazelle-skylib", + gazelle = ":gazelle-skylib", ) diff --git a/gazelle/bzl/gazelle.go b/gazelle/bzl/gazelle.go index f948390..a0b8aa6 100644 --- a/gazelle/bzl/gazelle.go +++ b/gazelle/bzl/gazelle.go @@ -152,23 +152,34 @@ func (*bzlLibraryLang) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo deps := make([]string, 0, len(imports)) for _, imp := range imports { - if strings.HasPrefix(imp, "@") || !c.IndexLibraries { + impLabel, err := label.Parse(imp) + if err != nil { + log.Printf("%s: import of %q is invalid: %v", from.String(), imp, err) + continue + } + + // the index only contains absolute labels, not relative + impLabel = impLabel.Abs(from.Repo, from.Pkg) + + if impLabel.Repo != "" || !c.IndexLibraries { // This is a dependency that is external to the current repo, or indexing // is disabled so take a guess at what hte target name should be. deps = append(deps, strings.TrimSuffix(imp, fileType)) } else { res := resolve.ImportSpec{ Lang: languageName, - Imp: imp, + Imp: impLabel.String(), } matches := ix.FindRulesByImport(res, languageName) if len(matches) == 0 { - log.Printf("%s: %q was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp) + log.Printf("%s: %q (%s) was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp, impLabel.String()) } for _, m := range matches { - deps = append(deps, m.Label.String()) + depLabel := m.Label + depLabel = depLabel.Rel(from.Repo, from.Pkg) + deps = append(deps, depLabel.String()) } } } diff --git a/gazelle/bzl/testdata/import/BUILD.out b/gazelle/bzl/testdata/import/BUILD.out index a19a11a..2d39feb 100644 --- a/gazelle/bzl/testdata/import/BUILD.out +++ b/gazelle/bzl/testdata/import/BUILD.out @@ -10,5 +10,5 @@ bzl_library( name = "foo", srcs = ["foo.bzl"], visibility = ["//visibility:public"], - deps = ["//:bar"], + deps = [":bar"], ) diff --git a/gazelle/bzl/testdata/relative_import/BUILD.in b/gazelle/bzl/testdata/relative_import/BUILD.in new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/bzl/testdata/relative_import/BUILD.out b/gazelle/bzl/testdata/relative_import/BUILD.out new file mode 100644 index 0000000..2d39feb --- /dev/null +++ b/gazelle/bzl/testdata/relative_import/BUILD.out @@ -0,0 +1,14 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "bar", + srcs = ["bar.bzl"], + visibility = ["//visibility:public"], +) + +bzl_library( + name = "foo", + srcs = ["foo.bzl"], + visibility = ["//visibility:public"], + deps = [":bar"], +) diff --git a/gazelle/bzl/testdata/relative_import/WORKSPACE b/gazelle/bzl/testdata/relative_import/WORKSPACE new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/bzl/testdata/relative_import/bar.bzl b/gazelle/bzl/testdata/relative_import/bar.bzl new file mode 100644 index 0000000..7ffea51 --- /dev/null +++ b/gazelle/bzl/testdata/relative_import/bar.bzl @@ -0,0 +1,6 @@ +""" +Doc string +""" + +def func(): + pass diff --git a/gazelle/bzl/testdata/relative_import/foo.bzl b/gazelle/bzl/testdata/relative_import/foo.bzl new file mode 100644 index 0000000..829cce3 --- /dev/null +++ b/gazelle/bzl/testdata/relative_import/foo.bzl @@ -0,0 +1,7 @@ +""" +Doc string +""" + +load(":bar.bzl", "func") + +func() diff --git a/gazelle/bzl/testdata/relative_import/nested/dir/BUILD.in b/gazelle/bzl/testdata/relative_import/nested/dir/BUILD.in new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/bzl/testdata/relative_import/nested/dir/BUILD.out b/gazelle/bzl/testdata/relative_import/nested/dir/BUILD.out new file mode 100644 index 0000000..2d39feb --- /dev/null +++ b/gazelle/bzl/testdata/relative_import/nested/dir/BUILD.out @@ -0,0 +1,14 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "bar", + srcs = ["bar.bzl"], + visibility = ["//visibility:public"], +) + +bzl_library( + name = "foo", + srcs = ["foo.bzl"], + visibility = ["//visibility:public"], + deps = [":bar"], +) diff --git a/gazelle/bzl/testdata/relative_import/nested/dir/bar.bzl b/gazelle/bzl/testdata/relative_import/nested/dir/bar.bzl new file mode 100644 index 0000000..7ffea51 --- /dev/null +++ b/gazelle/bzl/testdata/relative_import/nested/dir/bar.bzl @@ -0,0 +1,6 @@ +""" +Doc string +""" + +def func(): + pass diff --git a/gazelle/bzl/testdata/relative_import/nested/dir/foo.bzl b/gazelle/bzl/testdata/relative_import/nested/dir/foo.bzl new file mode 100644 index 0000000..829cce3 --- /dev/null +++ b/gazelle/bzl/testdata/relative_import/nested/dir/foo.bzl @@ -0,0 +1,7 @@ +""" +Doc string +""" + +load(":bar.bzl", "func") + +func() diff --git a/gazelle/bzl/testdata/workspace_name/BUILD.in b/gazelle/bzl/testdata/workspace_name/BUILD.in new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/bzl/testdata/workspace_name/BUILD.out b/gazelle/bzl/testdata/workspace_name/BUILD.out new file mode 100644 index 0000000..2d39feb --- /dev/null +++ b/gazelle/bzl/testdata/workspace_name/BUILD.out @@ -0,0 +1,14 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "bar", + srcs = ["bar.bzl"], + visibility = ["//visibility:public"], +) + +bzl_library( + name = "foo", + srcs = ["foo.bzl"], + visibility = ["//visibility:public"], + deps = [":bar"], +) diff --git a/gazelle/bzl/testdata/workspace_name/WORKSPACE b/gazelle/bzl/testdata/workspace_name/WORKSPACE new file mode 100644 index 0000000..2fa2441 --- /dev/null +++ b/gazelle/bzl/testdata/workspace_name/WORKSPACE @@ -0,0 +1 @@ +workspace(name = "com_example") diff --git a/gazelle/bzl/testdata/workspace_name/bar.bzl b/gazelle/bzl/testdata/workspace_name/bar.bzl new file mode 100644 index 0000000..7ffea51 --- /dev/null +++ b/gazelle/bzl/testdata/workspace_name/bar.bzl @@ -0,0 +1,6 @@ +""" +Doc string +""" + +def func(): + pass diff --git a/gazelle/bzl/testdata/workspace_name/foo.bzl b/gazelle/bzl/testdata/workspace_name/foo.bzl new file mode 100644 index 0000000..eb8d33c --- /dev/null +++ b/gazelle/bzl/testdata/workspace_name/foo.bzl @@ -0,0 +1,7 @@ +""" +Doc string +""" + +load("//:bar.bzl", "func") + +func() -- cgit v1.2.3 From 2a89db4749d1aa860ea42ab50491cdc40d9a199a Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Tue, 15 Sep 2020 17:53:03 -0600 Subject: Fix CODEOWNERS (#275) Previously permissions were granted to edit any file that existed in a directory titled `gazelle`. Now grants have been given recursively. --- CODEOWNERS | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 07b74fa..f47842c 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,4 +1,5 @@ +# More details on syntax here: https://help.github.com/articles/about-codeowners/ * @c-parsons @laurentlb @jin @aiuto -distribution/ @aiuto @fwe -rules/ @juliexxia -gazelle/ @achew22 @jayconrod +/distribution/ @aiuto @fwe +/rules/ @juliexxia +/gazelle/ @achew22 @jayconrod -- cgit v1.2.3 From 56ec790c9b881c82e84904705786a9b2b994cb0e Mon Sep 17 00:00:00 2001 From: David Sanderson <32687193+dws-uber@users.noreply.github.com> Date: Fri, 25 Sep 2020 16:32:06 -0400 Subject: Address latent buildifier issues. (#278) In https://buildkite.com/bazel/bazel-skylib/builds/1240#annotation-buildifier I noticed buildifier issues unrelated to my PR. This PR attempts to address these latent buildifier issues. --- lib/unittest.bzl | 5 ++++- tests/selects_tests.bzl | 5 ++++- tests/unittest_tests.bzl | 10 ++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/unittest.bzl b/lib/unittest.bzl index 0cdbd94..5b70df5 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -126,7 +126,10 @@ def _make(impl, attrs = {}): toolchains = [TOOLCHAIN_TYPE], ) -_ActionInfo = provider(fields = ["actions", "bin_path"]) +_ActionInfo = provider( + doc = "Information relating to the target under test.", + fields = ["actions", "bin_path"], +) def _action_retrieving_aspect_impl(target, ctx): return [ diff --git a/tests/selects_tests.bzl b/tests/selects_tests.bzl index 28f3ac4..7a980e6 100644 --- a/tests/selects_tests.bzl +++ b/tests/selects_tests.bzl @@ -129,7 +129,10 @@ def _set_conditions(condition_list): ans["//command_line_option:features"] = ["notmyfeature"] return ans -_BooleanInfo = provider() +_BooleanInfo = provider( + doc = "value for boolean tests", + fields = ["value"], +) def _boolean_attr_impl(ctx): return [_BooleanInfo(value = ctx.attr.myboolean)] diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index 3d5a198..0b992f9 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -54,7 +54,10 @@ def _change_setting_test(ctx): return analysistest.end(env) -_ChangeSettingInfo = provider() +_ChangeSettingInfo = provider( + doc = "min_os_version for change_setting_test", + fields = ["min_os_version"], +) def _change_setting_fake_rule(ctx): return [_ChangeSettingInfo(min_os_version = ctx.fragments.cpp.minimum_os_version())] @@ -180,7 +183,10 @@ inspect_actions_test = analysistest.make( ######################################## ####### inspect_output_dirs_test ####### ######################################## -_OutputDirInfo = provider(fields = ["bin_path"]) +_OutputDirInfo = provider( + doc = "bin_path for inspect_output_dirs_test", + fields = ["bin_path"], +) def _inspect_output_dirs_test(ctx): """Test verifying output directories used by a test.""" -- cgit v1.2.3 From 528e4241345536c487cca8b11db138104bb3bd68 Mon Sep 17 00:00:00 2001 From: Laurent Le Brun Date: Fri, 25 Sep 2020 22:55:01 +0200 Subject: Remove laurentlb from CODEOWNERS (#279) --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index f47842c..2b58657 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,5 +1,5 @@ # More details on syntax here: https://help.github.com/articles/about-codeowners/ -* @c-parsons @laurentlb @jin @aiuto +* @c-parsons @jin @aiuto /distribution/ @aiuto @fwe /rules/ @juliexxia /gazelle/ @achew22 @jayconrod -- cgit v1.2.3 From a81c2c0efe9fdabb9f5cfb666d737c394b1771c9 Mon Sep 17 00:00:00 2001 From: River Date: Thu, 15 Oct 2020 11:20:00 -0700 Subject: Regenerate new_sets.bzl docs. (#280) Lists are not supported. The code comments were fixed to match this in http://github.com/bazelbuild/bazel-skylib/commit/2d620ba1f8284695181fa092ec4064724ea99a9a, but the docs were never updated. --- docs/new_sets_doc.md | 485 ++++++++++++++------------------------------------- 1 file changed, 129 insertions(+), 356 deletions(-) diff --git a/docs/new_sets_doc.md b/docs/new_sets_doc.md index feec3b8..b25d92f 100755 --- a/docs/new_sets_doc.md +++ b/docs/new_sets_doc.md @@ -1,3 +1,7 @@ + + + + ## sets.make
@@ -9,27 +13,16 @@ Creates a new set.
 All elements must be hashable.
 
 
-### Parameters
+**PARAMETERS**
+
 
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
elements - optional. default is None -

- Optional sequence to construct the set out of. -

-
+| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| elements | Optional sequence to construct the set out of. | None | + + ## sets.copy
@@ -38,27 +31,16 @@ sets.copy(s)
 
 Creates a new set from another set.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
s - required. -

- A set, as returned by `sets.make()`. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| s | A set, as returned by sets.make(). | none | + + ## sets.to_list
@@ -67,27 +49,16 @@ sets.to_list(s)
 
 Creates a list from the values in the set.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
s - required. -

- A set, as returned by `sets.make()`. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| s | A set, as returned by sets.make(). | none | + + ## sets.insert
@@ -99,36 +70,17 @@ Inserts an element into the set.
 Element must be hashable.  This mutates the original set.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
s - required. -

- A set, as returned by `sets.make()`. -

-
e - required. -

- The element to be inserted. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| s | A set, as returned by sets.make(). | none | +| e | The element to be inserted. | none | + + ## sets.contains
@@ -137,36 +89,17 @@ sets.contains(a, e
 
 Checks for the existence of an element in a set.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
a - required. -

- A set, as returned by `sets.make()`. -

-
e - required. -

- The element to look for. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| a | A set, as returned by sets.make(). | none | +| e | The element to look for. | none | + + ## sets.is_equal
@@ -175,36 +108,17 @@ sets.is_equal(a, b
 
 Returns whether two sets are equal.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
a - required. -

- A set, as returned by `sets.make()`. -

-
b - required. -

- A set, as returned by `sets.make()`. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | + + ## sets.is_subset
@@ -213,36 +127,17 @@ sets.is_subset(a, b<
 
 Returns whether `a` is a subset of `b`.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
a - required. -

- A set, as returned by `sets.make()`. -

-
b - required. -

- A set, as returned by `sets.make()`. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | +
+ ## sets.disjoint
@@ -254,35 +149,16 @@ Returns whether two sets are disjoint.
 Two sets are disjoint if they have no elements in common.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
a - required. -

- A set, as returned by `sets.make()`. -

-
b - required. -

- A set, as returned by `sets.make()`. -

-
+**PARAMETERS** + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | + + + ## sets.intersection @@ -292,35 +168,16 @@ sets.intersection(a, - - - - - - - a - - required. -

- A set, as returned by `sets.make()`. -

- - - - b - - required. -

- A set, as returned by `sets.make()`. -

- - - - +**PARAMETERS** + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | + + +
## sets.union @@ -330,26 +187,15 @@ sets.union(args) Returns the union of several sets. -### Parameters - - - - - - - - - - - - -
args - optional. -

- An arbitrary number of sets or lists. -

-
+**PARAMETERS** + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| args | An arbitrary number of sets. | none | + + + ## sets.difference @@ -359,35 +205,16 @@ sets.difference(a, - - - - - - - a - - required. -

- A set, as returned by `sets.make()`. -

- - - - b - - required. -

- A set, as returned by `sets.make()`. -

- - - - +**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| a | A set, as returned by sets.make(). | none | +| b | A set, as returned by sets.make(). | none | + +
## sets.length @@ -397,27 +224,16 @@ sets.length(s) Returns the number of elements in a set. -### Parameters - - - - - - - - - - - - -
s - required. -

- A set, as returned by `sets.make()`. -

-
+**PARAMETERS** +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| s | A set, as returned by sets.make(). | none | + + + + ## sets.remove
@@ -429,35 +245,16 @@ Removes an element from the set.
 Element must be hashable.  This mutates the original set.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
s - required. -

- A set, as returned by `sets.make()`. -

-
e - required. -

- The element to be removed. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| s | A set, as returned by sets.make(). | none | +| e | The element to be removed. | none | + + ## sets.repr @@ -467,27 +264,16 @@ sets.repr(s) Returns a string value representing the set. -### Parameters - - - - - - - - - - - - -
s - required. -

- A set, as returned by `sets.make()`. -

-
+**PARAMETERS** +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| s | A set, as returned by sets.make(). | none | + + + + ## sets.str
@@ -496,24 +282,11 @@ sets.str(s)
 
 Returns a string value representing the set.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
s - required. -

- A set, as returned by `sets.make()`. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| s | A set, as returned by sets.make(). | none | -- cgit v1.2.3 From b2ffc94b17518efa40f42e6351cad3d01a7cbdb6 Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Mon, 19 Oct 2020 10:49:17 -0600 Subject: Gazelle now handles imports from `@bazel_tools` (#273) `@bazel_tools` is tricky since it is effectively a part of the standard library that can not have a `bzl_library` attached to it. As a simple fix for this, `bzl_library` can have a srcs dependency on it so that it includes the transitive closure of all of its dependencies. `@bazel_tools` imports are rewritten into the `srcs` attribute since they are `exports_files`ed from the @bazel_tools. Co-authored-by: c-parsons --- gazelle/bzl/gazelle.go | 39 +++++++++++++++++++----------- gazelle/bzl/testdata/bazel_tools/BUILD.in | 6 +++++ gazelle/bzl/testdata/bazel_tools/BUILD.out | 15 ++++++++++++ gazelle/bzl/testdata/bazel_tools/WORKSPACE | 0 gazelle/bzl/testdata/bazel_tools/foo.bzl | 10 ++++++++ 5 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 gazelle/bzl/testdata/bazel_tools/BUILD.in create mode 100644 gazelle/bzl/testdata/bazel_tools/BUILD.out create mode 100644 gazelle/bzl/testdata/bazel_tools/WORKSPACE create mode 100644 gazelle/bzl/testdata/bazel_tools/foo.bzl diff --git a/gazelle/bzl/gazelle.go b/gazelle/bzl/gazelle.go index a0b8aa6..b58eee6 100644 --- a/gazelle/bzl/gazelle.go +++ b/gazelle/bzl/gazelle.go @@ -161,26 +161,37 @@ func (*bzlLibraryLang) Resolve(c *config.Config, ix *resolve.RuleIndex, rc *repo // the index only contains absolute labels, not relative impLabel = impLabel.Abs(from.Repo, from.Pkg) + if impLabel.Repo == "bazel_tools" { + // The @bazel_tools repo is tricky because it is a part of the "shipped + // with bazel" core library for interacting with the outside world. + // This means that it can not depend on skylib. Fortunately there is a + // fairly simple workaround for this, which is that you can add those + // bzl files as `deps` entries. + deps = append(deps, imp) + continue + } + if impLabel.Repo != "" || !c.IndexLibraries { // This is a dependency that is external to the current repo, or indexing // is disabled so take a guess at what hte target name should be. deps = append(deps, strings.TrimSuffix(imp, fileType)) - } else { - res := resolve.ImportSpec{ - Lang: languageName, - Imp: impLabel.String(), - } - matches := ix.FindRulesByImport(res, languageName) + continue + } - if len(matches) == 0 { - log.Printf("%s: %q (%s) was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp, impLabel.String()) - } + res := resolve.ImportSpec{ + Lang: languageName, + Imp: impLabel.String(), + } + matches := ix.FindRulesByImport(res, languageName) - for _, m := range matches { - depLabel := m.Label - depLabel = depLabel.Rel(from.Repo, from.Pkg) - deps = append(deps, depLabel.String()) - } + if len(matches) == 0 { + log.Printf("%s: %q (%s) was not found in dependency index. Skipping. This may result in an incomplete deps section and require manual BUILD file intervention.\n", from.String(), imp, impLabel.String()) + } + + for _, m := range matches { + depLabel := m.Label + depLabel = depLabel.Rel(from.Repo, from.Pkg) + deps = append(deps, depLabel.String()) } } diff --git a/gazelle/bzl/testdata/bazel_tools/BUILD.in b/gazelle/bzl/testdata/bazel_tools/BUILD.in new file mode 100644 index 0000000..e267b5a --- /dev/null +++ b/gazelle/bzl/testdata/bazel_tools/BUILD.in @@ -0,0 +1,6 @@ +# Some comment to be preserved + +filegroup( + name = "allfiles", + srcs = glob(["**"]), +) diff --git a/gazelle/bzl/testdata/bazel_tools/BUILD.out b/gazelle/bzl/testdata/bazel_tools/BUILD.out new file mode 100644 index 0000000..576cfad --- /dev/null +++ b/gazelle/bzl/testdata/bazel_tools/BUILD.out @@ -0,0 +1,15 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +# Some comment to be preserved + +filegroup( + name = "allfiles", + srcs = glob(["**"]), +) + +bzl_library( + name = "foo", + srcs = ["foo.bzl"], + visibility = ["//visibility:public"], + deps = ["@bazel_tools//tools/build_defs/repo:http.bzl"], +) diff --git a/gazelle/bzl/testdata/bazel_tools/WORKSPACE b/gazelle/bzl/testdata/bazel_tools/WORKSPACE new file mode 100644 index 0000000..e69de29 diff --git a/gazelle/bzl/testdata/bazel_tools/foo.bzl b/gazelle/bzl/testdata/bazel_tools/foo.bzl new file mode 100644 index 0000000..b025d21 --- /dev/null +++ b/gazelle/bzl/testdata/bazel_tools/foo.bzl @@ -0,0 +1,10 @@ +""" +Doc string +""" + +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") + +def wrapped_http_archive(**kwargs): + http_archive( + **kwargs + ) -- cgit v1.2.3 From 182046f090d6ecae264c7e5d520da096370287e2 Mon Sep 17 00:00:00 2001 From: Andrew Z Allen Date: Wed, 21 Oct 2020 23:52:14 -0600 Subject: Handle "internal" directory visibility (#274) Both "internal" and "private" directories should be treated the same way and have visibility restrictions be placed upon them. --- gazelle/bzl/gazelle.go | 22 +++++++++++++++++----- .../bzl/testdata/private/nested/private/BUILD.out | 7 +++++++ .../bzl/testdata/private/nested/private/bar.bzl | 6 ++++++ .../nested/private/inside/internal/BUILD.out | 7 +++++++ .../private/nested/private/inside/internal/bar.bzl | 6 ++++++ gazelle/bzl/testdata/private/private/BUILD.out | 1 + 6 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 gazelle/bzl/testdata/private/nested/private/BUILD.out create mode 100644 gazelle/bzl/testdata/private/nested/private/bar.bzl create mode 100644 gazelle/bzl/testdata/private/nested/private/inside/internal/BUILD.out create mode 100644 gazelle/bzl/testdata/private/nested/private/inside/internal/bar.bzl diff --git a/gazelle/bzl/gazelle.go b/gazelle/bzl/gazelle.go index b58eee6..dccec27 100644 --- a/gazelle/bzl/gazelle.go +++ b/gazelle/bzl/gazelle.go @@ -233,11 +233,10 @@ func (*bzlLibraryLang) GenerateRules(args language.GenerateArgs) language.Genera r.SetAttr("srcs", []string{f}) - if args.File == nil || !args.File.HasDefaultVisibility() { - inPrivateDir := pathtools.Index(args.Rel, "private") >= 0 - if !inPrivateDir { - r.SetAttr("visibility", []string{"//visibility:public"}) - } + shouldSetVisibility := args.File == nil || !args.File.HasDefaultVisibility() + if shouldSetVisibility { + vis := checkInternalVisibility(args.Rel, "//visibility:public") + r.SetAttr("visibility", []string{vis}) } fullPath := filepath.Join(args.Dir, f) @@ -335,3 +334,16 @@ func (s srcsList) Contains(m string) bool { } return false } + +// checkInternalVisibility overrides the given visibility if the package is +// internal. +func checkInternalVisibility(rel, visibility string) string { + if i := pathtools.Index(rel, "internal"); i > 0 { + visibility = fmt.Sprintf("//%s:__subpackages__", rel[:i-1]) + } else if i := pathtools.Index(rel, "private"); i > 0 { + visibility = fmt.Sprintf("//%s:__subpackages__", rel[:i-1]) + } else if pathtools.HasPrefix(rel, "internal") || pathtools.HasPrefix(rel, "private") { + visibility = "//:__subpackages__" + } + return visibility +} diff --git a/gazelle/bzl/testdata/private/nested/private/BUILD.out b/gazelle/bzl/testdata/private/nested/private/BUILD.out new file mode 100644 index 0000000..442401c --- /dev/null +++ b/gazelle/bzl/testdata/private/nested/private/BUILD.out @@ -0,0 +1,7 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "bar", + srcs = ["bar.bzl"], + visibility = ["//nested:__subpackages__"], +) diff --git a/gazelle/bzl/testdata/private/nested/private/bar.bzl b/gazelle/bzl/testdata/private/nested/private/bar.bzl new file mode 100644 index 0000000..c8a4871 --- /dev/null +++ b/gazelle/bzl/testdata/private/nested/private/bar.bzl @@ -0,0 +1,6 @@ +""" +Test sample code. +""" + +def func(): + pass diff --git a/gazelle/bzl/testdata/private/nested/private/inside/internal/BUILD.out b/gazelle/bzl/testdata/private/nested/private/inside/internal/BUILD.out new file mode 100644 index 0000000..afaf8f3 --- /dev/null +++ b/gazelle/bzl/testdata/private/nested/private/inside/internal/BUILD.out @@ -0,0 +1,7 @@ +load("@bazel_skylib//:bzl_library.bzl", "bzl_library") + +bzl_library( + name = "bar", + srcs = ["bar.bzl"], + visibility = ["//nested/private/inside:__subpackages__"], +) diff --git a/gazelle/bzl/testdata/private/nested/private/inside/internal/bar.bzl b/gazelle/bzl/testdata/private/nested/private/inside/internal/bar.bzl new file mode 100644 index 0000000..c8a4871 --- /dev/null +++ b/gazelle/bzl/testdata/private/nested/private/inside/internal/bar.bzl @@ -0,0 +1,6 @@ +""" +Test sample code. +""" + +def func(): + pass diff --git a/gazelle/bzl/testdata/private/private/BUILD.out b/gazelle/bzl/testdata/private/private/BUILD.out index eb2e935..f442a99 100644 --- a/gazelle/bzl/testdata/private/private/BUILD.out +++ b/gazelle/bzl/testdata/private/private/BUILD.out @@ -3,4 +3,5 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library") bzl_library( name = "bar", srcs = ["bar.bzl"], + visibility = ["//:__subpackages__"], ) -- cgit v1.2.3 From ed7f03cde643bc0e17d521a3d7f45f1aeaa25c5c Mon Sep 17 00:00:00 2001 From: David Sanderson <32687193+dws-uber@users.noreply.github.com> Date: Thu, 12 Nov 2020 21:04:39 -0500 Subject: Enable unittest.suite to accept partial calls of test rules (#276) * Enable unittest.suite to accept partial calls of rules This permits using `unittest.suite` with test rules that have nondefault attributes, while retaining compatibility with current usage. For instance, this permits setting a `timeout` on each test in a `unittest.suite`. Previously, all tests in a `unittest.suite` would have the default timeout, with no good way to alter this. This made it hard to eliminate all the warnings produced from using the `--test_verbose_timeout_warnings` bazel option. While timeouts were the motivation, the solution here is not specific to timeouts. It will permit arbitrary additional arguments to the test rules in a `unittest.suite`. Fixes #98 * Respond to review feedback. * Document a breaking change in bazel that this code needs to be aware of. --- lib/BUILD | 1 + lib/partial.bzl | 27 +++++++++++++++++++++++++++ lib/unittest.bzl | 16 ++++++++++------ tests/partial_tests.bzl | 18 ++++++++++++++++++ tests/unittest_test.sh | 1 + tests/unittest_tests.bzl | 15 +++++++++++++++ 6 files changed, 72 insertions(+), 6 deletions(-) diff --git a/lib/BUILD b/lib/BUILD index 26a6120..7e7a9a4 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -71,6 +71,7 @@ bzl_library( srcs = ["unittest.bzl"], deps = [ ":new_sets", + ":partial", ":sets", ":types", ], diff --git a/lib/partial.bzl b/lib/partial.bzl index e2f24b7..8bfba7f 100644 --- a/lib/partial.bzl +++ b/lib/partial.bzl @@ -19,6 +19,11 @@ Partial function objects allow some parameters are bound before the call. Similar to https://docs.python.org/3/library/functools.html#functools.partial. """ +# create instance singletons to avoid unnecessary allocations +_a_dict_type = type({}) +_a_tuple_type = type(()) +_a_struct_type = type(struct()) + def _call(partial, *args, **kwargs): """Calls a partial created using `make`. @@ -124,7 +129,29 @@ def _make(func, *args, **kwargs): """ return struct(function = func, args = args, kwargs = kwargs) +def _is_instance(v): + """Returns True if v is a partial created using `make`. + + Args: + v: The value to check. + + Returns: + True if v was created by `make`, False otherwise. + """ + # Note that in bazel 3.7.0 and earlier, type(v.function) is the same + # as the type of a function even if v.function is a rule. But we + # cannot rely on this in later bazels due to breaking change + # https://github.com/bazelbuild/bazel/commit/e379ece1908aafc852f9227175dd3283312b4b82 + # + # Since this check is heuristic anyway, we simply check for the + # presence of a "function" attribute without checking its type. + return type(v) == _a_struct_type \ + and hasattr(v, "function") \ + and hasattr(v, "args") and type(v.args) == _a_tuple_type \ + and hasattr(v, "kwargs") and type(v.kwargs) == _a_dict_type + partial = struct( make = _make, call = _call, + is_instance = _is_instance, ) diff --git a/lib/unittest.bzl b/lib/unittest.bzl index 5b70df5..87dfd27 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -20,6 +20,7 @@ assertions used to within tests. """ load(":new_sets.bzl", new_sets = "sets") +load(":partial.bzl", "partial") load(":types.bzl", "types") # The following function should only be called from WORKSPACE files and workspace macros. @@ -232,10 +233,10 @@ def _suite(name, *test_rules): writing a macro in your `.bzl` file to instantiate all targets, and calling that macro from your BUILD file so you only have to load one symbol. - For the case where your unit tests do not take any (non-default) attributes -- - i.e., if your unit tests do not test rules -- you can use this function to - create the targets and wrap them in a single test_suite target. In your - `.bzl` file, write: + You can use this function to create the targets and wrap them in a single + test_suite target. If a test rule requires no arguments, you can simply list + it as an argument. If you wish to supply attributes explicitly, you can do so + using `partial.make()`. For instance, in your `.bzl` file, you could write: ``` def your_test_suite(): @@ -243,7 +244,7 @@ def _suite(name, *test_rules): "your_test_suite", your_test, your_other_test, - yet_another_test, + partial.make(yet_another_test, timeout = "short"), ) ``` @@ -269,7 +270,10 @@ def _suite(name, *test_rules): test_names = [] for index, test_rule in enumerate(test_rules): test_name = "%s_test_%d" % (name, index) - test_rule(name = test_name) + if partial.is_instance(test_rule): + partial.call(test_rule, name = test_name) + else: + test_rule(name = test_name) test_names.append(test_name) native.test_suite( diff --git a/tests/partial_tests.bzl b/tests/partial_tests.bzl index 6d778c3..73a579b 100644 --- a/tests/partial_tests.bzl +++ b/tests/partial_tests.bzl @@ -76,9 +76,27 @@ def _make_call_test(ctx): make_call_test = unittest.make(_make_call_test) +def _is_instance_test(ctx): + """Unit test for partial.is_instance.""" + env = unittest.begin(ctx) + + # We happen to use make_call_test here, but it could be any valid test rule. + asserts.true(env, partial.is_instance(partial.make(make_call_test))) + asserts.true(env, partial.is_instance(partial.make(make_call_test, timeout = "short"))) + asserts.true(env, partial.is_instance(partial.make(make_call_test, timeout = "short", tags = ["foo"]))) + asserts.false(env, partial.is_instance(None)) + asserts.false(env, partial.is_instance({})) + asserts.false(env, partial.is_instance(struct(foo = 1))) + asserts.false(env, partial.is_instance(struct(function = "not really function"))) + + return unittest.end(env) + +is_instance_test = unittest.make(_is_instance_test) + def partial_test_suite(): """Creates the test targets and test suite for partial.bzl tests.""" unittest.suite( "partial_tests", make_call_test, + is_instance_test, ) diff --git a/tests/unittest_test.sh b/tests/unittest_test.sh index baed490..9455d8e 100755 --- a/tests/unittest_test.sh +++ b/tests/unittest_test.sh @@ -73,6 +73,7 @@ exports_files(["*.bzl"]) EOF ln -sf "$(rlocation bazel_skylib/lib/dicts.bzl)" lib/dicts.bzl ln -sf "$(rlocation bazel_skylib/lib/new_sets.bzl)" lib/new_sets.bzl + ln -sf "$(rlocation bazel_skylib/lib/partial.bzl)" lib/partial.bzl ln -sf "$(rlocation bazel_skylib/lib/sets.bzl)" lib/sets.bzl ln -sf "$(rlocation bazel_skylib/lib/types.bzl)" lib/types.bzl ln -sf "$(rlocation bazel_skylib/lib/unittest.bzl)" lib/unittest.bzl diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index 0b992f9..7d30e2a 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -14,6 +14,7 @@ """Unit tests for unittest.bzl.""" +load("//lib:partial.bzl", "partial") load("//lib:unittest.bzl", "analysistest", "asserts", "unittest") ################################### @@ -42,6 +43,19 @@ def _basic_passing_test(ctx): basic_passing_test = unittest.make(_basic_passing_test) +################################################# +####### basic_passing_short_timeout_test ######## +################################################# +def _basic_passing_short_timeout_test(ctx): + """Unit tests for a basic library verification test.""" + env = unittest.begin(ctx) + + asserts.equals(env, ctx.attr.timeout, "short") + + return unittest.end(env) + +basic_passing_short_timeout_test = unittest.make(_basic_passing_short_timeout_test) + ################################### ####### change_setting_test ####### ################################### @@ -240,6 +254,7 @@ def unittest_passing_tests_suite(): unittest.suite( "unittest_tests", basic_passing_test, + partial.make(basic_passing_short_timeout_test, timeout = "short"), ) change_setting_test( -- cgit v1.2.3 From e19d391ac984cf941abfba9ea0506c49293eb934 Mon Sep 17 00:00:00 2001 From: alandonovan Date: Thu, 17 Dec 2020 17:20:24 -0500 Subject: Explain criteria for contributing (#286) * Explain criteria for contributing * Update README.md * Update README.md --- README.md | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4ab2420..8f8c63b 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,8 @@ [![Build status](https://badge.buildkite.com/921dc61e2d3a350ec40efb291914360c0bfa9b6196fa357420.svg?branch=master)](https://buildkite.com/bazel/bazel-skylib) -Skylib is a standard library that provides functions useful for manipulating -collections, file paths, and other features that are useful when writing custom -build rules in Bazel. - -> This library is currently under early development. Be aware that the APIs -> in these modules may change during this time. +Skylib is a library of Starlark functions for manipulating collections, file paths, +and various other data types in the domain of Bazel build rules. Each of the `.bzl` files in the `lib` directory defines a "module"—a `struct` that contains a set of related functions and/or other symbols that can @@ -66,6 +62,21 @@ s = shell.quote(p) ## Writing a new module +The criteria for adding a new function or module to this repository are: + +1. Is it widely needed? The new code must solve a problem that occurs often during the development of Bazel build rules. It is not sufficient that the new code is merely useful. Candidate code should generally have been proven to be necessary across several projects, either because it provides indispensible common functionality, or because it requires a single standardized implementation. + +1. Is its interface simpler than its implementation? A good abstraction provides a simple interface to a complex implementation, relieving the user from the burden of understanding. By contrast, a shallow abstraction provides little that the user could not easily have written out for themselves. If a function's doc comment is longer than its body, it's a good sign that the abstraction is too shallow. + +1. Is its interface unimpeachable? Given the problem it tries to solve, does it have sufficient parameters or generality to address all reasonable cases, or does it make arbitrary policy choices that limit its usefulness? If the function is not general, it likely does not belong here. Conversely, if it is general thanks only to a bewildering number of parameters, it also does not belong here. + +1. Is it efficient? Does it solve the problem using the asymptotically optimal algorithm, without using excessive looping, allocation, or other high constant factors? Starlark is an interpreted language with relatively expensive basic operations, and an approach that might make sense in C++ may not in Starlark. + +If your new module meets all these criteria, then you should consider sending us a pull request. It is always better to discuss your plans before executing them. + +Many of the declarations already in this repository do not meet this bar. + + Steps to add a module to Skylib: 1. Create a new `.bzl` file in the `lib` directory. -- cgit v1.2.3 From f80bc733d4b9f83d427ce3442be2e07427b2cc8d Mon Sep 17 00:00:00 2001 From: aiuto Date: Fri, 29 Jan 2021 13:38:17 -0500 Subject: update owners (#289) --- CODEOWNERS | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CODEOWNERS b/CODEOWNERS index 2b58657..a78f3c9 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,5 +1,3 @@ # More details on syntax here: https://help.github.com/articles/about-codeowners/ -* @c-parsons @jin @aiuto -/distribution/ @aiuto @fwe -/rules/ @juliexxia +* @brandjon @tetromino /gazelle/ @achew22 @jayconrod -- cgit v1.2.3 From b3ce9e70e5938214c605c8a0612f98f337dc8af5 Mon Sep 17 00:00:00 2001 From: Christopher Sauer Date: Wed, 31 Mar 2021 12:34:15 -0700 Subject: Add write_file and copy_file docs to README (#291) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 8f8c63b..61ce82f 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,8 @@ s = shell.quote(p) * [analysis_test](docs/analysis_test_doc.md) * [build_test](docs/build_test_doc.md) +* [copy_file](docs/copy_file_doc.md) +* [write_file](docs/write_file_doc.md) ## Writing a new module -- cgit v1.2.3 From 82c1d0fa3e6971d37ab63350af92d29071b163f7 Mon Sep 17 00:00:00 2001 From: Olek Wojnar <3818875+olekw@users.noreply.github.com> Date: Wed, 31 Mar 2021 15:46:21 -0400 Subject: Add shebang lines to tests directory shell scripts (#288) --- tests/copy_file/copy_file_tests.sh | 2 ++ tests/diff_test/diff_test_tests.sh | 2 ++ tests/write_file/write_file_tests.sh | 2 ++ 3 files changed, 6 insertions(+) diff --git a/tests/copy_file/copy_file_tests.sh b/tests/copy_file/copy_file_tests.sh index dfee635..90d79ee 100755 --- a/tests/copy_file/copy_file_tests.sh +++ b/tests/copy_file/copy_file_tests.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2019 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/diff_test/diff_test_tests.sh b/tests/diff_test/diff_test_tests.sh index ed894c2..5af60aa 100755 --- a/tests/diff_test/diff_test_tests.sh +++ b/tests/diff_test/diff_test_tests.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2019 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/write_file/write_file_tests.sh b/tests/write_file/write_file_tests.sh index 2464230..247c696 100755 --- a/tests/write_file/write_file_tests.sh +++ b/tests/write_file/write_file_tests.sh @@ -1,3 +1,5 @@ +#!/bin/bash + # Copyright 2019 The Bazel Authors. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); -- cgit v1.2.3 From 398f3122891b9b711f5aab1adc7597d9fce09085 Mon Sep 17 00:00:00 2001 From: c-parsons Date: Wed, 31 Mar 2021 16:06:00 -0400 Subject: lint warning fix (#115) --- tests/unittest_tests.bzl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index 7d30e2a..a3741f6 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -100,7 +100,7 @@ def _failure_testing_test(ctx): return analysistest.end(env) def _failure_testing_fake_rule(ctx): - ignore = [ctx] + _ignore = [ctx] fail("This rule should never work") failure_testing_fake_rule = rule( -- cgit v1.2.3 From 7b859037a673db6f606661323e74c5d4751595e6 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Mon, 3 May 2021 12:27:40 -0400 Subject: to_json/to_proto methods on structs are deprecated and will be removed (#295) --- WORKSPACE | 4 +++- lib/partial.bzl | 9 +++++---- lib/structs.bzl | 12 ++++++++---- rules/private/copy_file_private.bzl | 7 +++---- tests/copy_file/BUILD | 6 +++--- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index d78cfad..e8e042e 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -5,13 +5,15 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe") http_archive( name = "rules_pkg", + sha256 = "352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a", 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", ], - sha256 = "352c090cc3d3f9a6b4e676cf42a6047c16824959b438895a76c2989c6d7c246a", ) + load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + rules_pkg_dependencies() maybe( diff --git a/lib/partial.bzl b/lib/partial.bzl index 8bfba7f..a9c88d6 100644 --- a/lib/partial.bzl +++ b/lib/partial.bzl @@ -138,6 +138,7 @@ def _is_instance(v): Returns: True if v was created by `make`, False otherwise. """ + # Note that in bazel 3.7.0 and earlier, type(v.function) is the same # as the type of a function even if v.function is a rule. But we # cannot rely on this in later bazels due to breaking change @@ -145,10 +146,10 @@ def _is_instance(v): # # Since this check is heuristic anyway, we simply check for the # presence of a "function" attribute without checking its type. - return type(v) == _a_struct_type \ - and hasattr(v, "function") \ - and hasattr(v, "args") and type(v.args) == _a_tuple_type \ - and hasattr(v, "kwargs") and type(v.kwargs) == _a_dict_type + return type(v) == _a_struct_type and \ + hasattr(v, "function") and \ + hasattr(v, "args") and type(v.args) == _a_tuple_type and \ + hasattr(v, "kwargs") and type(v.kwargs) == _a_dict_type partial = struct( make = _make, diff --git a/lib/structs.bzl b/lib/structs.bzl index f291152..78066ad 100644 --- a/lib/structs.bzl +++ b/lib/structs.bzl @@ -25,10 +25,14 @@ def _to_dict(s): transformation is only applied to the struct's fields and not to any nested values. """ - attributes = dir(s) - attributes.remove("to_json") - attributes.remove("to_proto") - return {key: getattr(s, key) for key in attributes} + + # to_json()/to_proto() are disabled by --incompatible_struct_has_no_methods + # and will be removed entirely in a future Bazel release. + return { + key: getattr(s, key) + for key in dir(s) + if key != "to_json" and key != "to_proto" + } structs = struct( to_dict = _to_dict, diff --git a/rules/private/copy_file_private.bzl b/rules/private/copy_file_private.bzl index 75cb027..44f133a 100644 --- a/rules/private/copy_file_private.bzl +++ b/rules/private/copy_file_private.bzl @@ -65,11 +65,10 @@ def _copy_file_impl(ctx): target_file = ctx.file.src, is_executable = ctx.attr.is_executable, ) + elif ctx.attr.is_windows: + copy_cmd(ctx, ctx.file.src, ctx.outputs.out) else: - if ctx.attr.is_windows: - copy_cmd(ctx, ctx.file.src, ctx.outputs.out) - else: - copy_bash(ctx, ctx.file.src, ctx.outputs.out) + copy_bash(ctx, ctx.file.src, ctx.outputs.out) files = depset(direct = [ctx.outputs.out]) runfiles = ctx.runfiles(files = [ctx.outputs.out]) diff --git a/tests/copy_file/BUILD b/tests/copy_file/BUILD index 79ab7ba..cacb5b1 100644 --- a/tests/copy_file/BUILD +++ b/tests/copy_file/BUILD @@ -80,8 +80,8 @@ genrule( output_to_bindir = 1, tools = [ ":bin_gen", - ":bin_src", ":bin_gen_symlink", + ":bin_src", ":bin_src_symlink", ], ) @@ -147,8 +147,8 @@ copy_file( name = "copy_xsrc_symlink", src = "a_with_exec_bit.txt", out = "xout/a-out-symlink.sh", - is_executable = True, allow_symlink = True, + is_executable = True, ) copy_file( @@ -162,8 +162,8 @@ copy_file( name = "copy_xgen_symlink", src = ":gen", out = "xout/gen-out-symlink.sh", - is_executable = True, allow_symlink = True, + is_executable = True, ) genrule( -- cgit v1.2.3 From c6f6b5425b232baf5caecc3aae31d49d63ddec03 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Thu, 13 May 2021 10:22:43 -0400 Subject: Fix default branch name in README (#292) See https://github.com/bazelbuild/bazel-skylib/branches and https://github.com/bazelbuild/bazel-skylib/issues/281. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 61ce82f..0eb832f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Skylib -[![Build status](https://badge.buildkite.com/921dc61e2d3a350ec40efb291914360c0bfa9b6196fa357420.svg?branch=master)](https://buildkite.com/bazel/bazel-skylib) +[![Build status](https://badge.buildkite.com/921dc61e2d3a350ec40efb291914360c0bfa9b6196fa357420.svg?branch=main)](https://buildkite.com/bazel/bazel-skylib) Skylib is a library of Starlark functions for manipulating collections, file paths, and various other data types in the domain of Bazel build rules. -- cgit v1.2.3 From fd75066f159234265efb8f838b056be5a2e00a59 Mon Sep 17 00:00:00 2001 From: aiuto Date: Wed, 16 Jun 2021 13:00:06 -0400 Subject: update links to bazel docs (#306) --- CHANGELOG.md | 2 +- docs/build_test_doc.md | 2 +- docs/diff_test_doc.md | 2 +- docs/native_binary_doc.md | 4 ++-- docs/run_binary_doc.md | 4 ++-- rules/build_test.bzl | 2 +- rules/common_settings.bzl | 2 +- rules/diff_test.bzl | 2 +- rules/native_binary.bzl | 4 ++-- rules/run_binary.bzl | 4 ++-- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dce01b4..7939d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,7 +41,7 @@ Release 0.9.0 https://docs.google.com/document/d/1vc8v-kXjvgZOdQdnxPTaV0rrLxtP2XwnD2tAZlYJOqw/edit#bookmark=id.iiumwic0jphr - selects.bzl: Add config_setting_group for config_setting AND/OR-chaining Implements - https://github.com/bazelbuild/proposals/blob/master/designs/2018-11-09-config-setting-chaining.md. + https://github.com/bazelbuild/proposals/blob/HEAD/designs/2018-11-09-config-setting-chaining.md. - Make sets.bzl point to new_sets.bzl instead of old_sets.bzl. new_sets.bzl and old_sets.bzl should be removed in the following skylib release. diff --git a/docs/build_test_doc.md b/docs/build_test_doc.md index 6f3c597..b1cd020 100755 --- a/docs/build_test_doc.md +++ b/docs/build_test_doc.md @@ -57,7 +57,7 @@ Typical usage: optional.

- The common attributes for tests. + The common attributes for tests.

diff --git a/docs/diff_test_doc.md b/docs/diff_test_doc.md index 07ce8b9..a031145 100755 --- a/docs/diff_test_doc.md +++ b/docs/diff_test_doc.md @@ -49,7 +49,7 @@ The test succeeds if the files' contents match. optional.

- The common attributes for tests. + The common attributes for tests.

diff --git a/docs/native_binary_doc.md b/docs/native_binary_doc.md index 9cf90f4..742e81b 100755 --- a/docs/native_binary_doc.md +++ b/docs/native_binary_doc.md @@ -55,7 +55,7 @@ You can "bazel run" this rule like any other binary rule, and use it as a tool i optional.

- The common attributes for binaries. + The common attributes for binaries.

@@ -121,7 +121,7 @@ runfiles. optional.

- The common attributes for tests. + The common attributes for tests.

diff --git a/docs/run_binary_doc.md b/docs/run_binary_doc.md index 188e277..cde8b40 100755 --- a/docs/run_binary_doc.md +++ b/docs/run_binary_doc.md @@ -29,7 +29,7 @@ Runs a binary as a build action.

This rule does not require Bash (unlik List of strings; optional

- Command line arguments of the binary.

Subject to$(location) expansion. + Command line arguments of the binary.

Subject to$(location) expansion.

@@ -38,7 +38,7 @@ Runs a binary as a build action.

This rule does not require Bash (unlik Dictionary: String -> String; optional

- Environment variables of the action.

Subject to $(location) expansion. + Environment variables of the action.

Subject to $(location) expansion.

diff --git a/rules/build_test.bzl b/rules/build_test.bzl index edcb50a..f06e0d4 100644 --- a/rules/build_test.bzl +++ b/rules/build_test.bzl @@ -41,7 +41,7 @@ def build_test(name, targets, **kwargs): Args: name: The name of the test rule. targets: A list of targets to ensure build. - **kwargs: The common attributes for tests. + **kwargs: The common attributes for tests. """ if len(targets) == 0: fail("targets must be non-empty", "targets") diff --git a/rules/common_settings.bzl b/rules/common_settings.bzl index e80ab09..7f56a7f 100644 --- a/rules/common_settings.bzl +++ b/rules/common_settings.bzl @@ -18,7 +18,7 @@ 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/master/skylark/config.html#user-defined-build-settings +https://docs.bazel.build/versions/main/skylark/config.html#user-defined-build-settings """ BuildSettingInfo = provider( diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index 93cf363..71faf40 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -135,7 +135,7 @@ def diff_test(name, file1, file2, **kwargs): name: The name of the test rule. file1: Label of the file to compare to file2. file2: Label of the file to compare to file1. - **kwargs: The common attributes for tests. + **kwargs: The common attributes for tests. """ _diff_test( name = name, diff --git a/rules/native_binary.bzl b/rules/native_binary.bzl index 7d885a0..6675a92 100644 --- a/rules/native_binary.bzl +++ b/rules/native_binary.bzl @@ -76,7 +76,7 @@ def native_binary(name, src, out, data = None, **kwargs): src: label; path of the pre-built executable out: output; an output name for the copy of the binary. (Bazel requires that this rule make a copy of 'src'.) data: list of labels; data dependencies - **kwargs: The common attributes for binaries. + **kwargs: The common attributes for binaries. """ _native_binary( name = name, @@ -101,7 +101,7 @@ def native_test(name, src, out, data = None, **kwargs): src: label; path of the pre-built executable out: output; an output name for the copy of the binary. (Bazel requires that this rule make a copy of 'src'.) data: list of labels; data dependencies - **kwargs: The common attributes for tests. + **kwargs: The common attributes for tests. """ _native_test( name = name, diff --git a/rules/run_binary.bzl b/rules/run_binary.bzl index 10f1ab5..c251019 100644 --- a/rules/run_binary.bzl +++ b/rules/run_binary.bzl @@ -76,7 +76,7 @@ run_binary = rule( ), "env": attr.string_dict( doc = "Environment variables of the action.

Subject to " + - " $(location)" + + " $(location)" + " expansion.", ), "srcs": attr.label_list( @@ -91,7 +91,7 @@ run_binary = rule( ), "args": attr.string_list( doc = "Command line arguments of the binary.

Subject to" + - "$(location)" + + "$(location)" + " expansion.", ), }, -- cgit v1.2.3 From 775f66fb282ba8e7f24a27994942c7fbb82163f0 Mon Sep 17 00:00:00 2001 From: dmaclach Date: Wed, 14 Jul 2021 18:55:10 -0700 Subject: Update partial_doc.md (#308) Clean up the docs to make them look significantly better. No semantics changes, just styling. --- docs/partial_doc.md | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/docs/partial_doc.md b/docs/partial_doc.md index 4559ba3..71987d6 100755 --- a/docs/partial_doc.md +++ b/docs/partial_doc.md @@ -12,16 +12,22 @@ passed to it at the call sites. A partial 'function' can be defined with positional args and kwargs: # function with no args + ``` def function1(): ... + ``` # function with 2 args + ``` def function2(arg1, arg2): ... + ``` # function with 2 args and keyword args + ``` def function3(arg1, arg2, x, y): ... + ``` The positional args passed to the function are the args passed into make followed by any additional positional args given to call. The below example @@ -29,24 +35,30 @@ illustrates a function with two positional arguments where one is supplied by make and the other by call: # function demonstrating 1 arg at make site, and 1 arg at call site + ``` def _foo(make_arg1, func_arg1): - print(make_arg1 + " " + func_arg1 + "!") + print(make_arg1 + " " + func_arg1 + "!") + ``` For example: + ``` hi_func = partial.make(_foo, "Hello") bye_func = partial.make(_foo, "Goodbye") partial.call(hi_func, "Jennifer") partial.call(hi_func, "Dave") partial.call(bye_func, "Jennifer") partial.call(bye_func, "Dave") + ``` prints: + ``` "Hello, Jennifer!" "Hello, Dave!" "Goodbye, Jennifer!" "Goodbye, Dave!" + ``` The keyword args given to the function are the kwargs passed into make unioned with the keyword args given to call. In case of a conflict, the @@ -56,29 +68,34 @@ value for keyword arguments and override it at the call site. Example with a make site arg, a call site arg, a make site kwarg and a call site kwarg: + ``` def _foo(make_arg1, call_arg1, make_location, call_location): print(make_arg1 + " is from " + make_location + " and " + call_arg1 + " is from " + call_location + "!") func = partial.make(_foo, "Ben", make_location="Hollywood") partial.call(func, "Jennifer", call_location="Denver") - + ``` + Prints "Ben is from Hollywood and Jennifer is from Denver!". + ``` partial.call(func, "Jennifer", make_location="LA", call_location="Denver") - + ``` + Prints "Ben is from LA and Jennifer is from Denver!". Note that keyword args may not overlap with positional args, regardless of whether they are given during the make or call step. For instance, you can't do: +``` def foo(x): pass func = partial.make(foo, 1) partial.call(func, x=2) - +``` ### Parameters -- cgit v1.2.3 From b053a5ae113fe48ecd100a0055fcdaa223d2253a Mon Sep 17 00:00:00 2001 From: dmaclach Date: Mon, 26 Jul 2021 12:26:28 -0700 Subject: Update partial.bzl to generate better markdown (#309) --- docs/partial_doc.md | 122 ++++++++++++++++++---------------------------------- lib/partial.bzl | 20 ++++++++- 2 files changed, 62 insertions(+), 80 deletions(-) diff --git a/docs/partial_doc.md b/docs/partial_doc.md index 71987d6..ae2046a 100755 --- a/docs/partial_doc.md +++ b/docs/partial_doc.md @@ -1,3 +1,7 @@ + + + + ## partial.make
@@ -76,13 +80,13 @@ call site kwarg:
   func = partial.make(_foo, "Ben", make_location="Hollywood")
   partial.call(func, "Jennifer", call_location="Denver")
   ```
-  
+
 Prints "Ben is from Hollywood and Jennifer is from Denver!".
 
   ```
   partial.call(func, "Jennifer", make_location="LA", call_location="Denver")
   ```
-  
+
 Prints "Ben is from LA and Jennifer is from Denver!".
 
 Note that keyword args may not overlap with positional args, regardless of
@@ -97,46 +101,19 @@ func = partial.make(foo, 1)
 partial.call(func, x=2)
 ```
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
func - required. -

- The function to be called. -

-
args - optional. -

- Positional arguments to be passed to function. -

-
kwargs - optional. -

- Keyword arguments to be passed to function. Note that these can - be overridden at the call sites. -

-
+ +**PARAMETERS** +| 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 | + + + + ## partial.call
@@ -145,44 +122,31 @@ partial.call(partial, 
-  
-    
-    
-  
-  
-    
-      partial
-      
-        required.
-        

- The partial to be called. -

- - - - args - - optional. -

- Additional positional arguments to be appended to the ones given to - make. -

- - - - kwargs - - optional. -

- Additional keyword arguments to augment and override the ones - given to make. -

- - - - +**PARAMETERS** + + +| 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.is_instance + +
+partial.is_instance(v)
+
+ +Returns True if v is a partial created using `make`. + +**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value to check. | none | diff --git a/lib/partial.bzl b/lib/partial.bzl index a9c88d6..a642d96 100644 --- a/lib/partial.bzl +++ b/lib/partial.bzl @@ -51,16 +51,22 @@ def _make(func, *args, **kwargs): A partial 'function' can be defined with positional args and kwargs: # function with no args + ``` def function1(): ... + ``` # function with 2 args + ``` def function2(arg1, arg2): ... + ``` # function with 2 args and keyword args + ``` def function3(arg1, arg2, x, y): ... + ``` The positional args passed to the function are the args passed into make followed by any additional positional args given to call. The below example @@ -68,24 +74,30 @@ def _make(func, *args, **kwargs): make and the other by call: # function demonstrating 1 arg at make site, and 1 arg at call site + ``` def _foo(make_arg1, func_arg1): - print(make_arg1 + " " + func_arg1 + "!") + print(make_arg1 + " " + func_arg1 + "!") + ``` For example: + ``` hi_func = partial.make(_foo, "Hello") bye_func = partial.make(_foo, "Goodbye") partial.call(hi_func, "Jennifer") partial.call(hi_func, "Dave") partial.call(bye_func, "Jennifer") partial.call(bye_func, "Dave") + ``` prints: + ``` "Hello, Jennifer!" "Hello, Dave!" "Goodbye, Jennifer!" "Goodbye, Dave!" + ``` The keyword args given to the function are the kwargs passed into make unioned with the keyword args given to call. In case of a conflict, the @@ -95,16 +107,20 @@ def _make(func, *args, **kwargs): Example with a make site arg, a call site arg, a make site kwarg and a call site kwarg: + ``` def _foo(make_arg1, call_arg1, make_location, call_location): print(make_arg1 + " is from " + make_location + " and " + call_arg1 + " is from " + call_location + "!") func = partial.make(_foo, "Ben", make_location="Hollywood") partial.call(func, "Jennifer", call_location="Denver") + ``` Prints "Ben is from Hollywood and Jennifer is from Denver!". + ``` partial.call(func, "Jennifer", make_location="LA", call_location="Denver") + ``` Prints "Ben is from LA and Jennifer is from Denver!". @@ -112,11 +128,13 @@ def _make(func, *args, **kwargs): whether they are given during the make or call step. For instance, you can't do: + ``` def foo(x): pass func = partial.make(foo, 1) partial.call(func, x=2) + ``` Args: func: The function to be called. -- cgit v1.2.3 From 0c57e74606b4e87606b0a9164fbfa4947e89e29c Mon Sep 17 00:00:00 2001 From: Philipp Wollermann Date: Mon, 9 Aug 2021 17:15:50 +0200 Subject: Remove `$` from grep regexes (#311) Due to grep having dropped support for handling line-ending matches in a cross-platform way, grepping for `...$` will now fail on Windows, as it no longer ignores the CR part of the CRLF line endings on Windows. This should turn this project green again on Bazel CI. --- tests/write_file/write_file_tests.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/write_file/write_file_tests.sh b/tests/write_file/write_file_tests.sh index 247c696..0f48ca0 100755 --- a/tests/write_file/write_file_tests.sh +++ b/tests/write_file/write_file_tests.sh @@ -52,8 +52,8 @@ function test_write_empty_text() { function test_write_nonempty_text() { cat "$(rlocation bazel_skylib/tests/write_file/out/nonempty.txt)" >"$TEST_log" - expect_log '^aaa$' - expect_log '^bbb$' + expect_log '^aaa' + expect_log '^bbb' } function test_write_empty_bin() { @@ -62,7 +62,7 @@ function test_write_empty_bin() { function test_write_nonempty_bin() { cat "$(rlocation bazel_skylib/tests/write_file/nonempty-bin-out.txt)" >"$TEST_log" - expect_log '^potato$' + expect_log '^potato' } run_suite "write_file_tests test suite" -- cgit v1.2.3 From df3c9e2735f02a7fe8cd80db4db00fec8e13d25f Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 18 Aug 2021 08:23:43 -0700 Subject: =?UTF-8?q?diff=5Ftest:=20add=20ability=20for=20caller=20to=20spec?= =?UTF-8?q?ify=20a=20message=20printed=20on=20fai=E2=80=A6=20(#307)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Useful for the use case of a pair of .test and .update targets for checked-in golden files --- rules/diff_test.bzl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index 71faf40..acde2ea 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -58,7 +58,7 @@ if "!RF2!" equ "" ( fc.exe 2>NUL 1>NUL /B "!RF1!" "!RF2!" if %ERRORLEVEL% neq 0 ( if %ERRORLEVEL% equ 1 ( - echo>&2 FAIL: files "{file1}" and "{file2}" differ + echo>&2 FAIL: files "{file1}" and "{file2}" differ. {fail_msg} exit /b 1 ) else ( fc.exe /B "!RF1!" "!RF2!" @@ -66,6 +66,7 @@ if %ERRORLEVEL% neq 0 ( ) ) """.format( + fail_msg = ctx.attr.failure_message, file1 = _runfiles_path(ctx.file.file1), file2 = _runfiles_path(ctx.file.file2), ), @@ -95,10 +96,11 @@ else exit 1 fi if ! diff "$RF1" "$RF2"; then - echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ" + echo >&2 "FAIL: files \"{file1}\" and \"{file2}\" differ. {fail_msg}" exit 1 fi """.format( + fail_msg = ctx.attr.failure_message, file1 = _runfiles_path(ctx.file.file1), file2 = _runfiles_path(ctx.file.file2), ), @@ -112,6 +114,7 @@ fi _diff_test = rule( attrs = { + "failure_message": attr.string(), "file1": attr.label( allow_single_file = True, mandatory = True, -- cgit v1.2.3 From 08398cdc99b2042dfb5748fd49ef8393b9045c8e Mon Sep 17 00:00:00 2001 From: Daniel Wagner-Hall Date: Thu, 23 Sep 2021 21:21:58 +0100 Subject: Allow specifying additional aspects to tut (#299) --- lib/unittest.bzl | 7 +++++-- tests/unittest_tests.bzl | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/lib/unittest.bzl b/lib/unittest.bzl index 87dfd27..925e569 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -151,7 +151,8 @@ def _make_analysis_test( expect_failure = False, attrs = {}, fragments = [], - config_settings = {}): + config_settings = {}, + extra_target_under_test_aspects = []): """Creates an analysis test rule from its implementation function. An analysis test verifies the behavior of a "real" rule target by examining @@ -189,6 +190,8 @@ def _make_analysis_test( 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 @@ -209,7 +212,7 @@ def _make_analysis_test( target_attr_kwargs["cfg"] = test_transition attrs["target_under_test"] = attr.label( - aspects = [_action_retrieving_aspect], + aspects = [_action_retrieving_aspect] + extra_target_under_test_aspects, mandatory = True, **target_attr_kwargs ) diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index a3741f6..abddbdd 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -194,6 +194,50 @@ inspect_actions_test = analysistest.make( _inspect_actions_test, ) +#################################### +####### inspect_aspect_test ####### +#################################### +_AddedByAspectInfo = provider( + doc = "Example provider added by example aspect", + fields = { + "value": "(str)", + }, +) + +def _example_aspect_impl(target, ctx): + return [ + _AddedByAspectInfo(value = "attached by aspect"), + ] + +example_aspect = aspect( + implementation = _example_aspect_impl, +) + +def _inspect_aspect_test(ctx): + """Test verifying aspect run on a target.""" + env = analysistest.begin(ctx) + + tut = env.ctx.attr.target_under_test + asserts.equals(env, "attached by aspect", tut[_AddedByAspectInfo].value) + return analysistest.end(env) + +def _inspect_aspect_fake_rule(ctx): + out_file = ctx.actions.declare_file("out.txt") + ctx.actions.run_shell( + command = "echo 'hello' > %s" % out_file.basename, + outputs = [out_file], + ) + return [DefaultInfo(files = depset([out_file]))] + +inspect_aspect_fake_rule = rule( + implementation = _inspect_aspect_fake_rule, +) + +inspect_aspect_test = analysistest.make( + _inspect_aspect_test, + extra_target_under_test_aspects = [example_aspect], +) + ######################################## ####### inspect_output_dirs_test ####### ######################################## @@ -293,6 +337,15 @@ def unittest_passing_tests_suite(): tags = ["manual"], ) + inspect_aspect_test( + name = "inspect_aspect_test", + target_under_test = ":inspect_aspect_fake_target", + ) + inspect_aspect_fake_rule( + name = "inspect_aspect_fake_target", + tags = ["manual"], + ) + inspect_output_dirs_test( name = "inspect_output_dirs_test", target_under_test = ":inspect_output_dirs_fake_target", -- cgit v1.2.3 From 14f17ae7f71f347b5e720fca55e33df40bc4e5d5 Mon Sep 17 00:00:00 2001 From: Mansur <68459057+stdbug@users.noreply.github.com> Date: Fri, 24 Sep 2021 16:43:30 +0200 Subject: Windows support for build_test (#302) --- rules/BUILD | 5 ----- rules/build_test.bzl | 38 +++++++++++++++++++++++++++++++------- rules/empty_test.sh | 3 --- 3 files changed, 31 insertions(+), 15 deletions(-) delete mode 100755 rules/empty_test.sh diff --git a/rules/BUILD b/rules/BUILD index 26cda0c..6bb55b9 100644 --- a/rules/BUILD +++ b/rules/BUILD @@ -49,16 +49,11 @@ bzl_library( srcs = ["common_settings.bzl"], ) -# Exported for build_test.bzl to make sure of, it is an implementation detail -# of the rule and should not be directly used by anything else. -exports_files(["empty_test.sh"]) - filegroup( name = "test_deps", testonly = True, srcs = [ "BUILD", - "empty_test.sh", ] + glob(["*.bzl"]), ) diff --git a/rules/build_test.bzl b/rules/build_test.bzl index f06e0d4..697875b 100644 --- a/rules/build_test.bzl +++ b/rules/build_test.bzl @@ -16,6 +16,31 @@ load("//lib:new_sets.bzl", "sets") +def _empty_test_impl(ctx): + extension = ".bat" if ctx.attr.is_windows else ".sh" + content = "exit 0" if ctx.attr.is_windows else "#!/bin/bash\nexit 0" + executable = ctx.actions.declare_file(ctx.label.name + extension) + ctx.actions.write( + output = executable, + is_executable = True, + content = content, + ) + + return [DefaultInfo( + files = depset([executable]), + executable = executable, + runfiles = ctx.runfiles(files = ctx.files.data), + )] + +_empty_test = rule( + implementation = _empty_test_impl, + attrs = { + "data": attr.label_list(allow_files = True), + "is_windows": attr.bool(mandatory = True), + }, + test = True, +) + def build_test(name, targets, **kwargs): """Test rule checking that other targets build. @@ -23,9 +48,6 @@ def build_test(name, targets, **kwargs): the targets it depends on failing to build, and hence failing the attempt to run this test. - NOTE: At the moment, this won't work on Windows; but someone adding - support would be welcomed. - Typical usage: ``` @@ -75,16 +97,18 @@ def build_test(name, targets, **kwargs): outs = [full_name + ".out"], testonly = 1, visibility = ["//visibility:private"], - # TODO: Does this need something else for Windows? cmd = "touch $@", + cmd_bat = "type nul > $@", **genrule_args ) - native.sh_test( + _empty_test( name = name, - # TODO: Does this need something else for Windows? - srcs = ["@bazel_skylib//rules:empty_test.sh"], data = test_data, size = kwargs.pop("size", "small"), # Default to small for test size + is_windows = select({ + "@bazel_tools//src/conditions:host_windows": True, + "//conditions:default": False, + }), **kwargs ) diff --git a/rules/empty_test.sh b/rules/empty_test.sh deleted file mode 100755 index fde58b3..0000000 --- a/rules/empty_test.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -# This is a support file for build_test.bzl, it shouldn't be used by anything else. -exit 0 -- cgit v1.2.3 From 43a545a67ea2b9673365745b1b5372170d730922 Mon Sep 17 00:00:00 2001 From: Thaler Benedek Date: Fri, 24 Sep 2021 16:49:07 +0200 Subject: Make diff_test work on windows with --enable_runfiles (#314) --- rules/diff_test.bzl | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index acde2ea..ff570e6 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -44,16 +44,26 @@ for /F "tokens=2* usebackq" %%i in (`findstr.exe /l /c:"!F1! " "%MF%"`) do ( set RF1=!RF1:/=\\! ) if "!RF1!" equ "" ( - echo>&2 ERROR: !F1! not found - exit /b 1 + if exist "{file1}" ( + set RF1="{file1}" + set RF1=!RF1:/=\\! + ) else ( + echo>&2 ERROR: !F1! not found + exit /b 1 + ) ) for /F "tokens=2* usebackq" %%i in (`findstr.exe /l /c:"!F2! " "%MF%"`) do ( set RF2=%%i set RF2=!RF2:/=\\! ) if "!RF2!" equ "" ( - echo>&2 ERROR: !F2! not found - exit /b 1 + if exist "{file2}" ( + set RF2="{file2}" + set RF2=!RF2:/=\\! + ) else ( + echo>&2 ERROR: !F2! not found + exit /b 1 + ) ) fc.exe 2>NUL 1>NUL /B "!RF1!" "!RF2!" if %ERRORLEVEL% neq 0 ( -- cgit v1.2.3 From eabe5f7fe9ad744f0074d61c65fb29dd3d228a68 Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Fri, 24 Sep 2021 08:24:43 -0700 Subject: Run regenerate_docs.sh (#297) Co-authored-by: Alexandre Rostovtsev (merge conflict fixes) --- docs/analysis_test_doc.md | 35 +- docs/build_test_doc.md | 49 +-- docs/collections_doc.md | 103 ++---- docs/common_settings_doc.md | 242 ++++---------- docs/copy_file_doc.md | 82 +---- docs/dicts_doc.md | 39 +-- docs/diff_test_doc.md | 58 +--- docs/native_binary_doc.md | 129 ++------ docs/paths_doc.md | 243 ++++---------- docs/regenerate_docs.sh | 2 +- docs/run_binary_doc.md | 75 +---- docs/selects_doc.md | 112 ++----- docs/shell_doc.md | 57 ++-- docs/structs_doc.md | 29 +- docs/types_doc.md | 263 ++++++--------- docs/unittest_doc.md | 770 ++++++++++++-------------------------------- docs/versions_doc.md | 152 +++------ docs/write_file_doc.md | 82 +---- 18 files changed, 635 insertions(+), 1887 deletions(-) diff --git a/docs/analysis_test_doc.md b/docs/analysis_test_doc.md index 817be66..6585e29 100755 --- a/docs/analysis_test_doc.md +++ b/docs/analysis_test_doc.md @@ -1,4 +1,7 @@ + + + ## analysis_test
@@ -32,30 +35,12 @@ Test rule checking that other targets can be successfully analyzed.
       name: The name of the test rule.
       targets: A list of targets to ensure build.
 
-### Attributes
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
name - Name; required -

- A unique name for this target. -

-
targets - List of labels; required -
+**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | +| 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 b1cd020..6b0d629 100755 --- a/docs/build_test_doc.md +++ b/docs/build_test_doc.md @@ -1,3 +1,7 @@ + + + + ## build_test
@@ -10,9 +14,6 @@ This works not by an instance of this test failing, but instead by
 the targets it depends on failing to build, and hence failing
 the attempt to run this test.
 
-NOTE: At the moment, this won't work on Windows; but someone adding
-support would be welcomed.
-
 Typical usage:
 
 ```
@@ -26,42 +27,12 @@ Typical usage:
 ```
 
 
-### Parameters
+**PARAMETERS**
 
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
name - required. -

- The name of the test rule. -

-
targets - required. -

- A list of targets to ensure build. -

-
kwargs - optional. -

- The common attributes for tests. -

-
+| 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 | diff --git a/docs/collections_doc.md b/docs/collections_doc.md index 64ffb5e..1b54e34 100755 --- a/docs/collections_doc.md +++ b/docs/collections_doc.md @@ -1,3 +1,7 @@ + + + + ## collections.after_each
@@ -6,35 +10,16 @@ collections.after_each(separator
 
 Inserts `separator` after each item in `iterable`.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
separator - required. -

- The value to insert after each item in `iterable`. -

-
iterable - required. -

- The list into which to intersperse the separator. -

-
+**PARAMETERS** + + +| 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 | + + ## collections.before_each @@ -44,36 +29,17 @@ collections.before_each(separator - - - - - - - separator - - required. -

- The value to insert before each item in `iterable`. -

- - - - iterable - - required. -

- The list into which to intersperse the separator. -

- - - - +**PARAMETERS** +| 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 | + + +
+ ## collections.uniq
@@ -85,24 +51,11 @@ Returns a list of unique elements in `iterable`.
 Requires all the elements to be hashable.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
iterable - required. -

- An iterable to filter. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| iterable | An iterable to filter. | none | diff --git a/docs/common_settings_doc.md b/docs/common_settings_doc.md index 676f070..41271c7 100755 --- a/docs/common_settings_doc.md +++ b/docs/common_settings_doc.md @@ -10,25 +10,12 @@ bool_flag(name) A bool-typed build setting that can be set on the command line -### Attributes - - - - - - - - - - - - -
name - Name; required -

- A unique name for this target. -

-
+**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | +| name | A unique name for this target. | Name | required | | @@ -41,25 +28,12 @@ bool_setting(name) A bool-typed build setting that cannot be set on the command line -### Attributes - - - - - - - - - - - - -
name - Name; required -

- A unique name for this target. -

-
+**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | +| name | A unique name for this target. | Name | required | | @@ -72,25 +46,12 @@ int_flag(name) An int-typed build setting that can be set on the command line -### Attributes - - - - - - - - - - - - -
name - Name; required -

- A unique name for this target. -

-
+**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | +| name | A unique name for this target. | Name | required | | @@ -103,25 +64,12 @@ int_setting(name) An int-typed build setting that cannot be set on the command line -### Attributes - - - - - - - - - - - - -
name - Name; required -

- A unique name for this target. -

-
+**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | +| name | A unique name for this target. | Name | required | | @@ -134,34 +82,13 @@ string_flag(name, A string-typed build setting that can be set on the command line -### Attributes - - - - - - - - - - - - - - - - -
name - Name; required -

- A unique name for this target. -

-
values - List of strings; optional -

- The list of allowed values for this setting. An error is raised if any other value is given. -

-
+**ATTRIBUTES** + + +| 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 | [] | @@ -174,25 +101,12 @@ string_list_flag(name) A string list-typed build setting that can be set on the command line -### Attributes - - - - - - - - - - - - -
name - Name; required -

- A unique name for this target. -

-
+**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | +| name | A unique name for this target. | Name | required | | @@ -205,25 +119,12 @@ string_list_setting(name) A string list-typed build setting that cannot be set on the command line -### Attributes - - - - - - - - - - - - -
name - Name; required -

- A unique name for this target. -

-
+**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | +| name | A unique name for this target. | Name | required | | @@ -236,34 +137,13 @@ string_setting(name, - - - - - - - name - - Name; required -

- A unique name for this target. -

- - - - values - - List of strings; optional -

- The list of allowed values for this setting. An error is raised if any other value is given. -

- - - - +**ATTRIBUTES** + + +| 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 | [] | @@ -276,21 +156,11 @@ BuildSettingInfo(value) A singleton provider that contains the raw value of a build setting -### Fields - - - - - - - - - - - - -
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.

-
+**FIELDS** + + +| 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. | diff --git a/docs/copy_file_doc.md b/docs/copy_file_doc.md index 67148bc..52f10a5 100755 --- a/docs/copy_file_doc.md +++ b/docs/copy_file_doc.md @@ -15,78 +15,16 @@ Copies a file to another location. This rule uses a Bash command on Linux/macOS/non-Windows, and a cmd.exe command on Windows (no Bash is required). -### Parameters +**PARAMETERS** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
name - required. -

- Name of the rule. -

-
src - required. -

- A Label. The file to make a copy of. (Can also be the label of a rule - that generates a file.) -

-
out - required. -

- Path of the output file, relative to this package. -

-
is_executable - optional. default is False -

- 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. -

-
kwargs - optional. -

- further keyword arguments, e.g. `visibility` -

-
+ +| 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 | diff --git a/docs/dicts_doc.md b/docs/dicts_doc.md index 2e95cf8..0b54243 100755 --- a/docs/dicts_doc.md +++ b/docs/dicts_doc.md @@ -1,3 +1,7 @@ + + + + ## dicts.add
@@ -15,33 +19,12 @@ special cases for their inputs: the sum of zero dictionaries is the empty
 dictionary, and the sum of a single dictionary is a copy of itself.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
dictionaries - optional. -

- Zero or more dictionaries to be added. -

-
kwargs - optional. -

- Additional dictionary passed as keyword args. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| dictionaries | Zero or more dictionaries to be added. | none | +| kwargs | Additional dictionary passed as keyword args. | none | diff --git a/docs/diff_test_doc.md b/docs/diff_test_doc.md index a031145..cf1c2c5 100755 --- a/docs/diff_test_doc.md +++ b/docs/diff_test_doc.md @@ -1,3 +1,7 @@ + + + + ## diff_test
@@ -9,51 +13,13 @@ A test that compares two files.
 The test succeeds if the files' contents match.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
name - required. -

- The name of the test rule. -

-
file1 - required. -

- Label of the file to compare to file2. -

-
file2 - required. -

- Label of the file to compare to file1. -

-
kwargs - optional. -

- The common attributes for tests. -

-
+**PARAMETERS** + +| 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 | diff --git a/docs/native_binary_doc.md b/docs/native_binary_doc.md index 742e81b..a610c3a 100755 --- a/docs/native_binary_doc.md +++ b/docs/native_binary_doc.md @@ -1,3 +1,7 @@ + + + + ## native_binary
@@ -9,59 +13,19 @@ Wraps a pre-built binary or script with a binary rule.
 You can "bazel run" this rule like any other binary rule, and use it as a tool in genrule.tools for example. You can also augment the binary with runfiles.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-    
-      
-      
-    
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
name - required. -
src - required. -

- label; path of the pre-built executable -

-
out - required. -

- output; an output name for the copy of the binary. (Bazel requires that this rule make a copy of 'src'.) -

-
data - optional. default is None -

- list of labels; data dependencies -

-
kwargs - optional. -

- The common attributes for binaries. -

-
+**PARAMETERS** + +| 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 | + + + ## native_test @@ -75,57 +39,14 @@ You can "bazel test" this rule like any other test rule. You can also augment th runfiles. -### Parameters - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
name - required. -
src - required. -

- label; path of the pre-built executable -

-
out - required. -

- output; an output name for the copy of the binary. (Bazel requires that this rule make a copy of 'src'.) -

-
data - optional. default is None -

- list of labels; data dependencies -

-
kwargs - optional. -

- The common attributes for tests. -

-
+**PARAMETERS** + +| 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 | diff --git a/docs/paths_doc.md b/docs/paths_doc.md index 8797c01..cd19358 100755 --- a/docs/paths_doc.md +++ b/docs/paths_doc.md @@ -1,3 +1,7 @@ + + + + ## paths.basename
@@ -12,27 +16,16 @@ the Unix `basename` command (which would return the path segment preceding
 the final slash).
 
 
-### Parameters
+**PARAMETERS**
+
 
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
p - required. -

- The path whose basename should be returned. -

-
+| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| p | The path whose basename should be returned. | none | + + ## paths.dirname
@@ -46,26 +39,15 @@ The dirname is the portion of `p` up to but not including the file portion
 included, unless omitting them would make the dirname empty.
 
 
-### Parameters
+**PARAMETERS**
+
+
+| Name  | Description | Default Value |
+| :-------------: | :-------------: | :-------------: |
+| p |  The path whose dirname should be returned.   |  none |
 
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
p - required. -

- The path whose dirname should be returned. -

-
+ ## paths.is_absolute @@ -75,27 +57,16 @@ paths.is_absolute(path) Returns `True` if `path` is an absolute path. -### Parameters - - - - - - - - - - - - -
path - required. -

- A path (which is a string). -

-
+**PARAMETERS** +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| path | A path (which is a string). | none | + + + + ## paths.join
@@ -113,36 +84,17 @@ already ends in a separator.
 If any component is an absolute path, all previous components are discarded.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
path - required. -

- A path segment. -

-
others - optional. -

- Additional path segments. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| path | A path segment. | none | +| others | Additional path segments. | none | + + ## paths.normalize
@@ -166,26 +118,15 @@ POSIX platforms; specifically:
 - Multiple adjacent internal slashes are collapsed into a single slash.
 
 
-### Parameters
+**PARAMETERS**
+
+
+| Name  | Description | Default Value |
+| :-------------: | :-------------: | :-------------: |
+| path |  A path.   |  none |
 
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
path - required. -

- A path. -

-
+ ## paths.relativize @@ -204,35 +145,16 @@ Relativizing paths that start with parent directory references only works if the path both start with the same initial parent references. -### Parameters - - - - - - - - - - - - - - - - -
path - required. -

- The path to relativize. -

-
start - required. -

- The ancestor path against which to relativize. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| path | The path to relativize. | none | +| start | The ancestor path against which to relativize. | none | + + ## paths.replace_extension @@ -245,37 +167,17 @@ Replaces the extension of the file at the end of a path. If the path has no extension, the new extension is added to it. -### Parameters - - - - - - - - - - - - - - - - -
p - required. -

- The path whose extension should be replaced. -

-
new_extension - required. -

- The new extension for the file. The new extension should - begin with a dot if you want the new filename to have one. -

-
+**PARAMETERS** +| 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 | + + + + ## paths.split_extension
@@ -288,24 +190,11 @@ Leading periods on the basename are ignored, so
 `path.split_extension(".bashrc")` returns `(".bashrc", "")`.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
p - required. -

- The path whose root and extension should be split. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| p | The path whose root and extension should be split. | none | diff --git a/docs/regenerate_docs.sh b/docs/regenerate_docs.sh index 2ab9a08..26f397a 100755 --- a/docs/regenerate_docs.sh +++ b/docs/regenerate_docs.sh @@ -19,7 +19,7 @@ set -euo pipefail -bazel build docs:all --experimental_remap_main_repo +bazel build docs:all for filename in bazel-bin/docs/*_gen.md; do target_filename="$(echo $filename | sed -En "s/bazel-bin\/(.*)_gen.md/\1/p").md" diff --git a/docs/run_binary_doc.md b/docs/run_binary_doc.md index cde8b40..9d7bb99 100755 --- a/docs/run_binary_doc.md +++ b/docs/run_binary_doc.md @@ -1,4 +1,7 @@ + + + ## run_binary
@@ -7,69 +10,15 @@ run_binary(name, args<
 
 Runs a binary as a build action.

This rule does not require Bash (unlike native.genrule). -### Attributes +**ATTRIBUTES** - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
name - Name; required -

- A unique name for this target. -

-
args - List of strings; optional -

- Command line arguments of the binary.

Subject to$(location) expansion. -

-
env - Dictionary: String -> String; optional -

- Environment variables of the action.

Subject to $(location) expansion. -

-
outs - List of labels; required -

- Output files generated by the action.

These labels are available for $(location) expansion in args and env. -

-
srcs - List of labels; optional -

- Additional inputs of the action.

These labels are available for $(location) expansion in args and env. -

-
tool - Label; required -

- The tool to run in the action.

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 $(location) expansion in args and env. -

-
+| 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 | | diff --git a/docs/selects_doc.md b/docs/selects_doc.md index 55711c9..6bc1bda 100755 --- a/docs/selects_doc.md +++ b/docs/selects_doc.md @@ -24,37 +24,13 @@ Example: Key labels may appear at most once anywhere in the input. -### Parameters - - - - - - - - - - - - - - - - -
input_dict - required. -

- 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 `...`. -

-
no_match_error - optional. default is "" -

- Optional custom error to report if no condition matches. -

-
+**PARAMETERS** + + +| 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. | "" | @@ -71,25 +47,12 @@ Unlike `select()`, the contents of the dict can be inspected by Starlark macros. -### Parameters +**PARAMETERS** + - - - - - - - - - - - -
input_dict - required. -

- Same as `with_or`. -

-
+| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| input_dict | Same as with_or. | none | @@ -97,7 +60,7 @@ macros. ## selects.config_setting_group
-selects.config_setting_group(name, match_any, match_all)
+selects.config_setting_group(name, match_any, match_all, visibility)
 
Matches if all or any of its member `config_setting`s match. @@ -124,45 +87,14 @@ Example: ``` -### Parameters - - - - - - - - - - - - - - - - - - - - -
name - required. -

- The group's name. This is how `select()`s reference it. -

-
match_any - optional. default is [] -

- 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 - optional. default is [] -

- 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. -

-
+**PARAMETERS** + + +| 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 | diff --git a/docs/shell_doc.md b/docs/shell_doc.md index 6c655be..a414926 100755 --- a/docs/shell_doc.md +++ b/docs/shell_doc.md @@ -1,3 +1,7 @@ + + + + ## shell.array_literal
@@ -14,28 +18,16 @@ Note that all elements in the array are quoted (using `shell.quote`) for
 safety, even if they do not need to be.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
iterable - required. -

- A sequence of elements. Elements that are not strings will be - converted to strings first, by calling `str()`. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| iterable | A sequence of elements. Elements that are not strings will be converted to strings first, by calling str(). | none | + + ## shell.quote
@@ -48,24 +40,11 @@ This function quotes the given string (in case it contains spaces or other
 shell metacharacters.)
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
s - required. -

- The string to quote. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| s | The string to quote. | none | diff --git a/docs/structs_doc.md b/docs/structs_doc.md index 3b742cb..c2f1337 100755 --- a/docs/structs_doc.md +++ b/docs/structs_doc.md @@ -1,3 +1,7 @@ + + + + ## structs.to_dict
@@ -6,24 +10,11 @@ structs.to_dict(s)
 
 Converts a `struct` to a `dict`.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
s - required. -

- A `struct`. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| s | A struct. | none | diff --git a/docs/types_doc.md b/docs/types_doc.md index 038ae0a..f18c561 100755 --- a/docs/types_doc.md +++ b/docs/types_doc.md @@ -1,3 +1,7 @@ + + + + ## types.is_list
@@ -6,26 +10,15 @@ types.is_list(v)
 
 Returns True if v is an instance of a list.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
v - required. -

- The value whose type should be checked. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | + + ## types.is_string @@ -35,27 +28,16 @@ types.is_string(v) Returns True if v is an instance of a string. -### Parameters - - - - - - - - - - - - -
v - required. -

- The value whose type should be checked. -

-
+**PARAMETERS** +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | + + + + ## types.is_bool
@@ -64,27 +46,16 @@ types.is_bool(v)
 
 Returns True if v is an instance of a bool.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
v - required. -

- The value whose type should be checked. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | + + ## types.is_none
@@ -93,27 +64,16 @@ types.is_none(v)
 
 Returns True if v has the type of None.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
v - required. -

- The value whose type should be checked. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | + + ## types.is_int
@@ -122,26 +82,15 @@ types.is_int(v)
 
 Returns True if v is an instance of a signed integer.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
v - required. -

- The value whose type should be checked. -

-
+**PARAMETERS** + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | + + + ## types.is_tuple @@ -151,27 +100,16 @@ types.is_tuple(v) Returns True if v is an instance of a tuple. -### Parameters - - - - - - - - - - - - -
v - required. -

- The value whose type should be checked. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | + + ## types.is_dict
@@ -180,27 +118,16 @@ types.is_dict(v)
 
 Returns True if v is an instance of a dict.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
v - required. -

- The value whose type should be checked. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | + + ## types.is_function
@@ -209,26 +136,15 @@ types.is_function(v)
 
 Returns True if v is an instance of a function.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
v - required. -

- The value whose type should be checked. -

-
+**PARAMETERS** + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | + + + ## types.is_depset @@ -238,24 +154,29 @@ types.is_depset(v) Returns True if v is an instance of a `depset`. -### Parameters - - - - - - - - - - - - -
v - required. -

- The value whose type should be checked. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | + + + + +## types.is_set + +
+types.is_set(v)
+
+ +Returns True if v is a set created by sets.make(). + +**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| v | The value whose type should be checked. | none | diff --git a/docs/unittest_doc.md b/docs/unittest_doc.md index 4fbd96f..2b97abe 100755 --- a/docs/unittest_doc.md +++ b/docs/unittest_doc.md @@ -1,4 +1,7 @@ + + + ## unittest_toolchain
@@ -7,55 +10,24 @@ unittest_toolchain(name, 
-  
-    
-    
-  
-  
-    
-      name
-      
-        Name; required
-        

- A unique name for this target. -

- - - - failure_templ - - String; required - - - - file_ext - - String; required - - - - join_on - - String; required - - - - success_templ - - String; required - - - - +**ATTRIBUTES** + + +| Name | Description | Type | Mandatory | Default | +| :-------------: | :-------------: | :-------------: | :-------------: | :-------------: | +| name | A unique name for this target. | Name | required | | +| failure_templ | - | String | required | | +| file_ext | - | String | required | | +| join_on | - | String | required | | +| success_templ | - | String | required | | + + ## analysistest.make
-analysistest.make(impl, expect_failure, attrs, config_settings)
+analysistest.make(impl, expect_failure, attrs, fragments, config_settings)
 
Creates an analysis test rule from its implementation function. @@ -84,59 +56,20 @@ your_test = analysistest.make(_your_test) Recall that names of test rules must end in `_test`. -### Parameters - - - - - - - - - - - - - - - - - - - - - - - - -
impl - required. -

- The implementation function of the unit test. -

-
expect_failure - optional. default is False -

- 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 -

-
attrs - optional. default is {} -

- An optional dictionary to supplement the attrs passed to the - unit test's `rule()` constructor. -

-
config_settings - optional. default is {} -

- 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 -

-
+**PARAMETERS** +| 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 | {} | + + + + ## analysistest.begin
@@ -151,27 +84,15 @@ assertion failures so that they can be reported and logged at the end of the
 test.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
ctx - required. -

- The Skylark context. Pass the implementation function's `ctx` argument - in verbatim. -

-
+**PARAMETERS** + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| ctx | The Starlark context. Pass the implementation function's ctx argument in verbatim. | none | + + + ## analysistest.end @@ -185,26 +106,15 @@ This must be called and returned at the end of an analysis test implementation f that the results are reported. -### Parameters +**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| env | The test environment returned by analysistest.begin. | none | - - - - - - - - - - - -
env - required. -

- The test environment returned by `analysistest.begin`. -

-
+ ## analysistest.fail @@ -214,36 +124,17 @@ analysistest.fail(env, - - - - - - - env - - required. -

- The test environment returned by `unittest.begin`. -

- - - - msg - - required. -

- The message to log describing the failure. -

- - - - +**PARAMETERS** +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| env | The test environment returned by unittest.begin. | none | +| msg | The message to log describing the failure. | none | + + +
+ ## analysistest.target_actions
@@ -252,26 +143,33 @@ analysistest.target_actions(env)
 
 Returns a list of actions registered by the target under test.
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
env - required. -

- The test environment returned by `analysistest.begin`. -

-
+**PARAMETERS** + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| env | The test environment returned by analysistest.begin. | none | + + + + +## analysistest.target_bin_dir_path + +
+analysistest.target_bin_dir_path(env)
+
+ +Returns ctx.bin_dir.path for the target under test. + +**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| env | The test environment returned by analysistest.begin. | none | + + + ## analysistest.target_under_test @@ -281,27 +179,16 @@ analysistest.target_under_test(env Returns the target under test. -### Parameters - - - - - - - - - - - - -
env - required. -

- The test environment returned by `analysistest.begin`. -

-
+**PARAMETERS** +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| env | The test environment returned by analysistest.begin. | none | + + +
+ ## asserts.expect_failure
@@ -314,35 +201,16 @@ This requires that the analysis test is created with `analysistest.make()` and
 `expect_failures = True` is specified.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
env - required. -

- The test environment returned by `analysistest.begin`. -

-
expected_failure_msg - optional. default is "" -

- The error message to expect as a result of analysis failures. -

-
+**PARAMETERS** + +| 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. | "" | + + + ## asserts.equals @@ -352,55 +220,19 @@ asserts.equals(env, - - - - - - - env - - required. -

- The test environment returned by `unittest.begin`. -

- - - - expected - - required. -

- The expected value of some computation. -

- - - - actual - - required. -

- The actual value returned by some computation. -

- - - - msg - - optional. default is None -

- An optional message that will be printed that describes the failure. - If omitted, a default will be used. -

- - - - +**PARAMETERS** + + +| 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 | +
+ ## asserts.false
@@ -409,45 +241,17 @@ asserts.false(env, 
-  
-    
-    
-  
-  
-    
-      env
-      
-        required.
-        

- The test environment returned by `unittest.begin`. -

- - - - condition - - required. -

- A value that will be evaluated in a Boolean context. -

- - - - msg - - optional. default is "Expected condition to be false, but was true." -

- An optional message that will be printed that describes the failure. - If omitted, a default will be used. -

- - - - +**PARAMETERS** + + +| 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." | + +
## asserts.set_equals @@ -457,55 +261,19 @@ asserts.set_equals(env, - - - - - - - env - - required. -

- The test environment returned by `unittest.begin`. -

- - - - expected - - required. -

- The expected set resulting from some computation. -

- - - - actual - - required. -

- The actual set returned by some computation. -

- - - - msg - - optional. default is None -

- An optional message that will be printed that describes the failure. - If omitted, a default will be used. -

- - - - +**PARAMETERS** +| 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 | + + +
+ ## asserts.new_set_equals
@@ -514,54 +282,18 @@ asserts.new_set_equals(env, 
-  
-    
-    
-  
-  
-    
-      env
-      
-        required.
-        

- The test environment returned by `unittest.begin`. -

- - - - expected - - required. -

- The expected set resulting from some computation. -

- - - - actual - - required. -

- The actual set returned by some computation. -

- - - - msg - - optional. default is None -

- An optional message that will be printed that describes the failure. - If omitted, a default will be used. -

- - - - +**PARAMETERS** + +| 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 | + + +
## asserts.true @@ -571,46 +303,18 @@ asserts.true(env, - - - - - - - env - - required. -

- The test environment returned by `unittest.begin`. -

- - - - condition - - required. -

- A value that will be evaluated in a Boolean context. -

- - - - msg - - optional. default is "Expected condition to be true, but was false." -

- An optional message that will be printed that describes the failure. - If omitted, a default will be used. -

- - - - +**PARAMETERS** + + +| 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." | +
+ ## register_unittest_toolchains
@@ -619,8 +323,12 @@ register_unittest_toolchains()
 
 Registers the toolchains for unittest users.
 
+**PARAMETERS**
+
 
 
+
+
 ## unittest.make
 
 
@@ -653,36 +361,16 @@ your_test = unittest.make(_your_test)
 Recall that names of test rules must end in `_test`.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-    
-      
-      
-    
-  
-
impl - required. -

- The implementation function of the unit test. -

-
attrs - optional. default is {} -

- An optional dictionary to supplement the attrs passed to the - unit test's `rule()` constructor. -

-
+**PARAMETERS** + +| 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. | {} | + + + ## unittest.suite @@ -699,10 +387,10 @@ and then creating each target one by one. To reduce duplication, we recommend writing a macro in your `.bzl` file to instantiate all targets, and calling that macro from your BUILD file so you only have to load one symbol. -For the case where your unit tests do not take any (non-default) attributes -- -i.e., if your unit tests do not test rules -- you can use this function to -create the targets and wrap them in a single test_suite target. In your -`.bzl` file, write: +You can use this function to create the targets and wrap them in a single +test_suite target. If a test rule requires no arguments, you can simply list +it as an argument. If you wish to supply attributes explicitly, you can do so +using `partial.make()`. For instance, in your `.bzl` file, you could write: ``` def your_test_suite(): @@ -710,7 +398,7 @@ def your_test_suite(): "your_test_suite", your_test, your_other_test, - yet_another_test, + partial.make(yet_another_test, timeout = "short"), ) ``` @@ -729,37 +417,17 @@ is the index of the test in the `test_rules` list, which is used to uniquely name each target. -### Parameters - - - - - - - - - - - - - - - - -
name - required. -

- The name of the `test_suite` target, and the prefix of all the test - target names. -

-
test_rules - optional. -

- A list of test rules defines by `unittest.test`. -

-
+**PARAMETERS** + + +| 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 | + + ## unittest.begin
@@ -774,27 +442,15 @@ assertion failures so that they can be reported and logged at the end of the
 test.
 
 
-### Parameters
-
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
ctx - required. -

- The Skylark context. Pass the implementation function's `ctx` argument - in verbatim. -

-
+**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| ctx | The Starlark context. Pass the implementation function's ctx argument in verbatim. | none | + + ## unittest.end @@ -808,26 +464,15 @@ This must be called and returned at the end of a unit test implementation functi that the results are reported. -### Parameters +**PARAMETERS** - - - - - - - - - - - -
env - required. -

- The test environment returned by `unittest.begin`. -

-
+| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| env | The test environment returned by unittest.begin. | none | + + + ## unittest.fail @@ -837,33 +482,12 @@ unittest.fail(env, - - - - - - - env - - required. -

- The test environment returned by `unittest.begin`. -

- - - - msg - - required. -

- The message to log describing the failure. -

- - - - +**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| 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 d94076c..b39f5d0 100755 --- a/docs/versions_doc.md +++ b/docs/versions_doc.md @@ -1,3 +1,7 @@ + + +
+ ## versions.get
@@ -6,7 +10,11 @@ versions.get()
 
 Returns the current Bazel version
 
+**PARAMETERS**
+
+
 
+
 
 ## versions.parse
 
@@ -19,26 +27,15 @@ Parses a version string into a 3-tuple of ints
 int tuples can be compared directly using binary operators (<, >).
 
 
-### Parameters
+**PARAMETERS**
 
-
-  -    -    -  
-  
-    
-      
-      
-    
-  
-
bazel_version - required. -

- the Bazel version string -

-
+| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| bazel_version | the Bazel version string | none | + + + ## versions.check @@ -48,44 +45,17 @@ versions.check(minimum_bazel_ver Check that the version of Bazel is valid within the specified range. -### Parameters - - - - - - - - - - - - - - - - - - - - -
minimum_bazel_version - required. -

- minimum version of Bazel expected -

-
maximum_bazel_version - optional. default is None -

- maximum version of Bazel expected -

-
bazel_version - optional. default is None -

- the version of Bazel to check. Used for testing, defaults to native.bazel_version -

-
+**PARAMETERS** + +| 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 | + + +
## versions.is_at_most @@ -95,36 +65,17 @@ versions.is_at_most(threshold, - - - - - - - threshold - - required. -

- the maximum version string -

- - - - version - - required. -

- the version string to be compared to the threshold -

- - - - +**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| threshold | the maximum version string | none | +| version | the version string to be compared to the threshold | none | +
+ ## versions.is_at_least
@@ -133,33 +84,12 @@ versions.is_at_least(threshold, 
-  
-    
-    
-  
-  
-    
-      threshold
-      
-        required.
-        

- the minimum version string -

- - - - version - - required. -

- the version string to be compared to the threshold -

- - - - +**PARAMETERS** + + +| Name | Description | Default Value | +| :-------------: | :-------------: | :-------------: | +| threshold | the minimum version string | none | +| version | the version string to be compared to the threshold | none | diff --git a/docs/write_file_doc.md b/docs/write_file_doc.md index d8f098e..74f6327 100755 --- a/docs/write_file_doc.md +++ b/docs/write_file_doc.md @@ -1,3 +1,7 @@ + + +
+ ## write_file
@@ -6,74 +10,16 @@ write_file(name, out
-  
-    
-    
-  
-  
-    
-      name
-      
-        required.
-        

- Name of the rule. -

- - - - out - - required. -

- Path of the output file, relative to this package. -

- - - - content - - optional. default is [] -

- 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 - - optional. default is False -

- 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. -

- - - - newline - - optional. default is "auto" -

- one of ["auto", "unix", "windows"]: line endings to use. "auto" - for platform-determined, "unix" for LF, and "windows" for CRLF. -

- - - - kwargs - - optional. -

- further keyword arguments, e.g. visibility -

- - - - +| 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 | -- cgit v1.2.3 From 50d2680f5f670ad887a4a43c8322827850a1e605 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Mon, 27 Sep 2021 12:23:51 -0400 Subject: Update changelog for release 1.1.0 (#317) --- CHANGELOG.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7939d75..313c1b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,27 @@ +Release 1.1.0 + +**New Features** + +- Gazelle: support relative imports (#271) and imports from `@bazel_tools` + (#273) +- Add partial.is_instance() (#276) +- Allow unittest.suite() to accept partial calls of test rules (#276) +- Allow specifying additional aspects to target under test in + analysistest.make() (#299) +- Add Windows support for build_test (#302) + +**Incompatible Changes** + +- structs.to_dict() ignores deprecated to_json()/to_proto() methods (#295) + +**Contributors** + +aiuto, alandonovan, Alex Eagle, Alexandre Rostovtsev, Andrew Z Allen, c-parsons, +Christopher Sauer, Daniel Wagner-Hall, David Sanderson, dmaclach, Laurent Le +Brun, Mansur, Olek Wojnar, Philipp Wollermann, River, Samuel Giddins, Thaler +Benedek + + Release 1.0.3 **Significant Changes** -- cgit v1.2.3 From b2ed61686ebca2a44d44857fef5b3e1d31cc2483 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Mon, 27 Sep 2021 13:12:59 -0400 Subject: Missing version number bump in version.bzl for the new release (#318) Implying that the new release will have to be 1.1.1, not 1.1.0 --- CHANGELOG.md | 2 +- version.bzl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 313c1b3..16b937c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -Release 1.1.0 +Release 1.1.1 (initially tagged as 1.1.0) **New Features** diff --git a/version.bzl b/version.bzl index 3906779..bd2fb19 100644 --- a/version.bzl +++ b/version.bzl @@ -13,4 +13,4 @@ # limitations under the License. """The version of bazel-skylib.""" -version = "1.0.3" +version = "1.1.1" -- cgit v1.2.3 From 506c17293ef4043c68f8cb0ba5fa05d758e1231a Mon Sep 17 00:00:00 2001 From: Samuel Freilich Date: Mon, 4 Oct 2021 12:03:48 -0400 Subject: Improve escaping in unittest failure message (#320) --- docs/build_test_doc.md | 1 + docs/diff_test_doc.md | 1 + docs/native_binary_doc.md | 1 + docs/run_binary_doc.md | 1 + docs/unittest_doc.md | 17 +++++++---- lib/unittest.bzl | 78 +++++++++++++++++++++++++++++++++++++++++++---- tests/unittest_test.sh | 49 ++++++++++++++++++++++++++++- tests/unittest_tests.bzl | 24 ++++++++++++++- toolchains/unittest/BUILD | 8 ++--- 9 files changed, 162 insertions(+), 18 deletions(-) diff --git a/docs/build_test_doc.md b/docs/build_test_doc.md index 6b0d629..5974bc3 100755 --- a/docs/build_test_doc.md +++ b/docs/build_test_doc.md @@ -36,3 +36,4 @@ Typical usage: | 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/diff_test_doc.md b/docs/diff_test_doc.md index cf1c2c5..fc66934 100755 --- a/docs/diff_test_doc.md +++ b/docs/diff_test_doc.md @@ -23,3 +23,4 @@ The test succeeds if the files' contents match. | 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 a610c3a..9979dd2 100755 --- a/docs/native_binary_doc.md +++ b/docs/native_binary_doc.md @@ -50,3 +50,4 @@ runfiles. | 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/run_binary_doc.md b/docs/run_binary_doc.md index 9d7bb99..0f94f65 100755 --- a/docs/run_binary_doc.md +++ b/docs/run_binary_doc.md @@ -22,3 +22,4 @@ Runs a binary as a build action.

This rule does not require Bash (unlik | 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/unittest_doc.md b/docs/unittest_doc.md index 2b97abe..db9a839 100755 --- a/docs/unittest_doc.md +++ b/docs/unittest_doc.md @@ -5,7 +5,8 @@ ## unittest_toolchain
-unittest_toolchain(name, failure_templ, file_ext, join_on, success_templ)
+unittest_toolchain(name, escape_chars_with, escape_other_chars_with, failure_templ, file_ext,
+                   join_on, success_templ)
 
@@ -16,10 +17,12 @@ unittest_toolchain(name, Name | required | | -| failure_templ | - | String | required | | -| file_ext | - | String | required | | -| join_on | - | String | required | | -| success_templ | - | String | 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 | | @@ -27,7 +30,8 @@ unittest_toolchain(name, impl, expect_failure, attrs, fragments, config_settings) +analysistest.make(impl, expect_failure, attrs, fragments, config_settings, + extra_target_under_test_aspects)
Creates an analysis test rule from its implementation function. @@ -66,6 +70,7 @@ Recall that names of test rules must end in `_test`. | 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. | [] | diff --git a/lib/unittest.bzl b/lib/unittest.bzl index 925e569..af851a3 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -36,7 +36,14 @@ TOOLCHAIN_TYPE = "@bazel_skylib//toolchains/unittest:toolchain_type" _UnittestToolchainInfo = provider( doc = "Execution platform information for rules in the bazel_skylib repository.", - fields = ["file_ext", "success_templ", "failure_templ", "join_on"], + fields = [ + "file_ext", + "success_templ", + "failure_templ", + "join_on", + "escape_chars_with", + "escape_other_chars_with", + ], ) def _unittest_toolchain_impl(ctx): @@ -47,6 +54,8 @@ def _unittest_toolchain_impl(ctx): success_templ = ctx.attr.success_templ, failure_templ = ctx.attr.failure_templ, join_on = ctx.attr.join_on, + escape_chars_with = ctx.attr.escape_chars_with, + escape_other_chars_with = ctx.attr.escape_other_chars_with, ), ), ] @@ -54,10 +63,59 @@ def _unittest_toolchain_impl(ctx): unittest_toolchain = rule( implementation = _unittest_toolchain_impl, attrs = { - "failure_templ": attr.string(mandatory = True), - "file_ext": attr.string(mandatory = True), - "join_on": attr.string(mandatory = True), - "success_templ": attr.string(mandatory = True), + "failure_templ": attr.string( + mandatory = True, + doc = ( + "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." + ), + ), + "file_ext": attr.string( + mandatory = True, + doc = ( + "File extension for test script, including leading dot." + ), + ), + "join_on": attr.string( + mandatory = True, + doc = ( + "String used to join the lines in the failure " + + "message before including the resulting string " + + "in the script specified in `failure_templ`." + ), + ), + "success_templ": attr.string( + mandatory = True, + doc = ( + "Test script generated when the test passes. " + + "Should exit with status 0." + ), + ), + "escape_chars_with": attr.string_dict( + doc = ( + "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`." + ), + ), + "escape_other_chars_with": attr.string( + default = "", + doc = ( + "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 `\\`." + ), + ), }, ) @@ -336,7 +394,15 @@ def _end(env): tc = env.ctx.toolchains[TOOLCHAIN_TYPE].unittest_toolchain_info testbin = env.ctx.actions.declare_file(env.ctx.label.name + tc.file_ext) if env.failures: - cmd = tc.failure_templ % tc.join_on.join(env.failures) + failure_message_lines = "\n".join(env.failures).split("\n") + escaped_failure_message_lines = [ + "".join([ + tc.escape_chars_with.get(c, tc.escape_other_chars_with) + c + for c in line.elems() + ]) + for line in failure_message_lines + ] + cmd = tc.failure_templ % tc.join_on.join(escaped_failure_message_lines) else: cmd = tc.success_templ diff --git a/tests/unittest_test.sh b/tests/unittest_test.sh index 9455d8e..1d941b3 100755 --- a/tests/unittest_test.sh +++ b/tests/unittest_test.sh @@ -83,10 +83,11 @@ EOF # Create test files. mkdir -p testdir - cat > testdir/BUILD < testdir/BUILD <<'EOF' load("//tests:unittest_tests.bzl", "basic_passing_test", "basic_failing_test", + "failure_message_test", "fail_unexpected_passing_test", "fail_unexpected_passing_fake_rule") @@ -94,10 +95,26 @@ basic_passing_test(name = "basic_passing_test") basic_failing_test(name = "basic_failing_test") +failure_message_test( + name = "shell_escape_failure_message_test", + message = "Contains $FOO", +) + +failure_message_test( + name = "cmd_escape_failure_message_test", + message = "Contains %FOO%", +) + +failure_message_test( + name = "eof_failure_message_test", + message = "\nEOF\n more after EOF", +) + fail_unexpected_passing_test( name = "fail_unexpected_passing_test", target_under_test = ":fail_unexpected_passing_fake_target", ) + fail_unexpected_passing_fake_rule( name = "fail_unexpected_passing_fake_target", tags = ["manual"]) @@ -123,6 +140,36 @@ function test_basic_failing_test() { expect_log "In test _basic_failing_test from //tests:unittest_tests.bzl: Expected \"1\", but got \"2\"" } +function test_shell_escape_failure_message_test() { + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:shell_escape_failure_message_test --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true + + expect_log 'In test _failure_message_test from //tests:unittest_tests.bzl: Expected "", but got "Contains $FOO"' +} + +function test_cmd_escape_failure_message_test() { + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:cmd_escape_failure_message_test --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true + + expect_log 'In test _failure_message_test from //tests:unittest_tests.bzl: Expected "", but got "Contains %FOO%"' +} + +function test_eof_failure_message_test() { + local -r pkg="${FUNCNAME[0]}" + create_pkg "$pkg" + + bazel test testdir:eof_failure_message_test --test_output=all --verbose_failures \ + >"$TEST_log" 2>&1 && fail "Expected test to fail" || true + + expect_log '^ more after EOF' +} + function test_fail_unexpected_passing_test() { local -r pkg="${FUNCNAME[0]}" create_pkg "$pkg" diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index abddbdd..5541d74 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -18,8 +18,9 @@ load("//lib:partial.bzl", "partial") load("//lib:unittest.bzl", "analysistest", "asserts", "unittest") ################################### -####### fail_basic_test ########### +####### basic_failing_test ######## ################################### + def _basic_failing_test(ctx): """Unit tests for a basic library verification test that fails.""" env = unittest.begin(ctx) @@ -30,6 +31,27 @@ def _basic_failing_test(ctx): basic_failing_test = unittest.make(_basic_failing_test) +################################### +####### failure_message_test ###### +################################### + +def _failure_message_test(ctx): + """Failing unit test with arbitrary content in the message.""" + env = unittest.begin(ctx) + + if not ctx.attr.message: + unittest.fail(env, "Message must be non-empty.") + asserts.equals(env, "", ctx.attr.message) + + return unittest.end(env) + +failure_message_test = unittest.make( + _failure_message_test, + attrs = { + "message": attr.string(), + }, +) + ################################### ####### basic_passing_test ######## ################################### diff --git a/toolchains/unittest/BUILD b/toolchains/unittest/BUILD index 03ceff4..dd23962 100644 --- a/toolchains/unittest/BUILD +++ b/toolchains/unittest/BUILD @@ -9,6 +9,7 @@ toolchain_type( unittest_toolchain( name = "cmd", + escape_chars_with = {"%": "%"}, failure_templ = """@echo off echo %s exit /b 1 @@ -30,14 +31,13 @@ toolchain( unittest_toolchain( name = "bash", + escape_other_chars_with = "\\", failure_templ = """#!/bin/sh -cat <<'EOF' -%s -EOF +echo %s exit 1 """, file_ext = ".sh", - join_on = "\n", + join_on = "\necho ", success_templ = "#!/bin/sh\nexit 0", visibility = ["//visibility:public"], ) -- cgit v1.2.3 From 8e923ca4b9c922420bf460f48f933e9efb4c88d2 Mon Sep 17 00:00:00 2001 From: Yesudeep Mangalapilly Date: Mon, 25 Oct 2021 06:12:41 -0700 Subject: Use more portable `#!/usr/bin/env bash` shebang instead of hardcoded /bin/bash. (#329) --- docs/regenerate_docs.sh | 2 +- rules/build_test.bzl | 2 +- rules/diff_test.bzl | 2 +- tests/analysis_test_test.sh | 2 +- tests/common_settings_test.sh | 2 +- tests/copy_file/BUILD | 2 +- tests/copy_file/a.txt | 2 +- tests/copy_file/a_with_exec_bit.txt | 2 +- tests/copy_file/copy_file_tests.sh | 10 +++++----- tests/diff_test/diff_test_tests.sh | 2 +- tests/run_binary/BUILD | 2 +- tests/shell_tests.bzl | 2 +- tests/unittest.bash | 4 ++-- tests/unittest_test.sh | 2 +- tests/write_file/BUILD | 2 +- tests/write_file/write_file_tests.sh | 2 +- 16 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/regenerate_docs.sh b/docs/regenerate_docs.sh index 26f397a..d16ea63 100755 --- a/docs/regenerate_docs.sh +++ b/docs/regenerate_docs.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # diff --git a/rules/build_test.bzl b/rules/build_test.bzl index 697875b..9ec8ab1 100644 --- a/rules/build_test.bzl +++ b/rules/build_test.bzl @@ -18,7 +18,7 @@ load("//lib:new_sets.bzl", "sets") def _empty_test_impl(ctx): extension = ".bat" if ctx.attr.is_windows else ".sh" - content = "exit 0" if ctx.attr.is_windows else "#!/bin/bash\nexit 0" + content = "exit 0" if ctx.attr.is_windows else "#!/usr/bin/env bash\nexit 0" executable = ctx.actions.declare_file(ctx.label.name + extension) ctx.actions.write( output = executable, diff --git a/rules/diff_test.bzl b/rules/diff_test.bzl index ff570e6..49a1968 100644 --- a/rules/diff_test.bzl +++ b/rules/diff_test.bzl @@ -86,7 +86,7 @@ if %ERRORLEVEL% neq 0 ( test_bin = ctx.actions.declare_file(ctx.label.name + "-test.sh") ctx.actions.write( output = test_bin, - content = r"""#!/bin/bash + content = r"""#!/usr/bin/env bash set -euo pipefail F1="{file1}" F2="{file2}" diff --git a/tests/analysis_test_test.sh b/tests/analysis_test_test.sh index db9bbac..2edae15 100755 --- a/tests/analysis_test_test.sh +++ b/tests/analysis_test_test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # diff --git a/tests/common_settings_test.sh b/tests/common_settings_test.sh index 531e830..1e3d03d 100755 --- a/tests/common_settings_test.sh +++ b/tests/common_settings_test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # diff --git a/tests/copy_file/BUILD b/tests/copy_file/BUILD index cacb5b1..2e6914c 100644 --- a/tests/copy_file/BUILD +++ b/tests/copy_file/BUILD @@ -169,5 +169,5 @@ copy_file( genrule( name = "gen", outs = ["b.txt"], - cmd = "echo -e '#!/bin/bash\necho potato' > $@", + cmd = "echo -e '#!/usr/bin/env bash\necho potato' > $@", ) diff --git a/tests/copy_file/a.txt b/tests/copy_file/a.txt index acd332a..37b2322 100644 --- a/tests/copy_file/a.txt +++ b/tests/copy_file/a.txt @@ -1,2 +1,2 @@ -#!/bin/bash +#!/usr/bin/env bash echo aaa diff --git a/tests/copy_file/a_with_exec_bit.txt b/tests/copy_file/a_with_exec_bit.txt index acd332a..37b2322 100755 --- a/tests/copy_file/a_with_exec_bit.txt +++ b/tests/copy_file/a_with_exec_bit.txt @@ -1,2 +1,2 @@ -#!/bin/bash +#!/usr/bin/env bash echo aaa diff --git a/tests/copy_file/copy_file_tests.sh b/tests/copy_file/copy_file_tests.sh index 90d79ee..737afd7 100755 --- a/tests/copy_file/copy_file_tests.sh +++ b/tests/copy_file/copy_file_tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # @@ -42,25 +42,25 @@ source "$(rlocation bazel_skylib/tests/unittest.bash)" \ function test_copy_src() { cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out.txt)" >"$TEST_log" - expect_log '^#!/bin/bash$' + expect_log '^#!/usr/bin/env bash$' expect_log '^echo aaa$' } function test_copy_src_symlink() { cat "$(rlocation bazel_skylib/tests/copy_file/out/a-out-symlink.txt)" >"$TEST_log" - expect_log '^#!/bin/bash$' + expect_log '^#!/usr/bin/env bash$' expect_log '^echo aaa$' } function test_copy_gen() { cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out.txt)" >"$TEST_log" - expect_log '^#!/bin/bash$' + expect_log '^#!/usr/bin/env bash$' expect_log '^echo potato$' } function test_copy_gen_symlink() { cat "$(rlocation bazel_skylib/tests/copy_file/out/gen-out-symlink.txt)" >"$TEST_log" - expect_log '^#!/bin/bash$' + expect_log '^#!/usr/bin/env bash$' expect_log '^echo potato$' } diff --git a/tests/diff_test/diff_test_tests.sh b/tests/diff_test/diff_test_tests.sh index 5af60aa..4b58e6c 100755 --- a/tests/diff_test/diff_test_tests.sh +++ b/tests/diff_test/diff_test_tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # diff --git a/tests/run_binary/BUILD b/tests/run_binary/BUILD index f511c03..85c10f3 100644 --- a/tests/run_binary/BUILD +++ b/tests/run_binary/BUILD @@ -82,7 +82,7 @@ write_file( "@echo>>%OUT% ENV_PATH_CMD=(%ENV_PATH_CMD%)", ], "//conditions:default": [ - "#!/bin/bash", + "#!/usr/bin/env bash", "echo > \"$OUT\" \"arg1=($1)\"", "echo >> \"$OUT\" \"arg2=($2)\"", "echo >> \"$OUT\" \"ENV_LOCATION=($ENV_LOCATION)\"", diff --git a/tests/shell_tests.bzl b/tests/shell_tests.bzl index 32d517f..5b83f9f 100644 --- a/tests/shell_tests.bzl +++ b/tests/shell_tests.bzl @@ -69,7 +69,7 @@ def _shell_args_test_gen_impl(ctx): "back`echo q`uote", ] script_content = "\n".join([ - "#!/bin/bash", + "#!/usr/bin/env bash", "myarray=" + shell.array_literal(args), 'output=$(echo "${myarray[@]}")', # For logging: diff --git a/tests/unittest.bash b/tests/unittest.bash index 3bd07c7..a43678d 100755 --- a/tests/unittest.bash +++ b/tests/unittest.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # # Copyright 2015 The Bazel Authors. All rights reserved. # @@ -21,7 +21,7 @@ # A typical test suite looks like so: # # ------------------------------------------------------------------------ -# #!/bin/bash +# #!/usr/bin/env bash # # source path/to/unittest.bash || exit 1 # diff --git a/tests/unittest_test.sh b/tests/unittest_test.sh index 1d941b3..4795b7e 100755 --- a/tests/unittest_test.sh +++ b/tests/unittest_test.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # diff --git a/tests/write_file/BUILD b/tests/write_file/BUILD index 9ea3609..e4f2a94 100644 --- a/tests/write_file/BUILD +++ b/tests/write_file/BUILD @@ -113,7 +113,7 @@ write_file( name = "write_nonempty_bin", out = "out/nonempty.sh", content = [ - "#!/bin/bash", + "#!/usr/bin/env bash", "echo potato", ], is_executable = True, diff --git a/tests/write_file/write_file_tests.sh b/tests/write_file/write_file_tests.sh index 0f48ca0..e7039d0 100755 --- a/tests/write_file/write_file_tests.sh +++ b/tests/write_file/write_file_tests.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2019 The Bazel Authors. All rights reserved. # -- cgit v1.2.3 From 6e30a77347071ab22ce346b6d20cf8912919f644 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Wed, 27 Oct 2021 09:13:59 -0400 Subject: 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 | 81 ++++++++-------- 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, 737 insertions(+), 436 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,73 +3,78 @@ 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", - 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", - ], -) - -load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") - -rules_pkg_dependencies() - maybe( - name = "bazel_federation", + name = "io_bazel_rules_go", 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", + sha256 = "2b1641428dff9018f9e85c0384f03ec6c10660d935b750e3fa1492a281a53b0f", + urls = [ + "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("@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("@io_bazel_rules_go//go:deps.bzl", "go_register_toolchains", "go_rules_dependencies") -load("@bazel_federation//setup:rules_go.bzl", "rules_go_setup") +go_rules_dependencies() -rules_go_setup() +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. -load("//:internal_deps.bzl", "bazel_skylib_internal_deps") +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", + ], +) -bazel_skylib_internal_deps() +load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories") -load("//:internal_setup.bzl", "bazel_skylib_internal_setup") +stardoc_repositories() -bazel_skylib_internal_setup() +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", + ], +) + +load("@rules_pkg//:deps.bzl", "rules_pkg_dependencies") + +rules_pkg_dependencies() 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 -- cgit v1.2.3 From ecc11f9a4c06400d4797e7132e71fe8702490cf0 Mon Sep 17 00:00:00 2001 From: Geoffrey Martin-Noble Date: Wed, 12 Jan 2022 08:28:43 -0800 Subject: Fix name arg documentation for native_binary (#338) --- docs/native_binary_doc.md | 2 +- rules/native_binary.bzl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/native_binary_doc.md b/docs/native_binary_doc.md index cb69179..1a330ca 100755 --- a/docs/native_binary_doc.md +++ b/docs/native_binary_doc.md @@ -26,7 +26,7 @@ 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 | +| name | The name of the 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 | diff --git a/rules/native_binary.bzl b/rules/native_binary.bzl index 6675a92..9a1725f 100644 --- a/rules/native_binary.bzl +++ b/rules/native_binary.bzl @@ -72,7 +72,7 @@ def native_binary(name, src, out, data = None, **kwargs): You can "bazel run" this rule like any other binary rule, and use it as a tool in genrule.tools for example. You can also augment the binary with runfiles. Args: - name: The name of the test rule. + name: The name of the rule. src: label; path of the pre-built executable out: output; an output name for the copy of the binary. (Bazel requires that this rule make a copy of 'src'.) data: list of labels; data dependencies -- cgit v1.2.3 From 1e1c324391d81b3c768e4a11e50106929953f348 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Thu, 10 Feb 2022 14:50:56 -0500 Subject: Fix linter warnings with new buildifier version. (#349) --- rules/analysis_test.bzl | 2 +- tests/selects_tests.bzl | 3 --- tests/unittest_tests.bzl | 5 +++-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/rules/analysis_test.bzl b/rules/analysis_test.bzl index 46d32dd..3420d48 100644 --- a/rules/analysis_test.bzl +++ b/rules/analysis_test.bzl @@ -16,7 +16,7 @@ def _analysis_test_impl(ctx): """Implementation function for analysis_test. """ - _ignore = [ctx] + _ignore = [ctx] # @unused return [AnalysisTestResultInfo( success = True, message = "All targets succeeded analysis", diff --git a/tests/selects_tests.bzl b/tests/selects_tests.bzl index 7a980e6..a7697f2 100644 --- a/tests/selects_tests.bzl +++ b/tests/selects_tests.bzl @@ -156,9 +156,6 @@ def _expect_doesnt_match(ctx): asserts.equals(env, False, attrval) return analysistest.end(env) -def _config_setting_group_test(name, config_settings): - return analysistest.make() - ################################################### # and_config_setting_group_matches_test ################################################### diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index 5541d74..47dcee0 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -122,7 +122,7 @@ def _failure_testing_test(ctx): return analysistest.end(env) def _failure_testing_fake_rule(ctx): - _ignore = [ctx] + _ignore = [ctx] # @unused fail("This rule should never work") failure_testing_fake_rule = rule( @@ -146,7 +146,7 @@ def _fail_unexpected_passing_test(ctx): return analysistest.end(env) def _fail_unexpected_passing_fake_rule(ctx): - _ignore = [ctx] + _ignore = [ctx] # @unused return [] fail_unexpected_passing_fake_rule = rule( @@ -227,6 +227,7 @@ _AddedByAspectInfo = provider( ) def _example_aspect_impl(target, ctx): + _ignore = [target, ctx] # @unused return [ _AddedByAspectInfo(value = "attached by aspect"), ] -- cgit v1.2.3 From 7270e3b345371c1b6bbb65f5598dcac48b3593bd Mon Sep 17 00:00:00 2001 From: Kevin Kress Date: Thu, 10 Feb 2022 13:03:48 -0800 Subject: Add support for 'loading' unit tests, which evaluate a LOADING phase. (#347) This is a relatively simple addition to unittest that statically creates rules that either explicitly fail or not depending on if the test case is valid during LOADING phase of bazel. The test conditions are evaluated entirely in loading phase, but if we want an actual test to fail rather than just `fail()` killing the build, we can use this to assert state and report test failures. --- docs/unittest_doc.md | 47 ++++++++++++++++++++++++++++++++++ lib/unittest.bzl | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ tests/unittest_tests.bzl | 12 ++++++++- 3 files changed, 124 insertions(+), 1 deletion(-) diff --git a/docs/unittest_doc.md b/docs/unittest_doc.md index 4384438..fe885f2 100755 --- a/docs/unittest_doc.md +++ b/docs/unittest_doc.md @@ -352,6 +352,53 @@ Asserts that the given `condition` is true. | 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." | + + +## loadingtest.make + +
+loadingtest.make(name)
+
+ +Creates a loading phase test environment and test_suite. + +**PARAMETERS** + + +| Name | Description | Default Value | +| :------------- | :------------- | :------------- | +| name | name of the suite of tests to create | none | + +**RETURNS** + +loading phase environment passed to other loadingtest functions + + + + +## loadingtest.equals + +
+loadingtest.equals(env, test_case, expected, actual)
+
+ +Creates a test case for asserting state at LOADING phase. + +**PARAMETERS** + + +| Name | Description | Default Value | +| :------------- | :------------- | :------------- | +| env | Loading test env created from loadingtest.make | none | +| test_case | Name of the test case | none | +| expected | Expected value to test | none | +| actual | Actual value received. | none | + +**RETURNS** + +None, creates test case + + ## register_unittest_toolchains diff --git a/lib/unittest.bzl b/lib/unittest.bzl index af851a3..feea621 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -564,6 +564,67 @@ def _target_under_test(env): fail("test rule does not have a target_under_test") return result +def _loading_test_impl(ctx): + tc = ctx.toolchains[TOOLCHAIN_TYPE].unittest_toolchain_info + content = tc.success_templ + if ctx.attr.failure_message: + content = tc.failure_templ % ctx.attr.failure_message + + testbin = ctx.actions.declare_file("loading_test_" + ctx.label.name + tc.file_ext) + ctx.actions.write( + output = testbin, + content = content, + is_executable = True, + ) + return [DefaultInfo(executable = testbin)] + +_loading_test = rule( + implementation = _loading_test_impl, + attrs = { + "failure_message": attr.string(), + }, + toolchains = [TOOLCHAIN_TYPE], + test = True, +) + +def _loading_make(name): + """Creates a loading phase test environment and test_suite. + + Args: + name: name of the suite of tests to create + + Returns: + loading phase environment passed to other loadingtest functions + """ + native.test_suite( + name = name + "_tests", + tags = [name + "_test_case"], + ) + return struct(name = name) + +def _loading_assert_equals(env, test_case, expected, actual): + """Creates a test case for asserting state at LOADING phase. + + Args: + env: Loading test env created from loadingtest.make + test_case: Name of the test case + expected: Expected value to test + actual: Actual value received. + + Returns: + None, creates test case + """ + + msg = None + if expected != actual: + msg = 'Expected "%s", but got "%s"' % (expected, actual) + + _loading_test( + name = "%s_%s" % (env.name, test_case), + failure_message = msg, + tags = [env.name + "_test_case"], + ) + asserts = struct( expect_failure = _expect_failure, equals = _assert_equals, @@ -590,3 +651,8 @@ analysistest = struct( target_bin_dir_path = _target_bin_dir_path, target_under_test = _target_under_test, ) + +loadingtest = struct( + make = _loading_make, + equals = _loading_assert_equals, +) diff --git a/tests/unittest_tests.bzl b/tests/unittest_tests.bzl index 47dcee0..2f326a0 100644 --- a/tests/unittest_tests.bzl +++ b/tests/unittest_tests.bzl @@ -15,7 +15,7 @@ """Unit tests for unittest.bzl.""" load("//lib:partial.bzl", "partial") -load("//lib:unittest.bzl", "analysistest", "asserts", "unittest") +load("//lib:unittest.bzl", "analysistest", "asserts", "loadingtest", "unittest") ################################### ####### basic_failing_test ######## @@ -308,6 +308,13 @@ inspect_output_dirs_test = analysistest.make( }, ) +def _loading_phase_test(env): + loadingtest.equals(env, "self_glob", ["unittest_tests.bzl"], native.glob(["unittest_tests.bzl"])) + + # now use our own calls to assert we created a test case rule and test_suite for it. + loadingtest.equals(env, "test_exists", True, native.existing_rule(env.name + "_self_glob") != None) + loadingtest.equals(env, "suite_exists", True, native.existing_rule(env.name + "_tests") != None) + ######################################### # buildifier: disable=unnamed-macro @@ -377,3 +384,6 @@ def unittest_passing_tests_suite(): name = "inspect_output_dirs_fake_target", tags = ["manual"], ) + + loading_env = loadingtest.make("selftest") + _loading_phase_test(loading_env) -- cgit v1.2.3 From 2bc90bdf7dc9914d126cf8594c3838494fc00d19 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Thu, 10 Feb 2022 14:00:29 -0800 Subject: Allow unit test rules to be documented (#343) I find it more ergonomic to add notes or a description about a test to a `doc` attribute, similar to other rules, vs a comment block above it or in the `impl` function docstring. Hopefully this can improve the readability of test rules. --- docs/unittest_doc.md | 3 ++- lib/unittest.bzl | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/unittest_doc.md b/docs/unittest_doc.md index fe885f2..754ea32 100755 --- a/docs/unittest_doc.md +++ b/docs/unittest_doc.md @@ -37,7 +37,7 @@ unittest_toolchain(name, impl, expect_failure, attrs, fragments, config_settings, +analysistest.make(impl, doc, expect_failure, attrs, fragments, config_settings, extra_target_under_test_aspects)
@@ -73,6 +73,7 @@ Recall that names of test rules must end in `_test`. | Name | Description | Default Value | | :------------- | :------------- | :------------- | | impl | The implementation function of the unit test. | none | +| doc | A description of the rule that can be extracted by documentation generating tools. | "" | | 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. | [] | diff --git a/lib/unittest.bzl b/lib/unittest.bzl index feea621..519720c 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -206,6 +206,7 @@ _action_retrieving_aspect = aspect( # TODO(cparsons): Provide more full documentation on analysis testing in README. def _make_analysis_test( impl, + doc = "", expect_failure = False, attrs = {}, fragments = [], @@ -238,6 +239,7 @@ def _make_analysis_test( Args: impl: The implementation function of the unit test. + doc: A description of the rule that can be extracted by documentation generating tools. 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 attrs: An optional dictionary to supplement the attrs passed to the @@ -277,6 +279,7 @@ def _make_analysis_test( return rule( impl, + doc = doc, attrs = attrs, fragments = fragments, test = True, -- cgit v1.2.3 From cdd0afdfe63afedac43fd15c1d60bd23b2241e24 Mon Sep 17 00:00:00 2001 From: UebelAndre Date: Thu, 10 Feb 2022 14:55:11 -0800 Subject: Fixed positional args for unittest targets (#352) Followup to https://github.com/bazelbuild/bazel-skylib/pull/343 --- docs/unittest_doc.md | 6 +++--- lib/unittest.bzl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/unittest_doc.md b/docs/unittest_doc.md index 754ea32..5472d74 100755 --- a/docs/unittest_doc.md +++ b/docs/unittest_doc.md @@ -37,8 +37,8 @@ unittest_toolchain(name, impl, doc, expect_failure, attrs, fragments, config_settings, - extra_target_under_test_aspects) +analysistest.make(impl, expect_failure, attrs, fragments, config_settings, + extra_target_under_test_aspects, doc)
Creates an analysis test rule from its implementation function. @@ -73,12 +73,12 @@ Recall that names of test rules must end in `_test`. | Name | Description | Default Value | | :------------- | :------------- | :------------- | | impl | The implementation function of the unit test. | none | -| doc | A description of the rule that can be extracted by documentation generating tools. | "" | | 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. | [] | +| doc | A description of the rule that can be extracted by documentation generating tools. | "" | **RETURNS** diff --git a/lib/unittest.bzl b/lib/unittest.bzl index 519720c..3757b08 100644 --- a/lib/unittest.bzl +++ b/lib/unittest.bzl @@ -206,12 +206,12 @@ _action_retrieving_aspect = aspect( # TODO(cparsons): Provide more full documentation on analysis testing in README. def _make_analysis_test( impl, - doc = "", expect_failure = False, attrs = {}, fragments = [], config_settings = {}, - extra_target_under_test_aspects = []): + extra_target_under_test_aspects = [], + doc = ""): """Creates an analysis test rule from its implementation function. An analysis test verifies the behavior of a "real" rule target by examining @@ -239,7 +239,6 @@ def _make_analysis_test( Args: impl: The implementation function of the unit test. - doc: A description of the rule that can be extracted by documentation generating tools. 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 attrs: An optional dictionary to supplement the attrs passed to the @@ -252,6 +251,7 @@ def _make_analysis_test( 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. + doc: A description of the rule that can be extracted by documentation generating tools. Returns: A rule definition that should be stored in a global whose name ends in -- cgit v1.2.3 From c4dfec1bf1316ab4e9fffbb382cf48259e0944fb Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Fri, 11 Feb 2022 12:02:05 -0500 Subject: Update changelog and version for release 1.2.0 (#350) --- CHANGELOG.md | 17 +++++++++++++++++ version.bzl | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 16b937c..b43ca8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,20 @@ +Release 1.2.0 + +**New Features** + +- The unittest toolchain has better support for special characters in failure + messages (#320) +- Use portable Bash shebangs for BSD compatibility (#329) +- Add loadingtest - tests which evaluate during the loading phase (#347) +- Add doc parameter to analysistest.make, allowing analysis tests to be + documented in a Stardoc-friendly way (#343, #352) + +**Contributors** + +Alexandre Rostovtsev, Geoffrey Martin-Noble, Kevin Kress, Samuel Freilich, +UebelAndre, Yesudeep Mangalapilly + + Release 1.1.1 (initially tagged as 1.1.0) **New Features** diff --git a/version.bzl b/version.bzl index bd2fb19..dc7f0ef 100644 --- a/version.bzl +++ b/version.bzl @@ -13,4 +13,4 @@ # limitations under the License. """The version of bazel-skylib.""" -version = "1.1.1" +version = "1.2.0" -- cgit v1.2.3 From e30197f3799eb038fbed424e365573f493d52fa5 Mon Sep 17 00:00:00 2001 From: Ivo List Date: Wed, 23 Feb 2022 15:43:39 +0100 Subject: Extend owners of skylib. (#355) --- CODEOWNERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CODEOWNERS b/CODEOWNERS index a78f3c9..99094d4 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -1,3 +1,3 @@ # More details on syntax here: https://help.github.com/articles/about-codeowners/ -* @brandjon @tetromino +* @brandjon @tetromino @comius @hvadehra @c-mita /gazelle/ @achew22 @jayconrod -- cgit v1.2.3 From 5bffd04256c07a935c884339b433ca9e1d5c9a8e Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Wed, 23 Feb 2022 20:06:15 -0500 Subject: Add a maintainer's guide (#356) --- README.md | 5 ++ docs/maintainers_guide.md | 114 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 docs/maintainers_guide.md diff --git a/README.md b/README.md index 0eb832f..58e0878 100644 --- a/README.md +++ b/README.md @@ -119,3 +119,8 @@ ERROR: Analysis of target '//foo:bar' failed; build aborted: no matching toolcha then you probably forgot to load and call `bazel_skylib_workspace()` in your `WORKSPACE` file. + +### Maintainer's guide + +See the [maintaner's guide](docs/maintainers_guide.md) for instructions for +cutting a new release. diff --git a/docs/maintainers_guide.md b/docs/maintainers_guide.md new file mode 100644 index 0000000..8a009c2 --- /dev/null +++ b/docs/maintainers_guide.md @@ -0,0 +1,114 @@ +# Skylib Maintainer's Guide + +## The Parts of Skylib + +* `bzl_library.bzl` - used by almost all rule sets, and thus requiring + especial attention to maintaining backwards compatibility. Ideally, it ought + to be moved out of Skylib and and into Bazel's bundled `@bazel_tools` repo + (see https://github.com/bazelbuild/bazel-skylib/issues/127). +* Test libraries - `rules/analysis_test.bzl`, `rules/build_test.bzl`, + `lib/unittest.bzl`; these are under more active development than the rest of + Skylib, because we want to provide rule authors with a good testing story. + Ideally, these ought to be moved out of Skylib and evolved at a faster pace. +* A kitchen sink of utility modules (everything else). Formerly, these + features were piled on in a rather haphazard manner. For any new additions, + we want to be more conservative: add a feature only if it is widely needed + (or was already independently implemented in multiple rule sets), if the + interface is unimpeachable, if level of abstraction is not shallow, and the + implementation is efficient. + +## PR Review Standards + +Because Skylib is so widely used, breaking backwards compatibility can cause +widespread pain, and shouldn't be done lightly. Therefore: + +1. In the first place, avoid adding insufficiently thought out, insufficiently + tested features which will later need to be replaced in a + backwards-incompatible manner. See the criteria in README.md. +2. Given a choice between breaking backwards compatibilty and keeping it, try + to keep backwards compatibility. For example, if adding a new argument to a + function, add it to the end of the argument list, so that existing callers' + positional arguments continue to work. +3. Keep Skylib out-of-the-box compatible with the current stable Bazel release + (ideally - with two most recent stable releases). + * For example, when adding a new function which calls the new + `native.foobar()` method which was introduced in the latest Bazel + pre-release or is gated behind an `--incompatible` flag, use an `if + hasattr(native, "foobar")` check to keep the rest of your module (which + doesn't need `native.foobar()`) working even when `native.foobar()` is + not available. + +In addition, make sure that new code is documented and tested. + +If a PR adds or changes any docstrings, check that Markdown docs in `docs` +directory are updated; if not, ask the PR author to run +`./docs/regenerate_docs.sh`. (See +https://github.com/bazelbuild/bazel-skylib/pull/321 for the proposal to automate +this.) + +## Making a New Release + +1. Update CHANGELOG.md at the top. You may want to use the following template: + +-------------------------------------------------------------------------------- + +Release $VERSION + +**New Features** + +- Feature +- Feature + +**Incompatible Changes** + +- Change +- Change + +**Contributors** + +Name 1, Name 2, Name 3 (alphabetically from `git log`) + +-------------------------------------------------------------------------------- + +2. Bump `version` in version.bzl to the new version. +3. Ensure that the commits for steps 1 and 2 have been merged. All further + steps must be performed on a single, known-good git commit. +4. `bazel build //distribution:bazel-skylib-$VERSION.tar.gz` +5. Copy the `bazel-skylib-$VERSION.tar.gz` tarball to the mirror (you'll need + Bazel developer gcloud credentials; assuming you are a Bazel developer, you + can obtain them via `gcloud init`): + +``` +gsutil cp bazel-bin/distro/bazel-skylib-$VERSION.tar.gz gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz +gsutil setmeta -h "Cache-Control: public, max-age=31536000" "gs://bazel-mirror/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz" +``` + +6. Run `sha256sum bazel-bin/distro/bazel-skylib-$VERSION.tar.gz`; you'll need + the checksum for the release notes. +7. Draft a new release with a new tag named $VERSION in github. Attach + `bazel-skylib-$VERSION.tar.gz` to the release. For the release notes, use + the CHANGELOG.md entry plus the following template: + +-------------------------------------------------------------------------------- + +**WORKSPACE setup** + +``` +load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") +http_archive( + name = "bazel_skylib", + urls = [ + "https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz", + "https://github.com/bazelbuild/bazel-skylib/releases/download/$VERSION/bazel-skylib-$VERSION.tar.gz", + ], + sha256 = "$SHA256SUM", +) +load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace") +bazel_skylib_workspace() +``` + +**Using the rules** + +See [the source](https://github.com/bazelbuild/bazel-skylib/tree/$VERSION). + +-------------------------------------------------------------------------------- \ No newline at end of file -- cgit v1.2.3 From 898cd6ddffee2a29a013ae9b70411cfe0ad16268 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Thu, 10 Mar 2022 07:41:11 -0500 Subject: Remove unused, empty //rules:bins filegroup, allowing us to simplify distribution/BUILD (#359) //rules:bins has not been used since 14f17ae7f71f347b5e720fca55e33df40bc4e5d5 Alternative to https://github.com/bazelbuild/bazel-skylib/pull/358 --- BUILD | 7 ------- distribution/BUILD | 26 ++------------------------ rules/BUILD | 8 -------- 3 files changed, 2 insertions(+), 39 deletions(-) diff --git a/BUILD b/BUILD index d61528f..fd7798b 100644 --- a/BUILD +++ b/BUILD @@ -75,10 +75,3 @@ filegroup( "//toolchains/unittest:distribution", ] + glob(["*.bzl"]), ) - -filegroup( - name = "bins", - srcs = [ - "//rules:bins", - ], -) diff --git a/distribution/BUILD b/distribution/BUILD index ba903aa..8a9b1e7 100644 --- a/distribution/BUILD +++ b/distribution/BUILD @@ -6,37 +6,15 @@ package( default_visibility = ["//visibility:private"], ) -pkg_tar( - name = "srcs", - srcs = ["//:distribution"], - mode = "0444", - # Make it owned by root so it does not have the uid of the CI robot. - owner = "0.0", - package_dir = "", - strip_prefix = ".", -) - -pkg_tar( - name = "bins", - srcs = ["//:bins"], - mode = "0555", - # Make it owned by root so it does not have the uid of the CI robot. - owner = "0.0", - package_dir = "", - strip_prefix = ".", -) - # Build the artifact to put on the github release page. pkg_tar( name = "bazel-skylib-%s" % version, + srcs = ["//:distribution"], extension = "tar.gz", + mode = "0644", # Make it owned by root so it does not have the uid of the CI robot. owner = "0.0", strip_prefix = ".", - deps = [ - ":bins.tar", - ":srcs.tar", - ], ) print_rel_notes( diff --git a/rules/BUILD b/rules/BUILD index 6bb55b9..f7017bb 100644 --- a/rules/BUILD +++ b/rules/BUILD @@ -68,14 +68,6 @@ filegroup( ], ) -filegroup( - name = "bins", - srcs = glob(["*.sh"]), - visibility = [ - "//:__pkg__", - ], -) - # export bzl files for the documentation exports_files( glob(["*.bzl"]), -- cgit v1.2.3 From ee67264452174896741824ed25ade0f6d58ca642 Mon Sep 17 00:00:00 2001 From: Alexandre Rostovtsev Date: Thu, 10 Mar 2022 11:31:05 -0500 Subject: Update changelog and version for release 1.2.1 (#360) Make a point release to unbreak users who set `--incompatible_disallow_empty_glob`. See discussion in https://github.com/bazelbuild/bazel-skylib/pull/359 --- CHANGELOG.md | 10 ++++++++++ version.bzl | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b43ca8d..4567ed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +Release 1.2.1 + +Bugfix release: fixes build failure with --incompatible_disallow_empty_glob +(#359) + +**Contributors** + +Alexandre Rostovtsev, Ivo List + + Release 1.2.0 **New Features** diff --git a/version.bzl b/version.bzl index dc7f0ef..324adb5 100644 --- a/version.bzl +++ b/version.bzl @@ -13,4 +13,4 @@ # limitations under the License. """The version of bazel-skylib.""" -version = "1.2.0" +version = "1.2.1" -- cgit v1.2.3