From f9b68fef9b08f4bcb523e7315595c23a8c64f4d9 Mon Sep 17 00:00:00 2001 From: Joseph Brill <48932340+jcbrill@users.noreply.github.com> Date: Thu, 28 Dec 2023 12:20:07 -0500 Subject: MSVS/MSVC: msvs tool, msvs tests, and msvc detection fixes Updates: * Fix issue #2755: the msvs tool no longer writes the OS environment SCONS_HOME value into the SCons environment when the SCONS_HOME variable already exists in the SCons environment. * Update the windows registry keys for detection of Visual Studio 2015 Express ('14.0Exp'): the VS2015 registry key ('WDExpress') appears to be different than the registry key ('VCExpress') for earlier Visual Studio express versions. * Fix the vs-6.0-exec.py test script: the msvs generated project is 'foo.dsp' and the command-line invocation of the Visual Studio development environment program was attempting to build 'test.dsp'. * Update the msvs project generation test scripts: the msvs project execution tests could produce a "false positive" test result when the test executable is correctly built via the SConstruct env.Program() call and the command-line invocation of the Visual Studio development environment program fails. --- CHANGES.txt | 25 +++++++++++++++++++++++++ RELEASE.txt | 10 ++++++++++ SCons/Tool/MSCommon/vc.py | 12 +++++++++--- SCons/Tool/msvs.py | 6 +++++- test/MSVS/vs-10.0-exec.py | 5 +++++ test/MSVS/vs-10.0Exp-exec.py | 5 +++++ test/MSVS/vs-11.0-exec.py | 5 +++++ test/MSVS/vs-11.0Exp-exec.py | 5 +++++ test/MSVS/vs-14.0-exec.py | 5 +++++ test/MSVS/vs-14.0Exp-exec.py | 13 +++++++++++-- test/MSVS/vs-14.1-exec.py | 5 +++++ test/MSVS/vs-14.2-exec.py | 5 +++++ test/MSVS/vs-14.3-exec.py | 5 +++++ test/MSVS/vs-6.0-exec.py | 7 ++++++- test/MSVS/vs-7.0-exec.py | 5 +++++ test/MSVS/vs-7.1-exec.py | 5 +++++ test/MSVS/vs-8.0-exec.py | 5 +++++ test/MSVS/vs-8.0Exp-exec.py | 5 +++++ test/MSVS/vs-9.0-exec.py | 5 +++++ test/MSVS/vs-9.0Exp-exec.py | 5 +++++ 20 files changed, 136 insertions(+), 7 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 5a9d9e3..40c2d7c 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -8,6 +8,31 @@ NOTE: The 4.0.0 Release of SCons dropped Python 2.7 Support NOTE: 4.3.0 now requires Python 3.6.0 and above. Python 3.5.x is no longer supported RELEASE VERSION/DATE TO BE FILLED IN LATER + + From Joseph Brill: + - Fix issue #2755: the msvs tool no longer writes the OS environment SCONS_HOME + value into the SCons environment when the SCONS_HOME variable already exists + in the SCons environment. Prior to this change, a valid user-defined SCons + environment value for SCONS_HOME would be overwritten with the OS environment + value of SCONS_HOME which could be None (i.e., undefined). + - Update the windows registry keys for detection of Visual Studio 2015 Express + ('14.0Exp'): the VS2015 registry key ('WDExpress') appears to be different + than the registry key ('VCExpress') for earlier Visual Studio express + versions. The registry key value is relative to the installation root rather + than the VC folder and requires additional path components during evaluation. + - Fix the vs-6.0-exec.py test script: the msvs generated project is 'foo.dsp' + and the command-line invocation of the Visual Studio development environment + program was attempting to build 'test.dsp'. The command-line invocation was + changed to build 'foo.dsp'. + - Update the msvs project generation test scripts: the msvs project execution + tests could produce a "false positive" test result when the test executable is + correctly built via the SConstruct env.Program() call and the command-line + invocation of the Visual Studio development environment program fails. The + test passes due to the existence of the test executable from the initial + build. The tests were modified to delete the test executable, object file, + and sconsign file prior to the command-line invocation of the VS development + binary. + From Michał Górny: - Remove unecessary dependencies on pypi packages from setup.cfg diff --git a/RELEASE.txt b/RELEASE.txt index 7599d43..b5e732e 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -34,6 +34,16 @@ FIXES - Fix of the --debug=sconscript option to return exist statements when using return statement with stop flag enabled +- MSVS: prevent overwriting the SCons environment variable SCONS_HOME with the OS + environment value of SCONS_HOME in the msvs tool. +- MSVC: Fix the detection of Visual Studio 2015 Express ('14.0Exp') by adding a + registry key definition and updating the installation root-relative registry value + at runtime for the location of the VC folder. +- MSVS: Fix the msvs project generation test for MSVS 6.0 to use the correct name of + the generated project file. +- MSVS: Fix the msvs project generation test scripts so that "false positive" tests + results are not possible when the initial build is successful and the command-line + build of the project file fails. IMPROVEMENTS ------------ diff --git a/SCons/Tool/MSCommon/vc.py b/SCons/Tool/MSCommon/vc.py index 8780604..e43c618 100644 --- a/SCons/Tool/MSCommon/vc.py +++ b/SCons/Tool/MSCommon/vc.py @@ -718,6 +718,7 @@ _VCVER_TO_PRODUCT_DIR = { '14.0': [ (SCons.Util.HKEY_LOCAL_MACHINE, r'Microsoft\VisualStudio\14.0\Setup\VC\ProductDir')], '14.0Exp': [ + (SCons.Util.HKEY_LOCAL_MACHINE, r'Microsoft\WDExpress\14.0\Setup\VS\ProductDir'), (SCons.Util.HKEY_LOCAL_MACHINE, r'Microsoft\VCExpress\14.0\Setup\VC\ProductDir')], '12.0': [ (SCons.Util.HKEY_LOCAL_MACHINE, r'Microsoft\VisualStudio\12.0\Setup\VC\ProductDir'), @@ -905,9 +906,14 @@ def find_vc_pdir(env, msvc_version): except OSError: debug('no VC registry key %s', repr(key)) else: - if msvc_version == '9.0' and key.lower().endswith('\\vcforpython\\9.0\\installdir'): - # Visual C++ for Python registry key is installdir (root) not productdir (vc) - comps = os.path.join(comps, 'VC') + if msvc_version == '9.0': + if key.lower().endswith('\\vcforpython\\9.0\\installdir'): + # Visual C++ for Python registry key is installdir (root) not productdir (vc) + comps = os.path.join(comps, 'VC') + elif msvc_version == '14.0Exp': + if key.lower().endswith('\\setup\\vs\\productdir'): + # Visual Studio 14.0 Express registry key is installdir (root) not productdir (vc) + comps = os.path.join(comps, 'VC') debug('found VC in registry: %s', comps) if os.path.exists(comps): return comps diff --git a/SCons/Tool/msvs.py b/SCons/Tool/msvs.py index 16e422d..1297448 100644 --- a/SCons/Tool/msvs.py +++ b/SCons/Tool/msvs.py @@ -145,6 +145,8 @@ def msvs_parse_version(s): # the MSVS Project file invoke SCons the same way that scons.bat does, # which works regardless of how we were invoked. def getExecScriptMain(env, xml=None): + if 'SCONS_HOME' not in env: + env['SCONS_HOME'] = os.environ.get('SCONS_HOME') scons_home = env.get('SCONS_HOME') if not scons_home and 'SCONS_LIB_DIR' in os.environ: scons_home = os.environ['SCONS_LIB_DIR'] @@ -2109,7 +2111,9 @@ def generate(env) -> None: env['GET_MSVSSOLUTIONSUFFIX'] = GetMSVSSolutionSuffix env['MSVSPROJECTSUFFIX'] = '${GET_MSVSPROJECTSUFFIX}' env['MSVSSOLUTIONSUFFIX'] = '${GET_MSVSSOLUTIONSUFFIX}' - env['SCONS_HOME'] = os.environ.get('SCONS_HOME') + + if 'SCONS_HOME' not in env: + env['SCONS_HOME'] = os.environ.get('SCONS_HOME') def exists(env): return msvc_setup_env_tool(env, tool=tool_name) diff --git a/test/MSVS/vs-10.0-exec.py b/test/MSVS/vs-10.0-exec.py index df13454..d439437 100644 --- a/test/MSVS/vs-10.0-exec.py +++ b/test/MSVS/vs-10.0-exec.py @@ -90,6 +90,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-10.0Exp-exec.py b/test/MSVS/vs-10.0Exp-exec.py index 1c3b561..f0b0881 100644 --- a/test/MSVS/vs-10.0Exp-exec.py +++ b/test/MSVS/vs-10.0Exp-exec.py @@ -91,6 +91,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-11.0-exec.py b/test/MSVS/vs-11.0-exec.py index 8286841..f2dfe8e 100644 --- a/test/MSVS/vs-11.0-exec.py +++ b/test/MSVS/vs-11.0-exec.py @@ -91,6 +91,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-11.0Exp-exec.py b/test/MSVS/vs-11.0Exp-exec.py index e7cffad..b16f870 100644 --- a/test/MSVS/vs-11.0Exp-exec.py +++ b/test/MSVS/vs-11.0Exp-exec.py @@ -91,6 +91,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-14.0-exec.py b/test/MSVS/vs-14.0-exec.py index 7e919ba..a11f405 100644 --- a/test/MSVS/vs-14.0-exec.py +++ b/test/MSVS/vs-14.0-exec.py @@ -92,6 +92,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-14.0Exp-exec.py b/test/MSVS/vs-14.0Exp-exec.py index 5d2a585..5c49322 100644 --- a/test/MSVS/vs-14.0Exp-exec.py +++ b/test/MSVS/vs-14.0Exp-exec.py @@ -55,10 +55,14 @@ if not msvs_version in test.msvs_versions(): test.run(arguments = '-n -q -Q -f -', stdin = """\ env = Environment(tools = ['msvc'], MSVS_VERSION='%(msvs_version)s') -sconsEnv = repr(env['ENV']) -print("os.environ.update(" + sconsEnv + ")") +if env.WhereIs('cl'): + print("os.environ.update(%%s)" %% repr(env['ENV'])) """ % locals()) +if test.stdout() == "": + msg = "Visual Studio %s missing cl.exe; skipping test.\n" % msvs_version + test.skip_test(msg) + exec(test.stdout()) @@ -88,6 +92,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-14.1-exec.py b/test/MSVS/vs-14.1-exec.py index 2accaaf..d0324c2 100644 --- a/test/MSVS/vs-14.1-exec.py +++ b/test/MSVS/vs-14.1-exec.py @@ -92,6 +92,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-14.2-exec.py b/test/MSVS/vs-14.2-exec.py index 5a3079d..90c5641 100644 --- a/test/MSVS/vs-14.2-exec.py +++ b/test/MSVS/vs-14.2-exec.py @@ -92,6 +92,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-14.3-exec.py b/test/MSVS/vs-14.3-exec.py index 840b432..164c953 100644 --- a/test/MSVS/vs-14.3-exec.py +++ b/test/MSVS/vs-14.3-exec.py @@ -92,6 +92,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-6.0-exec.py b/test/MSVS/vs-6.0-exec.py index ab70872..38f715d 100644 --- a/test/MSVS/vs-6.0-exec.py +++ b/test/MSVS/vs-6.0-exec.py @@ -90,9 +90,14 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.run(chdir='sub dir', program=[test.get_msvs_executable(msvs_version)], - arguments=['Test.dsp', '/MAKE', 'foo - Win32 Release']) + arguments=['foo.dsp', '/MAKE', 'foo - Win32 Release']) test.run(program=test.workpath('sub dir', 'foo'), stdout="foo.c\n") diff --git a/test/MSVS/vs-7.0-exec.py b/test/MSVS/vs-7.0-exec.py index 3c41aa5..c0340c4 100644 --- a/test/MSVS/vs-7.0-exec.py +++ b/test/MSVS/vs-7.0-exec.py @@ -90,6 +90,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) test.run(chdir='sub dir', diff --git a/test/MSVS/vs-7.1-exec.py b/test/MSVS/vs-7.1-exec.py index f66b92d..015840b 100644 --- a/test/MSVS/vs-7.1-exec.py +++ b/test/MSVS/vs-7.1-exec.py @@ -90,6 +90,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) test.run(chdir='sub dir', diff --git a/test/MSVS/vs-8.0-exec.py b/test/MSVS/vs-8.0-exec.py index 91e99dd..228800a 100644 --- a/test/MSVS/vs-8.0-exec.py +++ b/test/MSVS/vs-8.0-exec.py @@ -91,6 +91,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-8.0Exp-exec.py b/test/MSVS/vs-8.0Exp-exec.py index 77cae64..ba9aa7a 100644 --- a/test/MSVS/vs-8.0Exp-exec.py +++ b/test/MSVS/vs-8.0Exp-exec.py @@ -91,6 +91,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-9.0-exec.py b/test/MSVS/vs-9.0-exec.py index 26a115d..75d7bb7 100644 --- a/test/MSVS/vs-9.0-exec.py +++ b/test/MSVS/vs-9.0-exec.py @@ -91,6 +91,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) import SCons.Platform.win32 diff --git a/test/MSVS/vs-9.0Exp-exec.py b/test/MSVS/vs-9.0Exp-exec.py index 0c274ba..36d0367 100644 --- a/test/MSVS/vs-9.0Exp-exec.py +++ b/test/MSVS/vs-9.0Exp-exec.py @@ -91,6 +91,11 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') +for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): + filepath = test.workpath('sub dir', filename) + if os.path.exists(filepath): + test.unlink(filepath) + test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) import SCons.Platform.win32 -- cgit v0.12 From 6827a03a4628f13fd79eaa14c24bf8df508d5aa0 Mon Sep 17 00:00:00 2001 From: Joseph Brill <48932340+jcbrill@users.noreply.github.com> Date: Thu, 28 Dec 2023 17:35:29 -0500 Subject: Add unlink_files method to TestCmd, replace file deletion loops with method calls in msvs executable test scripts, re-order CHANGES.txt. --- CHANGES.txt | 11 +++++++---- RELEASE.txt | 5 ++++- test/MSVS/vs-10.0-exec.py | 5 +---- test/MSVS/vs-10.0Exp-exec.py | 5 +---- test/MSVS/vs-11.0-exec.py | 5 +---- test/MSVS/vs-11.0Exp-exec.py | 5 +---- test/MSVS/vs-14.0-exec.py | 5 +---- test/MSVS/vs-14.0Exp-exec.py | 5 +---- test/MSVS/vs-14.1-exec.py | 5 +---- test/MSVS/vs-14.2-exec.py | 5 +---- test/MSVS/vs-14.3-exec.py | 5 +---- test/MSVS/vs-6.0-exec.py | 5 +---- test/MSVS/vs-7.0-exec.py | 5 +---- test/MSVS/vs-7.1-exec.py | 5 +---- test/MSVS/vs-8.0-exec.py | 5 +---- test/MSVS/vs-8.0Exp-exec.py | 5 +---- test/MSVS/vs-9.0-exec.py | 5 +---- test/MSVS/vs-9.0Exp-exec.py | 5 +---- testing/framework/TestCmd.py | 25 +++++++++++++++++++++++++ 19 files changed, 52 insertions(+), 69 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 40c2d7c..8d63f89 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 Ataf Fazledin Ahamed: + - Use of NotImplemented instead of NotImplementedError for special methods + of _ListVariable class + From Joseph Brill: - Fix issue #2755: the msvs tool no longer writes the OS environment SCONS_HOME value into the SCons environment when the SCONS_HOME variable already exists @@ -32,6 +36,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER build. The tests were modified to delete the test executable, object file, and sconsign file prior to the command-line invocation of the VS development binary. + - A method, unlink_files, was added to the TestCmd class that unlinks a list of + files from a specified directory. An attempt to unlink a file is made only when + the file exists, otherwise, the file is ignored. From Michał Górny: - Remove unecessary dependencies on pypi packages from setup.cfg @@ -40,10 +47,6 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER - Fix of the --debug=sconscript option to return exist statements when using return statement with stop flag enabled - From Ataf Fazledin Ahamed: - - Use of NotImplemented instead of NotImplementedError for special methods - of _ListVariable class - RELEASE 4.6.0 - Sun, 19 Nov 2023 17:22:20 -0700 From Max Bachmann: diff --git a/RELEASE.txt b/RELEASE.txt index b5e732e..b4478ef 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -16,7 +16,10 @@ Here is a summary of the changes since 4.6.0: NEW FUNCTIONALITY ----------------- -- List new features (presumably why a checkpoint is being released) +- A method, unlink_files, was added to the TestCmd class that unlinks a list of + files from a specified directory. An attempt to unlink a file is made only when + the file exists, otherwise, the file is ignored. + DEPRECATED FUNCTIONALITY ------------------------ diff --git a/test/MSVS/vs-10.0-exec.py b/test/MSVS/vs-10.0-exec.py index d439437..cf140a2 100644 --- a/test/MSVS/vs-10.0-exec.py +++ b/test/MSVS/vs-10.0-exec.py @@ -90,10 +90,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) diff --git a/test/MSVS/vs-10.0Exp-exec.py b/test/MSVS/vs-10.0Exp-exec.py index f0b0881..87ddf29 100644 --- a/test/MSVS/vs-10.0Exp-exec.py +++ b/test/MSVS/vs-10.0Exp-exec.py @@ -91,10 +91,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) diff --git a/test/MSVS/vs-11.0-exec.py b/test/MSVS/vs-11.0-exec.py index f2dfe8e..27dd794 100644 --- a/test/MSVS/vs-11.0-exec.py +++ b/test/MSVS/vs-11.0-exec.py @@ -91,10 +91,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) diff --git a/test/MSVS/vs-11.0Exp-exec.py b/test/MSVS/vs-11.0Exp-exec.py index b16f870..385a50d 100644 --- a/test/MSVS/vs-11.0Exp-exec.py +++ b/test/MSVS/vs-11.0Exp-exec.py @@ -91,10 +91,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) diff --git a/test/MSVS/vs-14.0-exec.py b/test/MSVS/vs-14.0-exec.py index a11f405..96e3389 100644 --- a/test/MSVS/vs-14.0-exec.py +++ b/test/MSVS/vs-14.0-exec.py @@ -92,10 +92,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) diff --git a/test/MSVS/vs-14.0Exp-exec.py b/test/MSVS/vs-14.0Exp-exec.py index 5c49322..d27d4d5 100644 --- a/test/MSVS/vs-14.0Exp-exec.py +++ b/test/MSVS/vs-14.0Exp-exec.py @@ -92,10 +92,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) diff --git a/test/MSVS/vs-14.1-exec.py b/test/MSVS/vs-14.1-exec.py index d0324c2..0a92509 100644 --- a/test/MSVS/vs-14.1-exec.py +++ b/test/MSVS/vs-14.1-exec.py @@ -92,10 +92,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) diff --git a/test/MSVS/vs-14.2-exec.py b/test/MSVS/vs-14.2-exec.py index 90c5641..a95982b 100644 --- a/test/MSVS/vs-14.2-exec.py +++ b/test/MSVS/vs-14.2-exec.py @@ -92,10 +92,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) diff --git a/test/MSVS/vs-14.3-exec.py b/test/MSVS/vs-14.3-exec.py index 164c953..ef9dc33 100644 --- a/test/MSVS/vs-14.3-exec.py +++ b/test/MSVS/vs-14.3-exec.py @@ -92,10 +92,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcxproj')) diff --git a/test/MSVS/vs-6.0-exec.py b/test/MSVS/vs-6.0-exec.py index 38f715d..7cffb48 100644 --- a/test/MSVS/vs-6.0-exec.py +++ b/test/MSVS/vs-6.0-exec.py @@ -90,10 +90,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.run(chdir='sub dir', program=[test.get_msvs_executable(msvs_version)], diff --git a/test/MSVS/vs-7.0-exec.py b/test/MSVS/vs-7.0-exec.py index c0340c4..7e81d4e 100644 --- a/test/MSVS/vs-7.0-exec.py +++ b/test/MSVS/vs-7.0-exec.py @@ -90,10 +90,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) diff --git a/test/MSVS/vs-7.1-exec.py b/test/MSVS/vs-7.1-exec.py index 015840b..e7f4203 100644 --- a/test/MSVS/vs-7.1-exec.py +++ b/test/MSVS/vs-7.1-exec.py @@ -90,10 +90,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) diff --git a/test/MSVS/vs-8.0-exec.py b/test/MSVS/vs-8.0-exec.py index 228800a..3a3de05 100644 --- a/test/MSVS/vs-8.0-exec.py +++ b/test/MSVS/vs-8.0-exec.py @@ -91,10 +91,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) diff --git a/test/MSVS/vs-8.0Exp-exec.py b/test/MSVS/vs-8.0Exp-exec.py index ba9aa7a..a3a83ad 100644 --- a/test/MSVS/vs-8.0Exp-exec.py +++ b/test/MSVS/vs-8.0Exp-exec.py @@ -91,10 +91,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) diff --git a/test/MSVS/vs-9.0-exec.py b/test/MSVS/vs-9.0-exec.py index 75d7bb7..e112f7a 100644 --- a/test/MSVS/vs-9.0-exec.py +++ b/test/MSVS/vs-9.0-exec.py @@ -91,10 +91,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) diff --git a/test/MSVS/vs-9.0Exp-exec.py b/test/MSVS/vs-9.0Exp-exec.py index 36d0367..cc95ba9 100644 --- a/test/MSVS/vs-9.0Exp-exec.py +++ b/test/MSVS/vs-9.0Exp-exec.py @@ -91,10 +91,7 @@ main(int argc, char *argv) test.run(chdir='sub dir', arguments='.') -for filename in ('foo.exe', 'foo.obj', '.sconsign.dblite'): - filepath = test.workpath('sub dir', filename) - if os.path.exists(filepath): - test.unlink(filepath) +test.unlink_files('sub dir', ['foo.exe', 'foo.obj', '.sconsign.dblite']) test.vcproj_sys_path(test.workpath('sub dir', 'foo.vcproj')) diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index c207aa7..98094c8 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -1872,6 +1872,31 @@ class TestCmd: file = self.canonicalize(file) os.unlink(file) + def unlink_files(self, dirpath, files): + """Unlinks a list of file names from the specified directory. + + The directory path may be a list, in which case the elements are + concatenated with the os.path.join() method. + + A file name may be a list, in which case the elements are + concatenated with the os.path.join() method. + + The directory path and file name are concatenated with the + os.path.join() method. The resulting file path is assumed to be + under the temporary working directory unless it is an absolute path + name. An attempt to unlink the resulting file is made only when the + file exists otherwise the file path is ignored. + """ + if is_List(dirpath): + dirpath = os.path.join(*dirpath) + for file in files: + if is_List(file): + file = os.path.join(*file) + filepath = os.path.join(dirpath, file) + filepath = self.canonicalize(filepath) + if os.path.exists(filepath): + self.unlink(filepath) + def verbose_set(self, verbose) -> None: """Sets the verbose level.""" self.verbose = verbose -- cgit v0.12 From 6b537ab913c878e05e824b6d52da0223a045fdf1 Mon Sep 17 00:00:00 2001 From: Joseph Brill <48932340+jcbrill@users.noreply.github.com> Date: Fri, 29 Dec 2023 08:42:00 -0500 Subject: Add unlink_files method tests to TestCmdTests.py. --- CHANGES.txt | 6 +-- RELEASE.txt | 6 +-- testing/framework/TestCmdTests.py | 97 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8d63f89..5e90b81 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -36,9 +36,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER build. The tests were modified to delete the test executable, object file, and sconsign file prior to the command-line invocation of the VS development binary. - - A method, unlink_files, was added to the TestCmd class that unlinks a list of - files from a specified directory. An attempt to unlink a file is made only when - the file exists, otherwise, the file is ignored. + - Method unlink_files was added to the TestCmd class that unlinks a list of + files from a specified directory. An attempt to unlink a file is made only + when the file exists; otherwise, the file is ignored. From Michał Górny: - Remove unecessary dependencies on pypi packages from setup.cfg diff --git a/RELEASE.txt b/RELEASE.txt index b4478ef..f031aad 100644 --- a/RELEASE.txt +++ b/RELEASE.txt @@ -16,9 +16,9 @@ Here is a summary of the changes since 4.6.0: NEW FUNCTIONALITY ----------------- -- A method, unlink_files, was added to the TestCmd class that unlinks a list of - files from a specified directory. An attempt to unlink a file is made only when - the file exists, otherwise, the file is ignored. +- Method unlink_files was added to the TestCmd class that unlinks a list of files + from a specified directory. An attempt to unlink a file is made only when the + file exists; otherwise, the file is ignored. DEPRECATED FUNCTIONALITY diff --git a/testing/framework/TestCmdTests.py b/testing/framework/TestCmdTests.py index 7cabf44..1331f9d 100644 --- a/testing/framework/TestCmdTests.py +++ b/testing/framework/TestCmdTests.py @@ -2993,6 +2993,103 @@ class unlink_TestCase(TestCmdTestCase): os.chmod(wdir_file5, 0o600) +class unlink_files_TestCase(TestCmdTestCase): + def test_unlink_files(self): + """Test unlink_files()""" + test = TestCmd.TestCmd(workdir = '', subdir = 'foo') + wdir_file1 = os.path.join(test.workdir, 'file1') + wdir_file2 = os.path.join(test.workdir, 'file2') + wdir_foo_file3a = os.path.join(test.workdir, 'foo', 'file3a') + wdir_foo_file3b = os.path.join(test.workdir, 'foo', 'file3b') + wdir_foo_file3c = os.path.join(test.workdir, 'foo', 'file3c') + wdir_foo_file3d = os.path.join(test.workdir, 'foo', 'file3d') + wdir_foo_file4a = os.path.join(test.workdir, 'foo', 'file4a') + wdir_foo_file4b = os.path.join(test.workdir, 'foo', 'file4b') + wdir_foo_file4c = os.path.join(test.workdir, 'foo', 'file4c') + wdir_foo_file4d = os.path.join(test.workdir, 'foo', 'file4d') + wdir_file5 = os.path.join(test.workdir, 'file5') + + with open(wdir_file1, 'w') as f: + f.write("") + with open(wdir_file2, 'w') as f: + f.write("") + with open(wdir_foo_file3a, 'w') as f: + f.write("") + with open(wdir_foo_file3b, 'w') as f: + f.write("") + with open(wdir_foo_file3c, 'w') as f: + f.write("") + with open(wdir_foo_file3d, 'w') as f: + f.write("") + with open(wdir_foo_file4a, 'w') as f: + f.write("") + with open(wdir_foo_file4b, 'w') as f: + f.write("") + with open(wdir_foo_file4c, 'w') as f: + f.write("") + with open(wdir_foo_file4d, 'w') as f: + f.write("") + with open(wdir_file5, 'w') as f: + f.write("") + + test.unlink_files('', [ + 'no_file_a', + 'no_file_b', + ]) + + test.unlink_files('', [ + 'file1', + 'file2', + ]) + assert not os.path.exists(wdir_file1) + assert not os.path.exists(wdir_file2) + + test.unlink_files('foo', [ + 'file3a', + 'file3b', + ]) + assert not os.path.exists(wdir_foo_file3a) + assert not os.path.exists(wdir_foo_file3b) + + test.unlink_files(['foo'], [ + 'file3c', + 'file3d', + ]) + assert not os.path.exists(wdir_foo_file3c) + assert not os.path.exists(wdir_foo_file3d) + + test.unlink_files('', [ + ['foo', 'file4a'], + ['foo', 'file4b'], + ]) + assert not os.path.exists(wdir_foo_file4a) + assert not os.path.exists(wdir_foo_file4b) + + test.unlink_files([''], [ + ['foo', 'file4c'], + ['foo', 'file4d'], + ]) + assert not os.path.exists(wdir_foo_file4c) + assert not os.path.exists(wdir_foo_file4d) + + # Make it so we can't unlink file5. + # For UNIX, remove write permission from the dir and the file. + # For Windows, open the file. + os.chmod(test.workdir, 0o500) + os.chmod(wdir_file5, 0o400) + with open(wdir_file5, 'r'): + try: + try: + test.unlink_files('', ['file5']) + except OSError: # expect "Permission denied" + pass + except: + raise + finally: + os.chmod(test.workdir, 0o700) + os.chmod(wdir_file5, 0o600) + + class touch_TestCase(TestCmdTestCase): def test_touch(self) -> None: """Test touch()""" -- cgit v0.12