BuildStream fails at runtime if it was built without git tags

Summary

If the BuildStream source/binary pacakge is not built from a git checkout without any tags, BuildStream will successfully build and install. However, it will complain at runtime like so:

$ bst -C doc/examples/first-project show
Error loading user configuration: Your git repository has no tags - BuildStream can't determine its version. Please run `git fetch --tags`.

I think this is worth fixing because this seems like a common pitfall. Here are a few reasons why this might happen:

  • CI systems often clone a single commit by default for performance reasons
  • git push doesn't push tags by default, so someone naively creating a mirror for BuildStream might fall into this trap
  • Some integration systems (like BuildStream itself!) do not track tags by default, so someone building BuildStream with BuildStream would also remember to turn on a separate knob

I will gladly admit that I have personally done all these mistakes at least once and know that some others have too. So, I think we should ensure that this error is reported at build time.

Reporting it at runtime is also a bit misguided because running git fetch --tags at that time isn't going to solve anything. The package is already built and installed. We should at least mention to reinstall BuildStream after fetching tags.

Steps to reproduce

# Create a shallow clone.
git clone --depth=1 https://gitlab.com/buildstream/buildstream

# Install BuildStream
# Note that `-e` option does not really matter here,
# failure behavior is the same in both cases.
pip install buildstream

# Try to run BuildStream.
bst -C buildstream/doc/examples/first-project show

# See the following error message:
#
# Error loading user configuration: Your git repository has no tags - BuildStream can't determine its version. Please run `git fetch --tags`.

What is the current bug behavior?

BuildStream throws a not-very-helpful error at runtime.

What is the expected correct behavior?

  • This is reported at build time so that it's not possible to install BuildStream without a proper version.
  • BuildStream throws a bettter error at runtime in case that somehow it happens anyway.