Remove vendored skylib except versions.bzl (#2083) Files loaded from //go:deps.bzl cannot depend on @bazel_skylib, so they'll continue using the vendored copy. They only need versions.bzl, which doesn't have compatibility problems. Files loaded from //go:def.bzl should depend on @bazel_skylib. Fixes #2071
diff --git a/WORKSPACE b/WORKSPACE index 0f87005..35563b6 100644 --- a/WORKSPACE +++ b/WORKSPACE
@@ -13,6 +13,7 @@ name = "bazel_gazelle", commit = "aa1a9cfe4845bc83482af92addbfcd41f8dc51f0", # master as of 2019-01-27 remote = "https://github.com/bazelbuild/bazel-gazelle", + shallow_since = "1548631399 -0500", ) load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")
diff --git a/go/private/actions/archive.bzl b/go/private/actions/archive.bzl index 656a7fa..9b96e17 100644 --- a/go/private/actions/archive.bzl +++ b/go/private/actions/archive.bzl
@@ -13,7 +13,7 @@ # limitations under the License. load( - "@io_bazel_rules_go//go/private:skylib/lib/sets.bzl", + "@bazel_skylib//lib:sets.bzl", "sets", ) load(
diff --git a/go/private/actions/asm.bzl b/go/private/actions/asm.bzl index 98b55be..1a3a9ab 100644 --- a/go/private/actions/asm.bzl +++ b/go/private/actions/asm.bzl
@@ -13,7 +13,7 @@ # limitations under the License. load( - "@io_bazel_rules_go//go/private:skylib/lib/sets.bzl", + "@bazel_skylib//lib:sets.bzl", "sets", ) load(
diff --git a/go/private/actions/compile.bzl b/go/private/actions/compile.bzl index 2e94276..4b86891 100644 --- a/go/private/actions/compile.bzl +++ b/go/private/actions/compile.bzl
@@ -17,7 +17,7 @@ "link_mode_args", ) load( - "@io_bazel_rules_go//go/private:skylib/lib/shell.bzl", + "@bazel_skylib//lib:shell.bzl", "shell", )
diff --git a/go/private/actions/cover.bzl b/go/private/actions/cover.bzl index ce016cc..960fe1e 100644 --- a/go/private/actions/cover.bzl +++ b/go/private/actions/cover.bzl
@@ -18,7 +18,7 @@ "effective_importpath_pkgpath", ) load( - "@io_bazel_rules_go//go/private:skylib/lib/structs.bzl", + "@bazel_skylib//lib:structs.bzl", "structs", )
diff --git a/go/private/actions/link.bzl b/go/private/actions/link.bzl index eb04076..8e9f734 100644 --- a/go/private/actions/link.bzl +++ b/go/private/actions/link.bzl
@@ -13,10 +13,14 @@ # limitations under the License. load( - "@io_bazel_rules_go//go/private:skylib/lib/sets.bzl", + "@bazel_skylib//lib:sets.bzl", "sets", ) load( + "@bazel_skylib//lib:shell.bzl", + "shell", +) +load( "@io_bazel_rules_go//go/private:common.bzl", "as_iterable", "has_shared_lib_extension", @@ -28,10 +32,6 @@ "extld_from_cc_toolchain", "extldflags_from_cc_toolchain", ) -load( - "@io_bazel_rules_go//go/private:skylib/lib/shell.bzl", - "shell", -) def _format_archive(d): return "{}={}={}".format(d.label, d.importmap, d.file.path)
diff --git a/go/private/context.bzl b/go/private/context.bzl index 4062110..3b718ac 100644 --- a/go/private/context.bzl +++ b/go/private/context.bzl
@@ -57,17 +57,13 @@ "goos_to_shared_extension", ) load( - "@io_bazel_rules_go//go/private:skylib/lib/paths.bzl", - "paths", -) -load( - "@io_bazel_rules_go//go/private:skylib/lib/structs.bzl", - "structs", -) -load( "@io_bazel_rules_go//go/platform:apple.bzl", "apple_ensure_options", ) +load( + "@bazel_skylib//lib:paths.bzl", + "paths", +) GoContext = provider() _GoContextData = provider()
diff --git a/go/private/rules/aspect.bzl b/go/private/rules/aspect.bzl index d6d9566..04d0944 100644 --- a/go/private/rules/aspect.bzl +++ b/go/private/rules/aspect.bzl
@@ -13,7 +13,7 @@ # limitations under the License. load( - "@io_bazel_rules_go//go/private:skylib/lib/sets.bzl", + "@bazel_skylib//lib:sets.bzl", "sets", ) load(
diff --git a/go/private/rules/cgo.bzl b/go/private/rules/cgo.bzl index c5c1a1d..6150743 100644 --- a/go/private/rules/cgo.bzl +++ b/go/private/rules/cgo.bzl
@@ -13,7 +13,7 @@ # limitations under the License. load( - "@io_bazel_rules_go//go/private:skylib/lib/sets.bzl", + "@bazel_skylib//lib:sets.bzl", "sets", ) load(
diff --git a/go/private/skylib/README.rst b/go/private/skylib/README.rst index 2a2db0c..ba8f034 100644 --- a/go/private/skylib/README.rst +++ b/go/private/skylib/README.rst
@@ -1,7 +1,10 @@ -This directory is a copy of github.com/bazelbuild/bazel-skylib/lib. +This directory is a partial copy of github.com/bazelbuild/bazel-skylib/lib. Version 0.5.0, retrieved on 2018-11-26. +Only versions.bzl is included right now. -This is needed only until nested workspaces works. -It has to be copied in because we use the functionality inside code that -go_rules_dependencies itself depends on, which means we cannot automatically -add the skylib dependency. +versions.bzl is needed by repository rules imported from //go:deps.bzl. +In particular, it's needed to check the minimum Bazel version and to choose +an implementation for io_bazel_rules_go_compat based on the Bazel version. + +Uses of Skylib outside of files loaded by //go:deps.bzl should use +the external Skylib repository, @bazel_skylib.
diff --git a/go/private/skylib/lib/collections.bzl b/go/private/skylib/lib/collections.bzl deleted file mode 100644 index de612ff..0000000 --- a/go/private/skylib/lib/collections.bzl +++ /dev/null
@@ -1,69 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Skylib module containing functions that operate on collections.""" - -def _after_each(separator, iterable): - """Inserts `separator` after each item in `iterable`. - - Args: - separator: The value to insert after each item in `iterable`. - iterable: The list into which to intersperse the separator. - - Returns: - A new list with `separator` after each item in `iterable`. - """ - result = [] - for x in iterable: - result.append(x) - result.append(separator) - - return result - -def _before_each(separator, iterable): - """Inserts `separator` before each item in `iterable`. - - Args: - separator: The value to insert before each item in `iterable`. - iterable: The list into which to intersperse the separator. - - Returns: - A new list with `separator` before each item in `iterable`. - """ - result = [] - for x in iterable: - result.append(separator) - result.append(x) - - return result - -def _uniq(iterable): - """Returns a list of unique elements in `iterable`. - - Requires all the elements to be hashable. - - Args: - iterable: An iterable to filter. - - Returns: - A new list with all unique elements from `iterable`. - """ - unique_elements = {element: None for element in iterable} - return unique_elements.keys() - -collections = struct( - after_each = _after_each, - before_each = _before_each, - uniq = _uniq, -)
diff --git a/go/private/skylib/lib/dicts.bzl b/go/private/skylib/lib/dicts.bzl deleted file mode 100644 index f702fa9..0000000 --- a/go/private/skylib/lib/dicts.bzl +++ /dev/null
@@ -1,41 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Skylib module containing functions that operate on dictionaries.""" - -def _add(*dictionaries): - """Returns a new `dict` that has all the entries of the given dictionaries. - - If the same key is present in more than one of the input dictionaries, the - last of them in the argument list overrides any earlier ones. - - This function is designed to take zero or one arguments as well as multiple - dictionaries, so that it follows arithmetic identities and callers can avoid - 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. - - Args: - *dictionaries: Zero or more dictionaries to be added. - - Returns: - A new `dict` that has all the entries of the given dictionaries. - """ - result = {} - for d in dictionaries: - result.update(d) - return result - -dicts = struct( - add = _add, -)
diff --git a/go/private/skylib/lib/new_sets.bzl b/go/private/skylib/lib/new_sets.bzl deleted file mode 100644 index 3e203c1..0000000 --- a/go/private/skylib/lib/new_sets.bzl +++ /dev/null
@@ -1,236 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Skylib module containing 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)`. -""" - -load(":skylib/lib/dicts.bzl", "dicts") - -def _make(elements = None): - """Creates a new set. - - All elements must be hashable. - - Args: - elements: Optional sequence to construct the set out of. - - Returns: - A set containing the passed in values. - """ - elements = elements if elements else [] - return struct(_values = {e: None for e in elements}) - -def _copy(s): - """Creates a new set from another set. - - Args: - s: A set, as returned by `sets.make()`. - - Returns: - A new set containing the same elements as `s`. - """ - return struct(_values = dict(s._values)) - -def _to_list(s): - """Creates a list from the values in the set. - - Args: - s: A set, as returned by `sets.make()`. - - Returns: - A list of values inserted into the set. - """ - return s._values.keys() - -def _insert(s, e): - """Inserts an element into the set. - - Element must be hashable. This mutates the orginal set. - - Args: - s: A set, as returned by `sets.make()`. - e: The element to be inserted. - - Returns: - The set `s` with `e` included. - """ - s._values[e] = None - return s - -def _remove(s, e): - """Removes an element from the set. - - Element must be hashable. This mutates the orginal set. - - Args: - s: A set, as returned by `sets.make()`. - e: The element to be removed. - - Returns: - The set `s` with `e` removed. - """ - s._values.pop(e) - return s - -def _contains(a, e): - """Checks for the existence of an element in a set. - - Args: - a: A set, as returned by `sets.make()`. - e: The element to look for. - - Returns: - True if the element exists in the set, False if the element does not. - """ - return e in a._values - -def _get_shorter_and_longer(a, b): - """Returns two sets in the order of shortest and longest. - - Args: - a: A set, as returned by `sets.make()`. - b: A set, as returned by `sets.make()`. - - Returns: - `a`, `b` if `a` is shorter than `b` - or `b`, `a` if `b` is shorter than `a`. - """ - if _length(a) < _length(b): - return a, b - return b, a - -def _is_equal(a, b): - """Returns whether two sets are equal. - - Args: - a: A set, as returned by `sets.make()`. - b: A set, as returned by `sets.make()`. - - Returns: - True if `a` is equal to `b`, False otherwise. - """ - return a._values == b._values - -def _is_subset(a, b): - """Returns whether `a` is a subset of `b`. - - Args: - a: A set, as returned by `sets.make()`. - b: A set, as returned by `sets.make()`. - - Returns: - True if `a` is a subset of `b`, False otherwise. - """ - for e in a._values.keys(): - if e not in b._values: - return False - return True - -def _disjoint(a, b): - """Returns whether two sets are disjoint. - - Two sets are disjoint if they have no elements in common. - - Args: - a: A set, as returned by `sets.make()`. - b: A set, as returned by `sets.make()`. - - Returns: - True if `a` and `b` are disjoint, False otherwise. - """ - shorter, longer = _get_shorter_and_longer(a, b) - for e in shorter._values.keys(): - if e in longer._values: - return False - return True - -def _intersection(a, b): - """Returns the intersection of two sets. - - Args: - a: A set, as returned by `sets.make()`. - b: A set, as returned by `sets.make()`. - - Returns: - A set containing the elements that are in both `a` and `b`. - """ - shorter, longer = _get_shorter_and_longer(a, b) - return struct(_values = {e: None for e in shorter._values.keys() if e in longer._values}) - -def _union(*args): - """Returns the union of several sets. - - Args: - *args: An arbitrary number of sets or lists. - - Returns: - The set union of all sets or lists in `*args`. - """ - return struct(_values = dicts.add(*[s._values for s in args])) - -def _difference(a, b): - """Returns the elements in `a` that are not in `b`. - - Args: - a: A set, as returned by `sets.make()`. - b: A set, as returned by `sets.make()`. - - Returns: - A set containing the elements that are in `a` but not in `b`. - """ - return struct(_values = {e: None for e in a._values.keys() if e not in b._values}) - -def _length(s): - """Returns the number of elements in a set. - - Args: - s: A set, as returned by `sets.make()`. - - Returns: - An integer representing the number of elements in the set. - """ - return len(s._values) - -def _repr(s): - """Returns a string value representing the set. - - Args: - s: A set, as returned by `sets.make()`. - - Returns: - A string representing the set. - """ - return repr(s._values.keys()) - -sets = struct( - make = _make, - copy = _copy, - to_list = _to_list, - insert = _insert, - contains = _contains, - is_equal = _is_equal, - is_subset = _is_subset, - disjoint = _disjoint, - intersection = _intersection, - union = _union, - difference = _difference, - length = _length, - remove = _remove, - repr = _repr, - str = _repr, -)
diff --git a/go/private/skylib/lib/partial.bzl b/go/private/skylib/lib/partial.bzl deleted file mode 100644 index d70aa0f..0000000 --- a/go/private/skylib/lib/partial.bzl +++ /dev/null
@@ -1,130 +0,0 @@ -# Copyright 2018 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. - -"""Skylark 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. -""" - -def _call(partial, *args, **kwargs): - """Calls a partial created using `make`. - - Args: - partial: The partial to be called. - *args: Additional positional arguments to be appended to the ones given to - make. - **kwargs: Additional keyword arguments to augment and override the ones - given to make. - - Returns: - Whatever the function in the partial returns. - """ - function_args = partial.args + args - function_kwargs = dict(partial.kwargs) - function_kwargs.update(kwargs) - return partial.function(*function_args, **function_kwargs) - -def _make(func, *args, **kwargs): - """Creates a partial that can be called using `call`. - - A partial can have args assigned to it at the make site, and can have args - 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 - 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 + "!") - - 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 - keyword args given to call take precedence. This allows you to set a default - 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) - - Args: - func: The function to be called. - *args: Positional arguments to be passed to function. - **kwargs: Keyword arguments to be passed to function. Note that these can - be overridden at the call sites. - - Returns: - A new `partial` that can be called using `call` - """ - return struct(function = func, args = args, kwargs = kwargs) - -partial = struct( - make = _make, - call = _call, -)
diff --git a/go/private/skylib/lib/paths.bzl b/go/private/skylib/lib/paths.bzl deleted file mode 100644 index 8e3fcae..0000000 --- a/go/private/skylib/lib/paths.bzl +++ /dev/null
@@ -1,242 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Skylib module containing 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. -""" - -def _basename(p): - """Returns the basename (i.e., the file portion) of a path. - - Note that if `p` ends with a slash, this function returns an empty string. - This matches the behavior of Python's `os.path.basename`, but differs from - the Unix `basename` command (which would return the path segment preceding - the final slash). - - Args: - p: The path whose basename should be returned. - - Returns: - The basename of the path, which includes the extension. - """ - return p.rpartition("/")[-1] - -def _dirname(p): - """Returns the dirname of a path. - - The dirname is the portion of `p` up to but not including the file portion - (i.e., the basename). Any slashes immediately preceding the basename are not - included, unless omitting them would make the dirname empty. - - Args: - p: The path whose dirname should be returned. - - Returns: - The dirname of the path. - """ - prefix, sep, _ = p.rpartition("/") - if not prefix: - return sep - else: - # If there are multiple consecutive slashes, strip them all out as Python's - # os.path.dirname does. - return prefix.rstrip("/") - -def _is_absolute(path): - """Returns `True` if `path` is an absolute path. - - Args: - path: A path (which is a string). - - Returns: - `True` if `path` is an absolute path. - """ - return path.startswith("/") or (len(path) > 2 and path[1] == ":") - -def _join(path, *others): - """Joins one or more path components intelligently. - - This function mimics the behavior of Python's `os.path.join` function on POSIX - platform. It returns the concatenation of `path` and any members of `others`, - inserting directory separators before each component except the first. The - separator is not inserted if the path up until that point is either empty or - already ends in a separator. - - If any component is an absolute path, all previous components are discarded. - - Args: - path: A path segment. - *others: Additional path segments. - - Returns: - A string containing the joined paths. - """ - result = path - - for p in others: - if _is_absolute(p): - result = p - elif not result or result.endswith("/"): - result += p - else: - result += "/" + p - - return result - -def _normalize(path): - """Normalizes a path, eliminating double slashes and other redundant segments. - - This function mimics the behavior of Python's `os.path.normpath` function on - POSIX platforms; specifically: - - - If the entire path is empty, "." is returned. - - All "." segments are removed, unless the path consists solely of a single - "." segment. - - Trailing slashes are removed, unless the path consists solely of slashes. - - ".." segments are removed as long as there are corresponding segments - earlier in the path to remove; otherwise, they are retained as leading ".." - segments. - - Single and double leading slashes are preserved, but three or more leading - slashes are collapsed into a single leading slash. - - Multiple adjacent internal slashes are collapsed into a single slash. - - Args: - path: A path. - - Returns: - The normalized path. - """ - if not path: - return "." - - if path.startswith("//") and not path.startswith("///"): - initial_slashes = 2 - elif path.startswith("/"): - initial_slashes = 1 - else: - initial_slashes = 0 - is_relative = (initial_slashes == 0) - - components = path.split("/") - new_components = [] - - for component in components: - if component in ("", "."): - continue - if component == "..": - if new_components and new_components[-1] != "..": - # Only pop the last segment if it isn't another "..". - new_components.pop() - elif is_relative: - # Preserve leading ".." segments for relative paths. - new_components.append(component) - else: - new_components.append(component) - - path = "/".join(new_components) - if not is_relative: - path = ("/" * initial_slashes) + path - - return path or "." - -def _relativize(path, start): - """Returns the portion of `path` that is relative to `start`. - - Because we do not have access to the underlying file system, this - implementation differs slightly from Python's `os.path.relpath` in that it - will fail if `path` is not beneath `start` (rather than use parent segments to - walk up to the common file system root). - - Relativizing paths that start with parent directory references only works if - the path both start with the same initial parent references. - - Args: - path: The path to relativize. - start: The ancestor path against which to relativize. - - Returns: - The portion of `path` that is relative to `start`. - """ - segments = _normalize(path).split("/") - start_segments = _normalize(start).split("/") - if start_segments == ["."]: - start_segments = [] - start_length = len(start_segments) - - if (path.startswith("/") != start.startswith("/") or - len(segments) < start_length): - fail("Path '%s' is not beneath '%s'" % (path, start)) - - for ancestor_segment, segment in zip(start_segments, segments): - if ancestor_segment != segment: - fail("Path '%s' is not beneath '%s'" % (path, start)) - - length = len(segments) - start_length - result_segments = segments[-length:] - return "/".join(result_segments) - -def _replace_extension(p, new_extension): - """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. - - Args: - p: The path whose extension should be replaced. - 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. - - Returns: - The path with the extension replaced (or added, if it did not have one). - """ - return _split_extension(p)[0] + new_extension - -def _split_extension(p): - """Splits the path `p` into a tuple containing the root and extension. - - Leading periods on the basename are ignored, so - `path.split_extension(".bashrc")` returns `(".bashrc", "")`. - - Args: - p: The path whose root and extension should be split. - - 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`. - """ - b = _basename(p) - last_dot_in_basename = b.rfind(".") - - # If there is no dot or the only dot in the basename is at the front, then - # there is no extension. - if last_dot_in_basename <= 0: - return (p, "") - - dot_distance_from_end = len(b) - last_dot_in_basename - return (p[:-dot_distance_from_end], p[-dot_distance_from_end:]) - -paths = struct( - basename = _basename, - dirname = _dirname, - is_absolute = _is_absolute, - join = _join, - normalize = _normalize, - relativize = _relativize, - replace_extension = _replace_extension, - split_extension = _split_extension, -)
diff --git a/go/private/skylib/lib/selects.bzl b/go/private/skylib/lib/selects.bzl deleted file mode 100755 index 4f9fea4..0000000 --- a/go/private/skylib/lib/selects.bzl +++ /dev/null
@@ -1,82 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Skylib module containing convenience interfaces for select().""" - -def _with_or(input_dict, no_match_error = ""): - """Drop-in replacement for `select()` that supports ORed keys. - - Args: - 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 `...`. - no_match_error: Optional custom error to report if no condition matches. - - Example: - - ```build - deps = selects.with_or({ - "//configs:one": [":dep1"], - ("//configs:two", "//configs:three"): [":dep2or3"], - "//configs:four": [":dep4"], - "//conditions:default": [":default"] - }) - ``` - - Key labels may appear at most once anywhere in the input. - - Returns: - A native `select()` that expands - - `("//configs:two", "//configs:three"): [":dep2or3"]` - - to - - ```build - "//configs:two": [":dep2or3"], - "//configs:three": [":dep2or3"], - ``` - """ - return select(_with_or_dict(input_dict), no_match_error = no_match_error) - -def _with_or_dict(input_dict): - """Variation of `with_or` that returns the dict of the `select()`. - - Unlike `select()`, the contents of the dict can be inspected by Skylark - macros. - - Args: - input_dict: Same as `with_or`. - - Returns: - A dictionary usable by a native `select()`. - """ - output_dict = {} - for (key, value) in input_dict.items(): - if type(key) == type(()): - for config_setting in key: - if config_setting in output_dict.keys(): - fail("key %s appears multiple times" % config_setting) - output_dict[config_setting] = value - else: - if key in output_dict.keys(): - fail("key %s appears multiple times" % key) - output_dict[key] = value - return output_dict - -selects = struct( - with_or = _with_or, - with_or_dict = _with_or_dict, -)
diff --git a/go/private/skylib/lib/sets.bzl b/go/private/skylib/lib/sets.bzl deleted file mode 100644 index 0c300fa..0000000 --- a/go/private/skylib/lib/sets.bzl +++ /dev/null
@@ -1,136 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Skylib module containing common set algorithms. - -CAUTION: Operating on sets, particularly sets contained in providers, may -asymptotically slow down the analysis phase. While constructing large sets with -addition/union is fast (there is no linear-time copy involved), the -`difference` function and various comparison predicates involve linear-time -traversals. - -For convenience, the functions in this module can take either sets or lists as -inputs; operations that take lists treat them as if they were sets (i.e., -duplicate elements are ignored). Functions that return new sets always return -them as the `set` type, regardless of the types of the inputs. -""" - -def _precondition_only_sets_or_lists(*args): - """Verifies that all arguments are either sets or lists. - - The build will fail if any of the arguments is neither a set nor a list. - - Args: - *args: A list of values that must be sets or lists. - """ - for a in args: - t = type(a) - if t not in ("depset", "list"): - fail("Expected arguments to be depset or list, but found type %s: %r" % - (t, a)) - -def _is_equal(a, b): - """Returns whether two sets are equal. - - Args: - a: A depset or a list. - b: A depset or a list. - - Returns: - True if `a` is equal to `b`, False otherwise. - """ - _precondition_only_sets_or_lists(a, b) - return sorted(depset(a)) == sorted(depset(b)) - -def _is_subset(a, b): - """Returns whether `a` is a subset of `b`. - - Args: - a: A depset or a list. - b: A depset or a list. - - Returns: - True if `a` is a subset of `b`, False otherwise. - """ - _precondition_only_sets_or_lists(a, b) - for e in a: - if e not in b: - return False - return True - -def _disjoint(a, b): - """Returns whether two sets are disjoint. - - Two sets are disjoint if they have no elements in common. - - Args: - a: A set or list. - b: A set or list. - - Returns: - True if `a` and `b` are disjoint, False otherwise. - """ - _precondition_only_sets_or_lists(a, b) - for e in a: - if e in b: - return False - return True - -def _intersection(a, b): - """Returns the intersection of two sets. - - Args: - a: A set or list. - b: A set or list. - - Returns: - A set containing the elements that are in both `a` and `b`. - """ - _precondition_only_sets_or_lists(a, b) - return depset([e for e in a if e in b]) - -def _union(*args): - """Returns the union of several sets. - - Args: - *args: An arbitrary number of sets or lists. - - Returns: - The set union of all sets or lists in `*args`. - """ - _precondition_only_sets_or_lists(*args) - args_deps = [depset(x) if type(x) == type([]) else x for x in args] - return depset(transitive = args_deps) - -def _difference(a, b): - """Returns the elements in `a` that are not in `b`. - - Args: - a: A set or list. - b: A set or list. - - Returns: - A set containing the elements that are in `a` but not in `b`. - """ - _precondition_only_sets_or_lists(a, b) - return depset([e for e in a if e not in b]) - -sets = struct( - difference = _difference, - disjoint = _disjoint, - intersection = _intersection, - is_equal = _is_equal, - is_subset = _is_subset, - union = _union, -)
diff --git a/go/private/skylib/lib/shell.bzl b/go/private/skylib/lib/shell.bzl deleted file mode 100644 index 4a851ca..0000000 --- a/go/private/skylib/lib/shell.bzl +++ /dev/null
@@ -1,54 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Skylib module containing shell utility functions.""" - -def _array_literal(iterable): - """Creates a string from a sequence that can be used as a shell array. - - For example, `shell.array_literal(["a", "b", "c"])` would return the string - `("a" "b" "c")`, which can be used in a shell script wherever an array - literal is needed. - - Note that all elements in the array are quoted (using `shell.quote`) for - safety, even if they do not need to be. - - Args: - iterable: A sequence of elements. Elements that are not strings will be - converted to strings first, by calling `str()`. - - Returns: - A string that represents the sequence as a shell array; that is, - parentheses containing the quoted elements. - """ - return "(" + " ".join([_quote(str(i)) for i in iterable]) + ")" - -def _quote(s): - """Quotes the given string for use in a shell command. - - This function quotes the given string (in case it contains spaces or other - shell metacharacters.) - - Args: - s: The string to quote. - - Returns: - A quoted version of the string that can be passed to a shell command. - """ - return "'" + s.replace("'", "'\\''") + "'" - -shell = struct( - array_literal = _array_literal, - quote = _quote, -)
diff --git a/go/private/skylib/lib/structs.bzl b/go/private/skylib/lib/structs.bzl deleted file mode 100644 index f291152..0000000 --- a/go/private/skylib/lib/structs.bzl +++ /dev/null
@@ -1,35 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""Skylib module containing functions that operate on structs.""" - -def _to_dict(s): - """Converts a `struct` to a `dict`. - - Args: - s: A `struct`. - - 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. - """ - attributes = dir(s) - attributes.remove("to_json") - attributes.remove("to_proto") - return {key: getattr(s, key) for key in attributes} - -structs = struct( - to_dict = _to_dict, -)
diff --git a/go/private/skylib/lib/types.bzl b/go/private/skylib/lib/types.bzl deleted file mode 100644 index 54061eb..0000000 --- a/go/private/skylib/lib/types.bzl +++ /dev/null
@@ -1,124 +0,0 @@ -# Copyright 2018 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -"""Skylib module containing functions checking types.""" - -# create instance singletons to avoid unnecessary allocations -_a_bool = True -_a_dict = {} -_a_list = [] -_a_string = "" -_a_tuple = () -_an_int = 1 - -def _a_function(): - pass - -def _is_list(v): - """Returns True if v is an instance of a list. - - Args: - v: The value whose type should be checked. - - Returns: - True if v is an instance of a list, False otherwise. - """ - return type(v) == type(_a_list) - -def _is_string(v): - """Returns True if v is an instance of a string. - - Args: - v: The value whose type should be checked. - - Returns: - True if v is an instance of a string, False otherwise. - """ - return type(v) == type(_a_string) - -def _is_bool(v): - """Returns True if v is an instance of a bool. - - Args: - v: The value whose type should be checked. - - Returns: - True if v is an instance of a bool, False otherwise. - """ - return type(v) == type(_a_bool) - -def _is_none(v): - """Returns True if v has the type of None. - - Args: - v: The value whose type should be checked. - - Returns: - True if v is None, False otherwise. - """ - return type(v) == type(None) - -def _is_int(v): - """Returns True if v is an instance of a signed integer. - - Args: - v: The value whose type should be checked. - - Returns: - True if v is an instance of a signed integer, False otherwise. - """ - return type(v) == type(_an_int) - -def _is_tuple(v): - """Returns True if v is an instance of a tuple. - - Args: - v: The value whose type should be checked. - - Returns: - True if v is an instance of a tuple, False otherwise. - """ - return type(v) == type(_a_tuple) - -def _is_dict(v): - """Returns True if v is an instance of a dict. - - Args: - v: The value whose type should be checked. - - Returns: - True if v is an instance of a dict, False otherwise. - """ - return type(v) == type(_a_dict) - -def _is_function(v): - """Returns True if v is an instance of a function. - - Args: - v: The value whose type should be checked. - - Returns: - True if v is an instance of a function, False otherwise. - """ - return type(v) == type(_a_function) - -types = struct( - is_list = _is_list, - is_string = _is_string, - is_bool = _is_bool, - is_none = _is_none, - is_int = _is_int, - is_tuple = _is_tuple, - is_dict = _is_dict, - is_function = _is_function, -)
diff --git a/go/private/skylib/lib/unittest.bzl b/go/private/skylib/lib/unittest.bzl deleted file mode 100644 index 0862130..0000000 --- a/go/private/skylib/lib/unittest.bzl +++ /dev/null
@@ -1,284 +0,0 @@ -# Copyright 2017 The Bazel Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -"""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. -""" - -load(":skylib/lib/sets.bzl", "sets") -load(":skylib/lib/new_sets.bzl", new_sets = "sets") - -def _make(impl, attrs = None): - """Creates a unit test rule from its implementation function. - - Each unit test is defined in an implementation function that must then be - associated with a rule so that a target can be built. This function handles - the boilerplate to create and return a test rule and captures the - implementation function's name so that it can be printed in test feedback. - - The optional `attrs` argument can be used to define dependencies for this - test, in order to form unit tests of rules. - - An example of a unit test: - - ``` - def _your_test(ctx): - env = unittest.begin(ctx) - - # Assert statements go here - - unittest.end(env) - - your_test = unittest.make(_your_test) - ``` - - Recall that names of test rules must end in `_test`. - - Args: - impl: The implementation function of the unit test. - 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`. - """ - - # Derive the name of the implementation function for better test feedback. - # Skylark currently stringifies a function as "<function NAME>", so we use - # that knowledge to parse the "NAME" portion out. If this behavior ever - # changes, we'll need to update this. - # TODO(bazel-team): Expose a ._name field on functions to avoid this. - impl_name = str(impl) - impl_name = impl_name.partition("<function ")[-1] - impl_name = impl_name.rpartition(">")[0] - - attrs = dict(attrs) if attrs else {} - attrs["_impl_name"] = attr.string(default = impl_name) - - return rule( - impl, - attrs = attrs, - _skylark_testable = True, - test = True, - ) - -def _suite(name, *test_rules): - """Defines a `test_suite` target that contains multiple tests. - - After defining your test rules in a `.bzl` file, you need to create targets - from those rules so that `blaze test` can execute them. Doing this manually - in a BUILD file would consist of listing each test in your `load` statement - 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: - - ``` - def your_test_suite(): - unittest.suite( - "your_test_suite", - your_test, - your_other_test, - yet_another_test, - ) - ``` - - Then, in your `BUILD` file, simply load the macro and invoke it to have all - of the targets created: - - ``` - load("//path/to/your/package:tests.bzl", "your_test_suite") - your_test_suite() - ``` - - If you pass _N_ unit test rules to `unittest.suite`, _N_ + 1 targets will be - created: a `test_suite` target named `${name}` (where `${name}` is the name - argument passed in here) and targets named `${name}_test_${i}`, where `${i}` - is the index of the test in the `test_rules` list, which is used to uniquely - name each target. - - Args: - name: The name of the `test_suite` target, and the prefix of all the test - target names. - *test_rules: A list of test rules defines by `unittest.test`. - """ - test_names = [] - for index, test_rule in enumerate(test_rules): - test_name = "%s_test_%d" % (name, index) - test_rule(name = test_name) - test_names.append(test_name) - - native.test_suite( - name = name, - tests = [":%s" % t for t in test_names], - ) - -def _begin(ctx): - """Begins a unit test. - - This should be the first function called in a unit test implementation - function. It initializes a "test environment" that is used to collect - assertion failures so that they can be reported and logged at the end of the - test. - - Args: - ctx: The Skylark context. Pass the implementation function's `ctx` argument - in verbatim. - - 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. - """ - return struct(ctx = ctx, failures = []) - -def _end(env): - """Ends a unit test and logs the results. - - This must be called before the end of a unit test implementation function so - that the results are reported. - - Args: - env: The test environment returned by `unittest.begin`. - """ - cmd = "\n".join([ - "cat << EOF", - "\n".join(env.failures), - "EOF", - "exit %d" % len(env.failures), - ]) - env.ctx.actions.write( - output = env.ctx.outputs.executable, - content = cmd, - is_executable = True, - ) - -def _fail(env, msg): - """Unconditionally causes the current test to fail. - - Args: - env: The test environment returned by `unittest.begin`. - msg: The message to log describing the failure. - """ - full_msg = "In test %s: %s" % (env.ctx.attr._impl_name, msg) - print(full_msg) - env.failures.append(full_msg) - -def _assert_true( - env, - condition, - msg = "Expected condition to be true, but was false."): - """Asserts that the given `condition` is true. - - Args: - env: The test environment returned by `unittest.begin`. - condition: A value that will be evaluated in a Boolean context. - msg: An optional message that will be printed that describes the failure. - If omitted, a default will be used. - """ - if not condition: - _fail(env, msg) - -def _assert_false( - env, - condition, - msg = "Expected condition to be false, but was true."): - """Asserts that the given `condition` is false. - - Args: - env: The test environment returned by `unittest.begin`. - condition: A value that will be evaluated in a Boolean context. - msg: An optional message that will be printed that describes the failure. - If omitted, a default will be used. - """ - if condition: - _fail(env, msg) - -def _assert_equals(env, expected, actual, msg = None): - """Asserts that the given `expected` and `actual` values are equal. - - Args: - env: The test environment returned by `unittest.begin`. - expected: The expected value of some computation. - actual: The actual value returned by some computation. - msg: An optional message that will be printed that describes the failure. - If omitted, a default will be used. - """ - if expected != actual: - expectation_msg = 'Expected "%s", but got "%s"' % (expected, actual) - if msg: - full_msg = "%s (%s)" % (msg, expectation_msg) - else: - full_msg = expectation_msg - _fail(env, full_msg) - -def _assert_set_equals(env, expected, actual, msg = None): - """Asserts that the given `expected` and `actual` sets are equal. - - Args: - env: The test environment returned by `unittest.begin`. - expected: The expected set resulting from some computation. - actual: The actual set returned by some computation. - msg: An optional message that will be printed that describes the failure. - If omitted, a default will be used. - """ - if type(actual) != type(depset()) or not sets.is_equal(expected, actual): - expectation_msg = "Expected %r, but got %r" % (expected, actual) - if msg: - full_msg = "%s (%s)" % (msg, expectation_msg) - else: - full_msg = expectation_msg - _fail(env, full_msg) - -def _assert_new_set_equals(env, expected, actual, msg = None): - """Asserts that the given `expected` and `actual` sets are equal. - - Args: - env: The test environment returned by `unittest.begin`. - expected: The expected set resulting from some computation. - actual: The actual set returned by some computation. - msg: An optional message that will be printed that describes the failure. - If omitted, a default will be used. - """ - if not new_sets.is_equal(expected, actual): - expectation_msg = "Expected %r, but got %r" % (expected, actual) - if msg: - full_msg = "%s (%s)" % (msg, expectation_msg) - else: - full_msg = expectation_msg - _fail(env, full_msg) - -asserts = struct( - equals = _assert_equals, - false = _assert_false, - set_equals = _assert_set_equals, - new_set_equals = _assert_new_set_equals, - true = _assert_true, -) - -unittest = struct( - make = _make, - suite = _suite, - begin = _begin, - end = _end, - fail = _fail, -)
diff --git a/proto/compiler.bzl b/proto/compiler.bzl index 20981a9..0b48ffa 100644 --- a/proto/compiler.bzl +++ b/proto/compiler.bzl
@@ -13,19 +13,19 @@ # limitations under the License. load( - "@io_bazel_rules_go//go:def.bzl", - "GoLibrary", - "go_context", -) -load( - "@io_bazel_rules_go//go/private:skylib/lib/sets.bzl", + "@bazel_skylib//lib:sets.bzl", "sets", ) load( - "@io_bazel_rules_go//go/private:skylib/lib/paths.bzl", + "@bazel_skylib//lib:paths.bzl", "paths", ) load( + "@io_bazel_rules_go//go:def.bzl", + "GoLibrary", + "go_context", +) +load( "@io_bazel_rules_go//go/private:rules/rule.bzl", "go_rule", )
diff --git a/proto/def.bzl b/proto/def.bzl index 3fa11ee..cd61674 100644 --- a/proto/def.bzl +++ b/proto/def.bzl
@@ -13,15 +13,15 @@ # limitations under the License. load( + "@bazel_skylib//lib:sets.bzl", + "sets", +) +load( "@io_bazel_rules_go//go:def.bzl", "GoLibrary", "go_context", ) load( - "@io_bazel_rules_go//go/private:skylib/lib/sets.bzl", - "sets", -) -load( "@io_bazel_rules_go//proto:compiler.bzl", "GoProtoCompiler", "proto_path",
diff --git a/tests/bazel_tests.bzl b/tests/bazel_tests.bzl index cf7cd43..d742b7b 100644 --- a/tests/bazel_tests.bzl +++ b/tests/bazel_tests.bzl
@@ -15,11 +15,11 @@ "go_rule", ) load( - "@io_bazel_rules_go//go/private:skylib/lib/paths.bzl", + "@bazel_skylib//lib:paths.bzl", "paths", ) load( - "@io_bazel_rules_go//go/private:skylib/lib/shell.bzl", + "@bazel_skylib//lib:shell.bzl", "shell", )
diff --git a/tests/core/starlark/common_tests.bzl b/tests/core/starlark/common_tests.bzl index 11eff53..ebf1024 100644 --- a/tests/core/starlark/common_tests.bzl +++ b/tests/core/starlark/common_tests.bzl
@@ -1,5 +1,5 @@ +load("@bazel_skylib//lib:unittest.bzl", "asserts", "unittest") load("@io_bazel_rules_go//go/private:common.bzl", "has_shared_lib_extension") -load("@io_bazel_rules_go//go/private:skylib/lib/unittest.bzl", "asserts", "unittest") def _versioned_shared_libraries_test(ctx): env = unittest.begin(ctx)