From 0c497da65e27aca8fa0a84f390b99a3a5efbd5cd Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Mon, 24 Aug 2015 20:56:44 +1000 Subject: [PATCH 1/2] Empty projects no longer ignore platform toolset when there are no "cpp" files present. Fixes #93 --- src/actions/vstudio/vs2010_vcxproj.lua | 14 +++++++++----- .../vstudio/vc2010/test_platform_toolset.lua | 11 ----------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index 7f6ec3cb..a910faa2 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -143,6 +143,7 @@ if cfg.kind == p.UTILITY then return { m.configurationType, + m.platformToolset, } else return { @@ -1515,12 +1516,15 @@ version = action.vstudio.platformToolset end if version then - -- should only be written if there is a C/C++ file in the config - for i = 1, #cfg.files do - if path.iscppfile(cfg.files[i]) then - m.element("PlatformToolset", nil, version) - break + if cfg.kind == p.NONE or cfg.kind == p.MAKEFILE then + for i = 1, #cfg.files do + if path.iscppfile(cfg.files[i]) then + m.element("PlatformToolset", nil, version) + break + end end + else + m.element("PlatformToolset", nil, version) end end end diff --git a/tests/actions/vstudio/vc2010/test_platform_toolset.lua b/tests/actions/vstudio/vc2010/test_platform_toolset.lua index 6e618956..37513990 100644 --- a/tests/actions/vstudio/vc2010/test_platform_toolset.lua +++ b/tests/actions/vstudio/vc2010/test_platform_toolset.lua @@ -56,17 +56,6 @@ end --- --- Element should only be written if C++ files are present. --- - - function suite.empty_onNoRelevantSources() - removefiles "hello.cpp" - prepare() - test.isemptycapture() - end - - -- -- Check for overrides from project scripts. -- From 01dfaf611c0360ee5920c57ebfa5a8bf211f5e07 Mon Sep 17 00:00:00 2001 From: Sam Surtees Date: Wed, 16 Sep 2015 22:31:40 +1000 Subject: [PATCH 2/2] Added tests and file type testing helper function --- src/actions/vstudio/vs2010_vcxproj.lua | 9 ++---- src/base/config.lua | 11 +++---- .../vstudio/vc2010/test_platform_toolset.lua | 29 +++++++++++++++++++ 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/actions/vstudio/vs2010_vcxproj.lua b/src/actions/vstudio/vs2010_vcxproj.lua index a910faa2..f0354bbf 100644 --- a/src/actions/vstudio/vs2010_vcxproj.lua +++ b/src/actions/vstudio/vs2010_vcxproj.lua @@ -348,7 +348,7 @@ end function m.resourceCompile(cfg) - if cfg.system ~= p.XBOX360 and config.hasResourceFiles(cfg) then + if cfg.system ~= p.XBOX360 and p.config.hasFile(cfg, path.isresourcefile) then local contents = p.capture(function () p.push() p.callArray(m.elements.resourceCompile, cfg) @@ -1517,11 +1517,8 @@ end if version then if cfg.kind == p.NONE or cfg.kind == p.MAKEFILE then - for i = 1, #cfg.files do - if path.iscppfile(cfg.files[i]) then - m.element("PlatformToolset", nil, version) - break - end + if p.config.hasFile(cfg, path.iscppfile) then + m.element("PlatformToolset", nil, version) end else m.element("PlatformToolset", nil, version) diff --git a/src/base/config.lua b/src/base/config.lua index a38c5ba0..45aed44c 100755 --- a/src/base/config.lua +++ b/src/base/config.lua @@ -359,14 +359,15 @@ --- --- Determine if a configuration contains one or more resource files. --- +--- +-- Returns true if any of the files in the provided container pass the +-- provided test function. +--- - function config.hasResourceFiles(self) + function config.hasFile(self, testfn) local files = self.files for i = 1, #files do - if path.isresourcefile(files[i]) then + if testfn(files[i]) then return true end end diff --git a/tests/actions/vstudio/vc2010/test_platform_toolset.lua b/tests/actions/vstudio/vc2010/test_platform_toolset.lua index 37513990..fcf80a68 100644 --- a/tests/actions/vstudio/vc2010/test_platform_toolset.lua +++ b/tests/actions/vstudio/vc2010/test_platform_toolset.lua @@ -75,3 +75,32 @@ v100 ]] end + + +-- +-- Check if platform toolset element is being emitted correctly. +-- + + function suite.output_onConsoleAppAndNoCpp() + kind "ConsoleApp" + removefiles "hello.cpp" + prepare() + test.capture [[ +v110 + ]] + end + + function suite.skipped_onNoMakefileAndNoCpp() + kind "Makefile" + removefiles "hello.cpp" + prepare() + test.isemptycapture() + end + + function suite.output_onNoMakefileAndCpp() + kind "Makefile" + prepare() + test.capture [[ +v110 + ]] + end