Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1407)

Side by Side Diff: third_party/sqlite/src/tool/mksqlite3c.tcl

Issue 1610963002: Import SQLite 3.10.2. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/tclsh 1 #!/usr/bin/tclsh
2 # 2 #
3 # To build a single huge source file holding all of SQLite (or at 3 # To build a single huge source file holding all of SQLite (or at
4 # least the core components - the test harness, shell, and TCL 4 # least the core components - the test harness, shell, and TCL
5 # interface are omitted.) first do 5 # interface are omitted.) first do
6 # 6 #
7 # make target_source 7 # make target_source
8 # 8 #
9 # The make target above moves all of the source code files into 9 # The make target above moves all of the source code files into
10 # a subdirectory named "tsrc". (This script expects to find the files 10 # a subdirectory named "tsrc". (This script expects to find the files
11 # there and will not work if they are not found.) There are a few 11 # there and will not work if they are not found.) There are a few
12 # generated C code files that are also added to the tsrc directory. 12 # generated C code files that are also added to the tsrc directory.
13 # For example, the "parse.c" and "parse.h" files to implement the 13 # For example, the "parse.c" and "parse.h" files to implement the
14 # the parser are derived from "parse.y" using lemon. And the 14 # the parser are derived from "parse.y" using lemon. And the
15 # "keywordhash.h" files is generated by a program named "mkkeywordhash". 15 # "keywordhash.h" files is generated by a program named "mkkeywordhash".
16 # 16 #
17 # After the "tsrc" directory has been created and populated, run 17 # After the "tsrc" directory has been created and populated, run
18 # this script: 18 # this script:
19 # 19 #
20 # tclsh mksqlite3c.tcl 20 # tclsh mksqlite3c.tcl --srcdir $SRC
21 # 21 #
22 # The amalgamated SQLite code will be written into sqlite3.c 22 # The amalgamated SQLite code will be written into sqlite3.c
23 # 23 #
24 24
25 # Begin by reading the "sqlite3.h" header file. Extract the version number 25 # Begin by reading the "sqlite3.h" header file. Extract the version number
26 # from in this file. The version number is needed to generate the header 26 # from in this file. The version number is needed to generate the header
27 # comment of the amalgamation. 27 # comment of the amalgamation.
28 # 28 #
29 if {[lsearch $argv --nostatic]>=0} { 29 set addstatic 1
30 set addstatic 0 30 set linemacros 0
31 } else { 31 for {set i 0} {$i<[llength $argv]} {incr i} {
32 set addstatic 1 32 set x [lindex $argv $i]
33 } 33 if {[regexp {^-+nostatic$} $x]} {
34 if {[lsearch $argv --linemacros]>=0} { 34 set addstatic 0
35 set linemacros 1 35 } elseif {[regexp {^-+linemacros} $x]} {
36 } else { 36 set linemacros 1
37 set linemacros 0 37 } else {
38 error "unknown command-line option: $x"
39 }
38 } 40 }
39 set in [open tsrc/sqlite3.h] 41 set in [open tsrc/sqlite3.h]
40 set cnt 0 42 set cnt 0
41 set VERSION ????? 43 set VERSION ?????
42 while {![eof $in]} { 44 while {![eof $in]} {
43 set line [gets $in] 45 set line [gets $in]
44 if {$line=="" && [eof $in]} break 46 if {$line=="" && [eof $in]} break
45 incr cnt 47 incr cnt
46 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION 48 regexp {#define\s+SQLITE_VERSION\s+"(.*)"} $line all VERSION
47 } 49 }
(...skipping 25 matching lines...) Expand all
73 ** if you want a wrapper to interface SQLite with your choice of programming 75 ** if you want a wrapper to interface SQLite with your choice of programming
74 ** language. The code for the "sqlite3" command-line shell is also in a 76 ** language. The code for the "sqlite3" command-line shell is also in a
75 ** separate file. This file contains only code for the core SQLite library. 77 ** separate file. This file contains only code for the core SQLite library.
76 */ 78 */
77 #define SQLITE_CORE 1 79 #define SQLITE_CORE 1
78 #define SQLITE_AMALGAMATION 1}] 80 #define SQLITE_AMALGAMATION 1}]
79 if {$addstatic} { 81 if {$addstatic} {
80 puts $out \ 82 puts $out \
81 {#ifndef SQLITE_PRIVATE 83 {#ifndef SQLITE_PRIVATE
82 # define SQLITE_PRIVATE static 84 # define SQLITE_PRIVATE static
83 #endif
84 #ifndef SQLITE_API
85 # define SQLITE_API
86 #endif} 85 #endif}
87 } 86 }
88 87
89 # These are the header files used by SQLite. The first time any of these 88 # These are the header files used by SQLite. The first time any of these
90 # files are seen in a #include statement in the C code, include the complete 89 # files are seen in a #include statement in the C code, include the complete
91 # text of the file in-line. The file only needs to be included once. 90 # text of the file in-line. The file only needs to be included once.
92 # 91 #
93 foreach hdr { 92 foreach hdr {
94 btree.h 93 btree.h
95 btreeInt.h 94 btreeInt.h
96 fts3.h 95 fts3.h
97 fts3Int.h 96 fts3Int.h
98 fts3_hash.h 97 fts3_hash.h
99 fts3_tokenizer.h 98 fts3_tokenizer.h
100 hash.h 99 hash.h
101 hwtime.h 100 hwtime.h
102 keywordhash.h 101 keywordhash.h
102 msvc.h
103 mutex.h 103 mutex.h
104 opcodes.h 104 opcodes.h
105 os_common.h 105 os_common.h
106 os_setup.h 106 os_setup.h
107 os_win.h 107 os_win.h
108 os.h 108 os.h
109 pager.h 109 pager.h
110 parse.h 110 parse.h
111 pcache.h 111 pcache.h
112 pragma.h
112 rtree.h 113 rtree.h
114 sqlite3.h
113 sqlite3ext.h 115 sqlite3ext.h
114 sqlite3.h 116 sqlite3rbu.h
115 sqliteicu.h 117 sqliteicu.h
116 sqliteInt.h 118 sqliteInt.h
117 sqliteLimit.h 119 sqliteLimit.h
118 vdbe.h 120 vdbe.h
119 vdbeInt.h 121 vdbeInt.h
122 vxworks.h
120 wal.h 123 wal.h
121 whereInt.h 124 whereInt.h
122 } { 125 } {
123 set available_hdr($hdr) 1 126 set available_hdr($hdr) 1
124 } 127 }
125 set available_hdr(sqliteInt.h) 0 128 set available_hdr(sqliteInt.h) 0
126 129
130 # These headers should be copied into the amalgamation without modifying any
131 # of their function declarations or definitions.
132 set varonly_hdr(sqlite3.h) 1
133
134 # These are the functions that accept a variable number of arguments. They
135 # always need to use the "cdecl" calling convention even when another calling
136 # convention (e.g. "stcall") is being used for the rest of the library.
137 set cdecllist {
138 sqlite3_config
139 sqlite3_db_config
140 sqlite3_log
141 sqlite3_mprintf
142 sqlite3_snprintf
143 sqlite3_test_control
144 sqlite3_vtab_config
145 }
146
127 # 78 stars used for comment formatting. 147 # 78 stars used for comment formatting.
128 set s78 \ 148 set s78 \
129 {*****************************************************************************} 149 {*****************************************************************************}
130 150
131 # Insert a comment into the code 151 # Insert a comment into the code
132 # 152 #
133 proc section_comment {text} { 153 proc section_comment {text} {
134 global out s78 154 global out s78
135 set n [string length $text] 155 set n [string length $text]
136 set nstar [expr {60 - $n}] 156 set nstar [expr {60 - $n}]
137 set stars [string range $s78 0 $nstar] 157 set stars [string range $s78 0 $nstar]
138 puts $out "/************** $text $stars/" 158 puts $out "/************** $text $stars/"
139 } 159 }
140 160
141 # Read the source file named $filename and write it into the 161 # Read the source file named $filename and write it into the
142 # sqlite3.c output file. If any #include statements are seen, 162 # sqlite3.c output file. If any #include statements are seen,
143 # process them appropriately. 163 # process them appropriately.
144 # 164 #
145 proc copy_file {filename} { 165 proc copy_file {filename} {
146 global seen_hdr available_hdr out addstatic linemacros 166 global seen_hdr available_hdr varonly_hdr cdecllist out addstatic linemacros
147 set ln 0 167 set ln 0
148 set tail [file tail $filename] 168 set tail [file tail $filename]
149 section_comment "Begin file $tail" 169 section_comment "Begin file $tail"
150 if {$linemacros} {puts $out "#line 1 \"$filename\""} 170 if {$linemacros} {puts $out "#line 1 \"$filename\""}
151 set in [open $filename r] 171 set in [open $filename r]
152 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)} 172 set varpattern {^[a-zA-Z][a-zA-Z_0-9 *]+(sqlite3[_a-zA-Z0-9]+)(\[|;| =)}
153 set declpattern {[a-zA-Z][a-zA-Z_0-9 ]+ \**(sqlite3[_a-zA-Z0-9]+)\(} 173 set declpattern {([a-zA-Z][a-zA-Z_0-9 ]+ \**)(sqlite3[_a-zA-Z0-9]+)(\(.*)}
154 if {[file extension $filename]==".h"} { 174 if {[file extension $filename]==".h"} {
155 set declpattern " *$declpattern" 175 set declpattern " *$declpattern"
156 } 176 }
157 set declpattern ^$declpattern 177 set declpattern ^$declpattern\$
158 while {![eof $in]} { 178 while {![eof $in]} {
159 set line [gets $in] 179 set line [gets $in]
160 incr ln 180 incr ln
161 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} { 181 if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
162 if {[info exists available_hdr($hdr)]} { 182 if {[info exists available_hdr($hdr)]} {
163 if {$available_hdr($hdr)} { 183 if {$available_hdr($hdr)} {
164 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} { 184 if {$hdr!="os_common.h" && $hdr!="hwtime.h"} {
165 set available_hdr($hdr) 0 185 set available_hdr($hdr) 0
166 } 186 }
167 section_comment "Include $hdr in the middle of $tail" 187 section_comment "Include $hdr in the middle of $tail"
168 copy_file tsrc/$hdr 188 copy_file tsrc/$hdr
169 section_comment "Continuing where we left off in $tail" 189 section_comment "Continuing where we left off in $tail"
170 if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""} 190 if {$linemacros} {puts $out "#line [expr {$ln+1}] \"$filename\""}
191 } else {
192 # Comment out the entire line, replacing any nested comment
193 # begin/end markers with the harmless substring "**".
194 puts $out "/* [string map [list /* ** */ **] $line] */"
171 } 195 }
172 } elseif {![info exists seen_hdr($hdr)]} { 196 } elseif {![info exists seen_hdr($hdr)]} {
173 if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} { 197 if {![regexp {/\*\s+amalgamator:\s+dontcache\s+\*/} $line]} {
174 set seen_hdr($hdr) 1 198 set seen_hdr($hdr) 1
175 } 199 }
176 puts $out $line 200 puts $out $line
177 } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} { 201 } elseif {[regexp {/\*\s+amalgamator:\s+keep\s+\*/} $line]} {
178 # This include file must be kept because there was a "keep" 202 # This include file must be kept because there was a "keep"
179 # directive inside of a line comment. 203 # directive inside of a line comment.
180 puts $out $line 204 puts $out $line
181 } else { 205 } else {
182 # Comment out the entire line, replacing any nested comment 206 # Comment out the entire line, replacing any nested comment
183 # begin/end markers with the harmless substring "**". 207 # begin/end markers with the harmless substring "**".
184 puts $out "/* [string map [list /* ** */ **] $line] */" 208 puts $out "/* [string map [list /* ** */ **] $line] */"
185 } 209 }
186 } elseif {[regexp {^#ifdef __cplusplus} $line]} { 210 } elseif {[regexp {^#ifdef __cplusplus} $line]} {
187 puts $out "#if 0" 211 puts $out "#if 0"
188 } elseif {!$linemacros && [regexp {^#line} $line]} { 212 } elseif {!$linemacros && [regexp {^#line} $line]} {
189 # Skip #line directives. 213 # Skip #line directives.
190 } elseif {$addstatic && ![regexp {^(static|typedef)} $line]} { 214 } elseif {$addstatic
191 regsub {^SQLITE_API } $line {} line 215 && ![regexp {^(static|typedef|SQLITE_PRIVATE)} $line]} {
192 if {[regexp $declpattern $line all funcname]} { 216 # Skip adding the SQLITE_PRIVATE or SQLITE_API keyword before
217 # functions if this header file does not need it.
218 if {![info exists varonly_hdr($tail)]
219 && [regexp $declpattern $line all rettype funcname rest]} {
220 regsub {^SQLITE_API } $line {} line
193 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions. 221 # Add the SQLITE_PRIVATE or SQLITE_API keyword before functions.
194 # so that linkage can be modified at compile-time. 222 # so that linkage can be modified at compile-time.
195 if {[regexp {^sqlite3_} $funcname]} { 223 if {[regexp {^sqlite3(_|rbu_)} $funcname]} {
196 puts $out "SQLITE_API $line" 224 set line SQLITE_API
225 append line " " [string trim $rettype]
226 if {[string index $rettype end] ne "*"} {
227 append line " "
228 }
229 if {[lsearch -exact $cdecllist $funcname] >= 0} {
230 append line SQLITE_CDECL
231 } else {
232 append line SQLITE_STDCALL
233 }
234 append line " " $funcname $rest
235 puts $out $line
197 } else { 236 } else {
198 puts $out "SQLITE_PRIVATE $line" 237 puts $out "SQLITE_PRIVATE $line"
199 } 238 }
200 } elseif {[regexp $varpattern $line all varname]} { 239 } elseif {[regexp $varpattern $line all varname]} {
201 # Add the SQLITE_PRIVATE before variable declarations or 240 # Add the SQLITE_PRIVATE before variable declarations or
202 # definitions for internal use 241 # definitions for internal use
203 if {![regexp {^sqlite3_} $varname]} { 242 regsub {^SQLITE_API } $line {} line
204 regsub {^extern } $line {} line 243 if {![regexp {^sqlite3_} $varname]} {
205 puts $out "SQLITE_PRIVATE $line" 244 regsub {^extern } $line {} line
206 } else { 245 puts $out "SQLITE_PRIVATE $line"
207 if {[regexp {const char sqlite3_version\[\];} $line]} { 246 } else {
208 set line {const char sqlite3_version[] = SQLITE_VERSION;} 247 if {[regexp {const char sqlite3_version\[\];} $line]} {
248 set line {const char sqlite3_version[] = SQLITE_VERSION;}
249 }
250 regsub {^SQLITE_EXTERN } $line {} line
251 puts $out "SQLITE_API $line"
209 } 252 }
210 regsub {^SQLITE_EXTERN } $line {} line
211 puts $out "SQLITE_API $line"
212 }
213 } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} { 253 } elseif {[regexp {^(SQLITE_EXTERN )?void \(\*sqlite3IoTrace\)} $line]} {
254 regsub {^SQLITE_API } $line {} line
214 regsub {^SQLITE_EXTERN } $line {} line 255 regsub {^SQLITE_EXTERN } $line {} line
215 puts $out "SQLITE_PRIVATE $line" 256 puts $out $line
216 } elseif {[regexp {^void \(\*sqlite3Os} $line]} { 257 } elseif {[regexp {^void \(\*sqlite3Os} $line]} {
258 regsub {^SQLITE_API } $line {} line
217 puts $out "SQLITE_PRIVATE $line" 259 puts $out "SQLITE_PRIVATE $line"
218 } else { 260 } else {
219 puts $out $line 261 puts $out $line
220 } 262 }
221 } else { 263 } else {
222 puts $out $line 264 puts $out $line
223 } 265 }
224 } 266 }
225 close $in 267 close $in
226 section_comment "End of $tail" 268 section_comment "End of $tail"
(...skipping 18 matching lines...) Expand all
245 mem1.c 287 mem1.c
246 mem2.c 288 mem2.c
247 mem3.c 289 mem3.c
248 mem5.c 290 mem5.c
249 mutex.c 291 mutex.c
250 mutex_noop.c 292 mutex_noop.c
251 mutex_unix.c 293 mutex_unix.c
252 mutex_w32.c 294 mutex_w32.c
253 malloc.c 295 malloc.c
254 printf.c 296 printf.c
297 treeview.c
255 random.c 298 random.c
256 threads.c 299 threads.c
257 utf.c 300 utf.c
258 util.c 301 util.c
259 hash.c 302 hash.c
260 opcodes.c 303 opcodes.c
261 304
262 os_unix.c 305 os_unix.c
263 os_win.c 306 os_win.c
264 307
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 legacy.c 342 legacy.c
300 loadext.c 343 loadext.c
301 pragma.c 344 pragma.c
302 prepare.c 345 prepare.c
303 select.c 346 select.c
304 table.c 347 table.c
305 trigger.c 348 trigger.c
306 update.c 349 update.c
307 vacuum.c 350 vacuum.c
308 vtab.c 351 vtab.c
352 wherecode.c
353 whereexpr.c
309 where.c 354 where.c
310 355
311 parse.c 356 parse.c
312 357
313 tokenize.c 358 tokenize.c
314 complete.c 359 complete.c
315 360
316 main.c 361 main.c
317 notify.c 362 notify.c
318 363
319 recover.c 364 recover.c
320 365
321 fts3.c 366 fts3.c
322 fts3_aux.c 367 fts3_aux.c
323 fts3_expr.c 368 fts3_expr.c
324 fts3_hash.c 369 fts3_hash.c
325 fts3_porter.c 370 fts3_porter.c
326 fts3_tokenizer.c 371 fts3_tokenizer.c
327 fts3_tokenizer1.c 372 fts3_tokenizer1.c
328 fts3_tokenize_vtab.c 373 fts3_tokenize_vtab.c
329 fts3_write.c 374 fts3_write.c
330 fts3_snippet.c 375 fts3_snippet.c
331 fts3_unicode.c 376 fts3_unicode.c
332 fts3_unicode2.c 377 fts3_unicode2.c
333 378
334 rtree.c 379 rtree.c
335 icu.c 380 icu.c
336 fts3_icu.c 381 fts3_icu.c
382 sqlite3rbu.c
383 dbstat.c
384 json1.c
385 fts5.c
337 } { 386 } {
338 copy_file tsrc/$file 387 copy_file tsrc/$file
339 } 388 }
340 389
341 close $out 390 close $out
OLDNEW
« no previous file with comments | « third_party/sqlite/src/tool/mkpragmatab.tcl ('k') | third_party/sqlite/src/tool/mksqlite3c-noext.tcl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698