【问题标题】:How to specify the gtest dependency for a cxx_test target when using Buck使用 Buck 时如何为 cxx_test 目标指定 gtest 依赖项
【发布时间】:2015-04-23 05:16:14
【问题描述】:

我正在尝试将现有的googletest 测试用例转换为使用Buck 构建。使用cxx_test 构建目标看起来很简单。

但是,在尝试构建时出现错误:

BUILD FAILED: .buckconfig: cxx:gtest_dep must be set

我的问题是应该将.buckconfig 设置设置为什么? googletest repo 的路径?构建 .so 或 .a 文件?查看源代码,它似乎需要成为另一个 Buck 构建目标。在某处是否有工作 Buck cxx_test 目标的示例?

【问题讨论】:

    标签: buck


    【解决方案1】:

    您应该指定一个build target,它指向您存储库中 gtest 库的位置。例如,您可以将它放在third-party/cxx/google-test 中,并且您在该目录中的BUCK 文件看起来像这样:

    导入操作系统
    def subdir_glob(glob_specs):
      """
      给定一个元组列表,(relative-sub-directory, glob-pattern) 的形式,
      将子目录相对路径的字典返回到完整路径。对...有用
      为 C/C++ 库定义头映射,它应该是相对于给定的
      子目录。
      """
    
      结果 = {}
    
      对于 dirpath,glob_specs 中的 glob_pattern:
        文件 = glob([os.path.join(dirpath, glob_pattern)])
        对于文件中的 f:
          如果目录路径:
            结果[f[len(dirpath) + 1:]] = f
          别的:
            结果[f] = f
    
     返回结果
    
    cxx_图书馆(
      名称 = '谷歌测试',
      srcs = glob(['src/**/*.cc'], excludes=['src/gtest-all.cc']),
      # 不是所有的编译器都支持 ,所以让 gtest 使用它
      # 内部实现。
      导出的预处理器标志 = [
        '-DGTEST_USE_OWN_TR1_TUPLE=1',
      ],
      header_namespace = '',
      导出的_headers = subdir_glob([
        ('', 'src/**/*.h'),
        ('包括', '**/*.h'),
      ]),
      部门= [
        ':pthread',
      ],
      能见度 = [
        '上市',
      ],
    )
    
    # libpthread 隐式包含在 android 运行时中,因此,在构建时
    # 在安卓平台上,我们什么都不做。
    prebuilt_cxx_library(
      名称 = 'pthread',
      header_only = 真,
      platform_linker_flags = [
        ('安卓', []),
        ('', ['-lpthread']),
      ],
      能见度 = [
        '上市',
      ],
    )

    然后在您的.buckconfig 中,您将拥有这个:

    [cxx]
      gtest_dep = //第三方/cxx/google-test:google-test

    注意 subdir glob 是 Buck 未来可能提供的东西。

    【讨论】:

    猜你喜欢
    • 2018-11-01
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    • 2012-02-27
    • 2017-09-29
    • 2018-09-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多