美文网首页
Bazel Build: 命令行

Bazel Build: 命令行

作者: 刘光聪 | 来源:发表于2020-02-29 19:17 被阅读0次

    常见命令

    Bazel构建和测试的独特之处在于将将构建和测试放置在隔离的沙箱之中,并使用智能的缓存机制,加快编译速度和运行测试的速度。是的,它能缓存测试的运行结果,在下次运行测试时,只需增量运行源码修改导致的测试用例。

    构建命令:

    $ bazel build [target]
    

    测试命令:

    $ bazel test [target]
    

    目标

    目标可以使用完整的标签标示。其中,

    • ...:表示当前包,及其子包中的所有规则
    • all:当前包中的所有规则
    • *all-targets:当前包中的所有规则和文件

    例如:

    # single target //foo/bar:wiz
    //foo/bar:wiz
    
    # equivalent to //foo/bar:bar
    //foo/bar
    
    # all rules in the package foo/bar
    //foo/bar:all
    
    # all rules in all packages beneath the directory foo
    //foo/...      
    
    # All rules in all packages beneath the directory foo
    //foo/...:all
    
    # all targets (rules and files) in all packages beneath the directory foo
    //foo/...:*    
    
    # all targets (rules and files) in all packages beneath the directory foo
    //foo/...:all-targets
    

    简写

    如果当前目录在某个包之下,则可略去当前包名的前缀。例如,当前目录为//foo

    # //foo:foo.
    :foo
    
    # //foo/bar:wiz
    bar:wiz Equivalent to //foo/bar:wiz.
    
    # 1. //foo/bar/wiz:wiz if foo/bar/wiz is a package,
    # 2. //foo/bar:wiz if foo/bar is a package, 
    # 3. //foo:bar/wiz otherwise.
    bar/wiz
    
    # //foo/bar:all
    bar:all
    
    # //foo:all
    :all
    
    # //foo/...:all.
    ...:all
    
    # //foo/...:all
    ... 
    
    # //foo/bar/...:all
    bar/...:all
    

    最佳实践

    理论上,良好的Bazel必须使得如下构建成功。

    $ bazel build //repo_name/...
    

    同理的,也必须通过当前工程所有测试用例。

    $ bazel test //repo_name/...
    

    相关文章

      网友评论

          本文标题:Bazel Build: 命令行

          本文链接:https://www.haomeiwen.com/subject/aevmhhtx.html