如何将自定义规则的输出放在`bazel-genfiles /`而不是`bazel-out /`?

时间:2017-08-09 09:05:39

标签: bazel

我们正在生成许多Go源文件,作为构建的一部分。之前我们使用了genruleexample here),这导致生成的文件存储在bazel-genfiles/中。

我们最近切换为使用rules_gohttps://github.com/bazelbuild/rules_go/tree/master/examples/bindata)中演示的自定义规则。此更改意味着输出源文件存储在bazel-bin/而不是bazel-genfiles/

输出位置的这种变化打破了我们开发人员使用的一些IDE中的Go集成。值得注意的是,vim-gobzl和VSCode使用的自动完成引擎,在bazel-genfiles/(Bazel)查找模式下运行时似乎希望在bazel-bin/中找到生成的源,而不是bazel-genfiles/ {1}},因此失败。

如何修改规则以将输出保存到bazel-bin/而不是rules_go?我的规则等同于 def _bindata_impl(ctx): out = ctx.new_file(ctx.label.name + ".go") ctx.action( inputs = ctx.files.srcs, outputs = [out], executable = ctx.file._bindata, arguments = [ "-o", out.path, "-pkg", ctx.attr.package, "-prefix", ctx.label.package, ] + [src.path for src in ctx.files.srcs], ) return [ DefaultInfo( files = depset([out]) ) ] bindata = rule( _bindata_impl, attrs = { "srcs": attr.label_list(allow_files = True, cfg = "data"), "package": attr.string(mandatory=True), "_bindata": attr.label(allow_files=True, single_file=True, default=Label("@com_github_jteeuwen_go_bindata//go-bindata:go-bindata")), }, ) 中的示例:

    Dim con As Object
    Dim rs As Object
    Dim cmd As Object
    Dim query As String
    Set con = CreateObject("ADODB.Connection")
    Set rs = CreateObject("ADODB.Recordset")
    Set cmd = CreateObject("ADODB.Command")

    col = 2
    strcon = "Provider=OraOLEDB.Oracle;" _
    & "Data Source= (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = SERVER_IP)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl.Multi-Act.Local))); " _
    & "Initial Catalog=DatabaseName;" _
    & "Trusted_connection=yes"

    con.Open (strcon)

我希望对gocodectx.new_file提出论据,但在Skylark参考或教程中找不到任何相关内容。

非常感谢!

1 个答案:

答案 0 :(得分:6)

尝试在output_to_genfiles=True定义中设置rule()。它在rule docs中提到。

所以:

bindata = rule(
        _bindata_impl,
        attrs = {
            "srcs": attr.label_list(allow_files = True, cfg = "data"),
            "package": attr.string(mandatory=True),
            "_bindata":  attr.label(allow_files=True, single_file=True, default=Label("@com_github_jteeuwen_go_bindata//go-bindata:go-bindata")),
        },
        output_to_genfiles = True,
    )
相关问题