forked from google/UIforETW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
package_etw.bat
229 lines (193 loc) · 9.66 KB
/
package_etw.bat
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
@setlocal
@echo Creating a package of files for easy use of ETW/WPT.
set UIforETW=%~dp0
set destdir=%UIforETW%etwpackage
set symboldir=%UIforETW%etwsymbols
rmdir %destdir% /s/q
rmdir %symboldir% /s/q
@if exist %destdir%\bin\UIforETW.exe goto pleasecloseUIforETW
@if exist %destdir%\bin\ETWProviders.dll goto pleasecloseSomething
mkdir %destdir%\bin
mkdir %destdir%\include
mkdir %destdir%\lib
mkdir %destdir%\third_party
mkdir %symboldir%
set wptredistmsi=Windows Performance Toolkit\Redistributables\WPTx64-x86_en-us.msi
set oldwptredistmsi=Windows Performance Toolkit\OldRedistributables\WPTx64-x86_en-us.msi
set wpt10=c:\Program Files (x86)\Windows Kits\10\
if not exist "%wpt10%%wptredistmsi%" goto nowpt10
if not exist "%wpt10%%oldwptredistmsi%" goto nooldwpt10
mkdir %destdir%\third_party\wpt10
mkdir %destdir%\third_party\oldwpt10
xcopy "%wpt10%%wptredistmsi%" %destdir%\third_party\wpt10
@if errorlevel 1 goto copyfailure
xcopy "%wpt10%%oldwptredistmsi%" %destdir%\third_party\oldwpt10
@if errorlevel 1 goto copyfailure
xcopy "%wpt10%Licenses\10.0.15063.0\sdk_license.rtf" %destdir%\third_party\wpt10
@if errorlevel 1 goto copyfailure
ren %destdir%\third_party\wpt10\sdk_license.rtf LICENSE.rtf
@rem Add VS tools to the path. Also adds signtool.exe to the path.
set vcvars32="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat"
if exist %vcvars32% goto community_installed
set vcvars32="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Auxiliary\Build\vcvars32.bat"
:community_installed
call %vcvars32%
@rem Build DelayedCreateProcess.exe to the bin directory
call DelayedCreateProcess\make.bat
cd /d %UIforETW%ETWInsights
devenv /rebuild "release|Win32" ETWInsights.sln
@if ERRORLEVEL 1 goto BuildFailure
xcopy Release\flame_graph.exe %UIforETW%\bin /y
cd /d %UIforETW%UIforETW
@rem Modify the UIforETW project to be statically linked and build that version
@rem so that it will run without any extra install requirements.
sed "s/UIforETW.vcxproj/UIforETWStatic.vcxproj/" <UIforETW.sln >UIforETWStatic.sln
@echo First do a test build with ETW marks disabled to test the inline functions.
sed "s/_WINDOWS/_WINDOWS;DISABLE_ETW_MARKS/" <UIforETW.vcxproj >UIforETWStatic.vcxproj
devenv /rebuild "release|Win32" UIforETWStatic.sln
@if ERRORLEVEL 1 goto BuildFailure
@rem Now prepare for the real builds
sed "s/UseOfMfc>Dynamic/UseOfMfc>Static/" <UIforETW.vcxproj >UIforETWStatic.vcxproj
if exist Release rmdir Release /s/q
if exist x64\Release rmdir x64\Release /s/q
devenv /rebuild "release|Win32" UIforETWStatic.sln
@if ERRORLEVEL 1 goto BuildFailure
devenv /rebuild "release|x64" UIforETWStatic.sln
@if ERRORLEVEL 1 goto BuildFailure
@rem Clean up after building the static version.
rmdir Release /s/q
rmdir x64\Release /s/q
del UIforETWStatic.vcxproj
del UIforETWStatic.sln
cd %UIforETW%\EventEmitter
devenv /rebuild "Release|x86" EventEmitter.sln
@if ERRORLEVEL 1 goto BuildFailure
devenv /rebuild "Release|x64" EventEmitter.sln
@if ERRORLEVEL 1 goto BuildFailure
xcopy %UIforETW%CONTRIBUTING %destdir%
xcopy %UIforETW%CONTRIBUTORS %destdir%
xcopy %UIforETW%AUTHORS %destdir%
xcopy %UIforETW%LICENSE %destdir%
xcopy %UIforETW%README %destdir%
xcopy /exclude:%UIforETW%excludecopy.txt %UIforETW%bin %destdir%\bin /s
xcopy %UIforETW%ETWProviders\etwproviders.man %destdir%\bin /y
xcopy /exclude:%UIforETW%excludecopy.txt %UIforETW%include %destdir%\include /s
xcopy /exclude:%UIforETW%excludecopy.txt %UIforETW%lib %destdir%\lib /s
xcopy /exclude:%UIforETW%excludecopy.txt %UIforETW%third_party %destdir%\third_party /s
@rem Get the destinations to exist so that the xcopy proceeds without a question.
echo >%destdir%\bin\UIforETW.exe
echo >%destdir%\bin\UIforETW32.exe
xcopy %UIforETW%bin\UIforETWStatic_devrel32.exe %destdir%\bin\UIforETW32.exe /y
xcopy %UIforETW%bin\UIforETWStatic_devrel.exe %destdir%\bin\UIforETW.exe /y
xcopy %UIforETW%bin\EventEmitter.exe %destdir%\bin /y
xcopy %UIforETW%bin\EventEmitter64.exe %destdir%\bin /y
xcopy %UIforETW%third_party\dbghelp.dll %destdir%\bin /y
xcopy %UIforETW%third_party\symsrv.dll %destdir%\bin /y
@rem Sign the important (requiring elevation) binaries
set bindir=%~dp0etwpackage\bin
signtool sign /d "UIforETW" /du "https://github.com/google/UIforETW/releases" /n "Bruce Dawson" /tr http://timestamp.digicert.com /td SHA256 /fd SHA256 %bindir%\UIforETW.exe %bindir%\UIforETW32.exe %bindir%\EventEmitter.exe %bindir%\EventEmitter64.exe %bindir%\flame_graph.exe %bindir%\RetrieveSymbols.exe %bindir%\DelayedCreateProcess.exe %bindir%\DummyChrome.dll %bindir%\ETWProviders.dll %bindir%\ETWProviders64.dll %bindir%\ETWProvidersARM64.dll
@if not %errorlevel% equ 0 goto signing_failure
@rem Copy the official binaries back to the local copy, for development purposes.
xcopy /exclude:%UIforETW%excludecopy.txt %destdir%\bin\UIforETW*.exe %UIforETW%bin /y
@if ERRORLEVEL 1 goto BuildFailure
@rem Grab all of the lab scripts
xcopy /exclude:%UIforETW%excludecopy.txt %UIforETW%LabScripts %destdir%\LabScripts /y /i /s
@if ERRORLEVEL 1 goto BuildFailure
xcopy %UIforETW%\bin\UIforETWStatic_devrel*.pdb %symboldir%
cd /d %UIforETW%
@rem Source indexing as described here:
@rem http://hamishgraham.net/post/GitHub-Source-Symbol-Indexer.aspx
@rem The next steps assume that you have cloned https://github.com/Haemoglobin/GitHub-Source-Indexer.git
@rem into the parent directory of the UIforETW repo.
@rem You also have to enable execution of power-shell scripts, by running something
@rem like this from an administrator command prompt:
@rem powershell Set-ExecutionPolicy Unrestricted
@rem Note that -dbgToolsPath and -verifyLocalRepo had to be added to the command line
@rem to get the script to behave. -dbgToolsPath is tricky because the default path has
@rem spaces and the script can't handle that, so I copy it to %temp%. God help you if
@rem that has spaces.
@rem verifyLocalRepo comes with its own challenges since github-sourceindexer.ps1 does
@rem a weak job of looking for git.exe. I had to edit FindGitExe to tell it exactly where
@rem to look - something like this:
@rem function FindGitExe {
@rem $gitexe = "c:\src\chromium\depot_tools\git-2.8.3-64_bin\cmd\git.exe"
@rem if (Test-Path $gitexe) {
@rem return $gitexe
@rem }
if not exist ..\GitHub-Source-Indexer\github-sourceindexer.ps1 goto NoSourceIndexing
if exist %temp%\srcsrv rmdir %temp%\srcsrv /s/q
mkdir %temp%\srcsrv
xcopy /s /y "c:\Program Files (x86)\Windows Kits\10\Debuggers\x64\srcsrv" %temp%\srcsrv
@rem Crazy gymnastics to get the current git hash into an environment variable:
echo|set /p="set hash=">sethash.bat
call git log -1 --pretty=%%%%H >>sethash.bat
call sethash.bat
del sethash.bat
@rem We need to create this sort of URL:
@rem https://raw.githubusercontent.com/google/UIforETW/ea1129d25ba58efd03ef649829348ca553f82383/.gitignore
@rem From this template:
@rem HTTP_EXTRACT_TARGET=%HTTP_ALIAS%/%var2%/%var3%/raw/%var4%/%var5%
@rem With these sort of arguments:
@rem c:\github\uiforetw\uiforetw\utility.h*google*UIforETW*master*UIforETW/utility.h
powershell ..\GitHub-Source-Indexer\github-sourceindexer.ps1 -symbolsFolder etwsymbols -userID "google" ^
-repository UIforETW -branch %hash% -sourcesRoot %UIforETW% -dbgToolsPath %temp%\srcsrv ^
-verifyLocalRepo -gitHubUrl https://raw.githubusercontent.com -serverIsRaw
@echo Run these commands if you want to verify what has been indexed:
@echo %temp%\srcsrv\pdbstr -r -p:etwsymbols\UIforETWStatic_devrel.pdb -s:srcsrv
@echo %temp%\srcsrv\pdbstr -r -p:etwsymbols\UIforETWStatic_devrel32.pdb -s:srcsrv
:NoSourceIndexing
@rem Copy the critical PE files to the symbol server as well, to demonstrate best practices.
copy etwpackage\bin\UIforETW*.exe etwsymbols
@rem Add the PE and PDB files to a local symbol server directory, to get the
@rem required directory structure:
if exist etwsymserver rmdir /s/q etwsymserver
"c:\Program Files (x86)\Windows Kits\10\Debuggers\x64\symstore.exe" add /r /f etwsymbols /s etwsymserver /t uiforetw
@rem Delete the excess files.
rmdir etwsymserver\000Admin /s/q
del etwsymserver\pingme.txt
del etwsymserver\refs.ptr /s
@rem Make the redistributable .zip file
del *.zip 2>nul
call python make_zip_file.py etwpackage.zip etwpackage
@echo on
@rem Rename to the current version.
call python rename_to_version.py UIforETW\Version.h
@echo on
@echo Now upload the new etwpackage*.zip
@echo But make sure that the PersistedPresets section from startup10.wpaProfile
@echo been deleted to avoid shipping modified presets and bloating the file.
@echo After releasing a version with an updated version number be sure to trigger
@echo the new version checking by running:
@echo xcopy UIforETW\Version.h UIforETW\VersionCopy.h /y
@echo git add UIforETW\VersionCopy.h
@echo git commit -m "Updating VersionCopy.h for updated version checking"
@echo git push
cd etwsymserver
@rem Upload to the randomascii-symbols public symbol server.
@echo Final step - ready to upload the symbols?
@pause
call python c:\src\depot_tools\gsutil.py cp -Z -R . gs://randomascii-symbols
cd ..
@echo on
@exit /b
:pleasecloseUIforETW
@echo UIforETW is running. Please close it and try again.
@exit /b
:pleasecloseSomething
@echo Something is running with ETWProviders.dll loaded. Please close it and try again.
@exit /b
:nowpt10
@echo WPT 10 redistributables not found. Aborting.
@exit /b
:nooldwpt10
@echo Old WPT 10 redistributables not found. Aborting.
@exit /b
:BuildFailure
@echo Build failure of some sort. Aborting.
@exit /b
:copyfailure
@echo Failed to copy file. Aborting.
@exit /b
:signing_failure
@echo Failed to sign files. Aborting.
@exit /b