blob: 208ce2b14211e1df899e292f9150be470fa38632 [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
mistachkin897f6832014-05-06 00:09:46 +0000177proc getMinVsVersionXmlChunk { vsVersion } {
178 switch -exact $vsVersion {
179 2012 {
180 return [appendArgs \
181 "\r\n " {MinVSVersion="11.0"}]
182 }
183 2013 {
184 return [appendArgs \
185 "\r\n " {MinVSVersion="12.0"}]
186 }
187 default {
188 return ""
189 }
190 }
191}
192
mistachkin12736142014-05-10 17:28:45 +0000193proc getMaxPlatformVersionXmlChunk { packageFlavor vsVersion } {
194 #
195 # NOTE: Only Visual Studio 2013 supports this SDK manifest attribute.
196 #
197 if {![string equal $vsVersion 2013]} then {
198 return ""
199 }
200
201 switch -exact $packageFlavor {
202 WinRT {
203 return [appendArgs \
204 "\r\n " {MaxPlatformVersion="8.0"}]
205 }
206 WinRT81 {
207 return [appendArgs \
208 "\r\n " {MaxPlatformVersion="8.1"}]
209 }
210 WP80 {
211 return [appendArgs \
212 "\r\n " {MaxPlatformVersion="8.0"}]
213 }
mistachkin79640732014-05-10 17:33:11 +0000214 WP81 {
215 return [appendArgs \
216 "\r\n " {MaxPlatformVersion="8.1"}]
217 }
mistachkin12736142014-05-10 17:28:45 +0000218 default {
219 return ""
220 }
221 }
222}
223
mistachkin897f6832014-05-06 00:09:46 +0000224proc getExtraFileListXmlChunk { packageFlavor vsVersion } {
mistachkin48680192012-07-27 02:36:06 +0000225 #
mistachkin441aa092014-05-06 21:26:34 +0000226 # NOTE: Windows Phone 8.0 does not require any extra attributes in its VSIX
mistachkin79640732014-05-10 17:33:11 +0000227 # package SDK manifests; however, it appears that Windows Phone 8.1
228 # does.
mistachkin48680192012-07-27 02:36:06 +0000229 #
mistachkin441aa092014-05-06 21:26:34 +0000230 if {[string equal $packageFlavor WP80]} then {
mistachkin897f6832014-05-06 00:09:46 +0000231 return ""
232 }
233
234 set appliesTo [expr {[string equal $packageFlavor Win32] ? \
235 "VisualC" : "WindowsAppContainer"}]
236
237 switch -exact $vsVersion {
238 2012 {
239 return [appendArgs \
240 "\r\n " AppliesTo=\" $appliesTo \" \
241 "\r\n " {DependsOn="Microsoft.VCLibs, version=11.0"}]
242 }
243 2013 {
244 return [appendArgs \
245 "\r\n " AppliesTo=\" $appliesTo \" \
246 "\r\n " {DependsOn="Microsoft.VCLibs, version=12.0"}]
247 }
248 default {
249 return ""
250 }
251 }
mistachkin48680192012-07-27 02:36:06 +0000252}
253
mistachkin0f801702012-10-20 08:40:05 +0000254proc replaceFileNameTokens { fileName name buildName platformName } {
mistachkin48680192012-07-27 02:36:06 +0000255 #
256 # NOTE: Returns the specified file name containing the platform name instead
257 # of platform placeholder tokens.
258 #
mistachkin0f801702012-10-20 08:40:05 +0000259 return [string map [list <build> $buildName <platform> $platformName \
260 <name> $name] $fileName]
mistachkin48680192012-07-27 02:36:06 +0000261}
262
mistachkin897f6832014-05-06 00:09:46 +0000263proc substFile { fileName } {
264 #
265 # NOTE: Performs all Tcl command, variable, and backslash substitutions in
266 # the specified file and then rewrites the contents of that same file
267 # with the substituted data.
268 #
269 return [writeFile $fileName [uplevel 1 [list subst [readFile $fileName]]]]
270}
271
mistachkin0f801702012-10-20 08:40:05 +0000272#
273# NOTE: This is the entry point for this script.
274#
mistachkin48680192012-07-27 02:36:06 +0000275set script [file normalize [info script]]
276
277if {[string length $script] == 0} then {
278 fail "script file currently being evaluated is unknown" true
279}
280
281set path [file dirname $script]
282set rootName [file rootname [file tail $script]]
283
284###############################################################################
285
286#
287# NOTE: Process and verify all the command line arguments.
288#
289set argc [llength $argv]
mistachkin897f6832014-05-06 00:09:46 +0000290if {$argc < 1 || $argc > 5} then {fail}
mistachkin48680192012-07-27 02:36:06 +0000291
292set binaryDirectory [lindex $argv 0]
293
294if {[string length $binaryDirectory] == 0} then {
295 fail "invalid binary directory"
296}
297
298if {![file exists $binaryDirectory] || \
299 ![file isdirectory $binaryDirectory]} then {
300 fail "binary directory does not exist"
301}
302
mistachkin0f801702012-10-20 08:40:05 +0000303if {$argc >= 2} then {
mistachkin48680192012-07-27 02:36:06 +0000304 set sourceDirectory [lindex $argv 1]
305} else {
306 #
307 # NOTE: Assume that the source directory is the parent directory of the one
308 # that contains this script file.
309 #
310 set sourceDirectory [file dirname $path]
311}
312
313if {[string length $sourceDirectory] == 0} then {
314 fail "invalid source directory"
315}
316
317if {![file exists $sourceDirectory] || \
318 ![file isdirectory $sourceDirectory]} then {
319 fail "source directory does not exist"
320}
321
mistachkin0f801702012-10-20 08:40:05 +0000322if {$argc >= 3} then {
323 set packageFlavor [lindex $argv 2]
324} else {
325 #
326 # NOTE: Assume the package flavor is WinRT.
327 #
328 set packageFlavor WinRT
329}
330
331if {[string length $packageFlavor] == 0} then {
332 fail "invalid package flavor"
333}
334
mistachkin0f801702012-10-20 08:40:05 +0000335if {$argc >= 4} then {
336 set platformNames [list]
337
338 foreach platformName [split [lindex $argv 3] ", "] {
mistachkin897f6832014-05-06 00:09:46 +0000339 set platformName [string trim $platformName]
340
mistachkin0f801702012-10-20 08:40:05 +0000341 if {[string length $platformName] > 0} then {
342 lappend platformNames $platformName
343 }
344 }
345}
346
mistachkin897f6832014-05-06 00:09:46 +0000347if {$argc >= 5} then {
348 set vsVersion [lindex $argv 4]
349} else {
350 set vsVersion 2012
351}
352
353if {[string length $vsVersion] == 0} then {
354 fail "invalid Visual Studio version"
355}
356
mistachkin12736142014-05-10 17:28:45 +0000357if {![string equal $vsVersion 2012] && ![string equal $vsVersion 2013]} then {
mistachkin897f6832014-05-06 00:09:46 +0000358 fail [appendArgs \
359 "unsupported Visual Studio version, must be one of: " \
360 [list 2012 2013]]
361}
362
363set shortNames(WinRT,2012) SQLite.WinRT
364set shortNames(WinRT,2013) SQLite.WinRT.2013
365set shortNames(WinRT81,2013) SQLite.WinRT81
366set shortNames(WP80,2012) SQLite.WP80
367set shortNames(WP80,2013) SQLite.WP80.2013
368set shortNames(WP81,2013) SQLite.WP81
369set shortNames(Win32,2012) SQLite.Win32
370set shortNames(Win32,2013) SQLite.Win32.2013
371
372set displayNames(WinRT,2012) "SQLite for Windows Runtime"
373set displayNames(WinRT,2013) "SQLite for Windows Runtime"
374set displayNames(WinRT81,2013) "SQLite for Windows Runtime (Windows 8.1)"
375set displayNames(WP80,2012) "SQLite for Windows Phone"
376set displayNames(WP80,2013) "SQLite for Windows Phone"
377set displayNames(WP81,2013) "SQLite for Windows Phone 8.1"
378set displayNames(Win32,2012) "SQLite for Windows"
379set displayNames(Win32,2013) "SQLite for Windows"
380
381if {[string equal $packageFlavor WinRT]} then {
382 set shortName $shortNames($packageFlavor,$vsVersion)
383 set displayName $displayNames($packageFlavor,$vsVersion)
384 set targetPlatformIdentifier Windows
385 set targetPlatformVersion v8.0
386 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin12736142014-05-10 17:28:45 +0000387 set maxPlatformVersion \
388 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000389 set extraSdkPath ""
390 set extraFileListAttributes \
391 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
392} elseif {[string equal $packageFlavor WinRT81]} then {
393 if {$vsVersion ne "2013"} then {
394 fail [appendArgs \
395 "unsupported combination, package flavor " $packageFlavor \
396 " is only supported with Visual Studio 2013"]
397 }
398 set shortName $shortNames($packageFlavor,$vsVersion)
399 set displayName $displayNames($packageFlavor,$vsVersion)
400 set targetPlatformIdentifier Windows
401 set targetPlatformVersion v8.1
402 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin12736142014-05-10 17:28:45 +0000403 set maxPlatformVersion \
404 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000405 set extraSdkPath ""
406 set extraFileListAttributes \
407 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
408} elseif {[string equal $packageFlavor WP80]} then {
409 set shortName $shortNames($packageFlavor,$vsVersion)
410 set displayName $displayNames($packageFlavor,$vsVersion)
411 set targetPlatformIdentifier "Windows Phone"
412 set targetPlatformVersion v8.0
413 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin12736142014-05-10 17:28:45 +0000414 set maxPlatformVersion \
415 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000416 set extraSdkPath "\\..\\$targetPlatformIdentifier"
417 set extraFileListAttributes \
418 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
419} elseif {[string equal $packageFlavor WP81]} then {
420 if {$vsVersion ne "2013"} then {
421 fail [appendArgs \
422 "unsupported combination, package flavor " $packageFlavor \
423 " is only supported with Visual Studio 2013"]
424 }
425 set shortName $shortNames($packageFlavor,$vsVersion)
426 set displayName $displayNames($packageFlavor,$vsVersion)
427 set targetPlatformIdentifier WindowsPhoneApp
428 set targetPlatformVersion v8.1
429 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin79640732014-05-10 17:33:11 +0000430 set maxPlatformVersion \
431 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000432 set extraSdkPath "\\..\\$targetPlatformIdentifier"
433 set extraFileListAttributes \
434 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
435} elseif {[string equal $packageFlavor Win32]} then {
436 set shortName $shortNames($packageFlavor,$vsVersion)
437 set displayName $displayNames($packageFlavor,$vsVersion)
438 set targetPlatformIdentifier Windows
439 set targetPlatformVersion v8.0
440 set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
mistachkin12736142014-05-10 17:28:45 +0000441 set maxPlatformVersion \
442 [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
mistachkin897f6832014-05-06 00:09:46 +0000443 set extraSdkPath ""
444 set extraFileListAttributes \
445 [getExtraFileListXmlChunk $packageFlavor $vsVersion]
446} else {
447 fail [appendArgs \
448 "unsupported package flavor, must be one of: " \
449 [list WinRT WinRT81 WP80 WP81 Win32]]
450}
451
mistachkin48680192012-07-27 02:36:06 +0000452###############################################################################
453
mistachkin391b3642012-07-31 00:43:31 +0000454#
455# NOTE: Evaluate the user-specific customizations file, if it exists.
456#
457set userFile [file join $path [appendArgs \
458 $rootName . $tcl_platform(user) .tcl]]
459
460if {[file exists $userFile] && \
461 [file isfile $userFile]} then {
462 source $userFile
463}
464
465###############################################################################
466
mistachkin48680192012-07-27 02:36:06 +0000467set templateFile [file join $path win sqlite.vsix]
468
469if {![file exists $templateFile] || \
470 ![file isfile $templateFile]} then {
471 fail [appendArgs "template file \"" $templateFile "\" does not exist"]
472}
473
474set currentDirectory [pwd]
mistachkinecf42d52012-10-28 19:35:55 +0000475set outputFile [file join $currentDirectory [appendArgs sqlite- \
476 $packageFlavor -output.vsix]]
mistachkin48680192012-07-27 02:36:06 +0000477
478if {[file exists $outputFile]} then {
479 fail [appendArgs "output file \"" $outputFile "\" already exists"]
480}
481
482###############################################################################
483
484#
485# NOTE: Make sure that a valid temporary directory exists.
486#
487set temporaryDirectory [getTemporaryPath]
488
489if {[string length $temporaryDirectory] == 0 || \
490 ![file exists $temporaryDirectory] || \
491 ![file isdirectory $temporaryDirectory]} then {
492 fail "cannot locate a usable temporary directory"
493}
494
495#
496# NOTE: Setup the staging directory to have a unique name inside of the
497# configured temporary directory.
498#
499set stagingDirectory [file normalize [file join $temporaryDirectory \
500 [appendArgs $rootName . [pid]]]]
501
502###############################################################################
503
504#
505# NOTE: Configure the external zipping tool. First, see if it has already
506# been pre-configured. If not, try to query it from the environment.
507# Finally, fallback on the default of simply "zip", which will then
508# be assumed to exist somewhere along the PATH.
509#
510if {![info exists zip]} then {
511 if {[info exists env(ZipTool)]} then {
512 set zip $env(ZipTool)
513 }
514 if {![info exists zip] || ![file exists $zip]} then {
515 set zip zip
516 }
517}
518
519#
520# NOTE: Configure the external unzipping tool. First, see if it has already
521# been pre-configured. If not, try to query it from the environment.
522# Finally, fallback on the default of simply "unzip", which will then
523# be assumed to exist somewhere along the PATH.
524#
525if {![info exists unzip]} then {
526 if {[info exists env(UnZipTool)]} then {
527 set unzip $env(UnZipTool)
528 }
529 if {![info exists unzip] || ![file exists $unzip]} then {
530 set unzip unzip
531 }
532}
533
534###############################################################################
535
536#
537# NOTE: Attempt to extract the SQLite version from the "sqlite3.h" header file
538# in the source directory. This script assumes that the header file has
539# already been generated by the build process.
540#
mistachkin391b3642012-07-31 00:43:31 +0000541set pattern {^#define\s+SQLITE_VERSION\s+"(.*)"$}
mistachkin48680192012-07-27 02:36:06 +0000542set data [readFile [file join $sourceDirectory sqlite3.h]]
543
544if {![regexp -line -- $pattern $data dummy version]} then {
545 fail [appendArgs "cannot locate SQLITE_VERSION value in \"" \
546 [file join $sourceDirectory sqlite3.h] \"]
547}
548
549###############################################################################
550
551#
mistachkin0f801702012-10-20 08:40:05 +0000552# NOTE: Setup all the master file list data. This includes the source file
553# names, the destination file names, and the file processing flags. The
554# possible file processing flags are:
555#
556# "buildNeutral" -- This flag indicates the file location and content do
557# not depend on the build configuration.
558#
559# "platformNeutral" -- This flag indicates the file location and content
560# do not depend on the build platform.
561#
562# "subst" -- This flag indicates that the file contains dynamic textual
563# content that needs to be processed using [subst] prior to
564# packaging the file into the final VSIX package. The primary
565# use of this flag is to insert the name of the VSIX package,
566# some package flavor-specific value, or the SQLite version
567# into a file.
568#
569# "noDebug" -- This flag indicates that the file should be skipped when
570# processing the debug build.
571#
572# "noRetail" -- This flag indicates that the file should be skipped when
573# processing the retail build.
574#
575# "move" -- This flag indicates that the file should be moved from the
576# source to the destination instead of being copied.
577#
578# This file metadata may be overridden, either in whole or in part, via
579# the user-specific customizations file.
mistachkin48680192012-07-27 02:36:06 +0000580#
mistachkin391b3642012-07-31 00:43:31 +0000581if {![info exists fileNames(source)]} then {
mistachkin0f801702012-10-20 08:40:05 +0000582 set fileNames(source) [list "" "" \
583 [file join $stagingDirectory DesignTime <build> <platform> sqlite3.props] \
584 [file join $sourceDirectory sqlite3.h] \
585 [file join $binaryDirectory <build> <platform> sqlite3.lib] \
586 [file join $binaryDirectory <build> <platform> sqlite3.dll]]
mistachkin48680192012-07-27 02:36:06 +0000587
mistachkin391b3642012-07-31 00:43:31 +0000588 if {![info exists no(symbols)]} then {
589 lappend fileNames(source) \
mistachkin0ec07442012-10-12 18:06:07 +0000590 [file join $binaryDirectory <build> <platform> sqlite3.pdb]
mistachkin391b3642012-07-31 00:43:31 +0000591 }
592}
mistachkin48680192012-07-27 02:36:06 +0000593
mistachkin391b3642012-07-31 00:43:31 +0000594if {![info exists fileNames(destination)]} then {
595 set fileNames(destination) [list \
mistachkin0f801702012-10-20 08:40:05 +0000596 [file join $stagingDirectory extension.vsixmanifest] \
597 [file join $stagingDirectory SDKManifest.xml] \
598 [file join $stagingDirectory DesignTime <build> <platform> <name>.props] \
599 [file join $stagingDirectory DesignTime <build> <platform> sqlite3.h] \
600 [file join $stagingDirectory DesignTime <build> <platform> sqlite3.lib] \
601 [file join $stagingDirectory Redist <build> <platform> sqlite3.dll]]
mistachkin391b3642012-07-31 00:43:31 +0000602
603 if {![info exists no(symbols)]} then {
604 lappend fileNames(destination) \
mistachkin0ec07442012-10-12 18:06:07 +0000605 [file join $stagingDirectory Redist <build> <platform> sqlite3.pdb]
mistachkin391b3642012-07-31 00:43:31 +0000606 }
607}
608
mistachkin0f801702012-10-20 08:40:05 +0000609if {![info exists fileNames(flags)]} then {
610 set fileNames(flags) [list \
611 [list buildNeutral platformNeutral subst] \
612 [list buildNeutral platformNeutral subst] \
613 [list buildNeutral platformNeutral subst move] \
614 [list buildNeutral platformNeutral] \
615 [list] [list] [list noRetail]]
mistachkin391b3642012-07-31 00:43:31 +0000616
617 if {![info exists no(symbols)]} then {
mistachkin0f801702012-10-20 08:40:05 +0000618 lappend fileNames(flags) [list noRetail]
mistachkin0ec07442012-10-12 18:06:07 +0000619 }
620}
621
622###############################################################################
623
624#
mistachkin0f801702012-10-20 08:40:05 +0000625# NOTE: Setup the list of builds supported by this script. These may be
626# overridden via the user-specific customizations file.
mistachkin0ec07442012-10-12 18:06:07 +0000627#
628if {![info exists buildNames]} then {
629 set buildNames [list Debug Retail]
630}
631
mistachkin48680192012-07-27 02:36:06 +0000632###############################################################################
633
634#
mistachkin0f801702012-10-20 08:40:05 +0000635# NOTE: Setup the list of platforms supported by this script. These may be
636# overridden via the command line or the user-specific customizations
637# file.
mistachkin48680192012-07-27 02:36:06 +0000638#
mistachkin897f6832014-05-06 00:09:46 +0000639if {![info exists platformNames] || [llength $platformNames] == 0} then {
mistachkin50afa2a2012-07-31 08:15:56 +0000640 set platformNames [list x86 x64 ARM]
mistachkin391b3642012-07-31 00:43:31 +0000641}
mistachkin48680192012-07-27 02:36:06 +0000642
643###############################################################################
644
645#
646# NOTE: Make sure the staging directory exists, creating it if necessary.
647#
648file mkdir $stagingDirectory
649
650#
mistachkin0f801702012-10-20 08:40:05 +0000651# NOTE: Build the Tcl command used to extract the template VSIX package to
652# the staging directory.
mistachkin48680192012-07-27 02:36:06 +0000653#
654set extractCommand [list exec -- $unzip $templateFile -d $stagingDirectory]
655
656#
mistachkin0f801702012-10-20 08:40:05 +0000657# NOTE: Extract the template VSIX package to the staging directory.
mistachkin48680192012-07-27 02:36:06 +0000658#
659eval $extractCommand
660
661###############################################################################
662
663#
mistachkin0f801702012-10-20 08:40:05 +0000664# NOTE: Process each file in the master file list. There are actually three
mistachkin21890122012-10-15 20:28:22 +0000665# parallel lists that contain the source file names, the destination file
mistachkin0f801702012-10-20 08:40:05 +0000666# names, and the file processing flags. If the "buildNeutral" flag is
667# present, the file location and content do not depend on the build
668# configuration and "CommonConfiguration" will be used in place of the
669# build configuration name. If the "platformNeutral" flag is present,
670# the file location and content do not depend on the build platform and
671# "neutral" will be used in place of the build platform name. If the
672# "subst" flag is present, the file is assumed to be a text file that may
673# contain Tcl variable, command, and backslash replacements, to be
674# dynamically replaced during processing using the Tcl [subst] command.
675# If the "noDebug" flag is present, the file will be skipped when
676# processing for the debug build. If the "noRetail" flag is present, the
677# file will be skipped when processing for the retail build. If the
678# "move" flag is present, the source file will be deleted after it is
679# copied to the destination file. If the source file name is an empty
680# string, the destination file name will be assumed to already exist in
681# the staging directory and will not be copied; however, Tcl variable,
682# command, and backslash replacements may still be performed on the
683# destination file prior to the final VSIX package being built if the
684# "subst" flag is present.
mistachkin48680192012-07-27 02:36:06 +0000685#
mistachkin21890122012-10-15 20:28:22 +0000686foreach sourceFileName $fileNames(source) \
687 destinationFileName $fileNames(destination) \
mistachkin0f801702012-10-20 08:40:05 +0000688 fileFlags $fileNames(flags) {
689 #
690 # NOTE: Process the file flags into separate boolean variables that may be
691 # used within the loop.
692 #
693 set isBuildNeutral [expr {[lsearch $fileFlags buildNeutral] != -1}]
694 set isPlatformNeutral [expr {[lsearch $fileFlags platformNeutral] != -1}]
695 set isMove [expr {[lsearch $fileFlags move] != -1}]
696 set useSubst [expr {[lsearch $fileFlags subst] != -1}]
697
mistachkin48680192012-07-27 02:36:06 +0000698 #
mistachkin0ec07442012-10-12 18:06:07 +0000699 # NOTE: If the current file is build-neutral, then only one build will
700 # be processed for it, namely "CommonConfiguration"; otherwise, each
701 # supported build will be processed for it individually.
mistachkin48680192012-07-27 02:36:06 +0000702 #
mistachkin0ec07442012-10-12 18:06:07 +0000703 foreach buildName \
mistachkin0f801702012-10-20 08:40:05 +0000704 [expr {$isBuildNeutral ? [list CommonConfiguration] : $buildNames}] {
mistachkin48680192012-07-27 02:36:06 +0000705 #
mistachkin0ec07442012-10-12 18:06:07 +0000706 # NOTE: Should the current file be skipped for this build?
mistachkin391b3642012-07-31 00:43:31 +0000707 #
mistachkin0f801702012-10-20 08:40:05 +0000708 if {[lsearch $fileFlags no${buildName}] != -1} then {
mistachkin0ec07442012-10-12 18:06:07 +0000709 continue
mistachkin48680192012-07-27 02:36:06 +0000710 }
711
712 #
mistachkin0ec07442012-10-12 18:06:07 +0000713 # NOTE: If the current file is platform-neutral, then only one platform
714 # will be processed for it, namely "neutral"; otherwise, each
715 # supported platform will be processed for it individually.
mistachkin48680192012-07-27 02:36:06 +0000716 #
mistachkin0ec07442012-10-12 18:06:07 +0000717 foreach platformName \
mistachkin0f801702012-10-20 08:40:05 +0000718 [expr {$isPlatformNeutral ? [list neutral] : $platformNames}] {
mistachkin48680192012-07-27 02:36:06 +0000719 #
mistachkin0ec07442012-10-12 18:06:07 +0000720 # NOTE: Use the actual platform name in the destination file name.
mistachkin48680192012-07-27 02:36:06 +0000721 #
mistachkin0f801702012-10-20 08:40:05 +0000722 set newDestinationFileName [replaceFileNameTokens $destinationFileName \
723 $shortName $buildName $platformName]
mistachkin0ec07442012-10-12 18:06:07 +0000724
725 #
726 # NOTE: Does the source file need to be copied to the destination file?
727 #
728 if {[string length $sourceFileName] > 0} then {
729 #
730 # NOTE: First, make sure the destination directory exists.
731 #
732 file mkdir [file dirname $newDestinationFileName]
733
734 #
735 # NOTE: Then, copy the source file to the destination file verbatim.
736 #
mistachkin0f801702012-10-20 08:40:05 +0000737 set newSourceFileName [replaceFileNameTokens $sourceFileName \
738 $shortName $buildName $platformName]
739
740 file copy $newSourceFileName $newDestinationFileName
741
742 #
743 # NOTE: If this is a move instead of a copy, delete the source file
744 # now.
745 #
746 if {$isMove} then {
747 file delete $newSourceFileName
748 }
mistachkin0ec07442012-10-12 18:06:07 +0000749 }
750
751 #
752 # NOTE: Does the destination file contain dynamic replacements that must
753 # be processed now?
754 #
755 if {$useSubst} then {
756 #
757 # NOTE: Perform any dynamic replacements contained in the destination
758 # file and then re-write it in-place.
759 #
760 substFile $newDestinationFileName
761 }
mistachkin48680192012-07-27 02:36:06 +0000762 }
763 }
764}
765
766###############################################################################
767
768#
769# NOTE: Change the current directory to the staging directory so that the
770# external archive building tool can pickup the necessary files using
771# relative paths.
772#
773cd $stagingDirectory
774
775#
mistachkin0f801702012-10-20 08:40:05 +0000776# NOTE: Build the Tcl command used to archive the final VSIX package in the
mistachkin48680192012-07-27 02:36:06 +0000777# output directory.
778#
779set archiveCommand [list exec -- $zip -r $outputFile *]
780
781#
mistachkin0f801702012-10-20 08:40:05 +0000782# NOTE: Build the final VSIX package archive in the output directory.
mistachkin48680192012-07-27 02:36:06 +0000783#
784eval $archiveCommand
785
786#
787# NOTE: Change back to the previously saved current directory.
788#
789cd $currentDirectory
790
791#
792# NOTE: Cleanup the temporary staging directory.
793#
794file delete -force $stagingDirectory
795
796###############################################################################
797
798#
799# NOTE: Success, emit the fully qualified path of the generated VSIX file.
800#
801puts stdout $outputFile