tools: Add useful script to develop ports

This commit is contained in:
apio 2024-01-04 21:04:58 +01:00
parent 64a941dc18
commit f8cc093e17
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 187 additions and 76 deletions

1
.gitignore vendored
View File

@ -19,3 +19,4 @@ base/etc/skel/LICENSE
kernel/config.cmake kernel/config.cmake
ports/out/ ports/out/
ports/temp/ ports/temp/
ports/dev/

View File

@ -13,7 +13,7 @@ then
exit 1 exit 1
fi fi
export WORKDIR=$LUNA_ROOT/ports/temp/ export WORKDIR=${WORKDIR:-$LUNA_ROOT/ports/temp}
show_error() show_error()
{ {
@ -28,12 +28,14 @@ source ports/$PORT_NAME/PACKAGE
[ -z ${format+x} ] && show_error "error: The port's PACKAGE file does not have a 'format' key." [ -z ${format+x} ] && show_error "error: The port's PACKAGE file does not have a 'format' key."
[ -z ${url+x} ] && show_error "error: The port's PACKAGE file does not have a 'url' key." [ -z ${url+x} ] && show_error "error: The port's PACKAGE file does not have a 'url' key."
if [ -x ${skip_dependencies+x} ]; then
if ! [ -z ${dependencies+x} ]; then if ! [ -z ${dependencies+x} ]; then
echo "Installing dependencies of $name: (${dependencies[@]})" echo "Installing dependencies of $name: (${dependencies[@]})"
for dep in ${dependencies[@]}; do for dep in ${dependencies[@]}; do
tools/install-package.sh $dep tools/install-package.sh $dep
done done
fi fi
fi
export portdir=$LUNA_ROOT/ports/$name/ export portdir=$LUNA_ROOT/ports/$name/
export srcdir=${srcdir:-$WORKDIR/$name-$version} export srcdir=${srcdir:-$WORKDIR/$name-$version}
@ -43,6 +45,7 @@ export installdir=$WORKDIR/pkgroot-$name
mkdir -p $WORKDIR mkdir -p $WORKDIR
cd $WORKDIR cd $WORKDIR
if [ -z ${skip_download_sources+x} ]; then
# Download package sources # Download package sources
case $format in case $format in
tar) tar)
@ -74,6 +77,7 @@ case $format in
show_error "error: Unrecognized 'format' key in PACKAGE file: '$format'" show_error "error: Unrecognized 'format' key in PACKAGE file: '$format'"
;; ;;
esac esac
fi
if ! [ "$set_cc_variables" = "no" ]; then if ! [ "$set_cc_variables" = "no" ]; then
export CC=x86_64-luna-gcc export CC=x86_64-luna-gcc
@ -89,8 +93,11 @@ fi
mkdir -p $builddir mkdir -p $builddir
cd $builddir cd $builddir
if [ -z ${skip_patch+x} ]; then
declare -F do_patch &>/dev/null && do_patch declare -F do_patch &>/dev/null && do_patch
fi
if [ -z ${skip_configure+x} ]; then
echo "Configuring $name..." echo "Configuring $name..."
if [ "$use_default_configure" = "true" ]; then if [ "$use_default_configure" = "true" ]; then
@ -101,7 +108,9 @@ else
declare -F do_configure &>/dev/null || show_error "error: If not using a default configure line, the PACKAGE file must provide a 'do_configure' function." declare -F do_configure &>/dev/null || show_error "error: If not using a default configure line, the PACKAGE file must provide a 'do_configure' function."
do_configure do_configure
fi fi
fi
if [ -z ${skip_build+x} ]; then
echo "Building $name..." echo "Building $name..."
export MAKEJOBS=$(nproc) export MAKEJOBS=$(nproc)
@ -114,9 +123,12 @@ else
declare -F do_build &>/dev/null || show_error "error: If not using a default build preset, the PACKAGE file must provide a 'do_build' function." declare -F do_build &>/dev/null || show_error "error: If not using a default build preset, the PACKAGE file must provide a 'do_build' function."
do_build do_build
fi fi
fi
if [ -z ${skip_install+x} ]; then
echo "Installing $name..." echo "Installing $name..."
rm -rf $installdir # clean it if it already existed
mkdir -p $installdir mkdir -p $installdir
export DESTDIR=$installdir export DESTDIR=$installdir
@ -137,6 +149,9 @@ set -e
cd $installdir cd $installdir
tar czf $LUNA_ROOT/ports/out/$name-$version.tar.gz * tar czf $LUNA_ROOT/ports/out/$name-$version.tar.gz *
fi
if [ -z ${preserve_workdir+x} ]; then
cd $LUNA_ROOT cd $LUNA_ROOT
rm -rf $WORKDIR rm -rf $WORKDIR
fi

95
tools/package-helper.sh Executable file
View File

@ -0,0 +1,95 @@
#!/usr/bin/env bash
set -e
source $(dirname $0)/env.sh
cd $LUNA_ROOT
SUBCOMMAND=$1
PORT_NAME=$2
if [ "$SUBCOMMAND" = "help" ]; then
echo "TODO: add help"
exit 1
fi
if ! [ -f ports/$PORT_NAME/PACKAGE ]
then
echo "Package $PORT_NAME does not exist. Make sure there is a valid PACKAGE file in the appropriate directory!"
exit 1
fi
source ports/$PORT_NAME/PACKAGE
export preserve_workdir=1
export WORKDIR=$LUNA_ROOT/ports/dev
case $SUBCOMMAND in
download)
export skip_configure=1
export skip_build=1
export skip_install=1
export skip_dependencies=1
export skip_patch=1
tools/make-package.sh $PORT_NAME
if [ "$format" = "tar" ]; then
cd ${srcdir:-$WORKDIR/$name-$version}
git init
git add .
git commit -m "Temporary development git repository for diffs."
cd $LUNA_ROOT
fi
echo "Created dev source tree in ${srcdir:-$WORKDIR/$name-$version}."
;;
setup-dependencies)
export skip_download_sources=1
export skip_build=1
export skip_install=1
export skip_configure=1
export skip_patch=1
tools/make-package.sh $PORT_NAME
;;
patch)
export skip_download_sources=1
export skip_build=1
export skip_install=1
export skip_configure=1
export skip_dependencies=1
tools/make-package.sh $PORT_NAME
;;
configure)
export skip_download_sources=1
export skip_build=1
export skip_install=1
export skip_dependencies=1
export skip_patch=1
tools/make-package.sh $PORT_NAME
;;
compile)
export skip_download_sources=1
export skip_configure=1
export skip_dependencies=1
export skip_patch=1
tools/make-package.sh $PORT_NAME
echo "Packaged dev build as $LUNA_ROOT/ports/out/$name-$version.tar.gz. Install it using tools/install-package.sh."
;;
generate-diff)
cd ${srcdir:-$WORKDIR/$name-$version}
git diff > $LUNA_ROOT/ports/$name/$name.patch
echo "Created $LUNA_ROOT/ports/$name/$name.patch. Remember to add patching code to the PACKAGE file!"
;;
cleanup)
rm -rfv $WORKDIR/*$name*
;;
*)
echo "No such subcommand. Run 'tools/package-helper.sh help $name' for help."
;;
esac