Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep build_info.json up to date and in sync with bazel build #172

Open
studgeek opened this issue Aug 13, 2024 · 6 comments
Open

Keep build_info.json up to date and in sync with bazel build #172

studgeek opened this issue Aug 13, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@studgeek
Copy link
Contributor

#171 introduces a build_info.json file that lists build info for downstream, non-bazel projects.

We should implement a way to ensure build_info.json stays in sync with emboss repo changes.

A few possible approaches to consider (there are probably others):

  1. Have the bazel build also use build_info.json. So there is one source of truth.
  2. Have the bazel build/tests verify it matches what is in bazel. So bazel build verifies info is correct.
  3. Have bazel build generate build_info.json. This can be tricky since it requires the build to change the source files.
  4. Have bazel build generate the expected build_info.json and test that it matches (a mix of 3 and 4).
@jasongraffius
Copy link
Collaborator

I think this could be tricky because of Bazel's hermetic guarantees, for instance:

  • Bazel can't read from any files that aren't bazel files (BUILD, BUILD.bazel, *.bzl, etc.).
  • All of Bazel's output is in the hermetic output directory.
  • The build graph isn't accessible to rules (a rule only knows of its own sub-graph).

So I don't think this can be done solely as a part of a Bazel build.

However, there may be some invocation of bazel query alongside a script to compare/verify similarity. I would worry that such a script could be brittle, though, if it has to make assumptions about the structure of the repo to make the comparison.

@jasongraffius
Copy link
Collaborator

Actually, it may be possible to use Bazel aspects for this, I'll have to look into/experiment with this

@studgeek
Copy link
Contributor Author

My though was some variant of approach 4 should work even with the restrictions you listed. With a lot of hand waving, my thought is there are essentially two steps.

The first is to generate the build info into an output file. Bazel aspects sounds like it could be great for this. Or perhaps an python action that takes the source files and generates the output file. For the latter the source files could be in a variable so the same list is used for normal usage and for generating the output file.

Then a python or C++ test that takes the build_info.json and generated output file as deps and then compares their contents.

@jasongraffius
Copy link
Collaborator

Yep yep, the generating the build graph part was the part I was hung up on, but it looks like it is likely doable from aspects

@reventlov
Copy link
Collaborator

We do something similar to option 4 for grammar.md: generate_grammar_md.py can be used to generate grammar.md, and docs_are_up_to_date_test.py checks that the generated file matches the checked-in file. I'm half planning to do something similar for the LR(1) parser tables, which take a noticeable amount of time to build at compiler startup.

I think that option 1 is out for the reasons Jason listed, option 2 is possible, but requires manual work, and option 3 is not directly possible because Bazel won't generate files into the source tree.

There is an option 5: have something parse the BUILD files outside of Bazel, and option 6: have a new top-level source of truth, from which the BUILD files are generated (with a test to ensure that the checked-in BUILD files match the new files).

@EricRahm
Copy link
Collaborator

  1. is probably more in line with what boringssl does, I'm kind of leaning towards that. Essentially it takes a top-level build.json file, runs it through a script that cleans it up and outputs some files to a gen/ directory that has a sources.{json,bzl,cmake,gni}. This is run outside of it's bazel build. The BUILD.bazel file then has access to the generated source list via load(":gen/sources.bzl",...)

@EricRahm EricRahm added the enhancement New feature or request label Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants