I'd like to maintain a list of dependencies and their versions per Bazel project.
How do I query for WORKSPACE rules the BUILD rules depend on? How can I access the contained attributes?
EDIT I'd like to query based on a BUILD rule. So if I have multiple rules, I only want the WORKSPACE info based on the one I asked for.
The way I did this was to keep the workspace deps in a separate format, iterate them, and then build a markdown document.
See https://github.com/pubref/rules_protobuf/blob/master/DEPENDENCIES.md
https://github.com/pubref/rules_protobuf/blob/master/protobuf/internal/proto_dependencies.bzl
There's probably a way to do it via a genquery and native.existing_rules, but I have not tried that.
HTH,
Paul
Related
New to Bazel. Looking to see if there is a way to create a Bazel rule that allows me to get a list of all targets and then feed that data into a kotlin file or something like that.
I was able to run bazel query //... --export xml > temp.xml this gives me all the targets and their build files info but I would like to retrieve this info using a bazel rule, any ideas of how I could go about this?
The short answer is no. The closest thing to this in Bazel is a genquery, though it's worth noting that there are some caveats to this approach as mentioned in the docs;
In order to keep the build consistent, the query is allowed only to visit the transitive closure of the targets specified in the scope attribute. Queries violating this rule will fail during execution if strict is unspecified or true (if strict is false, the out of scope targets will simply be skipped with a warning). The easiest way to make sure this does not happen is to mention the same labels in the scope as in the query expression.
If you are happy to blow past the warnings around 'build consistency' it might be possible to achieve this using a similar approach to the buildifier rules, where you would determine the path of the workspace and run Bazel query as a subprocess of Bazel. Personally, I wouldn't recommend this and instead would suggest that you just use the output of bazel query directly.
Is there a way to instruct bazel to list all the targets it has found without building or testing them?
bazel query can be used to discover targets within a bazel workspace (without building / testing them)
For example;
To find all labels in a given package:
bazel query //some/package:*
If only interested in rules, then:
bazel query 'kind(.*rule, //some/package:*)'
//some/package:* could be substituted for any valid label expression, eg including all descending packages, //some/package/...
The bazel query docs show further functions that could be used.
If you want to list targets taking into account select statements resolving, take a look at bazel cquery command.
query would list targets for all select options, cquery - only chosen ones
Documentation with great examples
We use Teamcity 2018 together with TFS.
We have one project in which the structure is following
Root <---- We want to checkout the whole Root-directory
\ProjectA <---- We want to show changes only from the sub-directory
\ProjectB
\ProjectB
We would like to watch changes from Root\ProjectA-directory and display only changes that were done under that directory.
However, we would like to checkout the whole Root-directory and run our build from there.
Is there any way to do this?
Trigger rules can help you accomplish this. Within your VCS trigger, you can specify a collection of rules to filter in or out various conditions that will cause your build configuration to trigger. These are independent of your VCS rules and those rules will handle what you choose to checkout as normal. The rule syntax is as follows:
+|-[:[user=VCS_username;][root=VCS_root_id;][comment=VCS_comment_regexp]]:Ant_like_wildcard
The Ant_like_wildcard is the element of particular interest to you in this case, as you can use them (among other things) to filter in or out a particular directory.
Here is an example from the TeamCity Documentation:
"-:lib/**" prevents the build from triggering by updates to the "lib" directory of the build sources
Using your example, your trigger rule would look something like:
+:ProjectA/**
You can use a single inclusion rather than multiple exclusions because of the way TeamCity handles those types of rules:
When specifying the rules, please note that as soon as you enter any "+" rule, TeamCity will change the implicit default from "include all" to "exclude all".
You can find the full TeamCity VCS Trigger documentation here
So, at work, I frequently have to create virtually identical ant scripts. Basically the application we provide to our clients is designed to be easily extensible, and we offer a service of designing and creating custom modules for it. Because of the complexity of our application, with lots of cross dependencies, I tend to develop the module within our core dev environment, compile it using IntelliJ, and then run a basic ant script that does the following tasks:
1) Clean build directory
2) Create build directory and directory hierarchy based on package paths.
3) Copy class files (and source files to a separate sources directory).
4) Jar it up.
The thing is, to do this I need to go through the script line by line and change a bunch of property names, so it works for the new use case. I also save all the scripts in case I need to go back to them.
This isn't the worst thing in the world, but I'm always looking for a better way to do things. Hence my idea:
For each specific implementation I would provide an ant script (or other file) of just properties. Key-value pairs, which would have specific prefixes for each key based on what it's used for. I would then want my ant script to run the various tasks, executing each one for the key-value pairs that are appropriate.
For example, copying the class files. I would have a property with a name like "classFile.filePath". I would want the script to call the task for every property it detects that starts with "classFile...".
Honestly, from my current research so far, I'm not confident that this is possible. But... I'm super stubborn, and always looking for new creative options. So, what options do I have? Or are there none?
It's possible to dynamically generate ANT scripts, for example the following does this using an XML input file:
Use pure Ant to search if list of files exists and take action based on condition
Personally I would always try and avoid this level of complexity. Ant is not a programming language.
Looking at what you're trying to achieve it does appear you could benefit from packaging your dependencies as jars and using a Maven repository manager like Nexus or Artifactory for storage. This would simplify each sub-project build. When building projects that depend on these published libraries you can use a dependency management tool like Apache ivy to download them.
Hope that helps your question is fairly broad.
I have a customized build process that sets the build name to the current version, updates the FileAssemblyVersion, drops to two different folders, and removes all unessential files from the drop folders, and I'm feeling that I'm starting to get the hang of custom actions and the workflows now.
So now I want to include a changelog in my drop folder; the Changeset comments. Either only the Changesets associated with this build, but possibly all changesets from a given changeset (such as a version number change, or another event).
What is the best way to approach this?
The Codeplex project TFSChangeLog can help you. From a command line you can create a XML file. Using XSLT you can create an output file of your choice.
http://tfschangelog.codeplex.com