mkvsix.tcl 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841
  1. #!/usr/bin/tclsh
  2. #
  3. # This script is used to generate a VSIX (Visual Studio Extension) file for
  4. # SQLite usable by Visual Studio.
  5. #
  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. #
  62. # 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.
  68. # Currently, the only supported package flavors are "WinRT", "WinRT81", "WP80",
  69. # "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
  77. # command prompt:
  78. #
  79. # CD /D C:\dev\sqlite\core
  80. # tclsh 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. #
  96. package require Tcl 8.4
  97. proc fail { {error ""} {usage false} } {
  98. if {[string length $error] > 0} then {
  99. puts stdout $error
  100. if {!$usage} then {exit 1}
  101. }
  102. puts stdout "usage:\
  103. [file tail [info nameofexecutable]]\
  104. [file tail [info script]] <binaryDirectory> \[sourceDirectory\]\
  105. \[packageFlavor\] \[platformNames\] \[vsVersion\]"
  106. exit 1
  107. }
  108. proc getEnvironmentVariable { name } {
  109. #
  110. # NOTE: Returns the value of the specified environment variable or an empty
  111. # string for environment variables that do not exist in the current
  112. # process environment.
  113. #
  114. return [expr {[info exists ::env($name)] ? $::env($name) : ""}]
  115. }
  116. proc getTemporaryPath {} {
  117. #
  118. # NOTE: Returns the normalized path to the first temporary directory found
  119. # in the typical set of environment variables used for that purpose
  120. # or an empty string to signal a failure to locate such a directory.
  121. #
  122. set names [list]
  123. foreach name [list TEMP TMP] {
  124. lappend names [string toupper $name] [string tolower $name] \
  125. [string totitle $name]
  126. }
  127. foreach name $names {
  128. set value [getEnvironmentVariable $name]
  129. if {[string length $value] > 0} then {
  130. return [file normalize $value]
  131. }
  132. }
  133. return ""
  134. }
  135. proc appendArgs { args } {
  136. #
  137. # NOTE: Returns all passed arguments joined together as a single string with
  138. # no intervening spaces between arguments.
  139. #
  140. eval append result $args
  141. }
  142. proc readFile { fileName } {
  143. #
  144. # NOTE: Reads and returns the entire contents of the specified file, which
  145. # may contain binary data.
  146. #
  147. set file_id [open $fileName RDONLY]
  148. fconfigure $file_id -translation binary
  149. set result [read $file_id]
  150. close $file_id
  151. return $result
  152. }
  153. proc writeFile { fileName data } {
  154. #
  155. # NOTE: Writes the entire contents of the specified file, which may contain
  156. # binary data.
  157. #
  158. set file_id [open $fileName {WRONLY CREAT TRUNC}]
  159. fconfigure $file_id -translation binary
  160. puts -nonewline $file_id $data
  161. close $file_id
  162. return ""
  163. }
  164. #
  165. # TODO: Modify this procedure when a new version of Visual Studio is released.
  166. #
  167. proc getMinVsVersionXmlChunk { vsVersion } {
  168. switch -exact $vsVersion {
  169. 2012 {
  170. return [appendArgs \
  171. "\r\n " {MinVSVersion="11.0"}]
  172. }
  173. 2013 {
  174. return [appendArgs \
  175. "\r\n " {MinVSVersion="12.0"}]
  176. }
  177. 2015 {
  178. return [appendArgs \
  179. "\r\n " {MinVSVersion="14.0"}]
  180. }
  181. default {
  182. return ""
  183. }
  184. }
  185. }
  186. #
  187. # TODO: Modify this procedure when a new version of Visual Studio is released.
  188. #
  189. proc getMaxPlatformVersionXmlChunk { packageFlavor vsVersion } {
  190. #
  191. # NOTE: Only Visual Studio 2013 and later support this attribute within the
  192. # SDK manifest.
  193. #
  194. if {![string equal $vsVersion 2013] && \
  195. ![string equal $vsVersion 2015]} then {
  196. return ""
  197. }
  198. switch -exact $packageFlavor {
  199. WinRT {
  200. return [appendArgs \
  201. "\r\n " {MaxPlatformVersion="8.0"}]
  202. }
  203. WinRT81 {
  204. return [appendArgs \
  205. "\r\n " {MaxPlatformVersion="8.1"}]
  206. }
  207. WP80 {
  208. return [appendArgs \
  209. "\r\n " {MaxPlatformVersion="8.0"}]
  210. }
  211. WP81 {
  212. return [appendArgs \
  213. "\r\n " {MaxPlatformVersion="8.1"}]
  214. }
  215. default {
  216. return ""
  217. }
  218. }
  219. }
  220. #
  221. # TODO: Modify this procedure when a new version of Visual Studio is released.
  222. #
  223. proc getExtraFileListXmlChunk { packageFlavor vsVersion } {
  224. #
  225. # NOTE: Windows Phone 8.0 does not require any extra attributes in its VSIX
  226. # package SDK manifests; however, it appears that Windows Phone 8.1
  227. # does.
  228. #
  229. if {[string equal $packageFlavor WP80]} then {
  230. return ""
  231. }
  232. set appliesTo [expr {[string equal $packageFlavor Win32] ? \
  233. "VisualC" : "WindowsAppContainer"}]
  234. switch -exact $vsVersion {
  235. 2012 {
  236. return [appendArgs \
  237. "\r\n " AppliesTo=\" $appliesTo \" \
  238. "\r\n " {DependsOn="Microsoft.VCLibs, version=11.0"}]
  239. }
  240. 2013 {
  241. return [appendArgs \
  242. "\r\n " AppliesTo=\" $appliesTo \" \
  243. "\r\n " {DependsOn="Microsoft.VCLibs, version=12.0"}]
  244. }
  245. 2015 {
  246. return [appendArgs \
  247. "\r\n " AppliesTo=\" $appliesTo \" \
  248. "\r\n " {DependsOn="Microsoft.VCLibs, version=14.0"}]
  249. }
  250. default {
  251. return ""
  252. }
  253. }
  254. }
  255. proc replaceFileNameTokens { fileName name buildName platformName } {
  256. #
  257. # NOTE: Returns the specified file name containing the platform name instead
  258. # of platform placeholder tokens.
  259. #
  260. return [string map [list <build> $buildName <platform> $platformName \
  261. <name> $name] $fileName]
  262. }
  263. proc 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. #
  272. # NOTE: This is the entry point for this script.
  273. #
  274. set script [file normalize [info script]]
  275. if {[string length $script] == 0} then {
  276. fail "script file currently being evaluated is unknown" true
  277. }
  278. set path [file dirname $script]
  279. set rootName [file rootname [file tail $script]]
  280. ###############################################################################
  281. #
  282. # NOTE: Process and verify all the command line arguments.
  283. #
  284. set argc [llength $argv]
  285. if {$argc < 1 || $argc > 5} then {fail}
  286. set binaryDirectory [lindex $argv 0]
  287. if {[string length $binaryDirectory] == 0} then {
  288. fail "invalid binary directory"
  289. }
  290. if {![file exists $binaryDirectory] || \
  291. ![file isdirectory $binaryDirectory]} then {
  292. fail "binary directory does not exist"
  293. }
  294. if {$argc >= 2} then {
  295. set sourceDirectory [lindex $argv 1]
  296. } else {
  297. #
  298. # NOTE: Assume that the source directory is the parent directory of the one
  299. # that contains this script file.
  300. #
  301. set sourceDirectory [file dirname $path]
  302. }
  303. if {[string length $sourceDirectory] == 0} then {
  304. fail "invalid source directory"
  305. }
  306. if {![file exists $sourceDirectory] || \
  307. ![file isdirectory $sourceDirectory]} then {
  308. fail "source directory does not exist"
  309. }
  310. if {$argc >= 3} then {
  311. set packageFlavor [lindex $argv 2]
  312. } else {
  313. #
  314. # NOTE: Assume the package flavor is WinRT.
  315. #
  316. set packageFlavor WinRT
  317. }
  318. if {[string length $packageFlavor] == 0} then {
  319. fail "invalid package flavor"
  320. }
  321. if {$argc >= 4} then {
  322. set platformNames [list]
  323. foreach platformName [split [lindex $argv 3] ", "] {
  324. set platformName [string trim $platformName]
  325. if {[string length $platformName] > 0} then {
  326. lappend platformNames $platformName
  327. }
  328. }
  329. }
  330. if {$argc >= 5} then {
  331. set vsVersion [lindex $argv 4]
  332. } else {
  333. set vsVersion 2012
  334. }
  335. if {[string length $vsVersion] == 0} then {
  336. fail "invalid Visual Studio version"
  337. }
  338. if {![string equal $vsVersion 2012] && ![string equal $vsVersion 2013] && \
  339. ![string equal $vsVersion 2015]} then {
  340. fail [appendArgs \
  341. "unsupported Visual Studio version, must be one of: " \
  342. [list 2012 2013 2015]]
  343. }
  344. set shortNames(WinRT,2012) SQLite.WinRT
  345. set shortNames(WinRT,2013) SQLite.WinRT.2013
  346. set shortNames(WinRT81,2013) SQLite.WinRT81
  347. set shortNames(WP80,2012) SQLite.WP80
  348. set shortNames(WP80,2013) SQLite.WP80.2013
  349. set shortNames(WP81,2013) SQLite.WP81
  350. set shortNames(Win32,2012) SQLite.Win32
  351. set shortNames(Win32,2013) SQLite.Win32.2013
  352. set shortNames(UWP,2015) SQLite.UWP.2015
  353. set displayNames(WinRT,2012) "SQLite for Windows Runtime"
  354. set displayNames(WinRT,2013) "SQLite for Windows Runtime"
  355. set displayNames(WinRT81,2013) "SQLite for Windows Runtime (Windows 8.1)"
  356. set displayNames(WP80,2012) "SQLite for Windows Phone"
  357. set displayNames(WP80,2013) "SQLite for Windows Phone"
  358. set displayNames(WP81,2013) "SQLite for Windows Phone 8.1"
  359. set displayNames(Win32,2012) "SQLite for Windows"
  360. set displayNames(Win32,2013) "SQLite for Windows"
  361. set displayNames(UWP,2015) "SQLite for Universal Windows Platform"
  362. if {[string equal $packageFlavor WinRT]} then {
  363. set shortName $shortNames($packageFlavor,$vsVersion)
  364. set displayName $displayNames($packageFlavor,$vsVersion)
  365. set targetPlatformIdentifier Windows
  366. set targetPlatformVersion v8.0
  367. set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
  368. set maxPlatformVersion \
  369. [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
  370. set extraSdkPath ""
  371. set extraFileListAttributes \
  372. [getExtraFileListXmlChunk $packageFlavor $vsVersion]
  373. } elseif {[string equal $packageFlavor WinRT81]} then {
  374. if {$vsVersion ne "2013"} then {
  375. fail [appendArgs \
  376. "unsupported combination, package flavor " $packageFlavor \
  377. " is only supported with Visual Studio 2013"]
  378. }
  379. set shortName $shortNames($packageFlavor,$vsVersion)
  380. set displayName $displayNames($packageFlavor,$vsVersion)
  381. set targetPlatformIdentifier Windows
  382. set targetPlatformVersion v8.1
  383. set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
  384. set maxPlatformVersion \
  385. [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
  386. set extraSdkPath ""
  387. set extraFileListAttributes \
  388. [getExtraFileListXmlChunk $packageFlavor $vsVersion]
  389. } elseif {[string equal $packageFlavor WP80]} then {
  390. set shortName $shortNames($packageFlavor,$vsVersion)
  391. set displayName $displayNames($packageFlavor,$vsVersion)
  392. set targetPlatformIdentifier "Windows Phone"
  393. set targetPlatformVersion v8.0
  394. set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
  395. set maxPlatformVersion \
  396. [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
  397. set extraSdkPath "\\..\\$targetPlatformIdentifier"
  398. set extraFileListAttributes \
  399. [getExtraFileListXmlChunk $packageFlavor $vsVersion]
  400. } elseif {[string equal $packageFlavor WP81]} then {
  401. if {$vsVersion ne "2013"} then {
  402. fail [appendArgs \
  403. "unsupported combination, package flavor " $packageFlavor \
  404. " is only supported with Visual Studio 2013"]
  405. }
  406. set shortName $shortNames($packageFlavor,$vsVersion)
  407. set displayName $displayNames($packageFlavor,$vsVersion)
  408. set targetPlatformIdentifier WindowsPhoneApp
  409. set targetPlatformVersion v8.1
  410. set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
  411. set maxPlatformVersion \
  412. [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
  413. set extraSdkPath "\\..\\$targetPlatformIdentifier"
  414. set extraFileListAttributes \
  415. [getExtraFileListXmlChunk $packageFlavor $vsVersion]
  416. } elseif {[string equal $packageFlavor UWP]} then {
  417. if {$vsVersion ne "2015"} then {
  418. fail [appendArgs \
  419. "unsupported combination, package flavor " $packageFlavor \
  420. " is only supported with Visual Studio 2015"]
  421. }
  422. set shortName $shortNames($packageFlavor,$vsVersion)
  423. set displayName $displayNames($packageFlavor,$vsVersion)
  424. set targetPlatformIdentifier UAP; # NOTE: Not "UWP".
  425. set targetPlatformVersion v0.8.0.0
  426. set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
  427. set maxPlatformVersion \
  428. [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
  429. set extraSdkPath "\\..\\$targetPlatformIdentifier"
  430. set extraFileListAttributes \
  431. [getExtraFileListXmlChunk $packageFlavor $vsVersion]
  432. } elseif {[string equal $packageFlavor Win32]} then {
  433. set shortName $shortNames($packageFlavor,$vsVersion)
  434. set displayName $displayNames($packageFlavor,$vsVersion)
  435. set targetPlatformIdentifier Windows
  436. set targetPlatformVersion v8.0
  437. set minVsVersion [getMinVsVersionXmlChunk $vsVersion]
  438. set maxPlatformVersion \
  439. [getMaxPlatformVersionXmlChunk $packageFlavor $vsVersion]
  440. set extraSdkPath ""
  441. set extraFileListAttributes \
  442. [getExtraFileListXmlChunk $packageFlavor $vsVersion]
  443. } else {
  444. fail [appendArgs \
  445. "unsupported package flavor, must be one of: " \
  446. [list WinRT WinRT81 WP80 WP81 UWP Win32]]
  447. }
  448. ###############################################################################
  449. #
  450. # NOTE: Evaluate the user-specific customizations file, if it exists.
  451. #
  452. set userFile [file join $path [appendArgs \
  453. $rootName . $tcl_platform(user) .tcl]]
  454. if {[file exists $userFile] && \
  455. [file isfile $userFile]} then {
  456. source $userFile
  457. }
  458. ###############################################################################
  459. set templateFile [file join $path win sqlite.vsix]
  460. if {![file exists $templateFile] || \
  461. ![file isfile $templateFile]} then {
  462. fail [appendArgs "template file \"" $templateFile "\" does not exist"]
  463. }
  464. set currentDirectory [pwd]
  465. set outputFile [file join $currentDirectory [appendArgs sqlite- \
  466. $packageFlavor -output.vsix]]
  467. if {[file exists $outputFile]} then {
  468. fail [appendArgs "output file \"" $outputFile "\" already exists"]
  469. }
  470. ###############################################################################
  471. #
  472. # NOTE: Make sure that a valid temporary directory exists.
  473. #
  474. set temporaryDirectory [getTemporaryPath]
  475. if {[string length $temporaryDirectory] == 0 || \
  476. ![file exists $temporaryDirectory] || \
  477. ![file isdirectory $temporaryDirectory]} then {
  478. fail "cannot locate a usable temporary directory"
  479. }
  480. #
  481. # NOTE: Setup the staging directory to have a unique name inside of the
  482. # configured temporary directory.
  483. #
  484. set stagingDirectory [file normalize [file join $temporaryDirectory \
  485. [appendArgs $rootName . [pid]]]]
  486. ###############################################################################
  487. #
  488. # NOTE: Configure the external zipping tool. First, see if it has already
  489. # been pre-configured. If not, try to query it from the environment.
  490. # Finally, fallback on the default of simply "zip", which will then
  491. # be assumed to exist somewhere along the PATH.
  492. #
  493. if {![info exists zip]} then {
  494. if {[info exists env(ZipTool)]} then {
  495. set zip $env(ZipTool)
  496. }
  497. if {![info exists zip] || ![file exists $zip]} then {
  498. set zip zip
  499. }
  500. }
  501. #
  502. # NOTE: Configure the external unzipping tool. First, see if it has already
  503. # been pre-configured. If not, try to query it from the environment.
  504. # Finally, fallback on the default of simply "unzip", which will then
  505. # be assumed to exist somewhere along the PATH.
  506. #
  507. if {![info exists unzip]} then {
  508. if {[info exists env(UnZipTool)]} then {
  509. set unzip $env(UnZipTool)
  510. }
  511. if {![info exists unzip] || ![file exists $unzip]} then {
  512. set unzip unzip
  513. }
  514. }
  515. ###############################################################################
  516. #
  517. # NOTE: Attempt to extract the SQLite version from the "sqlite3.h" header file
  518. # in the source directory. This script assumes that the header file has
  519. # already been generated by the build process.
  520. #
  521. set pattern {^#define\s+SQLITE_VERSION\s+"(.*)"$}
  522. set data [readFile [file join $sourceDirectory sqlite3.h]]
  523. if {![regexp -line -- $pattern $data dummy version]} then {
  524. fail [appendArgs "cannot locate SQLITE_VERSION value in \"" \
  525. [file join $sourceDirectory sqlite3.h] \"]
  526. }
  527. ###############################################################################
  528. #
  529. # NOTE: Setup all the master file list data. This includes the source file
  530. # names, the destination file names, and the file processing flags. The
  531. # possible file processing flags are:
  532. #
  533. # "buildNeutral" -- This flag indicates the file location and content do
  534. # not depend on the build configuration.
  535. #
  536. # "platformNeutral" -- This flag indicates the file location and content
  537. # do not depend on the build platform.
  538. #
  539. # "subst" -- This flag indicates that the file contains dynamic textual
  540. # content that needs to be processed using [subst] prior to
  541. # packaging the file into the final VSIX package. The primary
  542. # use of this flag is to insert the name of the VSIX package,
  543. # some package flavor-specific value, or the SQLite version
  544. # into a file.
  545. #
  546. # "noDebug" -- This flag indicates that the file should be skipped when
  547. # processing the debug build.
  548. #
  549. # "noRetail" -- This flag indicates that the file should be skipped when
  550. # processing the retail build.
  551. #
  552. # "move" -- This flag indicates that the file should be moved from the
  553. # source to the destination instead of being copied.
  554. #
  555. # This file metadata may be overridden, either in whole or in part, via
  556. # the user-specific customizations file.
  557. #
  558. if {![info exists fileNames(source)]} then {
  559. set fileNames(source) [list "" "" \
  560. [file join $stagingDirectory DesignTime <build> <platform> sqlite3.props] \
  561. [file join $sourceDirectory sqlite3.h] \
  562. [file join $binaryDirectory <build> <platform> sqlite3.lib] \
  563. [file join $binaryDirectory <build> <platform> sqlite3.dll]]
  564. if {![info exists no(symbols)]} then {
  565. lappend fileNames(source) \
  566. [file join $binaryDirectory <build> <platform> sqlite3.pdb]
  567. }
  568. }
  569. if {![info exists fileNames(destination)]} then {
  570. set fileNames(destination) [list \
  571. [file join $stagingDirectory extension.vsixmanifest] \
  572. [file join $stagingDirectory SDKManifest.xml] \
  573. [file join $stagingDirectory DesignTime <build> <platform> <name>.props] \
  574. [file join $stagingDirectory DesignTime <build> <platform> sqlite3.h] \
  575. [file join $stagingDirectory DesignTime <build> <platform> sqlite3.lib] \
  576. [file join $stagingDirectory Redist <build> <platform> sqlite3.dll]]
  577. if {![info exists no(symbols)]} then {
  578. lappend fileNames(destination) \
  579. [file join $stagingDirectory Redist <build> <platform> sqlite3.pdb]
  580. }
  581. }
  582. if {![info exists fileNames(flags)]} then {
  583. set fileNames(flags) [list \
  584. [list buildNeutral platformNeutral subst] \
  585. [list buildNeutral platformNeutral subst] \
  586. [list buildNeutral platformNeutral subst move] \
  587. [list buildNeutral platformNeutral] \
  588. [list] [list] [list noRetail]]
  589. if {![info exists no(symbols)]} then {
  590. lappend fileNames(flags) [list noRetail]
  591. }
  592. }
  593. ###############################################################################
  594. #
  595. # NOTE: Setup the list of builds supported by this script. These may be
  596. # overridden via the user-specific customizations file.
  597. #
  598. if {![info exists buildNames]} then {
  599. set buildNames [list Debug Retail]
  600. }
  601. ###############################################################################
  602. #
  603. # NOTE: Setup the list of platforms supported by this script. These may be
  604. # overridden via the command line or the user-specific customizations
  605. # file.
  606. #
  607. if {![info exists platformNames] || [llength $platformNames] == 0} then {
  608. set platformNames [list x86 x64 ARM]
  609. }
  610. ###############################################################################
  611. #
  612. # NOTE: Make sure the staging directory exists, creating it if necessary.
  613. #
  614. file mkdir $stagingDirectory
  615. #
  616. # NOTE: Build the Tcl command used to extract the template VSIX package to
  617. # the staging directory.
  618. #
  619. set extractCommand [list exec -- $unzip $templateFile -d $stagingDirectory]
  620. #
  621. # NOTE: Extract the template VSIX package to the staging directory.
  622. #
  623. eval $extractCommand
  624. ###############################################################################
  625. #
  626. # NOTE: Process each file in the master file list. There are actually three
  627. # parallel lists that contain the source file names, the destination file
  628. # names, and the file processing flags. If the "buildNeutral" flag is
  629. # present, the file location and content do not depend on the build
  630. # configuration and "CommonConfiguration" will be used in place of the
  631. # build configuration name. If the "platformNeutral" flag is present,
  632. # the file location and content do not depend on the build platform and
  633. # "neutral" will be used in place of the build platform name. If the
  634. # "subst" flag is present, the file is assumed to be a text file that may
  635. # contain Tcl variable, command, and backslash replacements, to be
  636. # dynamically replaced during processing using the Tcl [subst] command.
  637. # If the "noDebug" flag is present, the file will be skipped when
  638. # processing for the debug build. If the "noRetail" flag is present, the
  639. # file will be skipped when processing for the retail build. If the
  640. # "move" flag is present, the source file will be deleted after it is
  641. # copied to the destination file. If the source file name is an empty
  642. # string, the destination file name will be assumed to already exist in
  643. # the staging directory and will not be copied; however, Tcl variable,
  644. # command, and backslash replacements may still be performed on the
  645. # destination file prior to the final VSIX package being built if the
  646. # "subst" flag is present.
  647. #
  648. foreach sourceFileName $fileNames(source) \
  649. destinationFileName $fileNames(destination) \
  650. fileFlags $fileNames(flags) {
  651. #
  652. # NOTE: Process the file flags into separate boolean variables that may be
  653. # used within the loop.
  654. #
  655. set isBuildNeutral [expr {[lsearch $fileFlags buildNeutral] != -1}]
  656. set isPlatformNeutral [expr {[lsearch $fileFlags platformNeutral] != -1}]
  657. set isMove [expr {[lsearch $fileFlags move] != -1}]
  658. set useSubst [expr {[lsearch $fileFlags subst] != -1}]
  659. #
  660. # NOTE: If the current file is build-neutral, then only one build will
  661. # be processed for it, namely "CommonConfiguration"; otherwise, each
  662. # supported build will be processed for it individually.
  663. #
  664. foreach buildName \
  665. [expr {$isBuildNeutral ? [list CommonConfiguration] : $buildNames}] {
  666. #
  667. # NOTE: Should the current file be skipped for this build?
  668. #
  669. if {[lsearch $fileFlags no${buildName}] != -1} then {
  670. continue
  671. }
  672. #
  673. # NOTE: If the current file is platform-neutral, then only one platform
  674. # will be processed for it, namely "neutral"; otherwise, each
  675. # supported platform will be processed for it individually.
  676. #
  677. foreach platformName \
  678. [expr {$isPlatformNeutral ? [list neutral] : $platformNames}] {
  679. #
  680. # NOTE: Use the actual platform name in the destination file name.
  681. #
  682. set newDestinationFileName [replaceFileNameTokens $destinationFileName \
  683. $shortName $buildName $platformName]
  684. #
  685. # NOTE: Does the source file need to be copied to the destination file?
  686. #
  687. if {[string length $sourceFileName] > 0} then {
  688. #
  689. # NOTE: First, make sure the destination directory exists.
  690. #
  691. file mkdir [file dirname $newDestinationFileName]
  692. #
  693. # NOTE: Then, copy the source file to the destination file verbatim.
  694. #
  695. set newSourceFileName [replaceFileNameTokens $sourceFileName \
  696. $shortName $buildName $platformName]
  697. file copy $newSourceFileName $newDestinationFileName
  698. #
  699. # NOTE: If this is a move instead of a copy, delete the source file
  700. # now.
  701. #
  702. if {$isMove} then {
  703. file delete $newSourceFileName
  704. }
  705. }
  706. #
  707. # NOTE: Does the destination file contain dynamic replacements that must
  708. # be processed now?
  709. #
  710. if {$useSubst} then {
  711. #
  712. # NOTE: Perform any dynamic replacements contained in the destination
  713. # file and then re-write it in-place.
  714. #
  715. substFile $newDestinationFileName
  716. }
  717. }
  718. }
  719. }
  720. ###############################################################################
  721. #
  722. # NOTE: Change the current directory to the staging directory so that the
  723. # external archive building tool can pickup the necessary files using
  724. # relative paths.
  725. #
  726. cd $stagingDirectory
  727. #
  728. # NOTE: Build the Tcl command used to archive the final VSIX package in the
  729. # output directory.
  730. #
  731. set archiveCommand [list exec -- $zip -r $outputFile *]
  732. #
  733. # NOTE: Build the final VSIX package archive in the output directory.
  734. #
  735. eval $archiveCommand
  736. #
  737. # NOTE: Change back to the previously saved current directory.
  738. #
  739. cd $currentDirectory
  740. #
  741. # NOTE: Cleanup the temporary staging directory.
  742. #
  743. file delete -force $stagingDirectory
  744. ###############################################################################
  745. #
  746. # NOTE: Success, emit the fully qualified path of the generated VSIX file.
  747. #
  748. puts stdout $outputFile