first version.
[build-srcpkg.git] / shlib / test.shlib
blob96cddd20b5f09c05fb33f37fdbcf1cbf2b406325
5 # two part in this file:
6 # @ code in catalog.shlib
7 # @ code in codegen
11 . shlibinc
13 include catalog.shlib
16 ############################################################################
17 # funcs in codegen
18 ############################################################################
21 ITEM_CONT_TYPE_LIST=
23 CONT_TMPL_LIST=
24 CONT_VAR_LIST=
25 CONT_PROP_LIST=
26 CONT_FUNC_LIST=
27 CONT_ELEM_LIST=
28 CONT_CMNTAG_LIST=
29 CONT_CMNTDOC_LIST=
30 CONT_TEST_LIST=
31 CONT_SHTEST_LIST=
32 CONT_ARGS_LIST=
33 CONT_SHARGS_LIST=
35 DEF_TESTING_CATALOG="funclist.txt"
39 onDirSubjectDirEntering ()
41         local vname=
42         local tmp=
43         
44         eval tmp="\"\${LAYEDDIR_${DIR_TYPE^^}[@]}\""
45         cata_dbgout "@@@@@ onDirSubjectDirEntering($1, $2, $(echo "$tmp" | tr -s ' ' '/'))\n"
46         declare -p OUTPUT_DIR
47         mkdir -p "$OUTPUT_DIR"
50 # fyntax: onItemSubjectDirEntering <item-node-type> <item-node-name> <item-node-layerddir>
51 # fdesc: get other info by 'ITEM_XXX' and other vars.
52 onItemSubjectDirEntering ()
54         cata_dbgout "=====> onItemSubjectDirEntering($1, $2, $3)\n"
59 onItemEntering ()
61         cata_dbgout "=====> onItemEntering($1, $2, $3)\n"
62         
63         ITEM_CHKSUM="$(echo "$NTYPE $NNAME $NDESC" | cksum)"
64         ITEM_CHKSUM="${ITEM_CHKSUM:0:6}"
65         save_curr_ctx "$ITEM_CHKSUM"
66         #declare -A -g ITEM_CTX[$ITEM_CHKSUM]="$(declare -p NFULLCATAID ${!LAYEDDIR_*})"
67 #       echo $ITEM_CHKSUM ${CONTEX_BAK[$ITEM_CHKSUM]} >&2
70 # fyntax onItemExiting <item-node-type> <item-node-name>
71 # fdesc: get other info by 'ITEM_XXX' and other vars.
72 onItemExiting ()
74         local cont=
75         local vname=
76         
77         cata_dbgout "=======================================\n"
78         cata_dbgout "onItemExiting($1, $2, $3)\n"
79         
80         [[ -z $ITEM_CONT_TYPE_LIST ]] && return
81         
82 #       echo CONTENT LIST INFO:
83         for cont in $ITEM_CONT_TYPE_LIST; do
84                 vname="CONT_${cont^^}_LIST"
85 #               echo "$vname=\"${!vname}\""
86                 unset $vname
87         done
88         
89         declare -p FILE_EXT_LIST DIR_TYPE_LIST
90         
91         # file output
92         file_gen
93         
94         ITEM_CONT_TYPE_LIST=""
97 onItemFileProc ()
99         cata_dbgout "== onItemFileProc() $STR\n"
100         touch "$1"
103 onDirFileProc ()
105         cata_dbgout "== onDirFileProc() $STR\n"
106         touch "$1"
109 onContProc ()
111         local vname=
112         
113         cata_dbgout "onContProc($1, $2, $3)\n"
114         
115         # save to list
116         vname="CONT_${1^^}_LIST"
117         declare -g ${vname}+="$2"$'\n'
118         declare -g ${vname}+="$3"$'\n'
119         
120         if [[ ! "$ITEM_CONT_TYPE_LIST" =~ $1 ]]; then
121                 ITEM_CONT_TYPE_LIST+="$1"$'\n'
122         fi
125 onThisDoc ()
127         THISDOC="${THISDOC:0:-1}"
128         [[ -z "${THISDOC//[[:space:]]/}" ]] && return
129         
130         echo THISDOC="\"$THISDOC\""
131         
132         THISDOC=""
136 save_file_list ()
138         # at the end of file output, record file list in output dir
139         tmp="$(envar_get catalog::testdir::SUBJECTDIR)/* "
140         tmp+="$(envar_get catalog::docdir::SUBJECTDIR)/* "
141         tmp+="$(envar_get catalog::designdir::SUBJECTDIR)/* "
142         tmp+="$(envar_get catalog::exdir::SUBJECTDIR)/* "
143         tmp+="$(envar_get catalog::incdir::SUBJECTDIR)/* "
144         tmp+="$(envar_get catalog::srcdir::SUBJECTDIR)/* "
145         tmp+="$(envar_get catalog::libdir::SUBJECTDIR)/* "
146         tmp+="$(envar_get catalog::bindir::SUBJECTDIR)/* "
147         tmp+="$(envar_get catalog::shlibdir::SUBJECTDIR)/* "
148         echo tmp="$tmp"
149         mkdir "$(dirname $1)"
150         cd "$(dirname $1)"
151         find $tmp > "$1" 2>/dev/null
154 load_catanode_param ()
156         :
157         include param/param.shlib
158         
159         # init node parameter.
160         declare -g G_NODE_STR_FMT="$(envar_get catalog::catanode::STR_FMT)"
161         declare -g G_NODE_PAIRCHARS="$(envar_get catalog::catanode::PAIRCHARS)"
162         
163         declare -p G_NODE_STR_FMT G_NODE_PAIRCHARS
164                 
165 #       envar_create catalog::catanode::STR_FMT='<@{NCATAID}>@{ALIGN}[@{NTYPE}]@{ALIGN}@{NNAME}@{ALIGN}[@{NDESC}]'
166         G_OUTPUT_DIR_FMT="$(envar_get catalog::dirnode::OUTPUT_DIR_FMT)"
167         declare -p G_OUTPUT_DIR_FMT
170 cata_proc_init ()
172         vonItemEntering=onItemEntering
173         vonItemSubjectDirEntering=onItemSubjectDirEntering
174         vonItemExiting=onItemExiting
175         vonItemFileProc=onItemFileProc
177         vonDirSubjectDirEntering=onDirSubjectDirEntering
178         vonDirFileProc=onDirFileProc
180         vonContProc=onContProc
183 catalog_2_dirfiles ()
185         local finput=$1
186         local i
187         local xxx
189         cd "$test_path"
190         
191         cataid_create TEST
192         cataid_set_init_state TEST "inner"
193         
194         # load param.
195         load_catanode_param
196         
197 #       envar_create catalog::catanode::STR_FMT='<@{NCATAID}>@{ALIAN}[@{NTYPE}]@{ALIAN}@{NNAME}@{ALIAN}[@{NDESC}]'
198         G_OUTPUT_DIR_FMT="$(envar_get catalog::dirnode::OUTPUT_DIR_FMT)"
199         declare -p G_OUTPUT_DIR_FMT
200         
201         finput=${finput:-"${DEF_TESTING_CATALOG}"}
202         if [[ ! -e $finput ]]; then
203                 err "function list file '$finput' is not exist.\n"
204                 exit
205         fi
206         
207         cp "$finput" "$TESTING_TMP_DIR/"
208         finput=$TESTING_TMP_DIR/`basename $finput`
209         dos2unix $finput
210         
211         mkdir -p $SRCPKG_DIR/build/
212         cp $finput $SRCPKG_DIR/build/$(basename $finput)
213         
214         # analyze catalog file.
215         vonCataNodeProc=onDefaultCataNodeProc
216         catalog_each_line "$finput"
217         
218         save_file_list "$SRCPKG_DIR/build/codegen.dir.txt"
235 ############################################################################
236 # tmp
237 ############################################################################
240 cata_dbgout ()
242         :
243         dbgoutd "$@"
246 file_cont_gen ()
248         :
251 file_gen ()
253         return;
254         local file=
255         
256         # 
257         for file in $FILE_EXT_LIST; do
258                 # 
259                 :
260         done
264 # catanode analyzing for comparation.
266 OnAnyalyzeCataNodeProc ()
268         ITEM_CHKSUM="$(echo "$NTYPE $NNAME $NDESC" | cksum)"
269         
270         if [[ ${NODE_TYPE} != 'cont' ]]; then
271                 NODE_TBL[$ITEM_CHKSUM]="$(declare -p NCATAID NTYPE NNAME NDESC NODE_TYPE NFULLCATAID CONT_TYPE ITEM_TYPE SRC_TYPE CATACNT)"
272                 NODE_TBL[$ITEM_CHKSUM]="$(NODE_TBL[$ITEM_CHKSUM]//declare/declare -g)"
273                 NODE_TBL_EXIST[$ITEM_CHKSUM]="1"
274                 
275                 if [[ ${NODE_TYPE} == 'item' ]]; then
276                         ITEM_CHKSUM_ID="$ITEM_CHKSUM"
277                         save_curr_ctx "$ITEM_CHKSUM"
278                 fi
279         else
280                 eval CONT_NODE_TBL_${ITEM_CHKSUM_ID}[$ITEM_CHKSUM]="\"$(declare -p NCATAID NTYPE NNAME NDESC NODE_TYPE NFULLCATAID CONT_TYPE ITEM_TYPE SRC_TYPE CATACNT)\""
281                 eval CONT_NODE_TBL_${ITEM_CHKSUM_ID}[$ITEM_CHKSUM]="\"\$(CONT_NODE_TBL_${ITEM_CHKSUM_ID}[$ITEM_CHKSUM]//declare/declare -g)\""
282         fi
286 # catanode comparing.
288 OnCompareCataNodeProc ()
290         ITEM_CHKSUM="$(echo "$NTYPE $NNAME $NDESC" | cksum)"
291         
292         if [[ ${NODE_TYPE} != 'cont' ]]; then
293                 if [[ -n ${NODE_TBL[$ITEM_CHKSUM]} ]]; then
294 #                       unset NODE_TBL[$ITEM_CHKSUM]
295 #                       del_bak_ctx "$ITEM_CHKSUM"
296                         unset NODE_TBL_EXIST[$ITEM_CHKSUM]
297                 else
298                         NEW_NODE_TBL="$(declare -p NCATAID NTYPE NNAME NDESC NODE_TYPE NFULLCATAID CONT_TYPE ITEM_TYPE SRC_TYPE CATACNT)"
299                         NEW_NODE_TBL[$ITEM_CHKSUM]="$(NEW_NODE_TBL[$ITEM_CHKSUM]//declare/declare -g)"
300                 fi
301                 
302                 if [[ ${NODE_TYPE} == 'item' ]]; then
303                         ITEM_CHKSUM_ID="$ITEM_CHKSUM"
304                 fi
305         else
306                 local vname=
307                 
308                 vname="CONT_NODE_TBL_${ITEM_CHKSUM_ID}[$ITEM_CHKSUM]"
309                 if [[ -n ${!vname} ]]; then
310                         unset ${vname}
311                 else
312                         vname="NEW_$vname"
313                         eval $vname="\"$(declare -p NCATAID NTYPE NNAME NDESC NODE_TYPE NFULLCATAID CONT_TYPE ITEM_TYPE SRC_TYPE CATACNT)\""
314                         eval $vname="$(!vname//declare/declare -g)"
315                 fi
316         fi
319 deleted_node_tbl_foreach ()
321         local i=
322         local cnt=
323         
324         # ergodic deleted list, and get the ITEM_CHKSUM_ID from main design file.
325         # if it is existing
326         
327         cnt="${#NODE_TBL[@]}"
328         for ITEM_CHKSUM in ${!NODE_TBL[@]}; do
329                 # contex restore
330                 eval ${NODE_TBL[$ITEM_CHKSUM]}
331                 
332                 # get foreach file in current node.
333                 
334                 # TBD: output operation.
335         done
338 new_file_node_tbl_foreach ()
340         local i=
341         local cnt=
342         
343         ITEM_CHKSUM=
344         cnt="${#NODE_TBL[@]}"
345         for ITEM_CHKSUM in ${!NODE_TBL_EXIST[@]}; do
346                 # restore NODE contex
347                 eval ${NODE_TBL[$1]}
348                 
349                 $vonCataNodeProc
350         done
353 new_cont_node_tbl_foreach ()
355         local i=
356         local cnt=
357         local vname=
358         local var=
359         local itemid=
360         local item_node_list=
361         
362         ITEM_CHKSUM=
363         cnt="${#NODE_TBL[@]}"
364         item_node_list="${!NEW_CONT_NODE_TBL_} ${!CONT_NODE_TBL_}"
365         item_node_list="${item_node_list//NEW_CONT_NODE_TBL_/}"
366         item_node_list="${item_node_list//CONT_NODE_TBL_/}"
367         item_node_list="$(echo "$item_node_list" | uniq)"
368         for itemid in ${item_node_list}; do
369                 var="NEW_CONT_NODE_TBL_${itemid}[@]"
370                 for ITEM_CHKSUM in ${!var}; do
371                         # restore NODE contex
372                         var="NEW_CONT_NODE_TBL_${itemid}[$ITEM_CHKSUM]"
373                         eval ${!var}
374                         
375                         $vonCataNodeProc
376                 done
377                 
378                 for cont in $ITEM_CONT_TYPE_LIST; do
379                         vname="CONT_${cont^^}_LIST"
380                         eval "NEW_$vname=\"${!vname}\""
381                         unset $vname
382                 done
383                 
384                 # deleted list
385                 var="CONT_NODE_TBL_${itemid}[@]"
386                 for ITEM_CHKSUM in ${!var}; do
387                         # restore NODE contex
388                         var="${itemid}[$ITEM_CHKSUM]"
389                         eval ${!var}
390                         
391                         $vonCataNodeProc
392                 done
393                 
394                 for cont in $ITEM_CONT_TYPE_LIST; do
395                         vname="CONT_${cont^^}_LIST"
396                         eval "DEL_$vname=\"${!vname}\""
397                         unset $vname
398                 done
399                 
400                 # TBD: item file re-gen
401         done
404 catalog_content_cmp ()
406         local tmp="$1"
407         
408         tmp=${tmp:-"${DEF_TESTING_CATALOG}"}
409         [[ ! -e ${tmp} ]] && return
410         
411         [[ ! -e $SRCPKG_DIR/build/${DEF_TESTING_CATALOG} ]] && return
412         
413         vonCataNodeProc=OnAnyalyzeCataNodeProc
414         catalog_each_line "$SRCPKG_DIR/build/${DEF_TESTING_CATALOG}"
415         
416         vonCataNodeProc=OnCompareCataNodeProc
417         catalog_each_line "$tmp"
418         
419         # TBD: chk if NEW_* info is modified or new.
420         
421         deleted_node_tbl_foreach
422         new_file_node_tbl_foreach
423         new_cont_node_tbl_foreach
426 output_dir_cmp ()
428         save_file_list /tmp/codegen.dir.txt
429         
433 # * this feature is hard to be implemented in this code.
435 modified_node_chk ()
437         # foreach deleted node, compare NNAME NDESC in new catalog file.
438         :