-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdateProject.ps1
More file actions
189 lines (174 loc) · 6.18 KB
/
Copy pathupdateProject.ps1
File metadata and controls
189 lines (174 loc) · 6.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
<#
.SYNOPSIS
Add HTS extensions to msbuild project file
.DESCRIPTION
This script adds the HTS extensions to an msbuild project file.
It adds the htsCommon.props and htsCommon.targets imports to the project file.
It also adds a PropertyGroup for ProjectRootPath and HtsToolsDir if they are not already defined in the project file.
.PARAMETER projectFile
The path to the msbuild project file to update.
.PARAMETER classGuid
The class guid for the driver. If not specified, the guid in the sample inf file will be used.
.PARAMETER className
The class name for the driver. If not specified, the class name in the sample inf file will be used.
.PARAMETER providerString
The provider string for the driver. If not specified, the provider string in the sample inf file will be used.
.PARAMETER targetName
The target name for the driver. If not specified, the target name in the sample inf file will be used.
.PARAMETER projectRoot
The root directory of the project. If not specified, the root directory of the project file will be used.
.PARAMETER fixSampleInf
If specified, the script will update the sample inf file with the class guid,
class name, provider string, and target name specified in the parameters.
#>
param(
[Parameter(Mandatory=$true)]
[string] $projectFile,
[string] $classGuid,
[string] $className,
[string] $providerString,
[string] $targetName,
[string] $projectRoot,
[switch] $fixSampleInf
)
Function Format-XMLText {
Param(
[Parameter(ValueFromPipeline=$true,Mandatory=$true)]
[xml[]]
$xmlText
)
Process {
# Use a StringWriter, an XMLWriter and an XMLWriterSettings to format XML
$stringWriter = New-Object System.IO.StringWriter
$stringWriterSettings = New-Object System.Xml.XmlWriterSettings
# Turn on indentation
$stringWriterSettings.Indent = $true
# Turn off XML declaration
$stringWriterSettings.OmitXmlDeclaration = $true
# Create the XMLWriter from the StringWriter
$xmlWriter = [System.Xml.XmlWriter]::Create($stringWriter,$stringWriterSettings)
# Write the XML using the XMLWriter
$xmlText.WriteContentTo($xmlWriter)
# Don't forget to flush!
$xmlWriter.Flush()
$stringWriter.Flush()
# Output the text
$stringWriter.ToString()
# This works in a remote session, when [Console]::Out doesn't
}
}
Import-Module -Name "$PSScriptRoot\buildFuncs.psm1"
# fix up the project file
$hts1 = @"
<PropertyGroup Condition="'`$(ProjectRootPath)' ==''">
<ProjectRootPath>`$([MSBuild]::GetDirectoryNameOfFileAbove('`$(MSBuildThisFileDirectory)','BuildTools\build.ps1'))</ProjectRootPath>
</PropertyGroup>
<PropertyGroup Condition="'`$(HtsToolsDir)' == ''">
<HtsToolsDir>`$(ProjectRootPath)/BuildTools</HtsToolsDir>
</PropertyGroup>
<Import Project="`$(HtsToolsDir)\htsCommon.props" />
"@
$hts2 = @"
<Import Project="`$(HtsToolsDir)\htsCommon.targets" />
"@
log "updating project $projectfile with targetname $targetname"
$txt = get-content $projectFile
$origTarget = $null
$out = @()
foreach ($line in $txt) {
if ($line -like "*Microsoft.Cpp.targets*") {
$out += $hts1
$out += $line
$out += $hts2
} else {
$out += $line
}
}
if ($fixSampleInf) {
$xml = [xml]$out
$els = $xml.GetElementsByTagName("TargetName")
if ($els.Count) {
$origTarget = $els[0].InnerText
}
$els | ForEach-Object { $_.InnerText = $targetName }
$out = $xml | Format-XMLText
}
$out | Set-Content $projectFile
if ($origTarget -and ($fixSampleInf)) {
# update inx (or inf) files
$projPath = (get-item $projectFile).DirectoryName
$infs = Get-ChildItem -File -Path "$projPath\*.in[fx]"
log "origTarget $origTarget project path $projPath "
$infs | foreach-object {
log "modify inf $($_.FullName) replace $origTarget with $targetName"
$txt = get-content $_.FullName
$txt = $txt -replace $origTarget,$targetName
$txt = $txt -replace "Class=Sample","Class=$className"
$txt = $txt -replace "{78A1C341-4539-11d3-B88D-00C04FAD5171}",$classGuid
if ($providerString ) {
log "replace provideString with $providerString"
$pattern = '(^ProviderString\s*=\s*)(".*").*$'
$txt = $txt -replace $pattern, "`$1`"$providerString`""
}
$txt | Set-Content $_.FullName
}
}
# generate the version properties
$incPath = "$projectRoot\inc"
if (!(Test-Path -PathType Container $incPath)) {
log "creating include directory $incPath"
$null = New-Item -ItemType Directory -Path $incPath
}
& "$PSScriptRoot\versionFiles.ps1" -incPath $incPath -generateProps
# add vscode tasks for building
$vscodedir = "$projectRoot/.vscode"
$tasksFile = "$vscodedir/tasks.json"
if (!(test-path -PathType Leaf -Path $tasksFile)) {
log "creating $tasksfile"
if (!(test-path "$vscodedir")) {
$null = mkdir $vscodedir
}
@'
{
"version": "2.0.0",
"tasks": [
{
"label": "build all",
"type": "shell",
"command": "${workspaceFolder}/BuildTools/build.ps1 -configuration All -platform ALL",
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "build debug ",
"type": "shell",
"command": "${workspaceFolder}/BuildTools/build.ps1 -configuration Debug -platform x64",
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": false
}
},
{
"label": "build release ",
"type": "shell",
"command": "${workspaceFolder}/BuildTools/build.ps1 -configuration Release -platform x64",
"problemMatcher": [
"$msCompile"
],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
'@ | set-content $tasksFile
}