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 | |
| 48 | proc getEnvironmentVariable { name } { |
| 49 | # |
| 50 | # NOTE: Returns the value of the specified environment variable or an empty |
| 51 | # string for environment variables that do not exist in the current |
| 52 | # process environment. |
| 53 | # |
| 54 | return [expr {[info exists ::env($name)] ? $::env($name) : ""}] |
| 55 | } |
| 56 | |
| 57 | proc getTemporaryPath {} { |
| 58 | # |
| 59 | # NOTE: Returns the normalized path to the first temporary directory found |
| 60 | # in the typical set of environment variables used for that purpose |
| 61 | # or an empty string to signal a failure to locate such a directory. |
| 62 | # |
| 63 | set names [list] |
| 64 | |
| 65 | foreach name [list TEMP TMP] { |
| 66 | lappend names [string toupper $name] [string tolower $name] \ |
| 67 | [string totitle $name] |
| 68 | } |
| 69 | |
| 70 | foreach name $names { |
| 71 | set value [getEnvironmentVariable $name] |
| 72 | |
| 73 | if {[string length $value] > 0} then { |
| 74 | return [file normalize $value] |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | return "" |
| 79 | } |
| 80 | |
| 81 | proc appendArgs { args } { |
| 82 | # |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 83 | # NOTE: Returns all passed arguments joined together as a single string |
| 84 | # with no intervening spaces between arguments. |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 85 | # |
| 86 | eval append result $args |
| 87 | } |
| 88 | |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 89 | proc readFile { fileName } { |
| 90 | # |
| 91 | # NOTE: Reads and returns the entire contents of the specified file, which |
| 92 | # may contain binary data. |
| 93 | # |
| 94 | set file_id [open $fileName RDONLY] |
| 95 | fconfigure $file_id -encoding binary -translation binary |
| 96 | set result [read $file_id] |
| 97 | close $file_id |
| 98 | return $result |
| 99 | } |
| 100 | |
| 101 | proc writeFile { fileName data } { |
| 102 | # |
| 103 | # NOTE: Writes the entire contents of the specified file, which may contain |
| 104 | # binary data. |
| 105 | # |
| 106 | set file_id [open $fileName {WRONLY CREAT TRUNC}] |
| 107 | fconfigure $file_id -encoding binary -translation binary |
| 108 | puts -nonewline $file_id $data |
| 109 | close $file_id |
| 110 | return "" |
| 111 | } |
| 112 | |
| 113 | proc putsAndEval { command } { |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 114 | # |
| 115 | # NOTE: Outputs a command to the standard output channel and then evaluates |
| 116 | # it in the callers context. |
| 117 | # |
| 118 | catch { |
| 119 | puts stdout [appendArgs "Running: " [lrange $command 1 end] ...\n] |
| 120 | } |
| 121 | |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 122 | return [uplevel 1 $command] |
| 123 | } |
| 124 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 125 | proc isBadDirectory { directory } { |
| 126 | # |
| 127 | # NOTE: Returns non-zero if the directory is empty, does not exist, -OR- is |
| 128 | # not a directory. |
| 129 | # |
| 130 | catch { |
| 131 | puts stdout [appendArgs "Checking directory \"" $directory \"...\n] |
| 132 | } |
| 133 | |
| 134 | return [expr {[string length $directory] == 0 || \ |
| 135 | ![file exists $directory] || ![file isdirectory $directory]}] |
| 136 | } |
| 137 | |
| 138 | proc isBadFile { fileName } { |
| 139 | # |
| 140 | # NOTE: Returns non-zero if the file name is empty, does not exist, -OR- is |
| 141 | # not a regular file. |
| 142 | # |
| 143 | catch { |
| 144 | puts stdout [appendArgs "Checking file \"" $fileName \"...\n] |
| 145 | } |
| 146 | |
| 147 | return [expr {[string length $fileName] == 0 || \ |
| 148 | ![file exists $fileName] || ![file isfile $fileName]}] |
| 149 | } |
| 150 | |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 151 | # |
| 152 | # NOTE: This is the entry point for this script. |
| 153 | # |
| 154 | set script [file normalize [info script]] |
| 155 | |
| 156 | if {[string length $script] == 0} then { |
| 157 | fail "script file currently being evaluated is unknown" true |
| 158 | } |
| 159 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 160 | set path [file normalize [file dirname $script]] |
| 161 | set argc [llength $argv]; if {$argc > 1} then {fail "" true} |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 162 | |
| 163 | if {$argc == 1} then { |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 164 | set vsixFileName [lindex $argv 0] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 165 | } else { |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 166 | set vsixFileName [file join \ |
| 167 | [file dirname $path] sqlite-UWP-output.vsix] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 168 | } |
| 169 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 170 | ############################################################################### |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 171 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 172 | if {[isBadFile $vsixFileName]} then { |
| 173 | fail [appendArgs \ |
| 174 | "VSIX file \"" $vsixFileName "\" does not exist"] |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 175 | } |
| 176 | |
| 177 | set versionFileName [file join [file dirname $path] VERSION] |
| 178 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 179 | if {[isBadFile $versionFileName]} then { |
| 180 | fail [appendArgs \ |
| 181 | "Version file \"" $versionFileName "\" does not exist"] |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | set projectTemplateFileName [file join $path vsixtest.vcxproj.data] |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 185 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 186 | if {[isBadFile $projectTemplateFileName]} then { |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 187 | fail [appendArgs \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 188 | "Project template file \"" $projectTemplateFileName \ |
| 189 | "\" does not exist"] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | set envVarName VS140COMNTOOLS |
| 193 | set vsDirectory [getEnvironmentVariable $envVarName] |
| 194 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 195 | if {[isBadDirectory $vsDirectory]} then { |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 196 | fail [appendArgs \ |
| 197 | "Visual Studio 2015 directory \"" $vsDirectory \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 198 | "\" from environment variable \"" $envVarName \ |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 199 | "\" does not exist"] |
| 200 | } |
| 201 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 202 | set vsixInstaller [file join \ |
| 203 | [file dirname $vsDirectory] IDE VSIXInstaller.exe] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 204 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 205 | if {[isBadFile $vsixInstaller]} then { |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 206 | fail [appendArgs \ |
| 207 | "Visual Studio 2015 VSIX installer \"" $vsixInstaller \ |
| 208 | "\" does not exist"] |
| 209 | } |
| 210 | |
| 211 | set envVarName ProgramFiles |
| 212 | set programFiles [getEnvironmentVariable $envVarName] |
| 213 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 214 | if {[isBadDirectory $programFiles]} then { |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 215 | fail [appendArgs \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 216 | "Program Files directory \"" $programFiles \ |
| 217 | "\" from environment variable \"" $envVarName \ |
| 218 | "\" does not exist"] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 219 | } |
| 220 | |
| 221 | set msBuild [file join $programFiles MSBuild 14.0 Bin MSBuild.exe] |
| 222 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 223 | if {[isBadFile $msBuild]} then { |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 224 | fail [appendArgs \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 225 | "MSBuild v14.0 executable file \"" $msBuild \ |
| 226 | "\" does not exist"] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | set temporaryDirectory [getTemporaryPath] |
| 230 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 231 | if {[isBadDirectory $temporaryDirectory]} then { |
| 232 | fail [appendArgs \ |
| 233 | "Temporary directory \"" $temporaryDirectory \ |
| 234 | "\" does not exist"] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 235 | } |
| 236 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 237 | ############################################################################### |
| 238 | |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 239 | set installLogFileName [appendArgs \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 240 | [file rootname [file tail $vsixFileName]] \ |
| 241 | -install- [pid] .log] |
| 242 | |
| 243 | set commands(1) [list exec [file nativename $vsixInstaller]] |
| 244 | |
| 245 | lappend commands(1) /quiet /norepair |
| 246 | lappend commands(1) [appendArgs /logFile: $installLogFileName] |
| 247 | lappend commands(1) [file nativename $vsixFileName] |
| 248 | |
| 249 | ############################################################################### |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 250 | |
| 251 | set buildLogFileName [appendArgs \ |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 252 | [file rootname [file tail $vsixFileName]] \ |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 253 | -build-%configuration%-%platform%- [pid] .log] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 254 | |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 255 | set commands(2) [list exec [file nativename $msBuild]] |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 256 | |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 257 | lappend commands(2) [file nativename [file join $path vsixtest.sln]] |
| 258 | lappend commands(2) /target:Rebuild |
| 259 | lappend commands(2) /property:Configuration=%configuration% |
mistachkin | 5dad68d | 2016-02-24 23:31:14 +0000 | [diff] [blame] | 260 | lappend commands(2) /property:Platform=%platform% |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 261 | |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 262 | lappend commands(2) [appendArgs \ |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 263 | /logger:FileLogger,Microsoft.Build.Engine\;Logfile= \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 264 | [file nativename [file join $temporaryDirectory \ |
| 265 | $buildLogFileName]] \;Verbosity=diagnostic] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 266 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 267 | ############################################################################### |
| 268 | |
| 269 | set uninstallLogFileName [appendArgs \ |
| 270 | [file rootname [file tail $vsixFileName]] \ |
| 271 | -uninstall- [pid] .log] |
| 272 | |
| 273 | set commands(3) [list exec [file nativename $vsixInstaller]] |
| 274 | |
| 275 | lappend commands(3) /quiet /norepair |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 276 | lappend commands(3) [appendArgs /logFile: $uninstallLogFileName] |
| 277 | lappend commands(3) [appendArgs /uninstall:SQLite.UWP.2015] |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 278 | |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 279 | ############################################################################### |
mistachkin | 7aa3ebe | 2016-02-24 21:42:03 +0000 | [diff] [blame] | 280 | |
mistachkin | 5dad68d | 2016-02-24 23:31:14 +0000 | [diff] [blame] | 281 | if {1} then { |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 282 | catch { |
| 283 | puts stdout [appendArgs \ |
| 284 | "Install log: \"" [file nativename [file join \ |
| 285 | $temporaryDirectory $installLogFileName]] \"\n] |
| 286 | } |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 287 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 288 | catch { |
| 289 | puts stdout [appendArgs \ |
| 290 | "Build logs: \"" [file nativename [file join \ |
| 291 | $temporaryDirectory $buildLogFileName]] \"\n] |
| 292 | } |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 293 | |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 294 | catch { |
| 295 | puts stdout [appendArgs \ |
| 296 | "Uninstall log: \"" [file nativename [file join \ |
| 297 | $temporaryDirectory $uninstallLogFileName]] \"\n] |
| 298 | } |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | ############################################################################### |
| 302 | |
| 303 | if {1} then { |
mistachkin | 6ae4d84 | 2016-02-25 02:56:53 +0000 | [diff] [blame] | 304 | putsAndEval $commands(1) |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 305 | |
| 306 | set versionNumber [string trim [readFile $versionFileName]] |
| 307 | set data [readFile $projectTemplateFileName] |
| 308 | set data [string map [list %versionNumber% $versionNumber] $data] |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 309 | |
| 310 | set projectFileName [file join $path vsixtest.vcxproj] |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 311 | writeFile $projectFileName $data |
| 312 | |
| 313 | set platforms [list x86 x64 ARM] |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 314 | set configurations [list Debug Release] |
| 315 | |
| 316 | foreach platform $platforms { |
| 317 | foreach configuration $configurations { |
mistachkin | c32db46 | 2016-02-25 02:49:58 +0000 | [diff] [blame] | 318 | putsAndEval [string map [list \ |
mistachkin | 77b7e2a | 2016-02-25 08:02:16 +0000 | [diff] [blame^] | 319 | %platform% $platform %configuration% $configuration] \ |
| 320 | $commands(2)] |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 321 | } |
| 322 | } |
| 323 | |
mistachkin | 6ae4d84 | 2016-02-25 02:56:53 +0000 | [diff] [blame] | 324 | putsAndEval $commands(3) |
mistachkin | 78007b2 | 2016-02-24 23:25:23 +0000 | [diff] [blame] | 325 | } |