0

私はいくつかのカスタム C++ Bazel ルールを作成しています。cc_libraryヘッダーを で変更できるのと同じ方法で、C++ ヘッダーのインクルード パスを変更するためのサポートを追加する必要がありstrip_include_prefixます。

私のカスタムルールはctx.actions.run次のように実装されています:

custom_cc_library = rule(
  _impl,
  attrs = {
    ...
    "hdrs": attr.label_list(allow_files = [".h"]),
    "strip_include_prefix": attr.string(),
    ...
  },
)

次に_impl、次の関数を呼び出して書き換えhdrsます。

def _strip_prefix(ctx, hdrs, prefix):
    stripped = []
    for hdr in hdrs:
        stripped = hdr
        if file.path.startswith(strip_prefix):
            stripped_file = ctx.actions.declare_file(file.path[len(strip_prefix):])
            ctx.actions.run_shell(
                command = "mkdir -p {dest} && cp {src} {dest};".format(src=hdr.path, dest=stripped.path),
                inputs = [hdr],
                outputs = [stripped],
            )
        stripped.append(stripped_file)
    return stripped

Bazel はパッケージ ディレクトリの外にファイルをコピーしないため、これは機能しません。さらに、これを実装するための完全に間違ったアプローチのように感じます。

cc_libraryのパラメーターと同じ機能を実現するために、依存関係の C++ ヘッダー ディレクトリを変更する最良の方法は何strip_include_prefixですか?

4

1 に答える 1