Skip to content

Commit

Permalink
Ports: Switch to new ports system (SerenityOS#594)
Browse files Browse the repository at this point in the history
Much redundancy is removed from package scripts with this system.
It also supports simple dependency management, uninstalling (through
BSD ports style plist files), cleaning up after itself (with clean,
clean_dist, clean_all commands), etc.
  • Loading branch information
larb0b authored and awesomekling committed Sep 24, 2019
1 parent d5f1c57 commit 18249b5
Show file tree
Hide file tree
Showing 47 changed files with 6,557 additions and 422 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ Toolchain/Local
compile_commands.json
.clang_complete
*Endpoint.h
Ports/packages.db
278 changes: 181 additions & 97 deletions Ports/.port_include.sh
Original file line number Diff line number Diff line change
@@ -1,123 +1,207 @@
#!/bin/sh

# This script contains common helpers for all ports.
set -e

export CC=i686-pc-serenity-gcc
export CXX=i686-pc-serenity-g++

if [ -z "$MAKEOPTS" ]; then
MAKEOPTS="-j $(nproc)"
fi
if [ -z "$INSTALLOPTS" ]; then
INSTALLOPTS=""
fi
#!/bin/bash
if [ -z "$SERENITY_ROOT" ]; then
echo "You must have source'd UseIt.sh to build any ports!"
echo "You must source UseIt.sh to build ports."
exit 1
fi
set -eu
prefix=$(pwd)/..

if [ -z "$PORT_DIR" ]; then
echo "Must set PORT_DIR to where the source should be cloned."
exit 1
fi
export CC=i686-pc-serenity-gcc
export CXX=i686-pc-serenity-g++

run_command() {
echo "+ $@"
(cd "$PORT_DIR" && "$@")
echo "+ FINISHED: $@"
}
. "$@"
shift

: "${makeopts:=-j$(nproc)}"
: "${installopts:=}"
: "${workdir:=$port-$version}"
: "${configscript:=configure}"
: "${configopts:=}"
: "${useconfigure:=false}"
: "${depends:=}"
: "${patchlevel:=1}"

run_command_nocd() {
run_nocd() {
echo "+ $@ (nocd)"
("$@")
echo "+ FINISHED (nocd): $@"
}

run_fetch_git() {
if [ -d "$PORT_DIR/.git" ]; then
run_command git fetch
run_command git reset --hard FETCH_HEAD
run_command git clean -fx
else
run_command_nocd git clone "$1" "$PORT_DIR"
fi
run() {
echo "+ $@"
(cd "$workdir" && "$@")
}

run_fetch_web() {
if [ -d "$PORT_DIR" ]; then
run_command_nocd rm -rf "$PORT_DIR"
run_replace_in_file(){
run perl -p -i -e "$1" $2
}
# Checks if a function is defined. In this case, if the function is not defined in the port's script, then we will use our defaults. This way, ports don't need to include these functions every time, but they can override our defaults if needed.
func_defined() {
PATH= command -V "$1" > /dev/null 2>&1
}
func_defined fetch || fetch() {
OLDIFS=$IFS
IFS=$'\n'
for f in $files; do
IFS=$OLDIFS
read url filename <<< $(echo "$f")
run_nocd curl ${curlopts:-} "$url" -o "$filename"
case "$filename" in
*.tar*|.tbz*|*.txz|*.tgz)
run_nocd tar xf "$filename"
;;
*.gz)
run_nocd gunzip "$filename"
;;
*)
echo "Note: no case for file $filename."
;;
esac
done
if [ -d patches ]; then
for f in patches/*; do
run patch -p"$patchlevel" < "$f"
done
fi
file=$(basename "$1")
run_command_nocd curl -L "$1" -o "$file"
mkdir "$PORT_DIR"

# may need to make strip-components configurable, as I bet some sick person
# out there has an archive that isn't in a directory :shrug:
run_command_nocd tar xavf "$file" -C "$PORT_DIR" --strip-components=1
}

run_export_env() {
export $1="$2"
func_defined configure || configure() {
run ./"$configscript" --host=i686-pc-serenity $configopts
}

run_replace_in_file() {
run_command perl -p -i -e "$1" $2
func_defined build || build() {
run make $makeopts
}

run_patch() {
echo "+ Applying patch $1"
run_command patch "$2" < "$1"
func_defined install || install() {
run make DESTDIR="$SERENITY_ROOT"/Root $installopts install
}

run_configure_cmake() {
run_command cmake -DCMAKE_TOOLCHAIN_FILE="$SERENITY_ROOT/Toolchain/CMakeToolchain.txt" $CMAKEOPTS .
func_defined clean || clean() {
rm -rf "$workdir" *.out
}

run_configure_autotools() {
run_command ./configure --host=i686-pc-serenity "$@"
func_defined clean_dist || clean_dist() {
OLDIFS=$IFS
IFS=$'\n'
for f in $files; do
IFS=$OLDIFS
read url filename hash <<< $(echo "$f")
rm -f "$filename"
done
}

run_make() {
run_command make $MAKEOPTS "$@"
func_defined clean_all || clean_all() {
rm -rf "$workdir" *.out
OLDIFS=$IFS
IFS=$'\n'
for f in $files; do
IFS=$OLDIFS
read url filename hash <<< $(echo "$f")
rm -f "$filename"
done
}

run_make_install() {
run_command make $INSTALLOPTS install "$@"
addtodb() {
if [ ! -f "$prefix"/packages.db ]; then
echo "Note: $prefix/packages.db does not exist. Creating."
touch "$prefix"/packages.db
fi
if ! grep -E "^(auto|manual) $port $version" "$prefix"/packages.db > /dev/null; then
echo "Adding $port $version to database of installed ports!"
if [ "${1:-}" = "--auto" ]; then
echo "auto $port $version" >> "$prefix"/packages.db
else
echo "manual $port $version" >> "$prefix"/packages.db
if [ ! -z "${dependlist:-}" ]; then
echo "dependency $port$dependlist" >> "$prefix/packages.db"
fi
fi
else
>&2 echo "Warning: $port $version already installed. Not adding to database of installed ports!"
fi
}

run_send_to_file() {
echo "+ rewrite '$1'"
(cd "$PORT_DIR" && echo "$2" > "$1")
echo "+ FINISHED"
installdepends() {
for depend in $depends; do
dependlist="${dependlist:-} $depend"
done
for depend in $depends; do
if ! grep "$depend" "$prefix"/packages.db > /dev/null; then
(cd "../$depend" && ./package.sh --auto)
fi
done
}

if [ -z "$1" ]; then
echo "+ Fetching..."
uninstall() {
if grep "^manual $port " "$prefix"/packages.db > /dev/null; then
if [ -f plist ]; then
for f in `cat plist`; do
case $f in
*/)
run rmdir "$prefix"/$f || true
;;
*)
run rm -rf "$prefix"/$f
;;
esac
done
# Without || true, mv will not be executed if you are uninstalling your only remaining port.
grep -v "^manual $port " "$prefix"/packages.db > packages.dbtmp || true
mv packages.dbtmp "$prefix"/packages.db
else
>&2 echo "Error: This port does not have a plist yet. Cannot uninstall."
fi
else
>&2 echo "Error: $port is not installed. Cannot uninstall."
fi
}
do_fetch() {
installdepends
echo "Fetching $port!"
fetch
echo "+ Configuring..."
configure
echo "+ Building..."
}
do_configure() {
if [ "$useconfigure" = "true" ]; then
echo "Configuring $port!"
configure
else
echo "This port does not use a configure script. Skipping configure step."
fi
}
do_build() {
echo "Building $port!"
build
echo "+ Installing..."
}
do_install() {
echo "Installing $port!"
install
exit 0
fi
addtodb "${1:-}"
}
do_clean() {
echo "Cleaning workdir and .out files in $port!"
clean
}
do_clean_dist() {
echo "Cleaning dist in $port!"
clean_dist
}
do_clean_all() {
echo "Cleaning all in $port!"
clean_all
}
do_uninstall() {
echo "Uninstalling $port!"
uninstall
}
do_all() {
do_fetch
do_configure
do_build
do_install "${1:-}"
}

