list-dependencies-from-patches.awk (1585B)
1 #!/bin/awk -f 2 3 # Simple tool to list dependencies in form suitable for tsort utility. 4 # Run this script like this: 5 # awk -f /some/path/list-dependencies-from-patches.awk *.sql | tsort | tac 6 # To get patches in order that satisfies dependencies while loading them. 7 8 tolower($0) ~ /^[[:space:]]*select[[:space:]]+_v.register_patch\(/ { 9 if(!match($0, /\([[:space:]]*'/)) { 10 print "warning: malformed register_patch line: "FILENAME":"FNR >"/dev/stderr" 11 print "no patch name found" >"/dev/stderr" 12 next 13 } 14 line_remaining = substr($0, RSTART + RLENGTH) 15 16 if(!match(line_remaining, /'/)) { 17 print "warning: malformed register_patch line: "FILENAME":"FNR >"/dev/stderr" 18 print "not end of patch name" >"/dev/stderr" 19 next 20 } 21 patch_name = substr(line_remaining, 1, RSTART - 1) 22 line_remaining = substr(line_remaining, RSTART + RLENGTH) 23 24 print patch_name " " patch_name; 25 if(!match(line_remaining, /[[:space:]]*,[[:space:]]*ARRAY\[[[:space:]]*'/)) { 26 next 27 } 28 line_remaining = substr(line_remaining, RSTART + RLENGTH) 29 while(match(line_remaining, /[[:space:]]*,[[:space:]]*ARRAY\[[[:space:]]*'/)) { 30 print patch_name " " substr(line_remaining, 1, RSTART - 1) 31 line_remaining = substr(line_remaining, RSTART + RLENGTH) 32 } 33 if(!match(line_remaining, /'/)) { 34 print "warning: malformed register_patch line: "FILENAME":"FNR >"/dev/stderr" 35 print "not end of dependency name" >"/dev/stderr" 36 next 37 } 38 print patch_name " " substr(line_remaining, 1, RSTART - 1) 39 }