can bazel test if two rules are identical - bazel

I'd like to compare two rules to see whether or not they are identical (in particular, I'd like to be able to test a bazel target before and after a commit to see if it has changed)
Is there a way to accomplish this, perhaps with bazel query?

You can try bazel query with --output=build to have bazel print out the rule with everything expanded (e.g. macros evaluated, globs expanded, expressions evaluated, etc) before and after the change, and compare the results. See https://docs.bazel.build/versions/master/query.html#output-build for more information.

Related

In Nix, why does hashDrv replace the inputDrvs with a recursive hashDrv of their contents

In Section 5.4 of Eelco Dolstra's thesis on page 108 there is a definition of the hashDrv function in which, on box 69, the inputDrvs are replaced (recursively) with the hashDrv of the parsed contents of the file. I don't understand the motivation for performing this substitution as opposed to just using the the inputDrvs file names themselves without perform a substitution.
The consequence of this substitution appears to be that the output values of store derivations are recursively removed from the computation of all output values. However, since the output values themselves are computed from all the other data that goes into hashDrv, there doesn't seem to be any positive consequences for doing this substitution operation.
Indeed there appears to be negative consequences because this substitution means that the output hash file cannot be computed from the derivation contents itself, and instead you are required to have the entire tree of input derivations to perform the computation (see https://github.com/NixOS/nix/issues/2789#issuecomment-595143352).
While of course the output hash value for the derivation itself needs to be excluded from the computation of its hashDrv, it seems like it would have been better if the output hash values were simply derived from just the other contents of the derivation file.
OK so first all, it would be better still to just drop the inputDrvs and just use the output paths of those inputs for creating the store path, see the commit message of https://github.com/nixos/nix/commit/1511aa9f488ba0762c2da0bf8ab61b5fde47305d for Eelco saying as much:
Note that this is a privileged operation, because you can construct a
derivation that builds any store path whatsoever. Fixing this will
require changing the hashing scheme (i.e., the output paths should be
computed from the other fields in BasicDerivation, allowing them to be
verified without access to other derivations). However, this would be
quite nice because it would allow .drv-free building (e.g. "nix-env
-i" wouldn't have to write any .drv files to disk).
But, the hashDrv given is better than one that just hashes the drv as-is, because the "modulo fixed output derivations part". By ignoring the rest fixed output derivations and just returning a hash based on the fixed output hash (and name) alone, we gain the ability to change how fixed output derivations produce the data they do without changing downstream hashes. This how in Nixpkgs today, we can for example do https://github.com/NixOS/nixpkgs/pull/82130 and it won't be a mass rebuild.

Can I query for a set of tags?

I want to run a set of Bazel targets. My BUILD file look like this
load("#rules_java//java:defs.bzl", "java_binary")
java_binary(
name = "run_me",
srcs = glob(["src1/main/java/com/example/*.java"]),
tags = ["java", "good"],
)
java_binary(
name = "me_also",
srcs = glob(["src2/main/java/com/example/*.java"]),
tags = ["java", "good"],
)
java_binary(
name = "do_not_run_me",
srcs = glob(["src3/main/java/com/example/*.java"]),
tags = ["java", "bad"],
)
I want to run all the targets tagged as "good". I'm hoping to be able to do something like
bazel query 'tags(["good"], //...)'
I don't see the ability to query for tags in the documentation. I do see attr, so I tried
bazel query 'attr(tags, "\[good\]", //...)'
But that doesn't work. I assume because
List-type attributes (such as srcs, data, etc) are converted to strings of the form [value1, ..., valuen], starting with a [ bracket, ending with a ] bracket and using ", " (comma, space) to delimit multiple values
I am able to make it work with an exact match,
bazel query 'attr(tags, "\[good, java\]", //...)'
However, notice that
The ordering of the list swapped ("\[java, good\]") doesn't get any results). I'm not sure if it's alphabetizing or if it's putting them in a hash-set. But it means the ordering isn't reliable.
I don't want to have to list all the tags. I want to be able to run all the "good" targets even if some are also tagged "slow" or "local".
Can I use tags for this task? Are tags really just intended for tests? (The test_suite is the reason I thought to use tags in the first place.)
If by "run a set of Bazel targets" you mean bazel run, you can use --build_tag_filters for this:
https://docs.bazel.build/versions/3.2.0/command-line-reference.html#flag--build_tag_filters
Note however that bazel run supports running only 1 executable target at a time.
If you want to run many binaries in a single call, you'll need to continue to pursue bazel query.
The attr() filter accepts a regular expression, so to get around the problem of tags being in arbitrary order, you can do something like:
bazel query "attr(tags, '\\bgood\\b', //...)"
(where \b is the word boundary matcher)
If you have multiple tags, you can use intersect:
bazel query "attr(tags, '\\bgood\\b', //...) intersect attr(tags, '\\balso-good\\b', //...)"
That will give you the list of targets to run, then you can do something like:
targets=$(bazel query "attr(tags, '\\bgood\\b', //...)")
bazel build ${targets[#]}
for target in ${targets[#]}; do
bazel run $target &
done
bazel run will build the targets before running them, and bazel will wait on previous invocations of itself in the same workspace[1]. So to get the binaries to run in parallel (if that's something you want), the example builds all the targets before running them. (bazel won't block subsequent invocations of itself once the binary is running)
There's also another idea that seems nicer, which is to have an sh_binary which depends on all the binaries you want to run, and the sh_binary script simply runs them. You would then be able to do bazel run on that single sh_binary. The problem with that is you'd have to list each binary you want to run in the data attribute of the sh_binary, because it's not possible to create dependencies in a BUILD file using a query (despite there being a genquery rule -- that just outputs the results of the query to a file).
[1] unless you have separate output bases using --output_base for the different invocations

Query the output destination of a bazel target, with --symlink_prefix

Can bazel tell me where --symlink_prefix points?
Different users have different ~/.bazelrc files, which specify different values for this flag. I'd like to query, in a given workspace, where the binary files will get (or have been) written to.
Thanks.
bazel info bazel-bin and bazel info bazel-genfiles will tell you the absolute paths.

Error Adding Variables in SPSS

I am using the Data > Merge Files > Add Variables in SPSS. The two .sav files both contain a variable called "Student_No" which is numeric with the same width in each file. I am using this as the key variable in which to match cases. I am not indicating that cases are not sorted. It makes no difference if I indicate that the active or non-active data set is keyed. In either case the new variables are not properly matched with the cases.
What are some of the potential problems that might be causing this mismatch?
The dialog box pastes STAR JOIN syntax in some cases and MATCH FILES in others. There were some problems with STAR JOIN in older versions of Statistics, so you might need to use MATCH FILES instead. See the Command Syntax Reference for that command on how to do this.

Can tags in Rspec be ANDed or ORed?

In Cucumber, I had something like this
#do_this
#de #fr #it #us
Scenario: Do something irrelevant
Given ...
When ...
Then
#do_that
#de #fr #it #us
Scenario: Do a different irrelevant thing
Given ...
When ...
Then
It was possible to do something like cucumber -t #de -t #do_this, so only scenarios which matched both tags would be run. I can't seem to get the same behavior in Rspec, though. In the above example, only the first scenario would run, even though the second one also has a #de tag.
Background: I have a platform which is rolled out in many countries, and not all features are available in every country. So the nice thing was that I could just tag the scenarios accordingly, and then call individual scenarios from the command line. I am currently in the process of switching to Rspec from Cucumber because of several reasons, but this is the only thing holding me back at the moment. Of course I am also open for other suggestions on how to approach this.
Short version: I would like to call individual tests in Rspec who match two or more tags.
RSpec tag expressions are only ORed for inclusion and ANDed for exclusion, so you can't do what you want in general. Further, it appears that you can use either tag filters or a filter on the example descriptions, but not both, so I think that combining those two techniques is out as well. (Perhaps someone can correct me on this).
However, if you have a limited/structured situation implied by your example, I think you can do the following:
Define a boolean tag for each of the languages and use the traditional inclusion filter
Define a do tag with values of this, that, etc. and use a lambda exclusion filter which will exclude everything but the value(s) you want.
If you do the above, you will be able so specify examples which contain any of the languages you want and whatever subset of the do values you want
However, I doubt there is a way to specify the lambda expression format in the command line so I think you're limited to using the configuration option approach. In any event, see http://rubydoc.info/github/rspec/rspec-core/RSpec/Core/Configuration:filter_run_excluding for a description of the underlying capability.
That's a lot of limitations, I know. This seems like an area where RSpec could be fairly easily extended, so perhaps we'll see extensions in the future.

Resources