From 13746233c7416df0dfa7c0a5633bf37db449bf37 Mon Sep 17 00:00:00 2001 From: "Fred T. Hamster" Date: Wed, 11 Feb 2026 16:25:52 -0500 Subject: [PATCH] bit of gen deps cleanup got rid of old versions of the code. still works. bonus. --- scripts/clam/cpp/buildor_gen_deps.sh | 106 +++++++-------------------- 1 file changed, 27 insertions(+), 79 deletions(-) diff --git a/scripts/clam/cpp/buildor_gen_deps.sh b/scripts/clam/cpp/buildor_gen_deps.sh index 31a0a3b0..e42c59d5 100644 --- a/scripts/clam/cpp/buildor_gen_deps.sh +++ b/scripts/clam/cpp/buildor_gen_deps.sh @@ -33,7 +33,7 @@ if [ ! -z "$CLEAN" ]; then fi # uncomment to enable debugging noises. -DEBUG_BUILDOR_GEN_DEPS=yo +#DEBUG_BUILDOR_GEN_DEPS=yo # these semi-global variables used throughout the whole script to accumulate # information, rather than trying to juggle positional parameters everywhere. @@ -74,7 +74,6 @@ function seen_already { function add_new_dep { # make sure we haven't already processed this. local dep="$1"; shift -#log_it "looking for dep='$dep'" if seen_already "$dep"; then if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then log_it "bailing since seen: $dep" @@ -119,6 +118,8 @@ function bad_file { return $RET_FAIL } +#hmmm: this needs to go the way of the dodo and find_in_array... + # checks whether an item is already contained in a list. the first parameter # is taken as the item that one wants to add. the second through n-th # parameters are taken as the candidate list. if the item is present, then @@ -136,28 +137,6 @@ function already_listed { return $RET_FAIL } -# finds the index of a particular element in the remainder of a list. -# the variable __finders_indy will be set to -1 for no match, or it will be the -# index of the element if the item was found. -##__finders_indy=-1 -##function find_in_array { -## local to_find=$1 -## shift -## local indy=0 -## while (( $# > 0 )); do -## # return that we found it if the current item matches. -## if [ "$to_find" == "$1" ]; then -## __finders_indy=$indy -## return $RET_OKAY -## fi -## shift # toss next one out. -## indy=$(expr $indy + 1) -## done -## _finders_indy=-1 -## # failed to match it. -## return $RET_FAIL -##} - ############################################################################ # # this variable gets stored into when resolve_filename runs. @@ -171,7 +150,7 @@ declare -A resolve_matches # # tries to find a filename in the library hierarchy. function resolve_filename() { - # wipe out prior contents from resolved paths. + # wipe out prior global contents from resolved paths. unset resolve_target_array declare -gA resolve_target_array @@ -205,10 +184,8 @@ function resolve_filename() { fi # see if we can find that element in the previously resolved items. -#log_it "looking for '$src_key' in this list: '${!resolve_matches[@]}'" if [ ! -z "${resolve_matches[$src_key]}" ]; then local flounder="${resolve_matches[$src_key]}" -#log_it flounder is $flounder resolve_target_array[$flounder]=blup if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then log_it "FOUND \"$src_key\" AT $flounder" @@ -216,10 +193,6 @@ function resolve_filename() { return $RET_OKAY fi - # reset our global list. -# unset resolve_target_array -# declare -gA resolve_target_array - if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then log_it "HAVING TO FIND: dir='$dir' and base='$base'" fi @@ -236,7 +209,7 @@ function resolve_filename() { #log_it "with dir case, init list is: ${init_list}" if [ ${#init_list} -gt 0 ]; then eval resolve_target_array=(${init_list}) -log_it "after dir case addition, resolve targets are: " ${!resolve_target_array[@]} +#log_it "after dir case addition, resolve targets are: " ${!resolve_target_array[@]} fi fi if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then @@ -251,8 +224,6 @@ log_it "after dir case addition, resolve targets are: " ${!resolve_target_array[ fi # for unique matches, we will store the correspondence so we can find it very quickly later. resolve_matches[$src_key]="$first_item" -#log_it "resolve_matches list names now has: " ${!resolve_matches[@]} -#log_it "resolve_matches list values now has: " ${resolve_matches[@]} return $RET_OKAY fi return $RET_FAIL @@ -267,41 +238,33 @@ log_it "after dir case addition, resolve targets are: " ${!resolve_target_array[ function recurse_on_deps { # snag arguments into a list of dependencies to crawl. local -a active_deps=($@) -log_it "active deps passed as: " ${active_deps[@]} +#log_it "active deps passed as: " ${active_deps[@]} # pull off the first dependency so we can get all of its includes. local first_element="${active_deps[0]}" -#log_it "first_element is $first_element" -#log_it "active_deps before truncate ${active_deps[@]}" active_deps=(${active_deps[@]:1}) -#log_it "active_deps is now ${active_deps[@]}" # make the best guess we can at the real path. if ! resolve_filename $first_element; then - log_it "** FAILED to resolve the filename for '$first_element'" + log_it "-- FAILED to resolve the filename for '$first_element'" return $RET_FAIL fi local -a indies=( ${!resolve_target_array[@]} ) local to_examine=${indies[0]} + if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then + log_it "resolved path to_examine is '$to_examine'" + fi - # we didn't already have a failure (due to it being a bad file already + # we didn't already see a failure (due to it being a bad file already # or other problems). and once we execute the below code to grab the - # file's dependencies, it really is boring and we never want to see it - # again. -log_it "resolved path to examine is '$to_examine'" - if [ -z "$to_examine" ]; then -#this shouldn't happen. - log_it "hit the resolve_target_array list being empty; are we done?" -echo "really think this shouldn't happen; if we got to here, it means we should have a non-empty to examine string." -exit 1 - return $RET_FAIL - fi + # file's dependencies, the file really will be boring and we never want + # to see it again in our processing. boring_files[$to_examine]=yawn local dirtmp=$(dirname "$to_examine") local basetmp=$(basename "$to_examine") - log_it "dependent on: $(basename "$dirtmp")/$basetmp" + log_it "++ dependent on: $(basename "$dirtmp")/$basetmp" #hmmm: do a better, nicer output--gather the dependencies listed in debugging # line above into a list that will be printed out at the end. @@ -319,8 +282,6 @@ exit 1 # find all the includes in this file and save to the temp file. while read -r spoon; do -# has_guard="$(echo "$spoon" | sed -n -e 's/#ifdef __BUILD_STATIC_APPLICATION__/yep/p')" -# if [ ! -z "$has_guard" ]; then if [[ $spoon == *"#ifdef __BUILD_STATIC_APPLICATION__"* ]]; then # quit reading when we've seen the start of one of our guards. break @@ -355,14 +316,11 @@ exit 1 # check whether the dependency looks like one of our style of includes. # if it doesn't have a slash in it, then we need to give it the same # directory as the file we're working on. -# local slash_present=$(echo $chew_toy | sed -n -e 's/.*[\\\/].*/yep/p') local slash_present="${chew_toy/[^\/]*/}" -# if [ ! -z "$(echo $chew_toy | sed -n -e 's/#include/crud/p')" ]; then if [[ $chew_toy == *"#include"* ]]; then # the replacement above to get rid of #include failed. try something # more inclusive, so we match double quote includes also. -# chew_toy=$(echo $line_found | sed -e 's/^[ \t]*#include *[">]\(.*\)[">].*$/\1/') chew_toy="${chew_toy#*\#include *[\"<]}" chew_toy="${chew_toy/[\">]*}" if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then @@ -372,8 +330,7 @@ exit 1 # if it still has an #include or if it's not really a file, we can't # use it for anything. if [[ $chew_toy == *"#include"* ]]; then -# if [ ! -z "$(echo $chew_toy | sed -n -e 's/#include/crud/p')" ]; then - log_it "** bad include: $chew_toy" + log_it "-- BAD include: $chew_toy" continue fi @@ -383,7 +340,7 @@ exit 1 if [ -z "$fp_dir" ]; then # well, now we have no recourse, since we don't know where to # say this file comes from. - log_it "** unknown directory: $chew_toy" + log_it "-- UNKNOWN directory: $chew_toy" else # cool, we can rely on the existing directory. chew_toy="$fp_dir/$chew_toy" @@ -405,17 +362,15 @@ exit 1 # make sure we can see this file already, or we will need to seek it out. if [ ! -f "$chew_toy" ]; then # not an obvious filename yet. try resolving it. -log_it "ARGH resolving this now: $chew_toy" resolve_filename $chew_toy declare -a found_odd=(${!resolve_target_array[@]}) local odd_len=${#found_odd[*]} if [ $odd_len -eq 0 ]; then # whoops. we couldn't find it. probably a system header, so toss it. - log_it "** ignoring missing file: $chew_toy" + log_it "-- ignoring missing file: $chew_toy" bad_files[$chew_toy]=yup chew_toy="" elif [ $odd_len -eq 1 ]; then -log_it "says this worked: '$chew_toy' found as '{found_odd[0]}'" # there's exactly one match, which is very good. chew_toy="${found_odd[0]}" if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then @@ -424,14 +379,14 @@ log_it "says this worked: '$chew_toy' found as '{found_odd[0]}'" else # this is really wrong. there are multiple files with the same name? # that kind of things makes debugger tools angry or stupid. - log_it "** non-unique name: $chew_toy" + log_it "-- NON-UNIQUE name: $chew_toy" bad_files[$chew_toy]=urf chew_toy="" fi fi if [ ! -z "$chew_toy" -a ! -f "$chew_toy" ]; then - log_it "** FAILED to compute a real path for: $chew_toy" + log_it "-- FAILED to compute a real path for: $chew_toy" bad_files[$chew_toy]=meh chew_toy="" continue @@ -442,7 +397,6 @@ log_it "says this worked: '$chew_toy' found as '{found_odd[0]}'" # hence the emptiness check. if [ ! -z "$chew_toy" ]; then # add the dependency we found. -log_it "point Q1: about to add new dep: $chew_toy" if add_new_dep "$chew_toy"; then # if that worked, it's not existing or bad so we want to keep it. if ! already_listed "$chew_toy" ${active_deps[*]}; then @@ -468,7 +422,6 @@ log_it "point Q1: about to add new dep: $chew_toy" # if the dependency actually exists, then we'll add it to our list. if [ ! -z "$found_it" ]; then -log_it "point Q2: about to add new dep: $found_it" if add_new_dep "$found_it"; then # that was a new dependency, so we'll continue examining it. if ! already_listed "$found_it" ${active_deps[*]}; then @@ -496,9 +449,9 @@ function write_new_version { local opening_guard_line="\n#ifdef __BUILD_STATIC_APPLICATION__\n // static dependencies found by buildor_gen_deps.sh:" local closing_guard_line="#endif // __BUILD_STATIC_APPLICATION__\n" - if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then - log_it "will write deps to: $code_file" - fi +# if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then + log_it "++ writing new dependencies to: $code_file" +# fi local base="$(basename "$code_file")" local replacement_file="$(mktemp $TEMPORARIES_PILE/zz_buildor_deps_replacement_${base}.XXXXXX)" @@ -515,7 +468,6 @@ function write_new_version { | sed -n -e 's/#ifdef __BUILD_STATIC_APPLICATION__/yep/p')" ]; then break fi -#echo "orig line is '$orig_line'" if [ -z "$orig_line" ]; then # add another blank line to our list and don't print any of them yet. blanks+=($'\n') @@ -537,11 +489,7 @@ function write_new_version { \rm -f "$pending_deps" # iterate across all the dependencies we found. -# for line_please in ${dependency_accumulator[@]}; do for line_please in "${!dependency_accumulator[@]}"; do - -log_it "line please is '$line_please'" - # throw out any items that are in the same directory we started in. if [ "$prohibited_directory" == "$(dirname $line_please)" ]; then if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then @@ -552,16 +500,16 @@ log_it "line please is '$line_please'" # strip the line down to just the filename and single directory component. local chewed_line=$(echo $line_please | sed -e 's/.*[\\\/]\(.*\)[\\\/]\(.*\)$/\1\/\2/') -#log_it "chewed line is '$chewed_line'" + # see if this matches the header file ending; we don't want to add those to the cpp code. if [[ "$chewed_line" =~ ^.*\.h$ ]]; then -#! -z "$(echo $chewed_line | sed -n -e 's/\.h$/yow/p')" ]; then if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then log_it "skipping header file: $chewed_line" fi continue fi + # this one seems like a good code file to add, so chuck it in there. local new_include=" #include <$chewed_line>" if [ ! -z "$DEBUG_BUILDOR_GEN_DEPS" ]; then log_it "adding '$new_include'" @@ -630,7 +578,7 @@ function find_dependencies { for curr_parm in $*; do - log_it "----------------------------------------------------------------------------" + echo "----------------------------------------------------------------------------" echo "" # resets the bad list in between sessions. @@ -677,10 +625,10 @@ for curr_parm in $*; do done <"$outfile" \rm -f "$outfile" else - log_it "** parameter is not a file or directory: $curr_parm" + log_it "-- parameter is not a file or directory: $curr_parm" fi - log_it "ignored these files: " ${!bad_files[@]} + log_it "++ ignored these files: " ${!bad_files[@]} echo "" echo "" -- 2.34.1