title: How does Bazel's py_binary stamping work?
body: <p>The docs say that the "stamp" parameter will "enable link stamping" and that it will "encode build information into the binary" and "stamp the build information into the binary"</p>
  
  <p>But where does that information actually go, and how can I retrieve it?</p>
  
  <p>It does not seem to be a simple search-and-replace, nor variable definition, nor environment variable, nor format-string variable.  Test python script:</p>
  
  <pre><code>BUILD_HOST="ASDF"
  print("{BUILD_HOST}")
  print(BUILD_HOST)
  </code></pre>
  
  <p>Build rule:
  <code>py_binary(name="catself", srcs=["catself.py"], stamp=1)</code></p>
  
  <p>Output:</p>
  
  <pre><code>$ bazel run --stamp catself
  INFO: Analyzed target //:catself (0 packages loaded, 0 targets configured).
  INFO: Found 1 target...
  Target //:catself up-to-date:
    bazel-bin/catself
  INFO: Elapsed time: 0.083s, Critical Path: 0.01s
  INFO: 0 processes.
  INFO: Build completed successfully, 1 total action
  INFO: Build completed successfully, 1 total action
  {BUILD_HOST}
  ASDF
  </code></pre>