blob: ae7b91bf2c3557e89e5ce9a86b760501d77f4a45 [file] [log] [blame]
mistachkin7aa3ebe2016-02-24 21:42:03 +00001#!/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#
8# 1. Tcl 8.4 and later are supported, earlier versions have not been tested.
9#
10# 2. The "sqlite-UWP-output.vsix" file is assumed to exist in the parent
11# directory of the directory containing this script. The [optional] first
12# command line argument to this script may be used to specify an alternate
13# file. However, currently, the file must be compatible with both Visual
14# Studio 2015 and the Universal Windows Platform.
15#
16# 3. The temporary directory specified in the TEMP or TMP environment variables
17# must refer to an existing directory writable by the current user.
18#
19# 4. The VS140COMNTOOLS environment variable must refer to the Visual Studio
20# 2015 common tools directory.
21#
22# USAGE
23#
24# The first argument to this script is optional. If specified, it must be the
25# name of the VSIX file to test.
26#
27package require Tcl 8.4
28
29proc fail { {error ""} {usage false} } {
30 if {[string length $error] > 0} then {
31 puts stdout $error
32 if {!$usage} then {exit 1}
33 }
34
35 puts stdout "usage:\
36[file tail [info nameofexecutable]]\
37[file tail [info script]] \[vsixFile\]"
38
39 exit 1
40}
41
42proc getEnvironmentVariable { name } {
43 #
44 # NOTE: Returns the value of the specified environment variable or an empty
45 # string for environment variables that do not exist in the current
46 # process environment.
47 #
48 return [expr {[info exists ::env($name)] ? $::env($name) : ""}]
49}
50
51proc getTemporaryPath {} {
52 #
53 # NOTE: Returns the normalized path to the first temporary directory found
54 # in the typical set of environment variables used for that purpose
55 # or an empty string to signal a failure to locate such a directory.
56 #
57 set names [list]
58
59 foreach name [list TEMP TMP] {
60 lappend names [string toupper $name] [string tolower $name] \
61 [string totitle $name]
62 }
63
64 foreach name $names {
65 set value [getEnvironmentVariable $name]
66
67 if {[string length $value] > 0} then {
68 return [file normalize $value]
69 }
70 }
71
72 return ""
73}
74
75proc appendArgs { args } {
76 #
77 # NOTE: Returns all passed arguments joined together as a single string with
78 # no intervening spaces between arguments.
79 #
80 eval append result $args
81}
82
83#
84# NOTE: This is the entry point for this script.
85#
86set script [file normalize [info script]]
87
88if {[string length $script] == 0} then {
89 fail "script file currently being evaluated is unknown" true
90}
91
92set path [file dirname $script]
93
94###############################################################################
95
96#
97# NOTE: Process and verify all the command line arguments.
98#
99set argc [llength $argv]
100if {$argc > 1} then {fail}
101
102if {$argc == 1} then {
103 set fileName [lindex $argv 0]
104} else {
105 set fileName [file join [file dirname $path] sqlite-UWP-output.vsix]
106}
107
108if {[string length $fileName] == 0} then {
109 fail "invalid VSIX file name"
110}
111
112if {![file exists $fileName] || ![file isfile $fileName]} then {
113 fail [appendArgs "VSIX file \"" $fileName "\" does not exist"]
114}
115
116set envVarName VS140COMNTOOLS
117set vsDirectory [getEnvironmentVariable $envVarName]
118
119if {[string length $vsDirectory] == 0} then {
120 fail [appendArgs \
121 "Visual Studio 2015 environment variable \"" $envVarName "\" missing"]
122}
123
124if {![file exists $vsDirectory] || ![file isdirectory $vsDirectory]} then {
125 fail [appendArgs \
126 "Visual Studio 2015 directory \"" $vsDirectory \
127 "\" does not exist"]
128}
129
130set vsixInstaller [file join [file dirname $vsDirectory] IDE VSIXInstaller.exe]
131
132if {![file exists $vsixInstaller] || ![file isfile $vsixInstaller]} then {
133 fail [appendArgs \
134 "Visual Studio 2015 VSIX installer \"" $vsixInstaller \
135 "\" does not exist"]
136}
137
138set envVarName ProgramFiles
139set programFiles [getEnvironmentVariable $envVarName]
140
141if {[string length $programFiles] == 0} then {
142 fail [appendArgs \
143 "Windows environment variable \"" $envVarName "\" missing"]
144}
145
146if {![file exists $programFiles] || ![file isdirectory $programFiles]} then {
147 fail [appendArgs \
148 "Program Files directory \"" $programFiles "\" does not exist"]
149}
150
151set msBuild [file join $programFiles MSBuild 14.0 Bin MSBuild.exe]
152
153if {![file exists $msBuild] || ![file isfile $msBuild]} then {
154 fail [appendArgs \
155 "MSBuild 14.0 executable file \"" $msBuild "\" does not exist"]
156}
157
158set temporaryDirectory [getTemporaryPath]
159
160if {[string length $temporaryDirectory] == 0 || \
161 ![file exists $temporaryDirectory] || \
162 ![file isdirectory $temporaryDirectory]} then {
163 fail "cannot locate a usable temporary directory"
164}
165
166set installLogFileName [appendArgs \
167 [file rootname [file tail $fileName]] -install- [pid] .log]
168
169set buildLogFileName [appendArgs \
mistachkin78007b22016-02-24 23:25:23 +0000170 [file rootname [file tail $fileName]] \
171 -build-%configuration%-%platform%- [pid] .log]
mistachkin7aa3ebe2016-02-24 21:42:03 +0000172
173set uninstallLogFileName [appendArgs \
174 [file rootname [file tail $fileName]] -uninstall- [pid] .log]
175
mistachkin78007b22016-02-24 23:25:23 +0000176set commands(1) [list exec [file nativename $vsixInstaller] /quiet /norepair]
177lappend commands(1) [appendArgs /logFile: $installLogFileName]
178lappend commands(1) [file nativename $fileName]
mistachkin7aa3ebe2016-02-24 21:42:03 +0000179
mistachkin78007b22016-02-24 23:25:23 +0000180set commands(2) [list exec [file nativename $msBuild]]
181lappend commands(2) [file nativename [file join $path vsixtest.sln]]
182lappend commands(2) /target:Rebuild
183lappend commands(2) /property:Configuration=%configuration%
184lappend commands(2) /property:Platform=%clatform%
mistachkin7aa3ebe2016-02-24 21:42:03 +0000185
mistachkin78007b22016-02-24 23:25:23 +0000186lappend commands(2) [appendArgs \
mistachkin7aa3ebe2016-02-24 21:42:03 +0000187 /logger:FileLogger,Microsoft.Build.Engine\;Logfile= \
188 [file nativename [file join $temporaryDirectory $buildLogFileName]] \
189 \;Verbosity=diagnostic]
190
mistachkin78007b22016-02-24 23:25:23 +0000191set commands(3) [list exec [file nativename $vsixInstaller] /quiet /norepair]
192lappend commands(3) [appendArgs /logFile: $uninstallLogFileName]
193lappend commands(3) [appendArgs /uninstall:SQLite.UWP.2015]
mistachkin7aa3ebe2016-02-24 21:42:03 +0000194
195puts stdout [appendArgs \
196 "Install log will be \"" [file nativename [file join \
197 $temporaryDirectory $installLogFileName]] "\"."]
198
199puts stdout [appendArgs \
200 "Build log will be \"" [file nativename [file join \
201 $temporaryDirectory $buildLogFileName]] "\"."]
202
203puts stdout [appendArgs \
204 "Uninstall log will be \"" [file nativename [file join \
205 $temporaryDirectory $uninstallLogFileName]] "\"."]
206
207puts stdout [appendArgs \
mistachkin78007b22016-02-24 23:25:23 +0000208 "First command is \"" $commands(1) "\"."]
mistachkin7aa3ebe2016-02-24 21:42:03 +0000209
210puts stdout [appendArgs \
mistachkin78007b22016-02-24 23:25:23 +0000211 "Second command is \"" $commands(2) "\"."]
mistachkin7aa3ebe2016-02-24 21:42:03 +0000212
213puts stdout [appendArgs \
mistachkin78007b22016-02-24 23:25:23 +0000214 "Third command is \"" $commands(3) "\"."]
mistachkin7aa3ebe2016-02-24 21:42:03 +0000215
mistachkin78007b22016-02-24 23:25:23 +0000216if {0} then {
217 # eval $commands(1)
218
219 set platforms [list Win32 x64 ARM]
220 set configurations [list Debug Release]
221
222 foreach platform $platforms {
223 foreach configuration $configurations {
224 eval [string map [list \
225 %platform% $platform %configuration% \
226 $configuration] $commands(2)]
227 }
228 }
229
230 # eval $commands(3)
231}