• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2024 The Bazel Authors. All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#    http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14"""Macro to extract tools from a directory."""
15
16load("@bazel_skylib//rules/directory:glob.bzl", "directory_glob")
17load(":tool.bzl", "cc_tool")
18
19def cc_directory_tool(name, directory, executable, data = [], exclude = [], allow_empty = False, **kwargs):
20    """A tool extracted from a directory.
21
22    Args:
23        name: (str) The name of the generated target
24        directory: (Label) The directory to extract from
25        executable: (str) The relative path from the directory to the
26            executable.
27        data: (List[str]) A list of globs to runfiles for the executable,
28          relative to the directory.
29        exclude: (List[str]) A list of globs to exclude from data.
30        allow_empty: (bool) If false, any glob that fails to match anything will
31          result in a failure.
32        **kwargs: Kwargs to be passed through to cc_tool.
33    """
34    files_name = "_%s_files" % name
35    directory_glob(
36        name = files_name,
37        directory = directory,
38        srcs = [executable],
39        data = data,
40        exclude = exclude,
41        allow_empty = allow_empty,
42        visibility = ["//visibility:private"],
43    )
44
45    cc_tool(
46        name = name,
47        src = files_name,
48        **kwargs
49    )
50