Skip to content

Commit

Permalink
Lower minimum required Python version to 3.2.
Browse files Browse the repository at this point in the history
We raised this to python-3.6 be able to use newer features in
scripts/autogen-version, but it turns out that we need to support down
to at least python-3.5 for platforms like ubuntu-16 or debian-9.

We now go all the way to python-3.2 which is very conservative. For that
we got rid of uses of subprocess.run (since 3.5) and f-strings (since
3.6).
  • Loading branch information
bbannier committed May 4, 2021
1 parent a296383 commit 92501e8
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ project(spicy LANGUAGES ASM C CXX)

set(flex_minimum_version "2.6")
set(bison_minimum_version "3.0")
set(python_minimum_version "3.6")
set(python_minimum_version "3.2")
set(macos_minimum_version "19.0.0") # macOS 10.15.0 (Catalina)

## Initialize defaults & global options
Expand Down
58 changes: 39 additions & 19 deletions scripts/autogen-version
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import tempfile


def get_version(ref):
git_tree = subprocess.run(
git_tree = subprocess.call(
["git", "rev-parse", "--git-dir"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
if git_tree.returncode == 0:
if git_tree == 0:
hash = subprocess.check_output(
["git", "rev-parse", "--short", ref], universal_newlines=True
).strip()
Expand All @@ -34,7 +34,8 @@ def get_version(ref):

describe_arg = ref if ref != "HEAD" else "--dirty"
raw_git_version = subprocess.check_output(
["git", "describe", "--always", "--tags", "--match", "v*", describe_arg],
["git", "describe", "--always", "--tags",
"--match", "v*", describe_arg],
universal_newlines=True,
)
# Strip the 'v' from the version tag,
Expand Down Expand Up @@ -115,7 +116,8 @@ if ci_branch:
# On release tags, git describe doesn't emit the usual suffix,
# therefore the commit field remains empty.
# To avoid unpacking failures, we set commit to nothing.
version, commit, *_ = git_version.split('-') if '-' in git_version else (git_version, "")
version, commit, * \
_ = git_version.split('-') if '-' in git_version else (git_version, "")
dirty = "dirty" if "dirty" in git_version else ""
if commit and dirty:
commit = commit + "." + dirty
Expand All @@ -129,12 +131,12 @@ else:
prerelease = "branch"
chash = ""

on_release_tag = subprocess.run(
on_release_tag = subprocess.call(
["git", "describe", "--tags", "--match", "v*", "--exact-match"],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
if on_release_tag.returncode == 0:
if on_release_tag == 0:
prerelease = ""

str_prerelease = "-" + prerelease if prerelease else ""
Expand All @@ -149,30 +151,48 @@ if options.short:
elif options.cmake:
print(version)
else: # long
print(f"{version}{str_prerelease} ({str_branch}{chash})")
print("{version}{str_prerelease} ({str_branch}{chash})".format(
version=version,
str_prerelease=str_prerelease,
str_branch=str_branch,
chash=chash))

if options.header:
header_contents = f"""\
header_contents = """\
/* Autogenerated. Do not edit.
VERSION {version}{str_prerelease}
*/
#define PROJECT_VERSION_NUMBER {version_number}
#define PROJECT_VERSION_MAJOR {major}
#define PROJECT_VERSION_MINOR {minor}
#define PROJECT_VERSION_PATCH {patch}
#define PROJECT_VERSION_PRERELEASE "{prerelease}"
#define PROJECT_VERSION_STRING_SHORT "{version}{str_prerelease}"
#define PROJECT_VERSION_STRING_LONG "{version}{str_prerelease} ({str_branch}{chash})"
"""
# define PROJECT_VERSION_NUMBER {version_number}
# define PROJECT_VERSION_MAJOR {major}
# define PROJECT_VERSION_MINOR {minor}
# define PROJECT_VERSION_PATCH {patch}
# define PROJECT_VERSION_PRERELEASE "{prerelease}"
# define PROJECT_VERSION_STRING_SHORT "{version}{str_prerelease}"
# define PROJECT_VERSION_STRING_LONG "{version}{str_prerelease} ({str_branch}{chash})"
""".format(
version=version,
version_number=version_number,
major=major,
minor=minor,
patch=patch,
prerelease=prerelease,
str_prerelease=str_prerelease,
str_branch=str_branch,
chash=chash)
with tempfile.NamedTemporaryFile(mode="w") as hdr:
hdr.write(header_contents)
hdr.flush()
shutil.copy(hdr.name, options.header)

if options.store:
with tempfile.NamedTemporaryFile(mode="w") as store:
store.write(f"branch={branch}\n")
store.write(f"hash={chash}\n")
store.write(f"git_version={git_version}\n")
store.write("""\
branch={branch}
hash={chash}
git_version={git_version}
""".format(
branch=branch,
chash=chash,
git_version=git_version))
store.flush()
shutil.copy(store.name, options.store)

0 comments on commit 92501e8

Please sign in to comment.