mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 1 | #!/usr/bin/tclsh |
| 2 | # |
| 3 | # This script is used to quickly test a VSIX (Visual Studio Extension) file |
| 4 | # with Visual Studio 2015 on Windows. |
| 5 | # |
| 6 | # PREREQUISITES |
| 7 | # |
mistachkin | 6ae4d84 | 2016-02-25 02:56:53 +0000 | [diff] [blame] | 8 | # 1. This tool must be executed with "elevated administrator" privileges. |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 9 | # |
mistachkin | 6ae4d84 | 2016-02-25 02:56:53 +0000 | [diff] [blame] | 10 | # 2. Tcl 8.4 and later are supported, earlier versions have not been tested. |
| 11 | # |
| 12 | # 3. The "sqlite-UWP-output.vsix" file is assumed to exist in the parent |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 13 | # directory of the directory containing this script. The [optional] first |
| 14 | # command line argument to this script may be used to specify an alternate |
| 15 | # file. However, currently, the file must be compatible with both Visual |
| 16 | # Studio 2015 and the Universal Windows Platform. |
| 17 | # |
mistachkin | 6ae4d84 | 2016-02-25 02:56:53 +0000 | [diff] [blame] | 18 | # 4. The "VERSION" file is assumed to exist in the parent directory of the |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 19 | # directory containing this script. It must contain a version number that |
| 20 | # matches the VSIX file being tested. |
| 21 | # |
mistachkin | 6ae4d84 | 2016-02-25 02:56:53 +0000 | [diff] [blame] | 22 | # 5. The temporary directory specified in the TEMP or TMP environment variables |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 23 | # must refer to an existing directory writable by the current user. |
| 24 | # |
mistachkin | 6ae4d84 | 2016-02-25 02:56:53 +0000 | [diff] [blame] | 25 | # 6. The VS140COMNTOOLS environment variable must refer to the Visual Studio |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 26 | # 2015 common tools directory. |
| 27 | # |
| 28 | # USAGE |
| 29 | # |
| 30 | # The first argument to this script is optional. If specified, it must be the |
| 31 | # name of the VSIX file to test. |
| 32 | # |
| 33 | package require Tcl 8.4 |
| 34 | |
| 35 | proc fail { {error ""} {usage false} } { |
| 36 | if {[string length $error] > 0} then { |
| 37 | puts stdout $error |
| 38 | if {!$usage} then {exit 1} |
| 39 | } |
| 40 | |
| 41 | puts stdout "usage:\ |
| 42 | [file tail [info nameofexecutable]]\ |
| 43 | [file tail [info script]] \[vsixFile\]" |
| 44 | |
| 45 | exit 1 |
| 46 | } |
| 47 | |
mistachkin | 7856c1c | 2016-02-25 23:22:26 +0000 | [diff] [blame] | 48 | proc isWindows {} { |
| 49 | # |
| 50 | # NOTE: Returns non-zero only when running on Windows. |
| 51 | # |
| 52 | return [expr {[info exists ::tcl_platform(platform)] && \ |
| 53 | $::tcl_platform(platform) eq "windows"}] |
| 54 | } |
| 55 | |
| 56 | proc isAdministrator {} { |
| 57 | # |
| 58 | # NOTE: Returns non-zero only when running as "elevated administrator". |
| 59 | # |
| 60 | if {[isWindows]} then { |
| 61 | if {[catch {exec -- whoami /groups} groups] == 0} then { |
| 62 | set groups [string map [list \r\n \n] $groups] |
| 63 | |
| 64 | foreach group [split $groups \n] { |
| 65 | # |
| 66 | # NOTE: Match this group line against the "well-known" SID for |
| 67 | # the "Administrators" group on Windows. |
| 68 | # |
| 69 | if {[regexp -- {\sS-1-5-32-544\s} $group]} then { |
| 70 | # |
| 71 | # NOTE: Match this group line against the attributes column |
| 72 | # sub-value that should be present when running with |
| 73 | # elevated administrator credentials. |
| 74 | # |
| 75 | if {[regexp -- {\sEnabled group(?:,|\s)} $group]} then { |
| 76 | return true |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | return false |
| 84 | } |
| 85 | |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 86 | proc getEnvironmentVariable { name } { |
| 87 | # |
| 88 | # NOTE: Returns the value of the specified environment variable or an empty |
| 89 | # string for environment variables that do not exist in the current |
| 90 | # process environment. |
| 91 | # |
| 92 | return [expr {[info exists ::env($name)] ? $::env($name) : ""}] |
| 93 | } |
| 94 | |
| 95 | proc getTemporaryPath {} { |
| 96 | # |
| 97 | # NOTE: Returns the normalized path to the first temporary directory found |
| 98 | # in the typical set of environment variables used for that purpose |
| 99 | # or an empty string to signal a failure to locate such a directory. |
| 100 | # |
| 101 | set names [list] |
| 102 | |
| 103 | foreach name [list TEMP TMP] { |
| 104 | lappend names [string toupper $name] [string tolower $name] \ |
| 105 | [string totitle $name] |
| 106 | } |
| 107 | |
| 108 | foreach name $names { |
| 109 | set value [getEnvironmentVariable $name] |
| 110 | |
| 111 | if {[string length $value] > 0} then { |
| 112 | return [file normalize $value] |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | return "" |
| 117 | } |
| 118 | |
| 119 | proc appendArgs { args } { |
| 120 | # |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 121 | # NOTE: Returns all passed arguments joined together as a single string |
| 122 | # with no intervening spaces between arguments. |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 123 | # |
| 124 | eval append result $args |
| 125 | } |
| 126 | |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 127 | proc readFile { fileName } { |
| 128 | # |
| 129 | # NOTE: Reads and returns the entire contents of the specified file, which |
| 130 | # may contain binary data. |
| 131 | # |
| 132 | set file_id [open $fileName RDONLY] |
| 133 | fconfigure $file_id -encoding binary -translation binary |
| 134 | set result [read $file_id] |
| 135 | close $file_id |
| 136 | return $result |
| 137 | } |
| 138 | |
| 139 | proc writeFile { fileName data } { |
| 140 | # |
| 141 | # NOTE: Writes the entire contents of the specified file, which may contain |
| 142 | # binary data. |
| 143 | # |
| 144 | set file_id [open $fileName {WRONLY CREAT TRUNC}] |
| 145 | fconfigure $file_id -encoding binary -translation binary |
| 146 | puts -nonewline $file_id $data |
| 147 | close $file_id |
| 148 | return "" |
| 149 | } |
| 150 | |
| 151 | proc putsAndEval { command } { |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 152 | # |
| 153 | # NOTE: Outputs a command to the standard output channel and then evaluates |
| 154 | # it in the callers context. |
| 155 | # |
| 156 | catch { |
| 157 | puts stdout [appendArgs "Running: " [lrange $command 1 end] ...\n] |
| 158 | } |
| 159 | |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 160 | return [uplevel 1 $command] |
| 161 | } |
| 162 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 163 | proc isBadDirectory { directory } { |
| 164 | # |
| 165 | # NOTE: Returns non-zero if the directory is empty, does not exist, -OR- is |
| 166 | # not a directory. |
| 167 | # |
| 168 | catch { |
| 169 | puts stdout [appendArgs "Checking directory \"" $directory \"...\n] |
| 170 | } |
| 171 | |
| 172 | return [expr {[string length $directory] == 0 || \ |
| 173 | ![file exists $directory] || ![file isdirectory $directory]}] |
| 174 | } |
| 175 | |
| 176 | proc isBadFile { fileName } { |
| 177 | # |
| 178 | # NOTE: Returns non-zero if the file name is empty, does not exist, -OR- is |
| 179 | # not a regular file. |
| 180 | # |
| 181 | catch { |
| 182 | puts stdout [appendArgs "Checking file \"" $fileName \"...\n] |
| 183 | } |
| 184 | |
| 185 | return [expr {[string length $fileName] == 0 || \ |
| 186 | ![file exists $fileName] || ![file isfile $fileName]}] |
| 187 | } |
| 188 | |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 189 | # |
| 190 | # NOTE: This is the entry point for this script. |
| 191 | # |
| 192 | set script [file normalize [info script]] |
| 193 | |
| 194 | if {[string length $script] == 0} then { |
| 195 | fail "script file currently being evaluated is unknown" true |
| 196 | } |
| 197 | |
mistachkin | 7856c1c | 2016-02-25 23:22:26 +0000 | [diff] [blame] | 198 | if {![isWindows]} then { |
| 199 | fail "this tool only works properly on Windows" |
| 200 | } |
| 201 | |
| 202 | if {![isAdministrator]} then { |
| 203 | fail "this tool must run with \"elevated administrator\" privileges" |
| 204 | } |
| 205 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 206 | set path [file normalize [file dirname $script]] |
| 207 | set argc [llength $argv]; if {$argc > 1} then {fail "" true} |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 208 | |
| 209 | if {$argc == 1} then { |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 210 | set vsixFileName [lindex $argv 0] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 211 | } else { |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 212 | set vsixFileName [file join \ |
| 213 | [file dirname $path] sqlite-UWP-output.vsix] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 214 | } |
| 215 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 216 | ############################################################################### |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 217 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 218 | if {[isBadFile $vsixFileName]} then { |
| 219 | fail [appendArgs \ |
| 220 | "VSIX file \"" $vsixFileName "\" does not exist"] |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | set versionFileName [file join [file dirname $path] VERSION] |
| 224 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 225 | if {[isBadFile $versionFileName]} then { |
| 226 | fail [appendArgs \ |
| 227 | "Version file \"" $versionFileName "\" does not exist"] |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | set projectTemplateFileName [file join $path vsixtest.vcxproj.data] |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 231 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 232 | if {[isBadFile $projectTemplateFileName]} then { |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 233 | fail [appendArgs \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 234 | "Project template file \"" $projectTemplateFileName \ |
| 235 | "\" does not exist"] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | set envVarName VS140COMNTOOLS |
| 239 | set vsDirectory [getEnvironmentVariable $envVarName] |
| 240 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 241 | if {[isBadDirectory $vsDirectory]} then { |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 242 | fail [appendArgs \ |
| 243 | "Visual Studio 2015 directory \"" $vsDirectory \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 244 | "\" from environment variable \"" $envVarName \ |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 245 | "\" does not exist"] |
| 246 | } |
| 247 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 248 | set vsixInstaller [file join \ |
| 249 | [file dirname $vsDirectory] IDE VSIXInstaller.exe] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 250 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 251 | if {[isBadFile $vsixInstaller]} then { |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 252 | fail [appendArgs \ |
| 253 | "Visual Studio 2015 VSIX installer \"" $vsixInstaller \ |
| 254 | "\" does not exist"] |
| 255 | } |
| 256 | |
| 257 | set envVarName ProgramFiles |
| 258 | set programFiles [getEnvironmentVariable $envVarName] |
| 259 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 260 | if {[isBadDirectory $programFiles]} then { |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 261 | fail [appendArgs \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 262 | "Program Files directory \"" $programFiles \ |
| 263 | "\" from environment variable \"" $envVarName \ |
| 264 | "\" does not exist"] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | set msBuild [file join $programFiles MSBuild 14.0 Bin MSBuild.exe] |
| 268 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 269 | if {[isBadFile $msBuild]} then { |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 270 | fail [appendArgs \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 271 | "MSBuild v14.0 executable file \"" $msBuild \ |
| 272 | "\" does not exist"] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | set temporaryDirectory [getTemporaryPath] |
| 276 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 277 | if {[isBadDirectory $temporaryDirectory]} then { |
| 278 | fail [appendArgs \ |
| 279 | "Temporary directory \"" $temporaryDirectory \ |
| 280 | "\" does not exist"] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 281 | } |
| 282 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 283 | ############################################################################### |
| 284 | |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 285 | set installLogFileName [appendArgs \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 286 | [file rootname [file tail $vsixFileName]] \ |
| 287 | -install- [pid] .log] |
| 288 | |
| 289 | set commands(1) [list exec [file nativename $vsixInstaller]] |
| 290 | |
| 291 | lappend commands(1) /quiet /norepair |
| 292 | lappend commands(1) [appendArgs /logFile: $installLogFileName] |
| 293 | lappend commands(1) [file nativename $vsixFileName] |
| 294 | |
| 295 | ############################################################################### |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 296 | |
| 297 | set buildLogFileName [appendArgs \ |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 298 | [file rootname [file tail $vsixFileName]] \ |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 299 | -build-%configuration%-%platform%- [pid] .log] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 300 | |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 301 | set commands(2) [list exec [file nativename $msBuild]] |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 302 | |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 303 | lappend commands(2) [file nativename [file join $path vsixtest.sln]] |
| 304 | lappend commands(2) /target:Rebuild |
| 305 | lappend commands(2) /property:Configuration=%configuration% |
mistachkin | 5dad68d | 2016-02-24 23:31:14 +0000 | [diff] [blame] | 306 | lappend commands(2) /property:Platform=%platform% |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 307 | |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 308 | lappend commands(2) [appendArgs \ |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 309 | /logger:FileLogger,Microsoft.Build.Engine\;Logfile= \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 310 | [file nativename [file join $temporaryDirectory \ |
| 311 | $buildLogFileName]] \;Verbosity=diagnostic] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 312 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 313 | ############################################################################### |
| 314 | |
| 315 | set uninstallLogFileName [appendArgs \ |
| 316 | [file rootname [file tail $vsixFileName]] \ |
| 317 | -uninstall- [pid] .log] |
| 318 | |
| 319 | set commands(3) [list exec [file nativename $vsixInstaller]] |
| 320 | |
| 321 | lappend commands(3) /quiet /norepair |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 322 | lappend commands(3) [appendArgs /logFile: $uninstallLogFileName] |
| 323 | lappend commands(3) [appendArgs /uninstall:SQLite.UWP.2015] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 324 | |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 325 | ############################################################################### |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 326 | |
mistachkin | 5dad68d | 2016-02-24 23:31:14 +0000 | [diff] [blame] | 327 | if {1} then { |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 328 | catch { |
| 329 | puts stdout [appendArgs \ |
| 330 | "Install log: \"" [file nativename [file join \ |
| 331 | $temporaryDirectory $installLogFileName]] \"\n] |
| 332 | } |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 333 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 334 | catch { |
| 335 | puts stdout [appendArgs \ |
| 336 | "Build logs: \"" [file nativename [file join \ |
| 337 | $temporaryDirectory $buildLogFileName]] \"\n] |
| 338 | } |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 339 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 340 | catch { |
| 341 | puts stdout [appendArgs \ |
| 342 | "Uninstall log: \"" [file nativename [file join \ |
| 343 | $temporaryDirectory $uninstallLogFileName]] \"\n] |
| 344 | } |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | ############################################################################### |
| 348 | |
| 349 | if {1} then { |
mistachkin | 6ae4d84 | 2016-02-25 02:56:53 +0000 | [diff] [blame] | 350 | putsAndEval $commands(1) |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 351 | |
| 352 | set versionNumber [string trim [readFile $versionFileName]] |
| 353 | set data [readFile $projectTemplateFileName] |
| 354 | set data [string map [list %versionNumber% $versionNumber] $data] |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 355 | |
| 356 | set projectFileName [file join $path vsixtest.vcxproj] |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 357 | writeFile $projectFileName $data |
| 358 | |
| 359 | set platforms [list x86 x64 ARM] |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 360 | set configurations [list Debug Release] |
| 361 | |
| 362 | foreach platform $platforms { |
| 363 | foreach configuration $configurations { |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 364 | putsAndEval [string map [list \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame] | 365 | %platform% $platform %configuration% $configuration] \ |
| 366 | $commands(2)] |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
mistachkin | 6ae4d84 | 2016-02-25 02:56:53 +0000 | [diff] [blame] | 370 | putsAndEval $commands(3) |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 371 | } |