Buck: Is there any way to access the absolute paths of files in another build rule?

Created on 8 Apr 2018  路  3Comments  路  Source: facebook/buck

I noticed that a number of build rule arguments in the Buck documentation expect actual file paths as opposed to other build targets. Some examples of this are arguments such as exported_headers, static_lib, headers, etc. In all of my Buck projects I use a combination of genrule(), remote_file() and prebuilt_cxx_library() to get all my dependencies remotely and build them locally, yet when using rules such as prebuilt_cxx_library() these file-only rule arguments only add complexity to this approach, as I can't just incorporate the files produced by my other build rules.

Is there any way to access the file paths of files contained in a build rule, or even just another genrule()? I'd prefer to not have to clone all my dependencies locally and Buck-ify them just to have this work. Just to give an example, here's how I'm attempting to get GTest programatically:

remote_file(
  name = 'get-gtest', 
  url = 'https://github.com/google/googletest/archive/release-1.8.0.zip', 
  sha1 = '667f873ab7a4d246062565fad32fb6d8e203ee73', 
  type = 'exploded_zip'
)

genrule(
  name = 'build-gtest', 
  srcs = [':get-gtest'], 
  cmd = 'cd $SRCS/googletest-release-1.8.0/googletest && cmake . && make && cp -r ./libgtest.a ./include $OUT', 
  out = '.'
)

genrule(
  name = 'headers-gtest',
  srcs = [':build-gtest'], 
  cmd = 'cp -r $SRCS/include/* $OUT', 
  out = '.'
)

genrule(
  name = 'lib-gtest', 
  srcs = [':build-gtest'],
  cmd = 'cp $SRCS/libgtest.a $OUT',
  out = 'libgtest.a'
)

prebuilt_cxx_library(
  name = 'gtest',
  header_dirs = [':headers-gtest'], 
  # exported_headers expects file paths. There's no way to export these programatic files.
  exported_headers = [':headers-gtest'], 
  static_lib = ':lib-gtest', 
  visibility = ['PUBLIC']
)

As commented above, there's no way to export GTest's headers seeing the argument only expects file paths.

Most helpful comment

All 3 comments

@kageiit Interesting... should I open a PR for this or just a use a custom fork of Buck or something?

@Nickersoft Please open a pr :)

Was this page helpful?
0 / 5 - 0 ratings