|
| 1 | +// Simple Process Initialisation - kdb-common |
| 2 | +// Copyright (c) 2021 Jaskirat Rajasansir |
| 3 | + |
| 4 | +// Provides a simple initialisation of kdb-common with require and core libraries |
| 5 | + |
| 6 | + |
| 7 | +/ Environment variable to change the root that 'require' will initialise and search for libraries from. If this is not |
| 8 | +/ set, it will be the folder that 'boot.q' is specified from. If it is specified, 'require' is assumed to be |
| 9 | +/ available at *boot.q-dir*/src/require.q |
| 10 | +.boot.cfg.appRootEnvVar:`KDB_APPLICATION_ROOT; |
| 11 | + |
| 12 | +/ Commmand line argument to automatically load any additional libraries (comma separated) during initialisation |
| 13 | +.boot.cfg.loadLibsCmdArg:`$"load-libs"; |
| 14 | + |
| 15 | +/ The libraries that are always loaded |
| 16 | +.boot.cfg.coreLibs:`log`cargs; |
| 17 | + |
| 18 | + |
| 19 | +/ The root path of the kdb-common libraries |
| 20 | +.boot.root.kdbCommon:`:. |
| 21 | + |
| 22 | +/ The root path of the application. This will only be different from '.boot.root.kdbCommon' if $KDB_APPLICATION_ROOT is set |
| 23 | +.boot.root.app:`:.; |
| 24 | + |
| 25 | + |
| 26 | +/ The command line arguments parsed with '.cargs.getWithInternal' |
| 27 | +.boot.args:(`symbol$())!(); |
| 28 | + |
| 29 | + |
| 30 | +.boot.init:{ |
| 31 | + .boot.root[`kdbCommon`app]:first ` vs hsym .z.f; |
| 32 | + |
| 33 | + envRoot:getenv .boot.cfg.appRootEnvVar; |
| 34 | + |
| 35 | + if[0 < count envRoot; |
| 36 | + .boot.root.app:`$":",envRoot; |
| 37 | + ]; |
| 38 | + |
| 39 | + -1 "Application root: ",(1_ string .boot.root.app)," | kdb-common root: ",1_ string .boot.root.kdbCommon; |
| 40 | + |
| 41 | + require:` sv .boot.root.kdbCommon,`src`require.q; |
| 42 | + system "l ",1_ string require; |
| 43 | + |
| 44 | + .require.init .boot.root.app; |
| 45 | + .require.lib each .boot.cfg.coreLibs; |
| 46 | + |
| 47 | + .boot.args,:.cargs.getWithInternal[]; |
| 48 | + |
| 49 | + if[.boot.cfg.loadLibsCmdArg in key .boot.args; |
| 50 | + additionalLibs:`$"," vs .boot.args .boot.cfg.loadLibsCmdArg; |
| 51 | + |
| 52 | + if[0 < count additionalLibs except `; |
| 53 | + .require.lib each additionalLibs; |
| 54 | + ]; |
| 55 | + ]; |
| 56 | + }; |
| 57 | + |
| 58 | + |
| 59 | +.boot.init[]; |
0 commit comments