summaryrefslogtreecommitdiffstats
path: root/SCons
diff options
context:
space:
mode:
authorJoseph Brill <48932340+jcbrill@users.noreply.github.com>2024-10-20 11:19:05 (GMT)
committerJoseph Brill <48932340+jcbrill@users.noreply.github.com>2024-10-20 11:19:05 (GMT)
commitc815981f684ee98483b5fe85675e01954ff81aff (patch)
tree55350a63e5f3d97b5f802ebbce23c9e8896dfec5 /SCons
parentda65616846b54e1e84d508823b58740dcbf9d3ca (diff)
parent29730012bd763884ae664a3981f3fa717dabf90a (diff)
downloadSCons-c815981f684ee98483b5fe85675e01954ff81aff.zip
SCons-c815981f684ee98483b5fe85675e01954ff81aff.tar.gz
SCons-c815981f684ee98483b5fe85675e01954ff81aff.tar.bz2
Merge branch 'master' into jbrill-msvs-tests
Diffstat (limited to 'SCons')
-rw-r--r--SCons/EnvironmentTests.py361
-rw-r--r--SCons/Tool/MSCommon/common.py22
2 files changed, 198 insertions, 185 deletions
diff --git a/SCons/EnvironmentTests.py b/SCons/EnvironmentTests.py
index 361dda9..a37e424 100644
--- a/SCons/EnvironmentTests.py
+++ b/SCons/EnvironmentTests.py
@@ -1564,7 +1564,7 @@ def exists(env):
def test_gvars(self) -> None:
- """Test the Environment gvars() method"""
+ """Test the Environment gvars() method."""
env = self.TestEnvironment(XXX = 'x', YYY = 'y', ZZZ = 'z')
gvars = env.gvars()
assert gvars['XXX'] == 'x', gvars['XXX']
@@ -1572,7 +1572,7 @@ def exists(env):
assert gvars['ZZZ'] == 'z', gvars['ZZZ']
def test__update(self) -> None:
- """Test the _update() method"""
+ """Test the _update() method."""
env = self.TestEnvironment(X = 'x', Y = 'y', Z = 'z')
assert env['X'] == 'x', env['X']
assert env['Y'] == 'y', env['Y']
@@ -1592,106 +1592,103 @@ def exists(env):
assert env['SOURCES'] == 'sss', env['SOURCES']
def test_Append(self) -> None:
- """Test appending to construction variables in an Environment
- """
-
+ """Test appending to construction variables in an Environment."""
b1 = Environment()['BUILDERS']
b2 = Environment()['BUILDERS']
assert b1 == b2, diff_dict(b1, b2)
cases = [
- 'a1', 'A1', 'a1A1',
- 'a2', ['A2'], ['a2', 'A2'],
- 'a3', UL(['A3']), UL(['a', '3', 'A3']),
- 'a4', '', 'a4',
- 'a5', [], ['a5'],
- 'a6', UL([]), UL(['a', '6']),
- 'a7', [''], ['a7', ''],
- 'a8', UL(['']), UL(['a', '8', '']),
-
- ['e1'], 'E1', ['e1', 'E1'],
- ['e2'], ['E2'], ['e2', 'E2'],
- ['e3'], UL(['E3']), UL(['e3', 'E3']),
- ['e4'], '', ['e4'],
- ['e5'], [], ['e5'],
- ['e6'], UL([]), UL(['e6']),
- ['e7'], [''], ['e7', ''],
- ['e8'], UL(['']), UL(['e8', '']),
-
- UL(['i1']), 'I1', UL(['i1', 'I', '1']),
- UL(['i2']), ['I2'], UL(['i2', 'I2']),
- UL(['i3']), UL(['I3']), UL(['i3', 'I3']),
- UL(['i4']), '', UL(['i4']),
- UL(['i5']), [], UL(['i5']),
- UL(['i6']), UL([]), UL(['i6']),
- UL(['i7']), [''], UL(['i7', '']),
- UL(['i8']), UL(['']), UL(['i8', '']),
-
- {'d1':1}, 'D1', {'d1':1, 'D1':None},
- {'d2':1}, ['D2'], {'d2':1, 'D2':None},
- {'d3':1}, UL(['D3']), {'d3':1, 'D3':None},
- {'d4':1}, {'D4':1}, {'d4':1, 'D4':1},
- {'d5':1}, UD({'D5':1}), UD({'d5':1, 'D5':1}),
-
- UD({'u1':1}), 'U1', UD({'u1':1, 'U1':None}),
- UD({'u2':1}), ['U2'], UD({'u2':1, 'U2':None}),
- UD({'u3':1}), UL(['U3']), UD({'u3':1, 'U3':None}),
- UD({'u4':1}), {'U4':1}, UD({'u4':1, 'U4':1}),
- UD({'u5':1}), UD({'U5':1}), UD({'u5':1, 'U5':1}),
-
- '', 'M1', 'M1',
- '', ['M2'], ['M2'],
- '', UL(['M3']), UL(['M3']),
- '', '', '',
- '', [], [],
- '', UL([]), UL([]),
- '', [''], [''],
- '', UL(['']), UL(['']),
-
- [], 'N1', ['N1'],
- [], ['N2'], ['N2'],
- [], UL(['N3']), UL(['N3']),
- [], '', [],
- [], [], [],
- [], UL([]), UL([]),
- [], [''], [''],
- [], UL(['']), UL(['']),
-
- UL([]), 'O1', ['O', '1'],
- UL([]), ['O2'], ['O2'],
- UL([]), UL(['O3']), UL(['O3']),
- UL([]), '', UL([]),
- UL([]), [], UL([]),
- UL([]), UL([]), UL([]),
- UL([]), [''], UL(['']),
- UL([]), UL(['']), UL(['']),
-
- [''], 'P1', ['', 'P1'],
- [''], ['P2'], ['', 'P2'],
- [''], UL(['P3']), UL(['', 'P3']),
- [''], '', [''],
- [''], [], [''],
- [''], UL([]), UL(['']),
- [''], [''], ['', ''],
- [''], UL(['']), UL(['', '']),
-
- UL(['']), 'Q1', ['', 'Q', '1'],
- UL(['']), ['Q2'], ['', 'Q2'],
- UL(['']), UL(['Q3']), UL(['', 'Q3']),
- UL(['']), '', UL(['']),
- UL(['']), [], UL(['']),
- UL(['']), UL([]), UL(['']),
- UL(['']), [''], UL(['', '']),
- UL(['']), UL(['']), UL(['', '']),
+ ('a1', 'A1', 'a1A1'),
+ ('a2', ['A2'], ['a2', 'A2']),
+ ('a3', UL(['A3']), UL(['a', '3', 'A3'])),
+ ('a4', '', 'a4'),
+ ('a5', [], ['a5']),
+ ('a6', UL([]), UL(['a', '6'])),
+ ('a7', [''], ['a7', '']),
+ ('a8', UL(['']), UL(['a', '8', ''])),
+
+ (['e1'], 'E1', ['e1', 'E1']),
+ (['e2'], ['E2'], ['e2', 'E2']),
+ (['e3'], UL(['E3']), UL(['e3', 'E3'])),
+ (['e4'], '', ['e4']),
+ (['e5'], [], ['e5']),
+ (['e6'], UL([]), UL(['e6'])),
+ (['e7'], [''], ['e7', '']),
+ (['e8'], UL(['']), UL(['e8', ''])),
+
+ (UL(['i1']), 'I1', UL(['i1', 'I', '1'])),
+ (UL(['i2']), ['I2'], UL(['i2', 'I2'])),
+ (UL(['i3']), UL(['I3']), UL(['i3', 'I3'])),
+ (UL(['i4']), '', UL(['i4'])),
+ (UL(['i5']), [], UL(['i5'])),
+ (UL(['i6']), UL([]), UL(['i6'])),
+ (UL(['i7']), [''], UL(['i7', ''])),
+ (UL(['i8']), UL(['']), UL(['i8', ''])),
+
+ ({'d1':1}, 'D1', {'d1':1, 'D1':None}),
+ ({'d2':1}, ['D2'], {'d2':1, 'D2':None}),
+ ({'d3':1}, UL(['D3']), {'d3':1, 'D3':None}),
+ ({'d4':1}, {'D4':1}, {'d4':1, 'D4':1}),
+ ({'d5':1}, UD({'D5':1}), UD({'d5':1, 'D5':1})),
+
+ (UD({'u1':1}), 'U1', UD({'u1':1, 'U1':None})),
+ (UD({'u2':1}), ['U2'], UD({'u2':1, 'U2':None})),
+ (UD({'u3':1}), UL(['U3']), UD({'u3':1, 'U3':None})),
+ (UD({'u4':1}), {'U4':1}, UD({'u4':1, 'U4':1})),
+ ((UD({'u5':1}), UD({'U5':1}), UD({'u5':1, 'U5':1}))),
+
+ ('', 'M1', 'M1'),
+ ('', ['M2'], ['M2']),
+ ('', UL(['M3']), UL(['M3'])),
+ ('', '', ''),
+ ('', [], []),
+ ('', UL([]), UL([])),
+ ('', [''], ['']),
+ ('', UL(['']), UL([''])),
+
+ ([], 'N1', ['N1']),
+ ([], ['N2'], ['N2']),
+ ([], UL(['N3']), UL(['N3'])),
+ ([], '', []),
+ ([], [], []),
+ ([], UL([]), UL([])),
+ ([], [''], ['']),
+ ([], UL(['']), UL([''])),
+
+ (UL([]), 'O1', ['O', '1']),
+ (UL([]), ['O2'], ['O2']),
+ (UL([]), UL(['O3']), UL(['O3'])),
+ (UL([]), '', UL([])),
+ (UL([]), [], UL([])),
+ (UL([]), UL([]), UL([])),
+ (UL([]), [''], UL([''])),
+ (UL([]), UL(['']), UL([''])),
+
+ ([''], 'P1', ['', 'P1']),
+ ([''], ['P2'], ['', 'P2']),
+ ([''], UL(['P3']), UL(['', 'P3'])),
+ ([''], '', ['']),
+ ([''], [], ['']),
+ ([''], UL([]), UL([''])),
+ ([''], [''], ['', '']),
+ ([''], UL(['']), UL(['', ''])),
+
+ (UL(['']), 'Q1', ['', 'Q', '1']),
+ (UL(['']), ['Q2'], ['', 'Q2']),
+ (UL(['']), UL(['Q3']), UL(['', 'Q3'])),
+ (UL(['']), '', UL([''])),
+ (UL(['']), [], UL([''])),
+ (UL(['']), UL([]), UL([''])),
+ (UL(['']), [''], UL(['', ''])),
+ (UL(['']), UL(['']), UL(['', ''])),
]
env = Environment()
failed = 0
- while cases:
- input, append, expect = cases[:3]
+ for input, append, expect in cases:
env['XXX'] = copy.copy(input)
try:
- env.Append(XXX = append)
+ env.Append(XXX=append)
except Exception as e:
if failed == 0: print()
print(" %s Append %s exception: %s" % \
@@ -1703,8 +1700,7 @@ def exists(env):
if failed == 0: print()
print(" %s Append %s => %s did not match %s" % \
(repr(input), repr(append), repr(result), repr(expect)))
- failed = failed + 1
- del cases[:3]
+ failed += 1
assert failed == 0, "%d Append() cases failed" % failed
env['UL'] = UL(['foo'])
@@ -2376,101 +2372,99 @@ f5: \
assert env['OBJSUFFIX'] == '.obj', env['OBJSUFFIX']
def test_Prepend(self) -> None:
- """Test prepending to construction variables in an Environment
- """
+ """Test prepending to construction variables in an Environment."""
cases = [
- 'a1', 'A1', 'A1a1',
- 'a2', ['A2'], ['A2', 'a2'],
- 'a3', UL(['A3']), UL(['A3', 'a', '3']),
- 'a4', '', 'a4',
- 'a5', [], ['a5'],
- 'a6', UL([]), UL(['a', '6']),
- 'a7', [''], ['', 'a7'],
- 'a8', UL(['']), UL(['', 'a', '8']),
-
- ['e1'], 'E1', ['E1', 'e1'],
- ['e2'], ['E2'], ['E2', 'e2'],
- ['e3'], UL(['E3']), UL(['E3', 'e3']),
- ['e4'], '', ['e4'],
- ['e5'], [], ['e5'],
- ['e6'], UL([]), UL(['e6']),
- ['e7'], [''], ['', 'e7'],
- ['e8'], UL(['']), UL(['', 'e8']),
-
- UL(['i1']), 'I1', UL(['I', '1', 'i1']),
- UL(['i2']), ['I2'], UL(['I2', 'i2']),
- UL(['i3']), UL(['I3']), UL(['I3', 'i3']),
- UL(['i4']), '', UL(['i4']),
- UL(['i5']), [], UL(['i5']),
- UL(['i6']), UL([]), UL(['i6']),
- UL(['i7']), [''], UL(['', 'i7']),
- UL(['i8']), UL(['']), UL(['', 'i8']),
-
- {'d1':1}, 'D1', {'d1':1, 'D1':None},
- {'d2':1}, ['D2'], {'d2':1, 'D2':None},
- {'d3':1}, UL(['D3']), {'d3':1, 'D3':None},
- {'d4':1}, {'D4':1}, {'d4':1, 'D4':1},
- {'d5':1}, UD({'D5':1}), UD({'d5':1, 'D5':1}),
-
- UD({'u1':1}), 'U1', UD({'u1':1, 'U1':None}),
- UD({'u2':1}), ['U2'], UD({'u2':1, 'U2':None}),
- UD({'u3':1}), UL(['U3']), UD({'u3':1, 'U3':None}),
- UD({'u4':1}), {'U4':1}, UD({'u4':1, 'U4':1}),
- UD({'u5':1}), UD({'U5':1}), UD({'u5':1, 'U5':1}),
-
- '', 'M1', 'M1',
- '', ['M2'], ['M2'],
- '', UL(['M3']), UL(['M3']),
- '', '', '',
- '', [], [],
- '', UL([]), UL([]),
- '', [''], [''],
- '', UL(['']), UL(['']),
-
- [], 'N1', ['N1'],
- [], ['N2'], ['N2'],
- [], UL(['N3']), UL(['N3']),
- [], '', [],
- [], [], [],
- [], UL([]), UL([]),
- [], [''], [''],
- [], UL(['']), UL(['']),
-
- UL([]), 'O1', UL(['O', '1']),
- UL([]), ['O2'], UL(['O2']),
- UL([]), UL(['O3']), UL(['O3']),
- UL([]), '', UL([]),
- UL([]), [], UL([]),
- UL([]), UL([]), UL([]),
- UL([]), [''], UL(['']),
- UL([]), UL(['']), UL(['']),
-
- [''], 'P1', ['P1', ''],
- [''], ['P2'], ['P2', ''],
- [''], UL(['P3']), UL(['P3', '']),
- [''], '', [''],
- [''], [], [''],
- [''], UL([]), UL(['']),
- [''], [''], ['', ''],
- [''], UL(['']), UL(['', '']),
-
- UL(['']), 'Q1', UL(['Q', '1', '']),
- UL(['']), ['Q2'], UL(['Q2', '']),
- UL(['']), UL(['Q3']), UL(['Q3', '']),
- UL(['']), '', UL(['']),
- UL(['']), [], UL(['']),
- UL(['']), UL([]), UL(['']),
- UL(['']), [''], UL(['', '']),
- UL(['']), UL(['']), UL(['', '']),
+ ('a1', 'A1', 'A1a1'),
+ ('a2', ['A2'], ['A2', 'a2']),
+ ('a3', UL(['A3']), UL(['A3', 'a', '3'])),
+ ('a4', '', 'a4'),
+ ('a5', [], ['a5']),
+ ('a6', UL([]), UL(['a', '6'])),
+ ('a7', [''], ['', 'a7']),
+ ('a8', UL(['']), UL(['', 'a', '8'])),
+
+ (['e1'], 'E1', ['E1', 'e1']),
+ (['e2'], ['E2'], ['E2', 'e2']),
+ (['e3'], UL(['E3']), UL(['E3', 'e3'])),
+ (['e4'], '', ['e4']),
+ (['e5'], [], ['e5']),
+ (['e6'], UL([]), UL(['e6'])),
+ (['e7'], [''], ['', 'e7']),
+ (['e8'], UL(['']), UL(['', 'e8'])),
+
+ (UL(['i1']), 'I1', UL(['I', '1', 'i1'])),
+ (UL(['i2']), ['I2'], UL(['I2', 'i2'])),
+ (UL(['i3']), UL(['I3']), UL(['I3', 'i3'])),
+ (UL(['i4']), '', UL(['i4'])),
+ (UL(['i5']), [], UL(['i5'])),
+ (UL(['i6']), UL([]), UL(['i6'])),
+ (UL(['i7']), [''], UL(['', 'i7'])),
+ (UL(['i8']), UL(['']), UL(['', 'i8'])),
+
+ ({'d1':1}, 'D1', {'d1':1, 'D1':None}),
+ ({'d2':1}, ['D2'], {'d2':1, 'D2':None}),
+ ({'d3':1}, UL(['D3']), {'d3':1, 'D3':None}),
+ ({'d4':1}, {'D4':1}, {'d4':1, 'D4':1}),
+ ({'d5':1}, UD({'D5':1}), UD({'d5':1, 'D5':1})),
+
+ (UD({'u1':1}), 'U1', UD({'u1':1, 'U1':None})),
+ (UD({'u2':1}), ['U2'], UD({'u2':1, 'U2':None})),
+ (UD({'u3':1}), UL(['U3']), UD({'u3':1, 'U3':None})),
+ (UD({'u4':1}), {'U4':1}, UD({'u4':1, 'U4':1})),
+ (UD({'u5':1}), UD({'U5':1}), UD({'u5':1, 'U5':1})),
+
+ ('', 'M1', 'M1'),
+ ('', ['M2'], ['M2']),
+ ('', UL(['M3']), UL(['M3'])),
+ ('', '', ''),
+ ('', [], []),
+ ('', UL([]), UL([])),
+ ('', [''], ['']),
+ ('', UL(['']), UL([''])),
+
+ ([], 'N1', ['N1']),
+ ([], ['N2'], ['N2']),
+ ([], UL(['N3']), UL(['N3'])),
+ ([], '', []),
+ ([], [], []),
+ ([], UL([]), UL([])),
+ ([], [''], ['']),
+ ([], UL(['']), UL([''])),
+
+ (UL([]), 'O1', UL(['O', '1'])),
+ (UL([]), ['O2'], UL(['O2'])),
+ (UL([]), UL(['O3']), UL(['O3'])),
+ (UL([]), '', UL([])),
+ (UL([]), [], UL([])),
+ (UL([]), UL([]), UL([])),
+ (UL([]), [''], UL([''])),
+ (UL([]), UL(['']), UL([''])),
+
+ ([''], 'P1', ['P1', '']),
+ ([''], ['P2'], ['P2', '']),
+ ([''], UL(['P3']), UL(['P3', ''])),
+ ([''], '', ['']),
+ ([''], [], ['']),
+ ([''], UL([]), UL([''])),
+ ([''], [''], ['', '']),
+ ([''], UL(['']), UL(['', ''])),
+
+ (UL(['']), 'Q1', UL(['Q', '1', ''])),
+ (UL(['']), ['Q2'], UL(['Q2', ''])),
+ (UL(['']), UL(['Q3']), UL(['Q3', ''])),
+ (UL(['']), '', UL([''])),
+ (UL(['']), [], UL([''])),
+ (UL(['']), UL([]), UL([''])),
+ (UL(['']), [''], UL(['', ''])),
+ (UL(['']), UL(['']), UL(['', ''])),
]
env = Environment()
failed = 0
- while cases:
- input, prepend, expect = cases[:3]
+ for input, prepend, expect in cases:
env['XXX'] = copy.copy(input)
try:
- env.Prepend(XXX = prepend)
+ env.Prepend(XXX=prepend)
except Exception as e:
if failed == 0: print()
print(" %s Prepend %s exception: %s" % \
@@ -2482,8 +2476,7 @@ f5: \
if failed == 0: print()
print(" %s Prepend %s => %s did not match %s" % \
(repr(input), repr(prepend), repr(result), repr(expect)))
- failed = failed + 1
- del cases[:3]
+ failed += 1
assert failed == 0, "%d Prepend() cases failed" % failed
env['UL'] = UL(['foo'])
@@ -2597,8 +2590,10 @@ f5: \
env.PrependUnique(DDD1='b', delete_existing=True)
assert env['DDD1'] == ['b', 'a', 'c'], env['DDD1'] # b moves to front
+
env.PrependUnique(DDD1=['a', 'c'], delete_existing=True)
assert env['DDD1'] == ['a', 'c', 'b'], env['DDD1'] # a & c move to front
+
env.PrependUnique(DDD1=['d', 'e', 'd'], delete_existing=True)
assert env['DDD1'] == ['d', 'e', 'a', 'c', 'b'], env['DDD1']
diff --git a/SCons/Tool/MSCommon/common.py b/SCons/Tool/MSCommon/common.py
index af3afb5..5f01105 100644
--- a/SCons/Tool/MSCommon/common.py
+++ b/SCons/Tool/MSCommon/common.py
@@ -34,15 +34,25 @@ from contextlib import suppress
from subprocess import DEVNULL, PIPE
from pathlib import Path
+import SCons.Errors
import SCons.Util
import SCons.Warnings
class MSVCCacheInvalidWarning(SCons.Warnings.WarningOnByDefault):
pass
+def _check_logfile(logfile):
+ if logfile and '"' in logfile:
+ err_msg = (
+ "SCONS_MSCOMMON_DEBUG value contains double quote character(s)\n"
+ f" SCONS_MSCOMMON_DEBUG={logfile}"
+ )
+ raise SCons.Errors.UserError(err_msg)
+ return logfile
+
# SCONS_MSCOMMON_DEBUG is internal-use so undocumented:
# set to '-' to print to console, else set to filename to log to
-LOGFILE = os.environ.get('SCONS_MSCOMMON_DEBUG')
+LOGFILE = _check_logfile(os.environ.get('SCONS_MSCOMMON_DEBUG'))
if LOGFILE:
import logging
@@ -129,7 +139,15 @@ if LOGFILE:
log_handler = logging.StreamHandler(sys.stdout)
else:
log_prefix = ''
- log_handler = logging.FileHandler(filename=LOGFILE)
+ try:
+ log_handler = logging.FileHandler(filename=LOGFILE)
+ except (OSError, FileNotFoundError) as e:
+ err_msg = (
+ "Could not create logfile, check SCONS_MSCOMMON_DEBUG\n"
+ f" SCONS_MSCOMMON_DEBUG={LOGFILE}\n"
+ f" {e.__class__.__name__}: {str(e)}"
+ )
+ raise SCons.Errors.UserError(err_msg)
log_formatter = _CustomFormatter(log_prefix)
log_handler.setFormatter(log_formatter)
logger = logging.getLogger(name=__name__)