Skip to content

Commit

Permalink
ImportProject: use TokenList instead of Tokenizer in `ItemDefinit…
Browse files Browse the repository at this point in the history
…ionGroup::conditionIsTrue()`
  • Loading branch information
firewave committed Mar 11, 2024
1 parent 6b611ab commit 53dd484
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -553,20 +553,23 @@ namespace {
}
}

// see https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditions
// properties are .NET String objects and you can call any of its members on them
bool conditionIsTrue(const ProjectConfiguration &p) const {
if (condition.empty())
return true;
std::string c = '(' + condition + ");";
replaceAll(c, "$(Configuration)", p.configuration);
replaceAll(c, "$(Platform)", p.platformStr);

// TODO: evaluate without using the Tokenizer
// TODO: improve evaluation
const Settings s;
Tokenizer tokenizer(s, nullptr);
TokenList tokenlist(&s);
std::istringstream istr(c);
tokenizer.tokenize(istr,"vcxproj.c");
for (const Token *tok = tokenizer.tokens(); tok; tok = tok->next()) {
tokenlist.createTokens(istr, Standards::Language::C); // TODO: check result
for (const Token *tok = tokenlist.front(); tok; tok = tok->next()) {
if (tok->str() == "(" && tok->astOperand1() && tok->astOperand2()) {
// TODO: this is wrong - it is Contains() not Equals()
if (tok->astOperand1()->expressionString() == "Configuration.Contains")
return ('\'' + p.configuration + '\'') == tok->astOperand2()->str();
}
Expand Down
21 changes: 21 additions & 0 deletions test/testimportproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,27 @@ class TestImportProject : public TestFixture {
}

// TODO: test fsParseCommand()

// TODO: test vcxproj conditions
/*
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<PreprocessorDefinitions>CPPCHECKLIB_IMPORT</PreprocessorDefinitions>
</ClCompile>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.c" />
</ItemGroup>
</Project>
*/
};

REGISTER_TEST(TestImportProject)

0 comments on commit 53dd484

Please sign in to comment.