Bazel-如何递归地遍历delete_packages以忽略Maven输出? [英] Bazel- How to recursively glob deleted_packages to ignore maven outputs?
问题描述
我有一个从Maven迁移到Bazel的多模块项目.在迁移期间,人们将需要能够在两个构建系统上工作.
I have a mutli-module project which I'm migrating from Maven to Bazel. During this migration people will need to be able to work on both build systems.
mvn clean install
之后,Maven将某些BUILD
文件复制到target
文件夹中.
当我稍后尝试运行bazel build //...
时,它认为各种 target
文件夹下的BUILD
文件是有效的程序包,并且由于某些不匹配而失败.
After an mvn clean install
Maven copies some of the BUILD
files into the target
folder.
When I later try to run bazel build //...
it thinks the BUILD
files under the various target
folders are valid packages and fails due to some mismatch.
我见过deleted_packages
,但是AFAICT要求我指定要删除"的文件夹列表,而我不能对200多个模块执行此操作.
我正在寻找说bazel build //... --deleted_packages=**/target
的能力.
支持这个吗? (我的实验表明不是,但我可能是错的).如果不支持,是否有现有的破解方法?
I've seen deleted_packages
but AFAICT it requires I specify the list of folders to "delete" while I can't do that for 200+ modules.
I'm looking for the ability to say bazel build //... --deleted_packages=**/target
.
Is this supported? (my experimentation says it's not but I might be wrong). If it's not supported is there an existing hack for it?
推荐答案
@Laurent的答案给了我线索,但Bazel不接受相对路径,并且要求我将target
下的classes
和test-classes
文件夹都添加到删除软件包,所以我决定用完整的解决方案进行回答:
@Laurent's answer gave me the lead but Bazel didn't accept relative paths and required I add both classes
and test-classes
folders under target
to delete the package so I decided to answer with the complete solution:
#!/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
的原因.
This script was checked in under tools/bazel
which is why it calls bazel-real
at the end.
这篇关于Bazel-如何递归地遍历delete_packages以忽略Maven输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!