-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdriverProject.ps1
More file actions
201 lines (188 loc) · 6.48 KB
/
Copy pathdriverProject.ps1
File metadata and controls
201 lines (188 loc) · 6.48 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
190
191
192
193
194
195
196
197
198
199
200
201
<#
.SYNOPSIS
Create a driver project from an existing
sample in a local copy of the github
repo https://github.com/microsoft/Windows-driver-samples.
.PARAMETER outputJson
Outputs a json schema for the parameters to this script.
.PARAMETER sourcePath
The path to the sample project to copy.
.PARAMETER targetPath
The path to the directory where the new project will be created.
.PARAMETER targetName
The name of the new project.
.PARAMETER projectRoot
The root directory of the project. Defaults to the targetPath.
.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 JsonFile
A json file containing the parameters for this script. If specified, the parameters in the json file will be used instead of the command line parameters.
.NOTES
the JSON schema output file makes the parameters for this script clearer.
#>
[CmdletBinding()]
param(
[Parameter(ParameterSetName="json-schema")]
[switch] $outputJson,
[Parameter(Mandatory,
ParameterSetName="standard")]
[string] $sourcePath,
[Parameter(Mandatory,
ParameterSetName="standard")]
[string] $targetPath,
[Parameter(Mandatory,
ParameterSetName="standard")]
[string] $targetName,
[string] $projectRoot = $null,
[string] $classGuid = $null,
[string] $className = $null,
[string] $providerString = $null,
[string] $JsonFile = $null)
if ($PSCmdlet.ParameterSetName -eq 'json-schema') {
if ($outputJson) {
@"
{
"classGuid" : "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}",
"className" : "aaaaaaaa",
"providerString" : "company name",
"createGitRepo" : true,
"importBuildTools" : true,
"projectInit" : true,
"fixSampleInf" : true
}
"@
}
}
else {
Import-Module -Name "$PSScriptRoot\buildFuncs.psm1" -Force
$importBuildTools = $true
$createGitRepo = $true
$projectInit = $true
$fixSampleInf = $true
if ($jsonFile -and (test-path($JsonFile))) {
log "getting config from $JsonFile"
$json = Get-Content $jsonFile | ConvertFrom-Json
if (!$classGuid) {
if ( "classGuid" -in $json.PSobject.Properties.Name) {
$classGuid = $json.classGuid
}
}
if (!$className) {
if ( "className" -in $json.PSobject.Properties.Name) {
$className = $json.className
}
}
if (!$providerString) {
if ( "providerString" -in $json.PSobject.Properties.Name) {
$providerString = $json.providerString
}
}
if ( "createGitRepo" -in $json.PSobject.Properties.Name) {
$createGitRepo = $json.createGitRepo
}
if ( "importBuildTools" -in $json.PSobject.Properties.Name) {
$importBuildTools = $json.importBuildTools
}
if ( "projectInit" -in $json.PSobject.Properties.Name) {
$projectInit = $json.projectInit
}
if ( "fixSampleInf" -in $json.PSobject.Properties.Name) {
$fixSampleInf = $json.fixSampleInf
}
}
$createdTarget = $false
try {
if (!$projectRoot) {
$projectRoot = $targetPath
}
if (!(test-path -Path $targetPath -PathType Container -ErrorAction SilentlyContinue)) {
log "creating directory $targetPath"
$null = new-item -ItemType Directory -force -Path $targetPath
$createdTarget = $true
}
$targetPath = $targetPath | Resolve-Path
$projectRoot = $projectRoot | Resolve-Path
log "targetPath: $targetPath projectRoot: $projectRoot"
if ($targetPath -ne $projectRoot) {
$t = Get-ChildItem -Path $projectRoot -Recurse -Directory
if (! $t) {
log "targetPath: $targetPath must be a child directory of projectRoot $projectRoot"
throw "bad path"
}
}
Get-ChildItem -Path $sourcePath | Copy-Item -Destination $targetPath -Recurse
}
catch {
log "exception: $_.Exception"
if ($createdTarget) {
remove-item -Path $targetPath -Force
}
exit
}
Push-Location $projectRoot
if ($createGitRepo) {
if (isGitRepo) {
log "$projectRoot is an existing git repo, not initiailizing."
} else {
log "init git repo"
git init --initial-branch main > $null
@"
/bin
/logs
inc/ntverp.h
x64/
.vs/
*.user
.vscode/
*.aps
"@ | Set-Content ".\.gitignore"
}
git add -A
git commit -m "Initial commit of $targetName after copy from MSFT samples." -q
$modified = $false
if ($importBuildTools) {
$s = & git submodule status 2> $null | select-string -Pattern 'BuildTools'
if ($null -eq $s) {
log "add BuildTools submodule"
$null = git submodule add "https://github.com/HollisTech/BuildTools.git" 2>&1
$modified = $true
} else {
log "Buildtools already added as submodule."
}
}
if ($projectInit) {
log "update project files"
$updateParms = @{
classGuid = $classGuid
className = $className
providerString = $providerString
projectRoot = $projectRoot
fixSampleInf = $fixSampleInf
}
$suffix = ""
$count = 0
$projs = Get-ChildItem -File -Path $targetPath -Filter "*.vcxproj" -Recurse
log "found $($projs.Count) vcxproj files"
$projs | ForEach-Object {
$vc = $($_.FullName)
log "update $vc"
& "$PSScriptRoot\updateProject.ps1" -projectFile $vc -targetName "$targetName$suffix" @updateParms
$count++
$suffix = "-$count"
}
if ($count -gt 0) {
$modified = $true
}
}
if ($modified) {
log "commit results"
git add -A
git commit -m "Hollistech modifications for building" -q
}
}
Pop-Location
}