Start support for sourceless tasks

This commit is contained in:
southerntofu 2020-09-17 15:25:42 +02:00
parent fcb60d97b9
commit bc4e4c1180
1 changed files with 15 additions and 11 deletions

View File

@ -97,7 +97,7 @@ run() {
# Overriden by -f/--force to force rebuild when no update is available # Overriden by -f/--force to force rebuild when no update is available
FORCE=0 FORCE=0
# Find targeted projects from args and extra arguments # Find targeted projects and extra flags from args
PROJECTS=() PROJECTS=()
BASEDIR="$HOME/.forgebuild" BASEDIR="$HOME/.forgebuild"
FOUND_BASEDIR=0 FOUND_BASEDIR=0
@ -114,13 +114,12 @@ for arg in "$@"; do
FORCE=1 FORCE=1
elif [[ "$arg" = "-b" ]] || [[ "$arg" = "--basedir" ]]; then elif [[ "$arg" = "-b" ]] || [[ "$arg" = "--basedir" ]]; then
FOUND_BASEDIR=1 FOUND_BASEDIR=1
# Maybe it's a task name and we find a corresponding source? elif [ -x $BASEDIR/$arg ]; then
# TODO: Support source-less tasks https://tildegit.org/southerntofu/git-build.sh/issues/8
elif [ -f $BASEDIR/$arg.source ]; then
export i18n_task="$arg" export i18n_task="$arg"
debug found_task debug found_task
PROJECTS+=("$arg") PROJECTS+=("$arg")
# Maybe it's a repo URL and we find a corresponding task? # Maybe it's a repo URL and we find a corresponding task?
# TODO: maybe remove this? multiple URLs can point to the same repo so..
elif matches="$(grep --files-with-matches --word-regexp "$arg" $BASEDIR/*.source)"; then elif matches="$(grep --files-with-matches --word-regexp "$arg" $BASEDIR/*.source)"; then
# Iterate over the files found to extract the task name # Iterate over the files found to extract the task name
IFS= echo "$matches" | while read -r file; do IFS= echo "$matches" | while read -r file; do
@ -151,8 +150,9 @@ echo "$BASHPID" > $BASEDIR/.LOCK
# If no project argument passed, default to all projects # If no project argument passed, default to all projects
if [[ ${#PROJECTS[*]} = 0 ]]; then if [[ ${#PROJECTS[*]} = 0 ]]; then
info no_task info no_task
# TODO: sourceless tasks for file in $BASEDIR/*; do
for file in $BASEDIR/*.source; do # Skip non-executable files
[ ! -x $file ] && continue
# Extract the project name from path # Extract the project name from path
task="$(basename $file .source)" task="$(basename $file .source)"
export i18n_task="$task" export i18n_task="$task"
@ -161,16 +161,11 @@ if [[ ${#PROJECTS[*]} = 0 ]]; then
done done
fi fi
# Check if we have host-specific config or default to the config/ folder # Check if we have host-specific config or default to the config/ folder
[ -d $BASEDIR/$HOSTNAME ] && CONFDIR="$BASEDIR/$HOSTNAME" || CONFDIR=$BASEDIR/config [ -d $BASEDIR/$HOSTNAME ] && CONFDIR="$BASEDIR/$HOSTNAME" || CONFDIR=$BASEDIR/config
export i18n_config="$CONFDIR" export i18n_config="$CONFDIR"
info config info config
# TODO: sourceless tasks
for p_name in ${PROJECTS[*]}; do for p_name in ${PROJECTS[*]}; do
# For translations # For translations
export i18n_task="$p_name" export i18n_task="$p_name"
@ -190,6 +185,15 @@ for p_name in ${PROJECTS[*]}; do
continue continue
fi fi
info process info process
# Before we clone/checkout the source, maybe it's a sourceless task?
if [ ! -f $BASEDIR/$p_name.source ]; then
# If $p_name.done exists, the task was already run
[ -f $BASEDIR/$p_name.done ] && continue
run $p_name
continue
fi
# checkout a specific branch/commit # checkout a specific branch/commit
if [ -f $BASEDIR/$p_name.checkout ]; then if [ -f $BASEDIR/$p_name.checkout ]; then
p_branch="$(cat $BASEDIR/$p_name.checkout)" p_branch="$(cat $BASEDIR/$p_name.checkout)"