if [ "$1" = "fetch" ]; then
echo "+ Fetching..."
fetch
elif [ "$1" = "configure" ]; then
echo "+ Configuring..."
configure
elif [ "$1" = "build" ]; then
echo "+ Building..."
build
elif [ "$1" = "install" ]; then
echo "+ Installing..."
install
if [ -z "${1:-}" ]; then
do_all
else
echo "Unknown verb: $1"
echo "Supported: (one of) fetch configure build install"
exit 1
case "$1" in
fetch|configure|build|install|clean|clean_dist|clean_all|uninstall)
do_$1
;;
--auto)
do_all $1
;;
*)
>&2 echo "I don't understand $1! Supported arguments: fetch, configure, build, install, clean, clean_dist, clean_all, uninstall."
exit 1
;;
esac
fi
6 changes: 3 additions & 3 deletions Ports/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

Serenity has software patched to run on it.
These shell scripts will allow you to build that sort of software, easily.
For example, if you want to install SDL2, simply run the SDL2.sh script.
For example, if you want to install SDL2, simply run its package.sh script.
Note that you should have already built Serenity, and be in a Serenity build environment.

# Using ports scripts

To do everything, just run the script: `./SDL2.sh`
To do a single step, you can specify it: `./SDL2.sh build`
To do everything, just run the script: `./package.sh`
To do a single step, you can specify it: `./package.sh build`

# How do I contribute?

Expand Down
16 changes: 0 additions & 16 deletions Ports/SDL2/SDL2.sh

This file was deleted.

12 changes: 12 additions & 0 deletions Ports/SDL2/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash ../.port_include.sh
port=SDL2
version=serenity-git
workdir=SDL-master-serenity
useconfigure=true
curlopts="-L"
files="https://github.com/SerenityOS/SDL/archive/master-serenity.tar.gz SDL2-git.tar.gz"
configopts="-DCMAKE_TOOLCHAIN_FILE=$SERENITY_ROOT/Toolchain/CMakeToolchain.txt -DPULSEAUDIO=OFF"

configure() {
run cmake $configopts
}
28 changes: 0 additions & 28 deletions Ports/bash/bash.sh

This file was deleted.

12 changes: 12 additions & 0 deletions Ports/bash/package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash ../.port_include.sh
port=bash
version=5.0
useconfigure=true
configopts="--disable-nls --without-bash-malloc"
files="https://ftp.gnu.org/gnu/bash/bash-5.0.tar.gz bash-5.0.tar.gz"

build() {
run_replace_in_file "s/define GETCWD_BROKEN 1/undef GETCWD_BROKEN/" config.h
run_replace_in_file "s/define CAN_REDEFINE_GETENV 1/undef CAN_REDEFINE_GETENV/" config.h
run make $makeopts
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 18249b5

Please sign in to comment.