question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Shorthand for including an output file of a genrule directory as a src

See original GitHub issue

If you have a genrule that creates a directory with several files, it’s a bit of a pain to write another genrule rule for each (expected) output, just to be able to pass it to *_library (java, python, etc). It would be nice to allow you to somehow specify this in the sources - maybe via flavors (although it is a bit hackish)? e.g.

genrule(
    name='gen_my_thing',
    out='things',
    cmd='$(exe :my_custom_generator) $SRCDIR $OUT',
    srcs=glob(['File1.java', 'File2.java']),
)

java_library(
    name='lib',
    srcs=[
        ':gen_my_thing#lib_output/File1Out.java',
        ':gen_my_thing#lib_output/File2Out.java',
    ]
)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
njlrcommented, Mar 27, 2017

Yes, that works.

For those who stumble on this, try something like:

def extract(x):
  genrule(
    name = x,
    out = x,
    cmd = 'cp $(location :make)/install/include/' + x ' $OUT',
  )
  return ':' + x

headers = [
  'generated_header.h',
]

prebuilt_cxx_library(
  name = 'my-lib',
  exported_headers = dict({ (x, extract(x)) for x in headers }),
  # etc... 
1reaction
Conekocommented, Mar 27, 2017

You need to know the names of the files in advance and write them in the build files.

You can do that using a python loop if you wish, but you cannot list files in the output directory.

The same limitation exists with the new syntax.

Read more comments on GitHub >

github_iconTop Results From Across the Web

General Rules | Bazel
The build system automatically deletes any existing output files, but creates any necessary parent directories before it runs a genrule.
Read more >
Writing additional build rules - Please Build
To this end each rule builds in its own temporary directory (under plz-out/tmp ) containing only files defined as inputs to the rule....
Read more >
Bazel: genrule that outputs a directory - Stack Overflow
The output of a genrule must be a fixed list of files. As a work-around, you can create a zip from the output...
Read more >
Experimentations on Bazel: genrule - DEV Community ‍ ‍
When outs is a list of one file, then $@ can be used as a shortcut to identify the output file. Go back...
Read more >
How to use gen-file outs from one rule as srcs in another genrule
Right now this creates the generated header in the bazel-out directory. How can I make this create the output file in bazel-genfiles instead ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found