【问题标题】:Including runfiles in a filegroup在文件组中包含运行文件
【发布时间】:2018-07-06 15:13:57
【问题描述】:

我是 Bazel 的新手。

我认为 id 从尝试构建一个简单的 nodejs 项目开始,它使用 babel 进行一些转换作为构建过程的一部分,我遇到的问题是我似乎无法找到将这些转换后的文件放入文件组的方法.

这是我的 BUILD 文件。

load("@build_bazel_rules_nodejs//:defs.bzl", "nodejs_binary")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")


 # Group all our initial code.
 filegroup(
     name = "src",
     srcs = [
        ".babelrc",
        "package.json",
        "//config:src",
        "//handlers:src",
        "//migrations:src",
        "//models:src",
        "//services:src",
        "//tasks:src",
        "@dependencies//:node_modules",
     ],
 )

 # Group all our generated code.
 filegroup(
    name = "out",
    srcs = [
        "//:babel:runfiles" ### ???
    ],
 )

 nodejs_binary(
 name         = "babel",
 entry_point  = "babel-cli/bin/babel.js",
 templated_args = [
    ".",
    "--ignore node_modules,test/,migrations/,babel_bin_loader.js",
    "-d out",
    "--source-maps=both",
    "--copy-files",
],
node_modules = "@nodejs_build_tools//:node_modules",
data = [
    "//:src",
]
)

pkg_tar(
    name = "build",
    strip_prefix = "/",
    package_dir = "/usr/src/app",
    srcs = ["//:out"],
    mode = "0755",
)

我的问题是我不确定如何从我的 nodejs_binary 规则中引用运行文件。

https://github.com/bazelbuild/rules_nodejs/blob/master/internal/node/node.bzl#L130

似乎表明应该有一个 :runfiles 属性或类似的?

谢谢! :)

【问题讨论】:

    标签: node.js bazel


    【解决方案1】:

    事实证明,执行此操作的正确方法似乎是使用 genrule 来实际调用配置的 nodejs 二进制文件。例如。

    ## Artifact Construction ##
    genrule( 
        name = "construct_artifact",
        outs = ["artifact.tar"],
        cmd  = """./$(location babel)  . --ignore bazel- 
        out,node_modules,text/,migrations/ -d out/ --source-maps=both --copy-files && tar cvf $@ out/ """,
        srcs = [
            "//:src",
        ],
        tools = [
            "//:babel",
        ]
    )
    

    【讨论】:

      猜你喜欢
      • 2016-12-05
      • 1970-01-01
      • 2013-01-07
      • 2017-02-23
      • 2016-10-19
      • 1970-01-01
      • 1970-01-01
      • 2018-02-24
      • 1970-01-01
      相关资源
      最近更新 更多