Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

load("@io_bazel_rules_go//go/private:common.bzl", "MINIMUM_BAZEL_VERSION")
load("@io_bazel_rules_go//go/private:compat/compat_repo.bzl", "go_rules_compat")
load("@io_bazel_rules_go//go/private:skylib/lib/unittest.bzl", "register_unittest_toolchains")
load("@io_bazel_rules_go//go/private:skylib/lib/versions.bzl", "versions")
load("@io_bazel_rules_go//go/private:nogo.bzl", "DEFAULT_NOGO", "go_register_nogo")
load("@io_bazel_rules_go//go/platform:list.bzl", "GOOS_GOARCH")
Expand All @@ -28,6 +29,8 @@ def go_rules_dependencies():
if getattr(native, "bazel_version", None):
versions.check(MINIMUM_BAZEL_VERSION, bazel_version = native.bazel_version)

register_unittest_toolchains()

# Compatibility layer, needed to support older versions of Bazel.
_maybe(
go_rules_compat,
Expand Down
6 changes: 4 additions & 2 deletions go/private/skylib/README.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
This directory is a copy of github.com/bazelbuild/bazel-skylib/lib.
Version 0.5.0, retrieved on 2018-11-26.
This directory is a copy of github.com/bazelbuild/bazel-skylib/{lib,toolchains}
Version 0.8.0, retrieved on 2019-05-29, with the following changes:
- lib/BUILD is omitted
- all labels (e.g. in load() statements) are updated for this repository

This is needed only until nested workspaces works.
It has to be copied in because we use the functionality inside code that
Expand Down
5 changes: 4 additions & 1 deletion go/private/skylib/lib/collections.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def _uniq(iterable):
A new list with all unique elements from `iterable`.
"""
unique_elements = {element: None for element in iterable}
return unique_elements.keys()

# list() used here for python3 compatibility.
# TODO(bazel-team): Remove when testing frameworks no longer require python compatibility.
return list(unique_elements.keys())

collections = struct(
after_each = _after_each,
Expand Down
4 changes: 3 additions & 1 deletion go/private/skylib/lib/dicts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""Skylib module containing functions that operate on dictionaries."""

def _add(*dictionaries):
def _add(*dictionaries, **kwargs):
"""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
Expand All @@ -27,13 +27,15 @@ def _add(*dictionaries):

Args:
*dictionaries: Zero or more dictionaries to be added.
**kwargs: Additional dictionary passed as keyword args.

Returns:
A new `dict` that has all the entries of the given dictionaries.
"""
result = {}
for d in dictionaries:
result.update(d)
result.update(kwargs)
return result

dicts = struct(
Expand Down
2 changes: 1 addition & 1 deletion go/private/skylib/lib/new_sets.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
values in the set can be retrieved using `sets.to_list(my_set)`.
"""

load(":skylib/lib/dicts.bzl", "dicts")
load("@io_bazel_rules_go//go/private:skylib/lib/dicts.bzl", "dicts")

def _make(elements = None):
"""Creates a new set.
Expand Down
160 changes: 160 additions & 0 deletions go/private/skylib/lib/old_sets.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
# 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.
"""

_depset_type = type(depset())
_list_type = type([])

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_type, _list_type):
fail("Expected arguments to be depset or list, but found type %s: %r" %
(t, a))

def _depset_to_list(val):
"""Converts a depset to a list.

If the given value is a depset, will return the list representation of
the depset. Otherwise, will return the value itself.

Args:
val: The value to be optionally converted and returned.

Returns:
The converted value.
"""
if type(val) == _depset_type:
return val.to_list()
else:
return val

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)

# Convert both values to a depset then back to a list to remove duplicates.
a = _depset_to_list(depset(a))
b = _depset_to_list(depset(b))
return sorted(a) == sorted(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 _depset_to_list(a):
if e not in _depset_to_list(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 _depset_to_list(a):
if e in _depset_to_list(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 _depset_to_list(a) if e in _depset_to_list(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) == _list_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 _depset_to_list(a) if e not in _depset_to_list(b)])

sets = struct(
difference = _difference,
disjoint = _disjoint,
intersection = _intersection,
is_equal = _is_equal,
is_subset = _is_subset,
union = _union,
)
2 changes: 1 addition & 1 deletion go/private/skylib/lib/partial.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Skylark module for working with partial function objects.
"""Starlark module for working with partial function objects.

Partial function objects allow some parameters are bound before the call.

Expand Down
2 changes: 1 addition & 1 deletion go/private/skylib/lib/selects.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _with_or(input_dict, no_match_error = ""):
def _with_or_dict(input_dict):
"""Variation of `with_or` that returns the dict of the `select()`.

Unlike `select()`, the contents of the dict can be inspected by Skylark
Unlike `select()`, the contents of the dict can be inspected by Starlark
macros.

Args:
Expand Down
125 changes: 4 additions & 121 deletions go/private/skylib/lib/sets.bzl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 The Bazel Authors. All rights reserved.
# 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.
Expand All @@ -12,125 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

"""Skylib module containing common set algorithms.
"""Skylib module reexporting deprecated 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.
load("@io_bazel_rules_go//go/private:skylib/lib/old_sets.bzl", _sets = "sets")

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,
)
sets = _sets
Loading