mirror of
https://github.com/bazelbuild/bazel-skylib
synced 2024-11-30 10:41:18 +00:00
8386b9d32b
While build settings allow for much cleaner flag and setting definitions than `--define`, they have the major drawback that rules need to provide dedicated support for them, which isn't the case for native and most community-maintained rules. This change attempts to bridge this gap by optionally exposing the value of the common build setting types as Make variables to rules that depend on them via the `toolchains` attribute: If the new `make_variable` attribute is set, the value of the flag or setting is available as a Make variable with that. Consistency with pre-defined Make variables is enforced by limiting the character set for `make_variable` values to `[A-Z0-9_]`. The new attribute is also only added to int- and string-valued build settings as the other types lack a canonical stringification. Co-authored-by: Xùdōng Yáng <wyverald@gmail.com>
89 lines
2.5 KiB
Python
89 lines
2.5 KiB
Python
# Copyright 2022 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 tests for subpackages.bzl."""
|
|
|
|
load("//lib:subpackages.bzl", "subpackages")
|
|
load("//lib:unittest.bzl", "loadingtest")
|
|
|
|
def _all_test(env):
|
|
"""Unit tests for subpackages.all."""
|
|
|
|
all_pkgs = [
|
|
"common_settings",
|
|
"copy_directory",
|
|
"copy_file",
|
|
"diff_test",
|
|
"expand_template",
|
|
"select_file",
|
|
"write_file",
|
|
]
|
|
|
|
# Not all pkgs exist in all test environments.
|
|
if subpackages.exists("run_binary"):
|
|
all_pkgs.append("run_binary")
|
|
|
|
if subpackages.exists("native_binary"):
|
|
all_pkgs.append("native_binary")
|
|
|
|
# These exist in all cases
|
|
filtered_pkgs = [
|
|
"common_settings",
|
|
"copy_directory",
|
|
"copy_file",
|
|
"expand_template",
|
|
"select_file",
|
|
"write_file",
|
|
]
|
|
|
|
# subpackages is always in sorted order:
|
|
all_pkgs = sorted(all_pkgs)
|
|
|
|
# test defaults
|
|
loadingtest.equals(
|
|
env,
|
|
"all",
|
|
["//tests/" + pkg for pkg in all_pkgs],
|
|
subpackages.all(),
|
|
)
|
|
|
|
# test non-fully-qualified output
|
|
loadingtest.equals(
|
|
env,
|
|
"all_not_fully_qualified",
|
|
all_pkgs,
|
|
subpackages.all(fully_qualified = False),
|
|
)
|
|
|
|
# test exclusion
|
|
loadingtest.equals(
|
|
env,
|
|
"all_w_exclude",
|
|
filtered_pkgs,
|
|
subpackages.all(exclude = ["diff_test", "run_binary", "native_binary"], fully_qualified = False),
|
|
)
|
|
|
|
def _exists_test(env):
|
|
"""Unit tests for subpackages.exists."""
|
|
loadingtest.equals(env, "exists_yes", True, subpackages.exists("copy_file"))
|
|
loadingtest.equals(env, "exists_no", False, subpackages.exists("never_existed"))
|
|
|
|
def subpackages_test_suite():
|
|
"""Creates the test targets and test suite for subpackages.bzl tests."""
|
|
|
|
if subpackages.supported():
|
|
env = loadingtest.make("subpackages")
|
|
_all_test(env)
|
|
_exists_test(env)
|