"Fossies" - the Fresh Open Source Software Archive

Member "mesa-20.1.8/bin/git_sha1_gen.py" (16 Sep 2020, 1407 Bytes) of package /linux/misc/mesa-20.1.8.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "git_sha1_gen.py" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 20.1.5_vs_20.2.0-rc1.

    1 """
    2 Generate the contents of the git_sha1.h file.
    3 The output of this script goes to stdout.
    4 """
    5 
    6 
    7 import argparse
    8 import os
    9 import os.path
   10 import subprocess
   11 import sys
   12 
   13 
   14 def get_git_sha1():
   15     """Try to get the git SHA1 with git rev-parse."""
   16     git_dir = os.path.join(os.path.dirname(sys.argv[0]), '..', '.git')
   17     try:
   18         git_sha1 = subprocess.check_output([
   19             'git',
   20             '--git-dir=' + git_dir,
   21             'rev-parse',
   22             'HEAD',
   23         ], stderr=open(os.devnull, 'w')).decode("ascii")
   24     except:
   25         # don't print anything if it fails
   26         git_sha1 = ''
   27     return git_sha1
   28 
   29 def write_if_different(contents):
   30     """
   31     Avoid touching the output file if it doesn't need modifications
   32     Useful to avoid triggering rebuilds when nothing has changed.
   33     """
   34     if os.path.isfile(args.output):
   35         with open(args.output, 'r') as file:
   36             if file.read() == contents:
   37                 return
   38     with open(args.output, 'w') as file:
   39         file.write(contents)
   40 
   41 parser = argparse.ArgumentParser()
   42 parser.add_argument('--output', help='File to write the #define in',
   43                     required=True)
   44 args = parser.parse_args()
   45 
   46 git_sha1 = os.environ.get('MESA_GIT_SHA1_OVERRIDE', get_git_sha1())[:10]
   47 if git_sha1:
   48     write_if_different('#define MESA_GIT_SHA1 " (git-' + git_sha1 + ')"')
   49 else:
   50     write_if_different('#define MESA_GIT_SHA1 ""')