bash - Bazel genrule:在命令中使用换行符
问题描述
我使用一个有很多来源的类型,它们有一个很长的标识符。该命令需要明确列出所有源,这将导致 cmd 非常长。因此我尝试使用换行符(从 bash 或 shell 命令中知道)......但是,bazel 抱怨未终止的字符串。
genrule(
name = "Aggregate_Reports",
srcs = ["//really/long/path/to/module/ModuleA/src:CoverageHtml",
"//really/long/path/to/module/ModuleA/src:TestRun",
"//really/long/path/to/module/ModuleB/src:CoverageHtml",],
outs = ["UT_Summary.txt"],
message = "Create unified report",
tools = [":Create_Summary"],
cmd = "$(location :Create_Summary) -t \
$(location //really/long/path/to/module/ModuleA/src:TestRun) \
$(location //really/long/path/to/module/ModuleB/src:TestRun) \
-c \
$(location //really/long/path/to/module/ModuleA/src:CoverageHtml) \
$(location //really/long/path/to/module/ModuleB/src:CoverageHtml) \
-o $(@)",
executable = True,
visibility=["//visibility:public"],
)
用 $ 转义 \ 不会改变任何东西......
解决方案
与在 Python 中一样,您可以使用三引号来保留换行符:
cmd = """$(location :Create_Summary) -t \
$(location //really/long/path/to/module/ModuleA/src:TestRun) \
$(location //really/long/path/to/module/ModuleB/src:TestRun) \
-c \
$(location //really/long/path/to/module/ModuleA/src:CoverageHtml) \
$(location //really/long/path/to/module/ModuleB/src:CoverageHtml) \
-o $(@)""",
推荐阅读
- javascript - 在nodejs中导出变量时出错
- android - 错误:无法从静态上下文引用非静态方法 unbind()
- python - 为 python2/3 返回对 super() 的兼容调用
- java - Android java 我想使用我的过滤数据列表?
- swift - 使用 NSBezierPath 绘制一个点
- python - (Python)格式化列表中的元素
- php - PHP & SQL Server,致命错误:未捕获错误:调用未定义函数 sqlsrv_connect()
- javascript - 在 Material-ui 上为 React.js 设置容器宽度
- css - Bulma - 瓷砖没有打破到下一行
- angularjs - 仅在 nginx 中限制 REST API 对 Angular 应用程序的访问