blob: b7c5983dbe270694f6800282b5eefde1c1fb3da1 [file] [log] [blame]
mistachkin48680192012-07-27 02:36:06 +00001#!/usr/bin/tclsh
2#
3# This script is used to generate a VSIX (Visual Studio Extension) file for
4# SQLite usable by Visual Studio.
mistachkin7c5dbdf2012-10-19 00:23:31 +00005#
6# PREREQUISITES
7#
8# 1. Tcl 8.4 and later are supported, earlier versions have not been tested.
9#
10# 2. The "sqlite3.h" file is assumed to exist in the parent directory of the
11# directory containing this script. The [optional] second command line
12# argument to this script may be used to specify an alternate location.
13# This script also assumes that the "sqlite3.h" file corresponds with the
14# version of the binaries to be packaged. This assumption is not verified
15# by this script.
16#
17# 3. The temporary directory specified in the TEMP or TMP environment variables
18# must refer to an existing directory writable by the current user.
19#
20# 4. The "zip" and "unzip" command line tools must be located either in a
21# directory contained in the PATH environment variable or specified as the
22# exact file names to execute in the "ZipTool" and "UnZipTool" environment
23# variables, respectively.
24#
25# 5. The template VSIX file (which is basically a zip file) must be located in
26# a "win" directory inside the directory containing this script. It should
27# not contain any executable binaries. It should only contain dynamic
28# textual content files to be processed using [subst] and/or static content
29# files to be copied verbatim.
30#
31# 6. The executable and other compiled binary files to be packaged into the
32# final VSIX file (e.g. DLLs, LIBs, and PDBs) must be located in a single
33# directory tree. The top-level directory of the tree must be specified as
34# the first command line argument to this script. The second level
35# sub-directory names must match those of the build configuration (e.g.
36# "Debug" or "Retail"). The third level sub-directory names must match
37# those of the platform (e.g. "x86", "x64", and "ARM"). For example, the
38# binary files to be packaged would need to be organized as follows when
39# packaging the "Debug" and "Retail" build configurations for the "x86" and
40# "x64" platforms (in this example, "C:\temp" is the top-level directory as
41# specified in the first command line argument):
42#
43# C:\Temp\Debug\x86\sqlite3.lib
44# C:\Temp\Debug\x86\sqlite3.dll
45# C:\Temp\Debug\x86\sqlite3.pdb
46# C:\Temp\Debug\x64\sqlite3.lib
47# C:\Temp\Debug\x64\sqlite3.dll
48# C:\Temp\Debug\x64\sqlite3.pdb
49# C:\Temp\Retail\x86\sqlite3.lib
50# C:\Temp\Retail\x86\sqlite3.dll
51# C:\Temp\Retail\x86\sqlite3.pdb
52# C:\Temp\Retail\x64\sqlite3.lib
53# C:\Temp\Retail\x64\sqlite3.dll
54# C:\Temp\Retail\x64\sqlite3.pdb
55#
56# The above directory tree organization is performed automatically if the
57# "tool\build-all-msvc.bat" batch script is used to build the binary files
58# to be packaged.
59#
60# USAGE
61#
mistachkin0f801702012-10-20 08:40:05 +000062# The first argument to this script is required and must be the name of the
63# top-level directory containing the directories and files organized into a
64# tree as described in item 6 of the PREREQUISITES section, above. The second
65# argument is optional and if present must contain the name of the directory
66# containing the root of the source tree for SQLite. The third argument is
67# optional and if present must contain the flavor the VSIX package to build.
mistachkin441aa092014-05-06 21:26:34 +000068# Currently, the only supported package flavors are "WinRT", "WinRT81", "WP80",
mistachkinf5742592014-05-06 21:30:25 +000069# "WP81", and "Win32". The fourth argument is optional and if present must be
70# a string containing a list of platforms to include in the VSIX package. The
71# platform list is "platform1,platform2,platform3". The fifth argument is
72# optional and if present must contain the version of Visual Studio required by
73# the package. Currently, the only supported versions are "2012" and "2013".
74# The package flavors "WinRT81" and "WP81" are only supported when the Visual
75# Studio version is "2013". Typically, when on Windows, this script is
76# executed using commands similar to the following from a normal Windows
mistachkin897f6832014-05-06 00:09:46 +000077# command prompt:
mistachkin7c5dbdf2012-10-19 00:23:31 +000078#
79# CD /D C:\dev\sqlite\core
80# tclsh85 tool\mkvsix.tcl C:\Temp
81#
82# In the example above, "C:\dev\sqlite\core" represents the root of the source
83# tree for SQLite and "C:\Temp" represents the top-level directory containing
84# the executable and other compiled binary files, organized into a directory
85# tree as described in item 6 of the PREREQUISITES section, above.
86#
87# This script should work on non-Windows platforms as well, provided that all
88# the requirements listed in the PREREQUISITES section are met.
89#
90# NOTES
91#
92# The temporary directory is used as a staging area for the final VSIX file.
93# The template VSIX file is extracted, its contents processed, and then the
94# resulting files are packaged into the final VSIX file.
95#
96package require Tcl 8.4
97
mistachkin48680192012-07-27 02:36:06 +000098proc fail { {error ""} {usage false} } {
99 if {[string length $error] > 0} then {
100 puts stdout $error
101 if {!$usage} then {exit 1}
102 }
103
104 puts stdout "usage:\
105[file tail [info nameofexecutable]]\
mistachkin0f801702012-10-20 08:40:05 +0000106[file tail [info script]] <binaryDirectory> \[sourceDirectory\]\
mistachkin897f6832014-05-06 00:09:46 +0000107\[packageFlavor\] \[platformNames\] \[vsVersion\]"
mistachkin48680192012-07-27 02:36:06 +0000108
109 exit 1
110}
111
112proc getEnvironmentVariable { name } {
113 #
114 # NOTE: Returns the value of the specified environment variable or an empty
115 # string for environment variables that do not exist in the current
116 # process environment.
117 #
118 return [expr {[info exists ::env($name)] ? $::env($name) : ""}]
119}
120
121proc getTemporaryPath {} {
122 #
123 # NOTE: Returns the normalized path to the first temporary directory found
124 # in the typical set of environment variables used for that purpose
125 # or an empty string to signal a failure to locate such a directory.
126 #
127 set names [list]
128
129 foreach name [list TEMP TMP] {
130 lappend names [string toupper $name] [string tolower $name] \
131 [string totitle $name]
132 }
133
134 foreach name $names {
135 set value [getEnvironmentVariable $name]
136
137 if {[string length $value] > 0} then {
138 return [file normalize $value]
139 }
140 }
141
142 return ""
143}
144
145proc appendArgs { args } {
146 #
147 # NOTE: Returns all passed arguments joined together as a single string with
148 # no intervening spaces between arguments.
149 #
150 eval append result $args
151}
152
153proc readFile { fileName } {
154 #
155 # NOTE: Reads and returns the entire contents of the specified file, which
156 # may contain binary data.
157 #
158 set file_id [open $fileName RDONLY]
159 fconfigure $file_id -encoding binary -translation binary
160 set result [read $file_id]
161 close $file_id
162 return $result
163}
164
165proc writeFile { fileName data } {
166 #
167 # NOTE: Writes the entire contents of the specified file, which may contain
168 # binary data.
169 #
170 set file_id [open $fileName {WRONLY CREAT TRUNC}]
171 fconfigure $file_id -encoding binary -translation binary
172 puts -nonewline $file_id $data
173 close $file_id
174 return ""
175}
176
mistachkinf659cf42015-04-19 23:39:05 +0000177#
178# TODO: Modify this procedure when a new version of Visual Studio is released.
179#
mistachkin897f6832014-05-06 00:09:46 +0000180proc getMinVsVersionXmlChunk { vsVersion } {
181 switch -exact $vsVersion {
182 2012 {
183 return [appendArgs \
184 "\r\n " {MinVSVersion="11.0"}]
185 }
186 2013 {
187 return [appendArgs \
188 "\r\n " {MinVSVersion="12.0"}]
189 }
mistachkinf659cf42015-04-19 23:39:05 +0000190 2015 {
191 return [appendArgs \
192 "\r\n " {MinVSVersion="14.0"}]
193 }
mistachkin897f6832014-05-06 00:09:46 +0000194 default {
195 return ""
196 }
197 }
198}
199
mistachkinf659cf42015-04-19 23:39:05 +0000200#
201# TODO: Modify this procedure when a new version of Visual Studio is released.
202#
mistachkin12736142014-05-10 17:28:45 +0000203proc getMaxPlatformVersionXmlChunk { packageFlavor vsVersion } {
204 #
mistachkinf659cf42015-04-19 23:39:05 +0000205 # NOTE: Only Visual Studio 2013 and later support this attribute within the
206 # SDK manifest.
mistachkin12736142014-05-10 17:28:45 +0000207 #
mistachkinf659cf42015-04-19 23:39:05 +0000208 if {![string equal $vsVersion 2013] && \
209 ![string equal $vsVersion 2015]} then {
mistachkin12736142014-05-10 17:28:45 +0000210 return ""
211 }
212
213 switch -exact $packageFlavor {
214 WinRT {
215 return [appendArgs \
216 "\r\n " {MaxPlatformVersion="8.0"}]
217 }
218 WinRT81 {
219 return [appendArgs \
220 "\r\n " {MaxPlatformVersion="8.1"}]
221 }
222 WP80 {
223 return [appendArgs \
224 "\r\n " {MaxPlatformVersion="8.0"}]
225 }
mistachkin79640732014-05-10 17:33:11 +0000226 WP81 {
227 return [appendArgs \
228 "\r\n " {MaxPlatformVersion="8.1"}]
229 }
mistachkin12736142014-05-10 17:28:45 +0000230 default {
231 return ""
232 }
233 }
234}
235
mistachkinf659cf42015-04-19 23:39:05 +0000236#
237# TODO: Modify this procedure when a new version of Visual Studio is released.
238#
mistachkin897f6832014-05-06 00:09:46 +0000239proc getExtraFileListXmlChunk { packageFlavor vsVersion } {
mistachkin48680192012-07-27 02:36:06 +0000240 #
mistachkin441aa092014-05-06 21:26:34 +0000241 # NOTE: Windows Phone 8.0 does not require any extra attributes in its VSIX
mistachkin79640732014-05-10 17:33:11 +0000242 # package SDK manifests; however, it appears that Windows Phone 8.1
243 # does.
mistachkin48680192012-07-27 02:36:06 +0000244 #
mistachkin441aa092014-05-06 21:26:34 +0000245 if {[string equal $packageFlavor WP80]} then {
mistachkin897f6832014-05-06 00:09:46 +0000246 return ""
247 }
248
249 set appliesTo [expr {[string equal $packageFlavor Win32] ? \
250 "VisualC" : "WindowsAppContainer"}]
251
252 switch -exact $vsVersion {
253 2012 {
254 return [appendArgs \
255 "\r\n " AppliesTo=\" $appliesTo \" \
256 "\r\n " {DependsOn="Microsoft.VCLibs, version=11.0"}]
257 }
258 2013 {
259 return [appendArgs \
260 "\r\n " AppliesTo=\" $appliesTo \" \
261 "\r\n " {DependsOn="Microsoft.VCLibs, version=12.0"}]
262 }
mistachkinf659cf42015-04-19 23:39:05 +0000263 2015 {
mistachkinf659cf42015-04-19 23:39:05 +0000264 return [appendArgs \
265 "\r\n " AppliesTo=\" $appliesTo \" \
mistachkin809edfc2015-07-31 15:14:14 +0000266 "\r\n " {DependsOn="Microsoft.VCLibs, version=14.0"}]
mistachkinf659cf42015-04-19 23:39:05 +0000267 }
mistachkin897f6832014-05-06 00:09:46 +0000268 default {
269 return ""
270 }
271 }
mistachkin48680192012-07-27 02:36:06 +0000272}
273
mistachkin0f801702012-10-20 08:40:05 +0000274proc replaceFileNameTokens { fileName name buildName platformName } {
mistachkin48680192012-07-27 02:36:06 +0000275 #
276 # NOTE: Returns the specified file name containing the platform name instead
277 # of platform placeholder tokens.
278 #
mistachkin0f801702012-10-20 08:40:05 +0000279 return [string map [list <build> $buildName <platform> $platformName \
280 <name> $name] $fileName]
mistachkin48680192012-07-27 02:36:06 +0000281}
282
mistachkin897f6832014-05-06 00:09:46 +0000283proc substFile { fileName } {
284 #
285 # NOTE: Performs all Tcl command, variable, and backslash substitutions in
286 # the specified file and then rewrites the contents of that same file
287 # with the substituted data.
288 #
289 return [writeFile $fileName [uplevel 1 [list subst [readFile $fileName]]]]
290}
291
mistachkin0f801702012-10-20 08:40:05 +0000292#
293# NOTE: This is the entry point for this script.
294#
mistachkin48680192012-07-27 02:36:06 +0000295set script [file normalize [info script]]
296
297if {[string length $script] == 0} then {
298 fail "script file currently being evaluated is unknown" true
299}
300
301set path [file dirname $script]
302set rootName [file rootname [file tail $script]]
303
304###############################################################################
305
306#
307# NOTE: Process and verify all the command line arguments.
308#
309set argc [llength $argv]
mistachkin897f6832014-05-06 00:09:46 +0000310if {$argc < 1 || $argc > 5} then {fail}
mistachkin48680192012-07-27 02:36:06 +0000311
312set binaryDirectory [lindex $argv 0]
313
314if {[string length $binaryDirectory] == 0} then {
315 fail "invalid binary directory"
316}
317
318if {![file exists $binaryDirectory] || \
319 ![file isdirectory $binaryDirectory]} then {
320 fail "binary directory does not exist"
321}
322
mistachkin0f801702012-10-20 08:40:05 +0000323if {$argc >= 2} then {
mistachkin48680192012-07-27 02:36:06 +0000324 set sourceDirectory [lindex $argv 1]
325} else {
326 #
327 # NOTE: Assume that the source directory is the parent directory of the one
328 # that contains this script file.
329 #
330 set sourceDirectory [file dirname $path]
331}
332
333if {[string length $sourceDirectory] == 0} then {
334 fail "invalid source directory"
335}
336
337if {![file exists $sourceDirectory] || \
338 ![file isdirectory $sourceDirectory]} then {
339 fail "source directory does not exist"
340}
341
mistachkin0f801702012-10-20 08:40:05 +0000342if {$argc >= 3} then {
343 set packageFlavor [lindex $argv 2]
344} else {
345 #
346 # NOTE: Assume the package flavor is WinRT.
347 #
348 set packageFlavor WinRT
349}
350
351if {[string length $packageFlavor] == 0} then {
352 fail "invalid package flavor"
353}
354
mistachkin0f801702012-10-20 08:40:05 +0000355if {$argc >= 4} then {
356 set platformNames [list]
357
358 foreach platformName [split [lindex $argv 3] ", "] {
mistachkin897f6832014-05-06 00:09:46 +0000359 set platformName [string trim $platformName]
360
mistachkin0f801702012-10-20 08:40:05 +0000361 if {[string length $platformName] > 0} then {
362 lappend platformNames $platformName
363 }
364 }
365}
366
mistachkin897f6832014-05-06 00:09:46 +0000367if {$argc >= 5} then {
368 set vsVersion [lindex $argv 4]
369} else {
370 set vsVersion 2012
371}
372
373if {[string length $vsVersion] == 0} then {
374 fail "invalid Visual Studio version"
375}
376
mistachkinf659cf42015-04-19 23:39:05 +0000377if {![string equal $vsVersion 2012] && ![string equal $vsVersion 2013] && \
378 ![string equal $vsVersion 2015]} then {
mistachkin897f6832014-05-06 00:09:46 +0000379 fail [appendArgs \
380 "unsupported Visual Studio version, must be one of: " \
mistachkinf659cf42015-04-19 23:39:05 +0000381 [list 2012 2013 2015]]
mistachkin897f6832014-05-06 00:09:46 +0000382}
383
384set shortNames(WinRT,2012) SQLite.WinRT
385set shortNames(WinRT,2013) SQLite.WinRT.2013
386set shortNames(WinRT81,2013) SQLite.WinRT81
387set shortNames(WP80,2012) SQLite.WP80
388set shortNames(WP80,2013) SQLite.WP80.2013
389set shortNames(WP81,2013) SQLite.WP81
390set shortNames(Win32,2012) SQLite.Win32
391set shortNames(Win32,2013) SQLite.Win32.2013
mistachkinf659cf42015-04-19 23:39:05 +0000392set shortNames(UAP,2015) SQLite.UAP.2015
mistachkin897f6832014-05-06 00:09:46 +0000393
394set displayNames(WinRT,2012) "SQLite for Windows Runtime"
395set displayNames(WinRT,2013) "SQLite for Windows Runtime"
396set displayNames(WinRT81,2013) "SQLite for Windows Runtime (Windows 8.1)"
397set displayNames(WP80,2012) "SQLite for Windows Phone"
398set displayNames(WP80,2013) "SQLite for Windows Phone"
399set displayNames(WP81,2013) "SQLite for Windows Phone 8.1"
400set displayNames(Win32,2012) "SQLite for Windows"
401set displayNames(Win32,2013) "SQLite for Windows"
mistachkinf659cf42015-04-19 23:39:05 +0000402set displayNames(UAP,2015) "SQLite for Universal App Platform"
mistachkin897f6832014-05-06 00:09:46 +0000403
404if {[string equal $packageFlavor WinRT]} then {
405 set shortName $shortNames($packageFlavor,$vsVersion)
406 set displayName $displayNames($packageFlavor,$vsVersion)
407 set targetPlatformIdentifier Windows
408 set targetPlatformVersion v8.0
409 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin12736142014-05-10 17:28:45 +0000410 set maxPlatformVersion \
411 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000412 set extraSdkPath ""
413 set extraFileListAttributes \
414 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
415} elseif {[string equal $packageFlavor WinRT81]} then {
416 if {$vsVersion ne "2013"} then {
417 fail [appendArgs \
418 "unsupported combination, package flavor " $packageFlavor \
419 " is only supported with Visual Studio 2013"]
420 }
421 set shortName $shortNames($packageFlavor,$vsVersion)
422 set displayName $displayNames($packageFlavor,$vsVersion)
423 set targetPlatformIdentifier Windows
424 set targetPlatformVersion v8.1
425 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin12736142014-05-10 17:28:45 +0000426 set maxPlatformVersion \
427 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000428 set extraSdkPath ""
429 set extraFileListAttributes \
430 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
431} elseif {[string equal $packageFlavor WP80]} then {
432 set shortName $shortNames($packageFlavor,$vsVersion)
433 set displayName $displayNames($packageFlavor,$vsVersion)
434 set targetPlatformIdentifier "Windows Phone"
435 set targetPlatformVersion v8.0
436 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin12736142014-05-10 17:28:45 +0000437 set maxPlatformVersion \
438 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000439 set extraSdkPath "\\..\\$targetPlatformIdentifier"
440 set extraFileListAttributes \
441 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
442} elseif {[string equal $packageFlavor WP81]} then {
443 if {$vsVersion ne "2013"} then {
444 fail [appendArgs \
445 "unsupported combination, package flavor " $packageFlavor \
446 " is only supported with Visual Studio 2013"]
447 }
448 set shortName $shortNames($packageFlavor,$vsVersion)
449 set displayName $displayNames($packageFlavor,$vsVersion)
450 set targetPlatformIdentifier WindowsPhoneApp
451 set targetPlatformVersion v8.1
452 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin79640732014-05-10 17:33:11 +0000453 set maxPlatformVersion \
454 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000455 set extraSdkPath "\\..\\$targetPlatformIdentifier"
456 set extraFileListAttributes \
457 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
mistachkinf659cf42015-04-19 23:39:05 +0000458} elseif {[string equal $packageFlavor UAP]} then {
459 if {$vsVersion ne "2015"} then {
460 fail [appendArgs \
461 "unsupported combination, package flavor " $packageFlavor \
462 " is only supported with Visual Studio 2015"]
463 }
464 set shortName $shortNames($packageFlavor,$vsVersion)
465 set displayName $displayNames($packageFlavor,$vsVersion)
466 set targetPlatformIdentifier UAP
467 set targetPlatformVersion v0.8.0.0
468 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
469 set maxPlatformVersion \
470 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
471 set extraSdkPath "\\..\\$targetPlatformIdentifier"
472 set extraFileListAttributes \
473 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000474} elseif {[string equal $packageFlavor Win32]} then {
475 set shortName $shortNames($packageFlavor,$vsVersion)
476 set displayName $displayNames($packageFlavor,$vsVersion)
477 set targetPlatformIdentifier Windows
478 set targetPlatformVersion v8.0
479 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin12736142014-05-10 17:28:45 +0000480 set maxPlatformVersion \
481 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000482 set extraSdkPath ""
483 set extraFileListAttributes \
484 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
485} else {
486 fail [appendArgs \
487 "unsupported package flavor, must be one of: " \
mistachkinf659cf42015-04-19 23:39:05 +0000488 [list WinRT WinRT81 WP80 WP81 UAP Win32]]
mistachkin897f6832014-05-06 00:09:46 +0000489}
490
mistachkin48680192012-07-27 02:36:06 +0000491###############################################################################
492
mistachkin391b3642012-07-31 00:43:31 +0000493#
494# NOTE: Evaluate the user-specific customizations file, if it exists.
495#
496set userFile [file join $path [appendArgs \
497 $rootName . $tcl_platform(user) .tcl]]
498
499if {[file exists $userFile] && \
500 [file isfile $userFile]} then {
501 source $userFile
502}
503
504###############################################################################
505
mistachkin48680192012-07-27 02:36:06 +0000506set templateFile [file join $path win sqlite.vsix]
507
508if {![file exists $templateFile] || \
509 ![file isfile $templateFile]} then {
510 fail [appendArgs "template file \"" $templateFile "\" does not exist"]
511}
512
513set currentDirectory [pwd]
mistachkinecf42d52012-10-28 19:35:55 +0000514set outputFile [file join $currentDirectory [appendArgs sqlite- \
515 $packageFlavor -output.vsix]]
mistachkin48680192012-07-27 02:36:06 +0000516
517if {[file exists $outputFile]} then {
518 fail [appendArgs "output file \"" $outputFile "\" already exists"]
519}
520
521###############################################################################
522
523#
524# NOTE: Make sure that a valid temporary directory exists.
525#
526set temporaryDirectory [getTemporaryPath]
527
528if {[string length $temporaryDirectory] == 0 || \
529 ![file exists $temporaryDirectory] || \
530 ![file isdirectory $temporaryDirectory]} then {
531 fail "cannot locate a usable temporary directory"
532}
533
534#
535# NOTE: Setup the staging directory to have a unique name inside of the
536# configured temporary directory.
537#
538set stagingDirectory [file normalize [file join $temporaryDirectory \
539 [appendArgs $rootName . [pid]]]]
540
541###############################################################################
542
543#
544# NOTE: Configure the external zipping tool. First, see if it has already
545# been pre-configured. If not, try to query it from the environment.
546# Finally, fallback on the default of simply "zip", which will then
547# be assumed to exist somewhere along the PATH.
548#
549if {![info exists zip]} then {
550 if {[info exists env(ZipTool)]} then {
551 set zip $env(ZipTool)
552 }
553 if {![info exists zip] || ![file exists $zip]} then {
554 set zip zip
555 }
556}
557
558#
559# NOTE: Configure the external unzipping tool. First, see if it has already
560# been pre-configured. If not, try to query it from the environment.
561# Finally, fallback on the default of simply "unzip", which will then
562# be assumed to exist somewhere along the PATH.
563#
564if {![info exists unzip]} then {
565 if {[info exists env(UnZipTool)]} then {
566 set unzip $env(UnZipTool)
567 }
568 if {![info exists unzip] || ![file exists $unzip]} then {
569 set unzip unzip
570 }
571}
572
573###############################################################################
574
575#
576# NOTE: Attempt to extract the SQLite version from the "sqlite3.h" header file
577# in the source directory. This script assumes that the header file has
578# already been generated by the build process.
579#
mistachkin391b3642012-07-31 00:43:31 +0000580set pattern {^#define\s+SQLITE_VERSION\s+"(.*)"$}
mistachkin48680192012-07-27 02:36:06 +0000581set data [readFile [file join $sourceDirectory sqlite3.h]]
582
583if {![regexp -line -- $pattern $data dummy version]} then {
584 fail [appendArgs "cannot locate SQLITE_VERSION value in \"" \
585 [file join $sourceDirectory sqlite3.h] \"]
586}
587
588###############################################################################
589
590#
mistachkin0f801702012-10-20 08:40:05 +0000591# NOTE: Setup all the master file list data. This includes the source file
592# names, the destination file names, and the file processing flags. The
593# possible file processing flags are:
594#
595# "buildNeutral" -- This flag indicates the file location and content do
596# not depend on the build configuration.
597#
598# "platformNeutral" -- This flag indicates the file location and content
599# do not depend on the build platform.
600#
601# "subst" -- This flag indicates that the file contains dynamic textual
602# content that needs to be processed using [subst] prior to
603# packaging the file into the final VSIX package. The primary
604# use of this flag is to insert the name of the VSIX package,
605# some package flavor-specific value, or the SQLite version
606# into a file.
607#
608# "noDebug" -- This flag indicates that the file should be skipped when
609# processing the debug build.
610#
611# "noRetail" -- This flag indicates that the file should be skipped when
612# processing the retail build.
613#
614# "move" -- This flag indicates that the file should be moved from the
615# source to the destination instead of being copied.
616#
617# This file metadata may be overridden, either in whole or in part, via
618# the user-specific customizations file.
mistachkin48680192012-07-27 02:36:06 +0000619#
mistachkin391b3642012-07-31 00:43:31 +0000620if {![info exists fileNames(source)]} then {
mistachkin0f801702012-10-20 08:40:05 +0000621 set fileNames(source) [list "" "" \
622 [file join $stagingDirectory DesignTime <build> <platform> sqlite3.props] \
623 [file join $sourceDirectory sqlite3.h] \
624 [file join $binaryDirectory <build> <platform> sqlite3.lib] \
625 [file join $binaryDirectory <build> <platform> sqlite3.dll]]
mistachkin48680192012-07-27 02:36:06 +0000626
mistachkin391b3642012-07-31 00:43:31 +0000627 if {![info exists no(symbols)]} then {
628 lappend fileNames(source) \
mistachkin0ec07442012-10-12 18:06:07 +0000629 [file join $binaryDirectory <build> <platform> sqlite3.pdb]
mistachkin391b3642012-07-31 00:43:31 +0000630 }
631}
mistachkin48680192012-07-27 02:36:06 +0000632
mistachkin391b3642012-07-31 00:43:31 +0000633if {![info exists fileNames(destination)]} then {
634 set fileNames(destination) [list \
mistachkin0f801702012-10-20 08:40:05 +0000635 [file join $stagingDirectory extension.vsixmanifest] \
636 [file join $stagingDirectory SDKManifest.xml] \
637 [file join $stagingDirectory DesignTime <build> <platform> <name>.props] \
638 [file join $stagingDirectory DesignTime <build> <platform> sqlite3.h] \
639 [file join $stagingDirectory DesignTime <build> <platform> sqlite3.lib] \
640 [file join $stagingDirectory Redist <build> <platform> sqlite3.dll]]
mistachkin391b3642012-07-31 00:43:31 +0000641
642 if {![info exists no(symbols)]} then {
643 lappend fileNames(destination) \
mistachkin0ec07442012-10-12 18:06:07 +0000644 [file join $stagingDirectory Redist <build> <platform> sqlite3.pdb]
mistachkin391b3642012-07-31 00:43:31 +0000645 }
646}
647
mistachkin0f801702012-10-20 08:40:05 +0000648if {![info exists fileNames(flags)]} then {
649 set fileNames(flags) [list \
650 [list buildNeutral platformNeutral subst] \
651 [list buildNeutral platformNeutral subst] \
652 [list buildNeutral platformNeutral subst move] \
653 [list buildNeutral platformNeutral] \
654 [list] [list] [list noRetail]]
mistachkin391b3642012-07-31 00:43:31 +0000655
656 if {![info exists no(symbols)]} then {
mistachkin0f801702012-10-20 08:40:05 +0000657 lappend fileNames(flags) [list noRetail]
mistachkin0ec07442012-10-12 18:06:07 +0000658 }
659}
660
661###############################################################################
662
663#
mistachkin0f801702012-10-20 08:40:05 +0000664# NOTE: Setup the list of builds supported by this script. These may be
665# overridden via the user-specific customizations file.
mistachkin0ec07442012-10-12 18:06:07 +0000666#
667if {![info exists buildNames]} then {
668 set buildNames [list Debug Retail]
669}
670
mistachkin48680192012-07-27 02:36:06 +0000671###############################################################################
672
673#
mistachkin0f801702012-10-20 08:40:05 +0000674# NOTE: Setup the list of platforms supported by this script. These may be
675# overridden via the command line or the user-specific customizations
676# file.
mistachkin48680192012-07-27 02:36:06 +0000677#
mistachkin897f6832014-05-06 00:09:46 +0000678if {![info exists platformNames] || [llength $platformNames] == 0} then {
mistachkin50afa2a2012-07-31 08:15:56 +0000679 set platformNames [list x86 x64 ARM]
mistachkin391b3642012-07-31 00:43:31 +0000680}
mistachkin48680192012-07-27 02:36:06 +0000681
682###############################################################################
683
684#
685# NOTE: Make sure the staging directory exists, creating it if necessary.
686#
687file mkdir $stagingDirectory
688
689#
mistachkin0f801702012-10-20 08:40:05 +0000690# NOTE: Build the Tcl command used to extract the template VSIX package to
691# the staging directory.
mistachkin48680192012-07-27 02:36:06 +0000692#
693set extractCommand [list exec -- $unzip $templateFile -d $stagingDirectory]
694
695#
mistachkin0f801702012-10-20 08:40:05 +0000696# NOTE: Extract the template VSIX package to the staging directory.
mistachkin48680192012-07-27 02:36:06 +0000697#
698eval $extractCommand
699
700###############################################################################
701
702#
mistachkin0f801702012-10-20 08:40:05 +0000703# NOTE: Process each file in the master file list. There are actually three
mistachkin21890122012-10-15 20:28:22 +0000704# parallel lists that contain the source file names, the destination file
mistachkin0f801702012-10-20 08:40:05 +0000705# names, and the file processing flags. If the "buildNeutral" flag is
706# present, the file location and content do not depend on the build
707# configuration and "CommonConfiguration" will be used in place of the
708# build configuration name. If the "platformNeutral" flag is present,
709# the file location and content do not depend on the build platform and
710# "neutral" will be used in place of the build platform name. If the
711# "subst" flag is present, the file is assumed to be a text file that may
712# contain Tcl variable, command, and backslash replacements, to be
713# dynamically replaced during processing using the Tcl [subst] command.
714# If the "noDebug" flag is present, the file will be skipped when
715# processing for the debug build. If the "noRetail" flag is present, the
716# file will be skipped when processing for the retail build. If the
717# "move" flag is present, the source file will be deleted after it is
718# copied to the destination file. If the source file name is an empty
719# string, the destination file name will be assumed to already exist in
720# the staging directory and will not be copied; however, Tcl variable,
721# command, and backslash replacements may still be performed on the
722# destination file prior to the final VSIX package being built if the
723# "subst" flag is present.
mistachkin48680192012-07-27 02:36:06 +0000724#
mistachkin21890122012-10-15 20:28:22 +0000725foreach sourceFileName $fileNames(source) \
726 destinationFileName $fileNames(destination) \
mistachkin0f801702012-10-20 08:40:05 +0000727 fileFlags $fileNames(flags) {
728 #
729 # NOTE: Process the file flags into separate boolean variables that may be
730 # used within the loop.
731 #
732 set isBuildNeutral [expr {[lsearch $fileFlags buildNeutral] != -1}]
733 set isPlatformNeutral [expr {[lsearch $fileFlags platformNeutral] != -1}]
734 set isMove [expr {[lsearch $fileFlags move] != -1}]
735 set useSubst [expr {[lsearch $fileFlags subst] != -1}]
736
mistachkin48680192012-07-27 02:36:06 +0000737 #
mistachkin0ec07442012-10-12 18:06:07 +0000738 # NOTE: If the current file is build-neutral, then only one build will
739 # be processed for it, namely "CommonConfiguration"; otherwise, each
740 # supported build will be processed for it individually.
mistachkin48680192012-07-27 02:36:06 +0000741 #
mistachkin0ec07442012-10-12 18:06:07 +0000742 foreach buildName \
mistachkin0f801702012-10-20 08:40:05 +0000743 [expr {$isBuildNeutral ? [list CommonConfiguration] : $buildNames}] {
mistachkin48680192012-07-27 02:36:06 +0000744 #
mistachkin0ec07442012-10-12 18:06:07 +0000745 # NOTE: Should the current file be skipped for this build?
mistachkin391b3642012-07-31 00:43:31 +0000746 #
mistachkin0f801702012-10-20 08:40:05 +0000747 if {[lsearch $fileFlags no${buildName}] != -1} then {
mistachkin0ec07442012-10-12 18:06:07 +0000748 continue
mistachkin48680192012-07-27 02:36:06 +0000749 }
750
751 #
mistachkin0ec07442012-10-12 18:06:07 +0000752 # NOTE: If the current file is platform-neutral, then only one platform
753 # will be processed for it, namely "neutral"; otherwise, each
754 # supported platform will be processed for it individually.
mistachkin48680192012-07-27 02:36:06 +0000755 #
mistachkin0ec07442012-10-12 18:06:07 +0000756 foreach platformName \
mistachkin0f801702012-10-20 08:40:05 +0000757 [expr {$isPlatformNeutral ? [list neutral] : $platformNames}] {
mistachkin48680192012-07-27 02:36:06 +0000758 #
mistachkin0ec07442012-10-12 18:06:07 +0000759 # NOTE: Use the actual platform name in the destination file name.
mistachkin48680192012-07-27 02:36:06 +0000760 #
mistachkin0f801702012-10-20 08:40:05 +0000761 set newDestinationFileName [replaceFileNameTokens $destinationFileName \
762 $shortName $buildName $platformName]
mistachkin0ec07442012-10-12 18:06:07 +0000763
764 #
765 # NOTE: Does the source file need to be copied to the destination file?
766 #
767 if {[string length $sourceFileName] > 0} then {
768 #
769 # NOTE: First, make sure the destination directory exists.
770 #
771 file mkdir [file dirname $newDestinationFileName]
772
773 #
774 # NOTE: Then, copy the source file to the destination file verbatim.
775 #
mistachkin0f801702012-10-20 08:40:05 +0000776 set newSourceFileName [replaceFileNameTokens $sourceFileName \
777 $shortName $buildName $platformName]
778
779 file copy $newSourceFileName $newDestinationFileName
780
781 #
782 # NOTE: If this is a move instead of a copy, delete the source file
783 # now.
784 #
785 if {$isMove} then {
786 file delete $newSourceFileName
787 }
mistachkin0ec07442012-10-12 18:06:07 +0000788 }
789
790 #
791 # NOTE: Does the destination file contain dynamic replacements that must
792 # be processed now?
793 #
794 if {$useSubst} then {
795 #
796 # NOTE: Perform any dynamic replacements contained in the destination
797 # file and then re-write it in-place.
798 #
799 substFile $newDestinationFileName
800 }
mistachkin48680192012-07-27 02:36:06 +0000801 }
802 }
803}
804
805###############################################################################
806
807#
808# NOTE: Change the current directory to the staging directory so that the
809# external archive building tool can pickup the necessary files using
810# relative paths.
811#
812cd $stagingDirectory
813
814#
mistachkin0f801702012-10-20 08:40:05 +0000815# NOTE: Build the Tcl command used to archive the final VSIX package in the
mistachkin48680192012-07-27 02:36:06 +0000816# output directory.
817#
818set archiveCommand [list exec -- $zip -r $outputFile *]
819
820#
mistachkin0f801702012-10-20 08:40:05 +0000821# NOTE: Build the final VSIX package archive in the output directory.
mistachkin48680192012-07-27 02:36:06 +0000822#
823eval $archiveCommand
824
825#
826# NOTE: Change back to the previously saved current directory.
827#
828cd $currentDirectory
829
830#
831# NOTE: Cleanup the temporary staging directory.
832#
833file delete -force $stagingDirectory
834
835###############################################################################
836
837#
838# NOTE: Success, emit the fully qualified path of the generated VSIX file.
839#
840puts stdout $outputFile