From 0458fbeaddae9f4bb1e977ccd642a201c7b46c5f Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 24 Mar 2018 12:42:09 -0700 Subject: [PATCH 1/2] fix #3106 MSVC handling MSVC_BATCH with targetdir which requires escaping. --- src/CHANGES.txt | 2 ++ src/engine/SCons/Tool/msvc.py | 5 ++++- test/MSVC/MSVC_BATCH-spaces-targetdir.py | 11 +++++++++++ test/MSVC/MSVC_BATCH-spaces-targetdir/SConstruct | 8 ++++++++ test/MSVC/MSVC_BATCH-spaces-targetdir/src/a.c | 15 +++++++++++++++ test/MSVC/MSVC_BATCH-spaces-targetdir/src/b.c | 5 +++++ test/MSVC/MSVC_BATCH-spaces-targetdir/src/c.c | 5 +++++ test/MSVC/batch.py | 7 ++++--- 8 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 test/MSVC/MSVC_BATCH-spaces-targetdir.py create mode 100644 test/MSVC/MSVC_BATCH-spaces-targetdir/SConstruct create mode 100644 test/MSVC/MSVC_BATCH-spaces-targetdir/src/a.c create mode 100644 test/MSVC/MSVC_BATCH-spaces-targetdir/src/b.c create mode 100644 test/MSVC/MSVC_BATCH-spaces-targetdir/src/c.c diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 954af1178b..1cdc943381 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -25,6 +25,8 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE From William Deegan: - Remove long deprecated SCons.Options code and tests. This removes BoolOption,EnumOption, ListOption,PackageOption, and PathOption which have been replaced by *Variable() many years ago. + - Fix issue # 3106 MSVC if using MSVC_BATCH and target dir had a space would fail due to quirk in + MSVC's handling of escaped targetdirs when batch compiling. From Andrew Featherstone - Removed unused --warn options from the man page and source code. diff --git a/src/engine/SCons/Tool/msvc.py b/src/engine/SCons/Tool/msvc.py index e1b05360ca..f078c626b5 100644 --- a/src/engine/SCons/Tool/msvc.py +++ b/src/engine/SCons/Tool/msvc.py @@ -195,7 +195,10 @@ def msvc_output_flag(target, source, env, for_signature): # that the test(s) for this can be run on non-Windows systems # without having a hard-coded backslash mess up command-line # argument parsing. - return '/Fo${TARGET.dir}' + os.sep + # Adding double os.sep's as if the TARGET.dir has a space or otherwise + # needs to be quoted they are needed per MSVC's odd behavior + # See: https://github.com/SCons/scons/issues/3106 + return '/Fo${TARGET.dir}' + os.sep*2 CAction = SCons.Action.Action("$CCCOM", "$CCCOMSTR", batch_key=msvc_batch_key, diff --git a/test/MSVC/MSVC_BATCH-spaces-targetdir.py b/test/MSVC/MSVC_BATCH-spaces-targetdir.py new file mode 100644 index 0000000000..298e10eea6 --- /dev/null +++ b/test/MSVC/MSVC_BATCH-spaces-targetdir.py @@ -0,0 +1,11 @@ +import TestSCons + + + +test = TestSCons.TestSCons() + +test.skip_if_not_msvc() + + +test.dir_fixture('MSVC_BATCH-spaces-targetdir') +test.run() \ No newline at end of file diff --git a/test/MSVC/MSVC_BATCH-spaces-targetdir/SConstruct b/test/MSVC/MSVC_BATCH-spaces-targetdir/SConstruct new file mode 100644 index 0000000000..da8002b840 --- /dev/null +++ b/test/MSVC/MSVC_BATCH-spaces-targetdir/SConstruct @@ -0,0 +1,8 @@ +import os.path + +env=Environment(MSVC_BATCH=True) + +td='tar ge tdir' +VariantDir(td,'src') +env.Program(os.path.join(td,'test_program'), + [os.path.join(td,a) for a in ['a.c','b.c','c.c']]) diff --git a/test/MSVC/MSVC_BATCH-spaces-targetdir/src/a.c b/test/MSVC/MSVC_BATCH-spaces-targetdir/src/a.c new file mode 100644 index 0000000000..1741de8838 --- /dev/null +++ b/test/MSVC/MSVC_BATCH-spaces-targetdir/src/a.c @@ -0,0 +1,15 @@ +#include + +extern void myfuncb(); +extern void myfuncc(); + + +void myfunca() { + printf("myfunca\n"); +} + +int main(int argc, char *argv[]) { + myfunca(); + myfuncb(); + myfuncc(); +} \ No newline at end of file diff --git a/test/MSVC/MSVC_BATCH-spaces-targetdir/src/b.c b/test/MSVC/MSVC_BATCH-spaces-targetdir/src/b.c new file mode 100644 index 0000000000..e03c5d05ab --- /dev/null +++ b/test/MSVC/MSVC_BATCH-spaces-targetdir/src/b.c @@ -0,0 +1,5 @@ +#include + +void myfuncb() { + printf("myfuncb\n"); +} \ No newline at end of file diff --git a/test/MSVC/MSVC_BATCH-spaces-targetdir/src/c.c b/test/MSVC/MSVC_BATCH-spaces-targetdir/src/c.c new file mode 100644 index 0000000000..1c262d3e8c --- /dev/null +++ b/test/MSVC/MSVC_BATCH-spaces-targetdir/src/c.c @@ -0,0 +1,5 @@ +#include + +void myfuncc() { + printf("myfuncc\n"); +} \ No newline at end of file diff --git a/test/MSVC/batch.py b/test/MSVC/batch.py index 8b7945b486..af5b43e2e4 100644 --- a/test/MSVC/batch.py +++ b/test/MSVC/batch.py @@ -72,6 +72,7 @@ """) test.write('SConstruct', """ +DefaultEnvironment(tools=[]) cccom = r'%(_python_)s fake_cl.py $_MSVC_OUTPUT_FLAG $CHANGED_SOURCES' linkcom = r'%(_python_)s fake_link.py ${TARGET.windows} $SOURCES' env = Environment(tools=['msvc', 'mslink'], @@ -96,7 +97,7 @@ test.must_match('prog.exe', "prog.c\nf1.c\nf2.c\n", mode='r') test.must_match('fake_cl.log', """\ -/Fo. prog.c f1.c f2.c +/Fo.\\ prog.c f1.c f2.c """, mode='r') test.up_to_date(options = 'MSVC_BATCH=1', arguments = '.') @@ -109,8 +110,8 @@ test.must_match('prog.exe', "prog.c\nf1.c 2\nf2.c\n", mode='r') test.must_match('fake_cl.log', """\ -/Fo. prog.c f1.c f2.c -/Fo. f1.c +/Fo.\\ prog.c f1.c f2.c +/Fo.\\ f1.c """, mode='r') test.up_to_date(options = 'MSVC_BATCH=1', arguments = '.') From b42fd7c0e76ca252ce778e5258be1e770561704d Mon Sep 17 00:00:00 2001 From: William Deegan Date: Sat, 24 Mar 2018 17:23:50 -0400 Subject: [PATCH 2/2] Fix test so use os.sep instead of hardcoded backslash for MSVC_BATCH=true /Fo argument --- test/MSVC/batch.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/MSVC/batch.py b/test/MSVC/batch.py index af5b43e2e4..0d3063fa3b 100644 --- a/test/MSVC/batch.py +++ b/test/MSVC/batch.py @@ -32,6 +32,7 @@ platform. """ +import os import TestSCons test = TestSCons.TestSCons() @@ -97,8 +98,8 @@ test.must_match('prog.exe', "prog.c\nf1.c\nf2.c\n", mode='r') test.must_match('fake_cl.log', """\ -/Fo.\\ prog.c f1.c f2.c -""", mode='r') +/Fo.%s prog.c f1.c f2.c +"""%os.sep, mode='r') test.up_to_date(options = 'MSVC_BATCH=1', arguments = '.') @@ -110,9 +111,9 @@ test.must_match('prog.exe', "prog.c\nf1.c 2\nf2.c\n", mode='r') test.must_match('fake_cl.log', """\ -/Fo.\\ prog.c f1.c f2.c -/Fo.\\ f1.c -""", mode='r') +/Fo.%s prog.c f1.c f2.c +/Fo.%s f1.c +"""%(os.sep, os.sep), mode='r') test.up_to_date(options = 'MSVC_BATCH=1', arguments = '.')