blob: 3c0a8dbf56333e0f01ec113aadbc6e2b46d776ed [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 \
170 [file rootname [file tail $fileName]] -build- [pid] .log]
171
172set uninstallLogFileName [appendArgs \
173 [file rootname [file tail $fileName]] -uninstall- [pid] .log]
174
175set command(1) [list exec [file nativename $vsixInstaller] /quiet /norepair]
176lappend command(1) [appendArgs /logFile: $installLogFileName]
177lappend command(1) [file nativename $fileName]
178
179set command(2) [list exec [file nativename $msBuild]]
180lappend command(2) [file nativename [file join $path vsixtest.sln]]
181lappend command(2) /target:Rebuild /property:Configuration=Release
182
183lappend command(2) [appendArgs \
184 /logger:FileLogger,Microsoft.Build.Engine\;Logfile= \
185 [file nativename [file join $temporaryDirectory $buildLogFileName]] \
186 \;Verbosity=diagnostic]
187
188set command(3) [list exec [file nativename $vsixInstaller] /quiet /norepair]
189lappend command(3) [appendArgs /logFile: $uninstallLogFileName]
190lappend command(3) [appendArgs /uninstall:SQLite.UWP.2015]
191
192puts stdout [appendArgs \
193 "Install log will be \"" [file nativename [file join \
194 $temporaryDirectory $installLogFileName]] "\"."]
195
196puts stdout [appendArgs \
197 "Build log will be \"" [file nativename [file join \
198 $temporaryDirectory $buildLogFileName]] "\"."]
199
200puts stdout [appendArgs \
201 "Uninstall log will be \"" [file nativename [file join \
202 $temporaryDirectory $uninstallLogFileName]] "\"."]
203
204puts stdout [appendArgs \
205 "First command is \"" $command(1) "\"."]
206
207puts stdout [appendArgs \
208 "Second command is \"" $command(2) "\"."]
209
210puts stdout [appendArgs \
211 "Third command is \"" $command(3) "\"."]
212
213# eval exec $command(1)
214# eval exec $command(2)
215# eval exec $command(3)