From a8016c61cdac9e73c77f83143cd7aa3118330cef Mon Sep 17 00:00:00 2001 From: William Deegan Date: Tue, 6 Jun 2023 10:42:35 -0700 Subject: Skip checking for exception when writing to unwritable dir in test. Change logic which get's nodename to work on all platforms (was failing on windows) --- SCons/Script/Main.py | 4 +++- SCons/Util/stats.py | 8 ++++---- test/option/debug-json.py | 9 ++++++--- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/SCons/Script/Main.py b/SCons/Script/Main.py index d4b83b0..68a8183 100644 --- a/SCons/Script/Main.py +++ b/SCons/Script/Main.py @@ -533,7 +533,9 @@ def DebugOptions(json=None): try: if not os.path.isdir(json_dir): os.makedirs(json_dir, exist_ok=True) - except (FileNotFoundError, OSError) as e: + # Now try to open file and see if you can.. + open(SCons.Util.stats.JSON_OUTPUT_FILE,'w') + except OSError as e: raise SCons.Errors.UserError(f"Unable to create directory for JSON debug output file: {SCons.Util.stats.JSON_OUTPUT_FILE}") diff --git a/SCons/Util/stats.py b/SCons/Util/stats.py index 58fa5dd..d2f2574 100644 --- a/SCons/Util/stats.py +++ b/SCons/Util/stats.py @@ -33,7 +33,7 @@ There are basically two types of stats. though it might be useful to query during a run. """ -import os +import platform import json import sys from datetime import datetime @@ -190,7 +190,7 @@ def WriteJsonFile(): 'COMMAND_LINE_TARGETS' : [ str(clt) for clt in COMMAND_LINE_TARGETS], 'ARGV' : sys.argv, 'TIME' : datetime.now().isoformat(), - 'HOST' : os.uname().nodename, + 'HOST' : platform.node(), 'PYTHON_VERSION' : { 'major' : sys.version_info.major, 'minor' : sys.version_info.minor, @@ -201,9 +201,9 @@ def WriteJsonFile(): } - with open(JSON_OUTPUT_FILE, 'w') as sf: - sf.write(json.dumps(json_structure, indent=4)) + sf.write(json.dumps(json_structure, indent=4)) + # Local Variables: # tab-width:4 diff --git a/test/option/debug-json.py b/test/option/debug-json.py index f3e6e0f..867f3c2 100644 --- a/test/option/debug-json.py +++ b/test/option/debug-json.py @@ -32,6 +32,7 @@ import re import sys import TestSCons +from TestCmd import IS_WINDOWS test = TestSCons.TestSCons() @@ -81,9 +82,11 @@ test.run(arguments='--debug=count,json JSON=build/output/stats.json') test.must_exist('build/output/stats.json') check_json_file('build/output/stats.json') -test.run(arguments='--debug=count,json JSON=/cant/write/here/dumb.json', status=2, stderr=None) -test.must_not_exist('/cant/write/here/dumb.json') -test.pass_test('scons: *** Unable to create directory for JSON debug output file:' in test.stderr()) +# TODO: Not sure how to do this in a reasonable way on windows, so just skip for now +if not IS_WINDOWS: + test.run(arguments='--debug=count,json JSON=/cant/write/here/dumb.json', status=2, stderr=None) + test.must_not_exist('/cant/write/here/dumb.json') + test.pass_test('scons: *** Unable to create directory for JSON debug output file:' in test.stderr()) test.pass_test() -- cgit v0.12