kopia lustrzana https://github.com/micropython/micropython
py/makeversionhdr.py: Reinstate MICROPY_GIT_HASH in mpversion.h.
MICROPY_GIT_HASH was removed in 69e34b6b6b
but it is useful for, and used by, third-party code to tell which hash of
MicroPython is used.
Signed-off-by: Damien George <damien@micropython.org>
pull/13661/head
rodzic
1ef2944b98
commit
9242e3d16d
|
@ -25,7 +25,6 @@ def get_version_info_from_git(repo_path):
|
||||||
# Python 2.6 doesn't have check_output, so check for that
|
# Python 2.6 doesn't have check_output, so check for that
|
||||||
try:
|
try:
|
||||||
subprocess.check_output
|
subprocess.check_output
|
||||||
subprocess.check_call
|
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
@ -44,9 +43,25 @@ def get_version_info_from_git(repo_path):
|
||||||
return git_tag[0]
|
return git_tag[0]
|
||||||
else:
|
else:
|
||||||
return git_tag[0] + "-" + git_tag[1].replace("-", ".")
|
return git_tag[0] + "-" + git_tag[1].replace("-", ".")
|
||||||
except subprocess.CalledProcessError:
|
except (subprocess.CalledProcessError, OSError):
|
||||||
return None
|
return None
|
||||||
except OSError:
|
|
||||||
|
|
||||||
|
def get_hash_from_git(repo_path):
|
||||||
|
# Python 2.6 doesn't have check_output, so check for that.
|
||||||
|
try:
|
||||||
|
subprocess.check_output
|
||||||
|
except AttributeError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
try:
|
||||||
|
return subprocess.check_output(
|
||||||
|
["git", "rev-parse", "--short", "HEAD"],
|
||||||
|
cwd=repo_path,
|
||||||
|
stderr=subprocess.STDOUT,
|
||||||
|
universal_newlines=True,
|
||||||
|
).strip()
|
||||||
|
except (subprocess.CalledProcessError, OSError):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,10 +101,13 @@ def get_version_info_from_mpconfig(repo_path):
|
||||||
|
|
||||||
def make_version_header(repo_path, filename):
|
def make_version_header(repo_path, filename):
|
||||||
git_tag = None
|
git_tag = None
|
||||||
|
git_hash = None
|
||||||
if "MICROPY_GIT_TAG" in os.environ:
|
if "MICROPY_GIT_TAG" in os.environ:
|
||||||
git_tag = os.environ["MICROPY_GIT_TAG"]
|
git_tag = os.environ["MICROPY_GIT_TAG"]
|
||||||
|
git_hash = os.environ.get("MICROPY_GIT_HASH")
|
||||||
if git_tag is None:
|
if git_tag is None:
|
||||||
git_tag = get_version_info_from_git(repo_path)
|
git_tag = get_version_info_from_git(repo_path)
|
||||||
|
git_hash = get_hash_from_git(repo_path)
|
||||||
if git_tag is None:
|
if git_tag is None:
|
||||||
git_tag = get_version_info_from_mpconfig(repo_path)
|
git_tag = get_version_info_from_mpconfig(repo_path)
|
||||||
|
|
||||||
|
@ -104,12 +122,15 @@ def make_version_header(repo_path, filename):
|
||||||
).date()
|
).date()
|
||||||
|
|
||||||
# Generate the file with the git and version info
|
# Generate the file with the git and version info
|
||||||
|
# Note: MICROPY_GIT_HASH may be used by third-party code.
|
||||||
file_data = """\
|
file_data = """\
|
||||||
// This file was generated by py/makeversionhdr.py
|
// This file was generated by py/makeversionhdr.py
|
||||||
#define MICROPY_GIT_TAG "%s"
|
#define MICROPY_GIT_TAG "%s"
|
||||||
|
#define MICROPY_GIT_HASH "%s"
|
||||||
#define MICROPY_BUILD_DATE "%s"
|
#define MICROPY_BUILD_DATE "%s"
|
||||||
""" % (
|
""" % (
|
||||||
git_tag,
|
git_tag,
|
||||||
|
git_hash or "<no hash>",
|
||||||
build_date.strftime("%Y-%m-%d"),
|
build_date.strftime("%Y-%m-%d"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue