c++ - Bazel:如何将标题放入一个包含路径

标签 c++ bazel buck

在 Buck 中,可以这样写:

exported_headers = subdir_glob([
    ("lib/source", "video/**/*.h"),
    ("lib/source", "audio/**/*.h"),
],
excludes = [
    "lib/source/video/codecs/*.h",
],
prefix = "MediaLib/")

此行将使这些 header 在 MediaLib/下可用。 Bazel 中的等价物是什么?

最佳答案

我最终写了一条规则来做到这一点。它提供类似于文件组输出的内容,并且可以在宏中与 cc_library 结合使用。

def _impl_flat_hdr_dir(ctx):
    path = ctx.attr.include_path
    d = ctx.actions.declare_directory(path)
    dests = [ctx.actions.declare_file(path + "/" + h.basename)
             for h in ctx.files.hdrs]

    cmd = """
        mkdir -p {path};
        cp {hdrs} {path}/.
        """.format(path=d.path, hdrs=" ".join([h.path for h in ctx.files.hdrs]))

    ctx.actions.run_shell(
       command = cmd,
       inputs = ctx.files.hdrs,
       outputs = dests + [d],
       progress_message = "doing stuff!!!"
    )

    return struct(
       files = depset(dests)
    )

flat_hdr_dir = rule(
    _impl_flat_hdr_dir,
    attrs = {
        "hdrs": attr.label_list(allow_files = True),
        "include_path": attr.string(mandatory = True),
    },
    output_to_genfiles = True,
)

关于c++ - Bazel:如何将标题放入一个包含路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50662996/

相关文章:

java - 分析和检查由 Java 加载的 DLL 中的内存分配

c++ - 如何查看 Bazel 中使用的所有 copt(C/C++ 构建选项)?

character-encoding - Bazel:通过 javacopts 进行的 java_library 字符编码不起作用?

java - 在 osx 和 ubuntu 中安装 onos 失败

c++ - 使用针对 CPP 应用程序的 BUCK 构建链接 X11

android - Buck - 名称 'project_config' 未定义。如何解决?

c++ - C++ 中的友元方法 "not declared in this scope"

c++ - C++ 中的 MSD 基数排序(字典顺序)

c++ - 哪个事件属于 qt c++ 中的窗口焦点更改?

c++ - 如何将第 3 方 C 库添加到 tensorflow?