176 lines
3.8 KiB
Fish
176 lines
3.8 KiB
Fish
function build
|
|
argparse 'h/help' 'c/compiler=' 's/subcommand=' 'f/features=?' 'n/nightly' 'r/release' 'repository=' 'host=' 'd/destination=?' -- $argv
|
|
or return
|
|
|
|
if set -ql _flag_help
|
|
echo 'Remote build tool'
|
|
echo -e '\nUsage: build [VALUES] [OPTIONS]'
|
|
|
|
echo -e '\nValues:'
|
|
echo -e ' -c, --compiler [cargo|make]\tSpecify which compiler to use'
|
|
echo -e ' -s, --subcommand <SUBCOMMAND>\tSpecify a subcommand for the compiler'
|
|
echo -e ' --repository <REPO>\tThe git repository URL to clone from'
|
|
echo -e ' --host <HOST>\tThe remote SSH host'
|
|
|
|
echo -e '\nOptions:'
|
|
echo -e ' -f, --features=<FEATURES>\tcargo only - specify build features'
|
|
echo -e ' -d, --destination=<PATH>\tLocal path for the copied binary (default .)'
|
|
echo -e ' -n, --nightly\tcargo only - specify nightly rust'
|
|
echo -e ' -r, --release\tcargo only - specify to build in release mode (default debug)'
|
|
return 0
|
|
end
|
|
|
|
if set -ql _flag_host
|
|
set -x HOST $_flag_host
|
|
else
|
|
set_color red
|
|
echo 'A host must be specified!'
|
|
return 1
|
|
end
|
|
|
|
if set -ql _flag_repository
|
|
echo -n 'Cloning from '
|
|
set_color green
|
|
echo $_flag_repository
|
|
set_color white
|
|
|
|
set -x REPOSITORY $_flag_repository
|
|
else
|
|
set_color red
|
|
echo 'A git repository must be specified!'
|
|
return 1
|
|
end
|
|
|
|
set -x BASENAME $(basename $REPOSITORY | sed 's/.git//g')
|
|
|
|
switch $_flag_compiler
|
|
case 'cargo'
|
|
set -x COMPILER $_flag_compiler
|
|
set -x SUBCOMMAND $_flag_subcommand
|
|
if set -ql _flag_features
|
|
echo -n 'Using '
|
|
set_color blue
|
|
echo -n 'cargo '
|
|
set_color white
|
|
echo -n 'with features '
|
|
set_color cyan
|
|
echo $_flag_features
|
|
set_color white
|
|
|
|
set -x FEATURES $_flag_features
|
|
else
|
|
echo -n 'Using '
|
|
set_color blue
|
|
echo 'cargo'
|
|
set_color white
|
|
end
|
|
|
|
if set -ql _flag_nightly
|
|
echo -n 'Using '
|
|
set_color magenta
|
|
echo -n 'nightly '
|
|
set_color white
|
|
echo 'rust'
|
|
|
|
set -x NIGHTLY true
|
|
else
|
|
set -x NIGHTLY false
|
|
end
|
|
|
|
if set -ql _flag_release
|
|
echo -n 'Building in '
|
|
set_color blue
|
|
echo -n 'release '
|
|
set_color white
|
|
echo 'mode'
|
|
|
|
set -x RELEASE true
|
|
else
|
|
echo -n 'Building in '
|
|
set_color blue
|
|
echo -n 'debug '
|
|
set_color white
|
|
echo 'mode'
|
|
|
|
set -x RELEASE false
|
|
end
|
|
|
|
if $RELEASE
|
|
set -x BINARY_PATH '~/src/'$BASENAME'/target/release/'$BASENAME
|
|
else
|
|
set -x BINARY_PATH '~/src/'$BASENAME'/target/debug/'$BASENAME
|
|
end
|
|
|
|
# TODO: Add colours
|
|
case 'make'
|
|
echo 'Using make...'
|
|
set -x COMPILER $_flag_compiler
|
|
set -x SUBCOMMAND $_flag_subcommand
|
|
if set -ql _flag_features
|
|
set_color red
|
|
echo 'make compiler does not support features'
|
|
return 1
|
|
end
|
|
|
|
if set -ql _flag_nightly
|
|
set_color red
|
|
echo 'make does not support nightly features!'
|
|
return 1
|
|
end
|
|
if set -ql _flag_release
|
|
set_color red
|
|
echo 'make does not support release mode!'
|
|
return 1
|
|
end
|
|
case '*'
|
|
set_color red
|
|
echo 'Unknown compiler!'
|
|
return 1
|
|
end
|
|
|
|
|
|
if set -ql FEATURES
|
|
if $RELEASE
|
|
set -x BUILD_COMMAND $COMPILER $SUBCOMMAND '--release --features' $FEATURES
|
|
else
|
|
set -x BUILD_COMMAND $COMPILER $SUBCOMMAND '--features' $FEATURES
|
|
end
|
|
|
|
echo -ne '\nRunning: '
|
|
set_color green
|
|
echo -ne $BUILD_COMMAND
|
|
set_color white
|
|
echo -e '\n'
|
|
|
|
set -xl COMMANDS 'cd ~/src; git clone' $REPOSITORY '; cd ' $BASENAME '; ' $BUILD_COMMAND
|
|
ssh -t $HOST $COMMANDS
|
|
else
|
|
if $RELEASE
|
|
set -x BUILD_COMMAND $COMPILER $SUBCOMMAND '--release'
|
|
else
|
|
set -x BUILD_COMMAND $COMPILER $SUBCOMMAND
|
|
end
|
|
|
|
echo -ne '\nRunning: '
|
|
set_color green
|
|
echo -ne $BUILD_COMMAND
|
|
set_color white
|
|
echo -e '\n'
|
|
|
|
set -xl COMMANDS 'cd ~/src; git clone' $REPOSITORY '; cd ' $BASENAME '; ' $BUILD_COMMAND
|
|
ssh -t $HOST $COMMANDS
|
|
end
|
|
|
|
|
|
echo -ne '\nFetching binary from: '
|
|
set_color green
|
|
echo $BINARY_PATH
|
|
set_color white
|
|
|
|
if set -ql _flag_destination
|
|
scp $HOST:$BINARY_PATH $_flag_destination
|
|
else
|
|
scp $HOST:$BINARY_PATH .
|
|
end
|
|
end
|