gpt4 book ai didi

Bazel 映射目录位于 `src` 到 `build` 之外

转载 作者:行者123 更新时间:2023-12-04 13:25:02 26 4
gpt4 key购买 nike

我不知道 Bazel 或者它是如何工作的,但我必须解决这个问题,最终归结为 bazel 没有将某个目录复制到 build.gradle 中。
我重构了一个代码,因此首先尝试从目录 private-keys 中读取某个键( jwk ) .运行时总是找不到文件。我认为 bazel 没有复制 private-keys目录(与 src 处于同一级别)到 build .

Project/
|-- private-keys\
|-- src/
| |-- //other directories
| |-- index.ts
|
|-- package.json
|-- BUILD.bazel
src里面有复制目录的映射对象我尝试使用 ../private-keys那里但没有工作。
以下是如何 BUILD.bazel好像
SOURCES = glob(
["src/**/*.ts"],
exclude = [
"src/**/*.spec.ts",
"src/__mocks__/**/*.ts",
],
)

mappings_dict = {
"api": "build/api",
....
}

ts_project(
name = "compile_ts",
srcs = SOURCES,
incremental = True,
out_dir = "build",
root_dir = "src",
tsc = "@npm//typescript/bin:tsc",
tsconfig = ":ts_config_build",
deps = DEPENDENCIES + TYPE_DEPENDENCIES,
)

ts_project(
name = "compile_ts",
srcs = SOURCES,
incremental = True,
out_dir = "build",
root_dir = "src",
tsc = "@npm//typescript/bin:tsc",
tsconfig = ":ts_config_build",
deps = DEPENDENCIES + TYPE_DEPENDENCIES,
)

_mappings = module_mappings(
name = "mappings",
mappings = mappings_dict,
)

# Application binary and docker imaage
nodejs_image(
name = "my-service",
data = [
":compile_ts",
"@npm//source-map-support",
] + _mappings,
entry_point = "build/index.js",
templated_args = [
"--node_options=--require=source-map-support/register",
"--bazel_patch_module_resolver",
],
)

最佳答案

构建目标的命令始终在单独的目录中运行。要告诉 Bazel 它需要复制一些额外的文件,您需要将这些文件包装在 filegroup 中。目标(参见 bazel docs)。
然后将此类文件组目标添加到 deps目标的属性。(参见示例 here)。
在你的情况下,它会是这样的

filegroup(
name = "private_keys",
srcs = glob(["private_keys/**"]),
)

ts_project(
name = "compile_ts",
srcs = SOURCES,
data = [ ":private_keys" ], # <-- !!!
incremental = True,
out_dir = "build",
root_dir = "src",
tsc = "@npm//typescript/bin:tsc",
tsconfig = ":ts_config_build",
deps = DEPENDENCIES + TYPE_DEPENDENCIES,
)
您也可以插入 glob(...)直接进入 data属性但是,将其设置为文件组使其可重用......并使您看起来像专业人士。 :)

关于Bazel 映射目录位于 `src` 到 `build` 之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68953010/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com