Bazel仅清理一个缓存规则的子集

发布于 2025-01-30 18:37:50 字数 1132 浏览 0 评论 0原文

我目前正在MonorePo中开发,该MonorePo具有很大的工作区文件。

目前,我注意到我的测试规则之一,当我更新我的测试之一时,没有重新构建其依赖性规则。以下是一个示例:

load("@npm//@grafana/toolkit:index.bzl", "grafana_toolkit")
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")

APPLICATION_DEPS = glob(
    [   
        # My updated test file is included in this glob
        "src/**/*", 
    ],
) + [
    "my-config-files.json"
]

RULE_DEPS = [
    "@npm//@grafana/data",
    "@npm//@grafana/ui",
    "@npm//emotion",
    "@npm//fs-extra",
]

copy_to_bin(
    name = "bin_files",
    srcs = APPLICATION_DEPS,
)


grafana_toolkit(
    name = "test",
    args = [
        "plugin:test",
    ],
    chdir = package_name(),
    data = RULE_DEPS + [
        ":bin_files",
    ],
)

然后,我有一个名为something.test.ts的文件。我运行Bazel运行:Test,我的测试可能表明我失败了,我看到了问题并解决了问题。问题在于,下次我进行测试时,我从输出中看到它仍然失败,因为它正在运行旧测试而不是新测试。

问题

我通常通过运行bazel Clean来解决不更新的陈旧文件的方法。问题是做Bazel Clean意味着我清洁了所有内容。这使得重新运行所有的构建步骤要花很长的时间。我想知道是否有一种方法可以指定我仅清洁缓存的子集(例如,我的bin_files规则的输出)。这样,我只能重建我想重建的东西,而不是重建。

I am currently developing in a monorepo that has a pretty large workspace file.

Right now, I am noting that one of my testing rules, is not getting its dependency rules re-built when I update one of my tests. Here is an example of this:

load("@npm//@grafana/toolkit:index.bzl", "grafana_toolkit")
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")

APPLICATION_DEPS = glob(
    [   
        # My updated test file is included in this glob
        "src/**/*", 
    ],
) + [
    "my-config-files.json"
]

RULE_DEPS = [
    "@npm//@grafana/data",
    "@npm//@grafana/ui",
    "@npm//emotion",
    "@npm//fs-extra",
]

copy_to_bin(
    name = "bin_files",
    srcs = APPLICATION_DEPS,
)


grafana_toolkit(
    name = "test",
    args = [
        "plugin:test",
    ],
    chdir = package_name(),
    data = RULE_DEPS + [
        ":bin_files",
    ],
)

I then have a file called maybe something.test.ts. I run bazel run :test and my test might show that I failed and I see the problem and fix it. The problem is that the next time I run my test, I see from the output that it's still failing because it's running the old test instead of the new test.

The Problem

The way that I normally fix this sort of issue with stale files not updating, is by running bazel clean. The problem is that doing bazel clean means I clean EVERYTHING. And that makes re-running all the build steps take pretty damn long. I'm wondering if there is a way I can specify that I only clean a subset of the cache (maybe only the output of my bin_files rule, for example). That way, rather than starting all over again, I only rebuild what I want to rebuild.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凶凌 2025-02-06 18:37:50

实际上,我找到了一种快速简便的方法来完成我最初要求的事情,基本上就是转到bazel-bin目录,然后删除我要重新删除的输出-跑步。因此,也许在这种情况下,我可以在Bazel-bin目录中删除bin_files输出,然后再次运行我的bin_files Rule。

话虽这么说,我认为@ahumsky可能是正确的,因为如果您需要这样做,那么其他事情很可能是一个错误。就我而言,我正在运行规则的构建版本,而不是我的规则的测试版本。因此,清洁我的缓存子集与我的原始问题没有任何关系。

I've actually found a pretty quick and easy way to do what I was originally asking is basically to just go to the bazel-bin directory, and delete the output of whichever rule it is I want to re-run. So maybe in this case, I could delete the bin_files output in my bazel-bin directory then run my bin_files rule again.

With that being said, I think @ahumsky might be right in that if you're needing to do this, it's more likely a bug with something else. In my case, I was running a build version of my rule instead of a test version of my rule. So, cleaning a subset of my cache didn't really have anything to do with my original problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文