spiegel-keyman/resources/build/builder-report.sh
Marc Durdin f394245636 maint(common): consolidate builder scripts
Clarifies the confusing builder.inc.sh / build-utils.sh distinction by
giving the scripts more appropriate names. Most build scripts should use
builder-full.inc.sh; some helper scripts can use builder-basic.inc.sh.
Documented in resources/build/README.md.

Renames:
* resources/build/builder.inc.sh to resources/build/builder-full.inc.sh
* resources/build/build-utils.sh to resources/build/builder-basic.inc.sh

Other changes:
* Moves Android-specific functions out of builder-basic.inc.sh and into
  android/build.sh.
* Renames functions in builder-basic.inc.sh

More functions may be moved from builder-basic.inc.sh into utils.inc.sh
or other scripts in the future.

Fixes: #14065
Build-bot: build all
Test-bot: skip
2025-08-02 08:11:24 +10:00

103 lines
2.5 KiB
Bash
Executable file

#!/usr/bin/env bash
#
# Reports on all builder scripts in repo and builds a dependency tree
#
# Exit on command failure and when using unset variables:
set -eu
# Include some helper functions from resources
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
. "${THIS_SCRIPT%/*}/../../resources/build/builder-basic.inc.sh"
## END STANDARD BUILD SCRIPT INCLUDE
cd "$KEYMAN_ROOT"
builder_scripts=(`find . -name "build.sh" | xargs grep -l "builder_describe"`)
non_builder_scripts=(`find . -name "build.sh" | xargs grep -L "builder_describe"`)
declare -A dependencies
function get_script_dependencies() {
local script="${1#./}"
if [[ $script =~ "node_modules/" ]]; then
# we may get builder scripts copied into node_modules by npm
return 0
fi
script="${script%/build.sh}"
echo "$script"
local deps=`./$script/build.sh --builder-report-dependencies`
dependencies[$script]="$deps"
}
echo
echo "${COLOR_BLUE}## Locating builds${COLOR_RESET}"
echo
for e in "${builder_scripts[@]}"; do
get_script_dependencies "$e"
done
# Find top-level projects
root_dependencies=()
for e in "${!dependencies[@]}"; do
if [[ ! " ${dependencies[@]} " =~ " $e " ]]; then
root_dependencies+=($e)
fi
done
# Sort results
IFS=$'\n' root_dependencies=($(sort <<<"${root_dependencies[*]}")); unset IFS
IFS=$'\n' sorted_dependencies=($(sort <<<"${!dependencies[*]}")); unset IFS
# Print project dependency tree
function print_dependencies() {
local depth=$1
local name=$2
if (($depth > 0 )); then printf ' %.0s' $(seq 1 $depth); fi
echo "$name"
for e in ${dependencies[$name]}; do
if [[ -z $e ]]; then continue; fi
print_dependencies $((depth + 1)) $e
done
}
echo
echo "${COLOR_BLUE}## Project Dependency Tree${COLOR_RESET}"
echo
for e in "${root_dependencies[@]}"; do
print_dependencies 0 $e
echo
done
# Print list of all non-builder scripts
echo "${COLOR_BLUE}## Legacy build scripts (not using builder)${COLOR_RESET}"
echo
for e in "${non_builder_scripts[@]}"; do
scriptname="${e#./}"
if [[ $scriptname =~ "node_modules/" ]]; then
# we may get build.sh scripts copied into node_modules by npm
continue
fi
scriptname="${scriptname%/build.sh}"
echo "$scriptname"
done
# Print list of all projects and dependencies
echo
echo "${COLOR_BLUE}## All Projects and Dependencies${COLOR_RESET}"
echo
for e in "${sorted_dependencies[@]}"; do
echo "$e: ${dependencies[$e]}"
done
echo