Skip to content

Commit

Permalink
Implement GetSConsVersion static method
Browse files Browse the repository at this point in the history
  • Loading branch information
Repiteo committed Apr 13, 2024
1 parent 5dd1d9c commit 264f7c1
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ NOTE: 4.3.0 now requires Python 3.6.0 and above. Python 3.5.x is no longer suppo

RELEASE VERSION/DATE TO BE FILLED IN LATER

From Thaddeus Crews:
- GetSConsVersion() to grab the latest SCons version without needing to
dig into private functions.

From Raymond Li:
- Fix issue #3935: OSErrors are now no longer hidden during execution of
Actions. All exceptions during the execution of an Action are now
Expand Down
2 changes: 1 addition & 1 deletion RELEASE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Here is a summary of the changes since 4.7.0:
NEW FUNCTIONALITY
-----------------

- List new features (presumably why a checkpoint is being released)
- GetSConsVersion() to grab the current SCons version from an exposed api.

DEPRECATED FUNCTIONALITY
------------------------
Expand Down
16 changes: 12 additions & 4 deletions SCons/Script/SConscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import sys
import traceback
import time
from typing import Tuple

class SConscriptReturn(Exception):
pass
Expand Down Expand Up @@ -385,7 +386,7 @@ class SConsEnvironment(SCons.Environment.Base):
# Private methods of an SConsEnvironment.
#
@staticmethod
def _get_major_minor_revision(version_string):
def _get_major_minor_revision(version_string: str) -> Tuple[int, int, int]:
"""Split a version string into major, minor and (optionally)
revision parts.
Expand Down Expand Up @@ -484,15 +485,22 @@ def Default(self, *targets) -> None:
SCons.Script._Set_Default_Targets(self, targets)

@staticmethod
def EnsureSConsVersion(major, minor, revision: int=0) -> None:
def GetSConsVersion() -> Tuple[int, int, int]:
"""Return the current SCons version.
.. versionadded:: 4.8.0
"""
return SConsEnvironment._get_major_minor_revision(SCons.__version__)

@staticmethod
def EnsureSConsVersion(major: int, minor: int, revision: int = 0) -> None:
"""Exit abnormally if the SCons version is not late enough."""
# split string to avoid replacement during build process
if SCons.__version__ == '__' + 'VERSION__':
SCons.Warnings.warn(SCons.Warnings.DevelopmentVersionWarning,
"EnsureSConsVersion is ignored for development version")
return
scons_ver = SConsEnvironment._get_major_minor_revision(SCons.__version__)
if scons_ver < (major, minor, revision):
if SConsEnvironment.GetSConsVersion() < (major, minor, revision):
if revision:
scons_ver_string = '%d.%d.%d' % (major, minor, revision)
else:
Expand Down
1 change: 1 addition & 0 deletions SCons/Script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ def Variables(files=None, args=ARGUMENTS):
#
# Static functions that do not trigger initialization of
# DefaultEnvironment() and don't use its state.
GetSConsVersion = _SConscript.SConsEnvironment.GetSConsVersion
EnsureSConsVersion = _SConscript.SConsEnvironment.EnsureSConsVersion
EnsurePythonVersion = _SConscript.SConsEnvironment.EnsurePythonVersion
Exit = _SConscript.SConsEnvironment.Exit
Expand Down
14 changes: 14 additions & 0 deletions test/EnsureSConsVersion.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@

test.run(status=2)

test.write('SConstruct', """\
env = Environment()
env.EnsureSConsVersion(env.GetSConsVersion())
Exit(0)
""")

test.run()



test.write('SConstruct', """\
Expand Down Expand Up @@ -121,6 +129,12 @@

test.run(status=2)

test.write('SConstruct', """\
import SCons
EnsureSConsVersion(GetSConsVersion())
""")

test.run()


test.pass_test()
Expand Down

0 comments on commit 264f7c1

Please sign in to comment.