bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.29k stars 4.09k forks source link

When using buildstamping for c++ targets only limited information is available #4863

Open marcushines-zz opened 6 years ago

marcushines-zz commented 6 years ago

Description of the problem / feature request:

When using buildstamping I have a custom script to insert custom values into the build stamp information. This is properly injecting the key/value pairs into the files.

user@box:~/repo$ cat bazel-out/stable-status.txt 
BUILD_EMBED_LABEL 
BUILD_HOST box
BUILD_USER user
user@box:~/yeti$ cat bazel-out/volatile-status.txt 
BUILD_SCM_BRANCH master
BUILD_SCM_REVISION "redacted"
BUILD_SCM_STATUS Modified
BUILD_SCM_TAG 1.12.1
BUILD_TIMESTAMP 1521153565848

however since the cpp buildinfo is based on a class there is no way to additional information. This would be really helpful if instead a struct it was a map so users could embed arbitrary data into the binary. Since the implementation is only a #define in the generated header files this would be great to enable

Feature requests: what underlying problem are you trying to solve with this feature?

Include all build metadata into binaries for reporting infrastructure to make use of.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

just make a cc_binary and build with --stamp and then view the produced headers files vs the contains of the txt files

you will need to add your own custom keys into the file via a script like

#!/bin/bash

# This script will be run bazel when building process starts to
# generate key-value information that represents the status of the
# workspace. The output should be like
#
# KEY1 VALUE1
# KEY2 VALUE2
#
# If the script exits with non-zero code, it's considered as a failure
# and the output will be discarded.

git_rev=$(git rev-parse HEAD)
if [[ $? != 0 ]];
then
    exit 1
fi
echo "BUILD_SCM_REVISION ${git_rev}"

git_tag=$(git describe --abbrev=0 --tags)
if [[ $? != 0 ]];
then
    exit 1
fi
echo "BUILD_SCM_TAG ${git_tag}"

git_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ $? != 0 ]];
then
    exit 1
fi
echo "BUILD_SCM_BRANCH ${git_branch}"

# Check whether there are any uncommited changes
git diff-index --quiet HEAD --
if [[ $? == 0 ]];
then
    tree_status="Clean"
else
    tree_status="Modified"
fi
echo "BUILD_SCM_STATUS ${tree_status}"

What operating system are you running Bazel on?

Linux 4.9.0-6-amd64 #1 SMP Debian 4.9.82-1

What's the output of bazel info release?

release 0.11.1

If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.

NA

What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?

private

github-actions[bot] commented 1 year ago

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 3 years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.

github-actions[bot] commented 1 year ago

This issue has been automatically closed due to inactivity. If you're still interested in pursuing this, please reach out to the triage team (@bazelbuild/triage). Thanks!