I am using Bazel and have many BUILDĀ files and would like to auto-generate parts. There are two options.
1) I create a BUILD.template file and replace the corresponding elements in the file and rename it back to BUILD after the generation is done.
.. or ..
2) I use an additional file like BUILD.ext and use an include directive inside the BUILD file which includes that given file. But I can't find any include support.
Any help is highly appreciated!
One possibility is that you can define your templates as bazel macros in .bzl files, and load those macros in your BUILD files.
Related
I have a Latex project that is including multiple PDFs. These PDFs are added in the final document through the includepdf tag when the project is compiled over Overleaf. My question is can Latex automatically generate a ToC from included PDFs, i.e., can it automatically read the \section \subsection tags from the included files and automatically generate it? Or maybe this is only possible if I included the separate project or sources into the final solution and compile that.
Your help is so welcome!
Including a rendered pdf file in your project would make you limited in accessing details of those documents. You will then only be able to select specific pages or add some content on specific places of those files (e.g. your own page numbers).
Since you have access to those projects, best is to nest those raw tex files under your current project using one (or a combination) of the following methods:
Input command: \input{foo.tex}: in this case the input file mustn't be a separate project (no \begindocument and \enddocument in it)
Include command: \include{foo.tex}: very similar to input command but a bit limited about nested includes.
import package: very similar to input and include commands but allows nested imports and also accepts a different logic for path resolution on its input (i.e. it accepts relative path to the file from where it is called).
subfiles package: In this case the subfile can have its own document body and is able to be rendered separately. The subfiles would use the preambles of your main project.
standalone package: Similar to subfiles but the main project would use the preambles of your subfiles in this case.
Overleaf nicely allows you to add files from another project which is the best choice when the other file is still being developed in a separate project. In this case, the file remains under control of the other project.
For further info, here is a very nice guide on how to write modular documents in latex and here is a brief tutorial on subfiles and standalone.
I am aware that bazel accepts both BUILD and BUILD.bazel as valid filenames.
The android tools seem to also have a BUILD.tools file.
In general, does bazel have any restrictions for a BUILD file's extension? For example, could i have BUILD.generated to delineate generate BUILD files from non-generated BUILD files?
The .tools extension is part of building Bazel itself. From the perspective of Bazel, it's just any ordinary file. It gets picked up here: https://github.com/bazelbuild/bazel/blob/bbc8ed16aee07c3ba9321d58aa4c0ffc55fa2ba9/tools/android/BUILD#L197
then eventually gets processed here: https://github.com/bazelbuild/bazel/blob/c816b89a2224c3c318f1228755ef41c53975f45c/src/create_embedded_tools.py#L74
For the use case you mention, one way to go about it is to generate a .bzl file with a meaningful name that contains a macro that you can call from a BUILD or BUILD.bazel file. That way you can separate the generated rules from manually maintained rules. This is similar to how generate_workspace works: https://docs.bazel.build/versions/master/generate-workspace.html
I'm writing a post-build tool that needs the location of a list of target's jar files.
For these locations I have an aspect that runs on a list of targets (separately for each target using --aspects) and fetch the jar file path for each of them.
I've managed to get each jar file path in a custom output file (e.g. jar.txt) in each target's output folder.
But this will mean I would need to go over each jar.txt file separately to get the location.
Is there a way to accumulate the jar files paths in a single file?
Something like:
Try and write to the same output folder with append command in the aspect. I'm not sure if a shared output folder is possible.
Create a synthetic target which depends on all the relevant targets, then run an aspect on this target and accumulate the jars and only write them at the root after the recursion is back.
Are 1. or 2. valid options?
What is the recommended strategy to accumulate data in bazel aspects output files?
Bazel doesn't provide facitlities in Skylark for accumulating information between targets that are not related to each other in the target graph (e.g. ones that are mentioned on the command line next to each other).
One possibility would be to write a Skylark rule that depends on all the targets you usually mention on the command line and built that one; that rule will be able to collate the classpaths from each Java target to a single file.
Another possibility is to tell Bazel to write build events (that includes all the outputs of all targets the specified build pattern expands to) to a file using the --experimental_build_event_{json,text,binary}_file. (The "experimental" will be removed soon.). The files contain instances of this message:
https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/buildeventstream/proto/build_event_stream.proto
Natan,
If I understand correctly, you want to transitively propagate the information from each aspect node out into a single result. To do this, build the transitive set in your aspect rule implementation and pass it via the "provider" mechanism [^1]. I wrote up some examples on bazel aspects, perhaps you'll find it useful[^2].
https://github.com/pcj/bazel_aspects/blob/master/aspects.bzl#L94-L104
https://github.com/pcj/bazel_aspects
I am trying to create a rule (maybe one already exists?), to un-tar a file during a bazel build step.
If I understand correctly all output files need to be known during the "Analysis Phase". To work around this I have a file lets call it manifest.txt which lists all the files in the tar file. However, I don't quite understand how I can read this file as a list outputs for my skylark rule? Is there an easy way to read a file and have each line be a generated output?
Thanks.
This is only possible if the manifest file is a source file, i.e. it is NOT generated by some rule in the build.
Rules must declare all their outputs without relying on the content of generated files, therefore it's not supported to create for example a genrule whose outs is computed based on a manifest file that's generated by another rule.
To work with a tar file input, the rule needs to unpack the tar with an action, and ultimately produce a predictable amount of outputs (i.e. independent of how many files are there in the tar). Typically this is done by repacking the outputs, that is, the rule would consume one tar and produce another.
I'm want to compile meshlab(http://sourceforge.net/p/meshlab/code/HEAD/tree/) and put the generated file outside the source directory to keep the source clean. Is it possible to just specify a build directory as the way in cmake?
The answer in this post Qmake and Make using separate folders for sources and headers, requires to modify the .pro file and doesn't work in my case. Users may want to specify the build dir path as they like, right?
I think what are trying to do is a QMake Shadow Build. This question about Manually Configuring Shadow Builds in QMake should help you.