如何在使用Buck时指定cxx_test目标的gtest依赖项

时间:2015-04-22 04:12:26

标签: buck

我正在尝试使用googletest转换现有的Buck测试用例。这似乎是使用cxx_test构建目标直接进行的。

然而,在尝试构建时,我收到错误:

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

我的问题是.buckconfig设置应该设置为什么? googletest回购路径?内置.so或.a文件?看一下源代码,它似乎需要成为另一个Buck构建目标。在某处有一个可行的Buck cxx_test目标的例子吗?

1 个答案:

答案 0 :(得分:4)

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

import os
def subdir_glob(glob_specs):
  """
  Given a list of tuples, the form of (relative-sub-directory, glob-pattern),
  return a dict of sub-directory relative paths to full paths.  Useful for
  defining header maps for C/C++ libraries which should be relative the given
  sub-directory.
  """

  results = {}

  for dirpath, glob_pattern in glob_specs:
    files = glob([os.path.join(dirpath, glob_pattern)])
    for f in files:
      if dirpath:
        results[f[len(dirpath) + 1:]] = f
      else:
        results[f] = f

 return results

cxx_library(
  name = 'google-test',
  srcs = glob(['src/**/*.cc'], excludes=['src/gtest-all.cc']),
  # Not all compilers support <tr1/tuple>, so have gtest use it's
  # internal implementation.
  exported_preprocessor_flags = [
    '-DGTEST_USE_OWN_TR1_TUPLE=1',
  ],
  header_namespace = '',
  exported_headers = subdir_glob([
    ('', 'src/**/*.h'),
    ('include', '**/*.h'),
  ]),
  deps = [
    ':pthread',
  ],
  visibility = [
    'PUBLIC',
  ],
)

# libpthread is implicitly included in the android runtime so, when building
# on an android platform, we don't do anything.
prebuilt_cxx_library(
  name = 'pthread',
  header_only = True,
  platform_linker_flags = [
    ('android', []),
    ('', ['-lpthread']),
  ],
  visibility = [
    'PUBLIC',
  ],
)

然后在您的.buckconfig中,您将拥有以下内容:

[cxx]
  gtest_dep = //third-party/cxx/google-test:google-test

请注意,subir glob是Buck可能在将来提供的东西。

相关问题