Bazel-如何递归 glob deleted_packages 以忽略 Maven 输出?
Bazel- How to recursively glob deleted_packages to ignore maven outputs?
我有一个多模块项目,我正在从 Maven 迁移到 Bazel。在此迁移期间,人们将需要能够在两个构建系统上工作。
在 mvn clean install
Maven 将一些 BUILD
文件复制到 target
文件夹后。
当我稍后尝试 运行 bazel build //...
它认为 various target
文件夹下的 BUILD
文件是有效的包并且由于以下原因而失败有些不匹配。
我看过 deleted_packages
,但 AFAICT 要求我将文件夹列表指定为 "delete",而我不能为 200 多个模块指定文件夹列表。
我正在寻找说 bazel build //... --deleted_packages=**/target
.
的能力
这受支持吗? (我的实验表明不是,但我可能是错的)。如果不支持,是否有针对它的现有破解方法?
抱歉,我认为这不受支持。一些头脑风暴:
- 是否可以选择将 maven 输出指向其他地方?
- 是否可以选择不使用 //... 但明确目标?
- 也许只是在 运行 bazel 之前删除坏的 BUILD 文件?
你能用你的 shell 找到要忽略的包列表吗?
deleted=$(find . -name target -type d)
bazel build //... --deleted_packages="$deleted"
@Laurent 的回答给了我领先,但 Bazel 不接受相对路径并要求我在 target
下添加 classes
和 test-classes
文件夹以删除包所以我决定回答完整的解决方案:
#!/bin/bash
#find all the target folders under the current working dir
target_folders=$(find . -name target -type d)
#find the repo root (currently assuming it's git based)
repo_root=$(git rev-parse --show-toplevel)
repo_root_length=${#repo_root}
#the current bazel package prefix is the PWD minus the repo root and adding a slash
current_bazel_package="/${PWD:repo_root_length}"
deleted_packages=""
for target in $target_folders
do
#cannonicalize the package path
full_package_path="$current_bazel_package${target:1}"
classes_full="${full_package_path}/classes"
test_classes_full="${full_package_path}/test-classes"
deleted_packages="$deleted_packages,$classes_full,$test_classes_full"
done
#remove the leading comma and call bazel-real with the other args
bazel-real "$@" --deleted_packages=${deleted_packages:1}
此脚本已在 tools/bazel
下签入,这就是它在最后调用 bazel-real
的原因。
我有一个多模块项目,我正在从 Maven 迁移到 Bazel。在此迁移期间,人们将需要能够在两个构建系统上工作。
在 mvn clean install
Maven 将一些 BUILD
文件复制到 target
文件夹后。
当我稍后尝试 运行 bazel build //...
它认为 various target
文件夹下的 BUILD
文件是有效的包并且由于以下原因而失败有些不匹配。
我看过 deleted_packages
,但 AFAICT 要求我将文件夹列表指定为 "delete",而我不能为 200 多个模块指定文件夹列表。
我正在寻找说 bazel build //... --deleted_packages=**/target
.
的能力
这受支持吗? (我的实验表明不是,但我可能是错的)。如果不支持,是否有针对它的现有破解方法?
抱歉,我认为这不受支持。一些头脑风暴:
- 是否可以选择将 maven 输出指向其他地方?
- 是否可以选择不使用 //... 但明确目标?
- 也许只是在 运行 bazel 之前删除坏的 BUILD 文件?
你能用你的 shell 找到要忽略的包列表吗?
deleted=$(find . -name target -type d)
bazel build //... --deleted_packages="$deleted"
@Laurent 的回答给了我领先,但 Bazel 不接受相对路径并要求我在 target
下添加 classes
和 test-classes
文件夹以删除包所以我决定回答完整的解决方案:
#!/bin/bash
#find all the target folders under the current working dir
target_folders=$(find . -name target -type d)
#find the repo root (currently assuming it's git based)
repo_root=$(git rev-parse --show-toplevel)
repo_root_length=${#repo_root}
#the current bazel package prefix is the PWD minus the repo root and adding a slash
current_bazel_package="/${PWD:repo_root_length}"
deleted_packages=""
for target in $target_folders
do
#cannonicalize the package path
full_package_path="$current_bazel_package${target:1}"
classes_full="${full_package_path}/classes"
test_classes_full="${full_package_path}/test-classes"
deleted_packages="$deleted_packages,$classes_full,$test_classes_full"
done
#remove the leading comma and call bazel-real with the other args
bazel-real "$@" --deleted_packages=${deleted_packages:1}
此脚本已在 tools/bazel
下签入,这就是它在最后调用 bazel-real
的原因。