Skip to content

Commit

Permalink
Handle case when property sheets have conditioned elements inside them
Browse files Browse the repository at this point in the history
Previously we supported only the case then the vcxproj had conditioned elements.
  • Loading branch information
hero101111 committed Nov 3, 2017
1 parent a97f737 commit 78a96b3
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions ClangPowerTools/ClangPowerTools/clang-build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ function Select-ProjectNodes([Parameter(Mandatory=$true)] [string][string] $xpa
}

[System.Xml.XmlElement[]] $nodes = Help:Get-ProjectFileNodes -projectFile $global:projectFiles[$fileIndex] `
-xpath $xpath
-xpath $xpath

# nothing on this level, go above
if ($nodes.Count -eq 0)
Expand Down Expand Up @@ -833,7 +833,7 @@ function Select-ProjectNodes([Parameter(Mandatory=$true)] [string][string] $xpa
Items for other config-platform pairs will be removed from the DOM.
This is needed so that our XPath selectors don't get confused when looking for data.
#>
function SanitizeProject()
function Get-ProjectDefaultConfigPlatformCondition()
{
[string]$configPlatformCondition = ""
[System.Xml.XmlElement[]] $configNodes = Select-ProjectNodes -xpath $kVcxprojXpathDefaultConfigPlatform
Expand All @@ -850,7 +850,19 @@ function SanitizeProject()
throw "Could not detect a configuration platform"
}

[System.Xml.XmlElement[]] $configNodes = Select-ProjectNodes -xpath $kVcxprojXpathConfigPlatformSpecificElements
return $configPlatformCondition
}

<#
.DESCRIPTION
Sanitizes a project xml file, by removing config-platform pairs different from the
one we selected.
This is needed so that our XPath selectors don't get confused when looking for data.
#>
function SanitizeProjectFile([string]$configPlatformCondition, [xml]$projectFile)
{
[System.Xml.XmlElement[]] $configNodes = Help:Get-ProjectFileNodes -projectFile $projectFile `
-xpath $kVcxprojXpathConfigPlatformSpecificElements

foreach ($node in $configNodes)
{
Expand Down Expand Up @@ -959,7 +971,10 @@ function LoadProject([string] $vcxprojPath)
$global:xpathNS = New-Object System.Xml.XmlNamespaceManager($global:projectFiles[0].NameTable)
$global:xpathNS.AddNamespace("ns", $global:projectFiles[0].DocumentElement.NamespaceURI)

SanitizeProject
[string]$configPlatformCondition = Get-ProjectDefaultConfigPlatformCondition

SanitizeProjectFile -projectFile $global:projectFiles[0] `
-configPlatformCondition $configPlatformCondition

# see if we can find a Directory.Build.props automatic prop sheet
[string[]] $propSheetAbsolutePaths = @()
Expand Down Expand Up @@ -989,6 +1004,9 @@ function LoadProject([string] $vcxprojPath)
{
[xml] $propSheetXml = Get-Content $propSheetPath

SanitizeProjectFile -projectFile $propSheetXml `
-configPlatformCondition $configPlatformCondition

$global:projectFiles += $propSheetXml
}
}
Expand Down

0 comments on commit 78a96b3

Please sign in to comment.