Skip to content

Commit

Permalink
Allow clean by itself and properly clean root build dir
Browse files Browse the repository at this point in the history
  • Loading branch information
L1ghtmann committed Jan 13, 2024
1 parent cad2f69 commit a077127
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 50 deletions.
69 changes: 41 additions & 28 deletions bin/dragon
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ fi

while ! [[ -z $1 ]]; do
case $1 in

# --------
# Set Variables
# --------
Expand Down Expand Up @@ -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"
;;
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand All @@ -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
# --------
Expand All @@ -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

Expand Down
50 changes: 28 additions & 22 deletions src/dragon/shscripts/building
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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
Expand Down

0 comments on commit a077127

Please sign in to comment.