From 5b918afc6fd2ac9cbe0b5bed02ac1ba35a78fa8d Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Wed, 14 Feb 2024 10:28:04 -0600 Subject: Explicitly wrap non-serializable values in json dump --- CHANGES.txt | 11 +++++++---- RELEASE.txt | 2 ++ SCons/Environment.py | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 132b51c..5276033 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -43,6 +43,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER method so that the generated function argument list matches the function's prototype when including a header file. + From Thaddeus Crews: + - Explicitly wrap non-serializable values in json dump + From William Deegan: - Fix sphinx config to handle SCons versions with post such as: 4.6.0.post1 @@ -1437,12 +1440,12 @@ RELEASE 3.1.0 - Mon, 20 Jul 2019 16:59:23 -0700 scons: rebuilding `file3' because: the dependency order changed: ->Sources - Old:xxx New:zzz - Old:yyy New:yyy - Old:zzz New:xxx + Old:xxx New:zzz + Old:yyy New:yyy + Old:zzz New:xxx ->Depends ->Implicit - Old:/usr/bin/python New:/usr/bin/python + Old:/usr/bin/python New:/usr/bin/python - Fix Issue #3350 - SCons Exception EnvironmentError is conflicting with Python's EnvironmentError. - Fix spurious rebuilds on second build for cases where builder has > 1 target and the source file is generated. This was causing the > 1th target to not have it's implicit list cleared when the source diff --git a/RELEASE.txt b/RELEASE.txt index 4698e60..2052c78 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -75,6 +75,8 @@ IMPROVEMENTS - The NewParallel scheduler now only adds threads as new work requiring execution is discovered, up to the limit set by -j. This should reduce resource utilization when the achievable parallelism in the DAG is less than the -j limit. +- Dumping an environment with `json` formatting will now explicitly specify if a given + value cannot be serialized. PACKAGING diff --git a/SCons/Environment.py b/SCons/Environment.py index e61ec1f..bb3901c 100644 --- a/SCons/Environment.py +++ b/SCons/Environment.py @@ -1708,7 +1708,7 @@ class Base(SubstitutionEnvironment): elif fmt == 'json': import json def non_serializable(obj): - return str(type(obj).__qualname__) + return '<>' % type(obj).__qualname__ return json.dumps(cvars, indent=4, default=non_serializable) else: raise ValueError("Unsupported serialization format: %s." % fmt) -- cgit v0.12 From eb93cd5537466a9f17957fac15d9c3aa524b5e47 Mon Sep 17 00:00:00 2001 From: Thaddeus Crews Date: Wed, 13 Mar 2024 09:43:14 -0500 Subject: Implement test case for non-serializable json --- SCons/EnvironmentTests.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SCons/EnvironmentTests.py b/SCons/EnvironmentTests.py index c40439a..8a385c1 100644 --- a/SCons/EnvironmentTests.py +++ b/SCons/EnvironmentTests.py @@ -3177,11 +3177,12 @@ def generate(env): def test_Dump(self) -> None: """Test the Dump() method""" - env = self.TestEnvironment(FOO = 'foo') + env = self.TestEnvironment(FOO='foo', FOOFLAGS=CLVar('--bar --baz')) assert env.Dump('FOO') == "'foo'", env.Dump('FOO') assert len(env.Dump()) > 200, env.Dump() # no args version assert env.Dump('FOO', 'json') == '"foo"' # JSON key version + self.assertEqual(env.Dump('FOOFLAGS', 'json'), '"<>"') import json env_dict = json.loads(env.Dump(format = 'json')) assert env_dict['FOO'] == 'foo' # full JSON version -- cgit v0.12