diff --git a/bin/dragon b/bin/dragon index cafb5bc7b..a37e4b16a 100644 --- a/bin/dragon +++ b/bin/dragon @@ -56,7 +56,6 @@ fi while ! [[ -z $1 ]]; do case $1 in - # -------- # Set Variables # -------- @@ -95,7 +94,8 @@ while ! [[ -z $1 ]]; do set -xv export DGEN_DEBUG=1 ;; - c | clean ) clean=1 + c | clean ) gen=1 + clean=1 ;; vn ) NINJA_ARGS="-v" ;; @@ -152,37 +152,59 @@ while ! [[ -z $1 ]]; do shift done + # -------- -# Build, then package (if needed) +# Generate project info # -------- -if [[ $build -eq 1 ]]; then - # shellcheck disable=SC2154 +if [[ $gen -eq 1 ]]; then # Invoke the generator - if [[ $gen -eq 1 ]]; then - rm -rf "$DRAGON_DATA_DIR/ninja/build.ninja" 2>/dev/null - mkdir -p "$DRAGON_DATA_DIR/"{ninja,modules} + # shellcheck disable=SC2154 + rm -rf "$DRAGON_DATA_DIR/ninja/build.ninja" 2>/dev/null + mkdir -p "$DRAGON_DATA_DIR/"{ninja,modules} - generate + generate - if [[ $DRAGONGEN_FAILURE -eq 1 ]]; then - cleanbuildfail - fi + if [[ $DRAGONGEN_FAILURE -eq 1 ]]; then + cleanbuildfail fi +fi + +get_subprojs() +{ set -f # If there's more than one project in the root directory we need to iterate by name. + # Relying on generator to obtain project info # shellcheck disable=SC2207 subsb=($(python3 -c "print('${project_dirs}' if ('${project_dirs}'.count('.')<2) else '${project_names}')")) set +f + for i in "${subsb[@]}"; do + echo "$i" + done +} + + +# -------- +# Clean project(s) +# -------- +if [[ $clean -eq 1 ]]; then + # clean subproj build dir(s) + get_subprojs | while read -r i; do + clean_dir $i + done + # ensure clean primary build dir + clean_dir . +fi + +# -------- +# Build, then package (if needed) +# -------- +if [[ $build -eq 1 ]]; then mkdir -p "$DRAGON_DATA_DIR" cp DragonMake "$DRAGON_DATA_DIR/DragonMake" 2> /dev/null - if [[ $clean -eq 1 && ! -f $DRAGON_DATA_DIR/.clean ]]; then - clean_dir $PWD - fi - - for i in "${subsb[@]}"; do + get_subprojs | while read -r i; do # Copy the DragonMake into the subproject's build directory # Primarily for bundle filter gen, right now. if [[ -d $i ]]; then @@ -203,17 +225,6 @@ if [[ $build -eq 1 ]]; then if [[ $norm -eq 0 ]]; then find . -name '*.ninja' -type f -delete fi -else - if [[ $gen -eq 1 ]]; then - rm -rf "$DRAGON_DATA_DIR/ninja/build.ninja" 2>/dev/null - mkdir -p "$DRAGON_DATA_DIR/"{ninja,modules} - - generate - - if [[ $DRAGONGEN_FAILURE -eq 1 ]]; then - cleanbuildfail - fi - fi fi @@ -236,6 +247,7 @@ if [[ $install -eq 1 && $DRAGON_DPKG -eq 1 ]]; then python3 -m dragon.device run ${INSTALL_CMD} || drexit fi + # -------- # On-device debugging # -------- @@ -246,6 +258,7 @@ if [[ $debug -eq 1 ]]; then ssh -p $DRBPORT root@$DRBIP "lldb -n $debugproc || killall lldb" || drexit fi + rm -rf "$DRAGON_DATA_DIR/packages" > /dev/null set +xv diff --git a/src/dragon/shscripts/building b/src/dragon/shscripts/building index 90ad7e6ba..9b29b7731 100644 --- a/src/dragon/shscripts/building +++ b/src/dragon/shscripts/building @@ -1,19 +1,34 @@ #!/usr/bin/env bash -clean_dir() +get_name() { - prefix_print "Cleaning $1" - if [[ -z $DRAGON_DIR ]]; then - drexit_reason "nil DRAGON_DIR" - fi - if [[ -f $DRAGON_DIR/DragonMake ]]; then - cp $DRAGON_DIR/DragonMake .DragonMake + if [[ $1 == "." ]]; then + i=$(basename $PWD) + else + i=$1 fi - rm -rf $DRAGON_DIR/* - if [[ -f .DragonMake ]]; then - mv .DragonMake $DRAGON_DIR/DragonMake + echo "$i" +} + +clean_dir() +{ + DNAME=$(get_name $1) + pushd $DNAME &> /dev/null + if ! [[ -f $DRAGON_DIR/.clean ]]; then + prefix_print "Cleaning $DNAME" + if [[ -z $DRAGON_DIR ]]; then + drexit_reason "nil DRAGON_DIR" + fi + if [[ -f $DRAGON_DIR/DragonMake ]]; then + cp $DRAGON_DIR/DragonMake .DragonMake + fi + rm -rf $DRAGON_DIR/* + if [[ -f .DragonMake ]]; then + mv .DragonMake $DRAGON_DIR/DragonMake + fi + touch $DRAGON_DIR/.clean fi - touch $DRAGON_DIR/.clean + popd &> /dev/null } validate_objcs() @@ -35,19 +50,10 @@ build() python3 -m dragongen.cliutils needsobjcs && validate_objcs - if [[ $1 == "." ]]; then - DNAME=${TWEAK_NAME} - else - DNAME=$1 - fi - - if [[ $clean -eq 1 && ! -f $DRAGON_DIR/.clean ]]; then - clean_dir $DNAME - fi - mkdir -p $DRAGON_DIR/_/.dragonbuilding $DRAGON_DIR/modules - prefix_print "Building ${DNAME}" + DNAME=$(get_name $1) + prefix_print "Building $DNAME" if ! [[ -e build.ninja ]]; then mv "${i}.ninja" build.ninja