Skip to content
Snippets Groups Projects
repo.sh 4.65 KiB
Newer Older
Jeremy Soller's avatar
Jeremy Soller committed
#!/usr/bin/env bash
set -e
APPSTREAM="0"
Jeremy Soller's avatar
Jeremy Soller committed
recipes=""
    if [ "$arg" == "--appstream" ]
    then
        APPSTREAM="1"
    elif [ "$arg" == "--debug" ]
    elif [ "$arg" == "--nonstop" ]
    then
        set +e
Jeremy Soller's avatar
Jeremy Soller committed
        recipes+=" $arg"
Jeremy Soller's avatar
Jeremy Soller committed
if [ "$recipes" == "" ]
    recipes="$(target/release/list_recipes)"
# All $recipes that are in the new TOML format.
toml_recipes=""

    recipe_path=`target/release/find_recipe $recipe`
    COOKBOOK_RECIPE="$recipe_path"
    TARGET_DIR="${COOKBOOK_RECIPE}/target/${TARGET}"
    COOKBOOK_BUILD="${TARGET_DIR}/build"
    COOKBOOK_STAGE="${TARGET_DIR}/stage"
    COOKBOOK_SOURCE="${COOKBOOK_RECIPE}/source"
    COOKBOOK_SYSROOT="${TARGET_DIR}/sysroot"

    if [ -e "${COOKBOOK_RECIPE}/recipe.toml" ]
        toml_recipes+=" $recipe"
Jeremy Soller's avatar
Jeremy Soller committed
        target/release/cook "$recipe"
    if [ ! -d "${COOKBOOK_SOURCE}" ]
Jeremy Soller's avatar
Jeremy Soller committed
        echo -e "\033[01;38;5;155mrepo - fetching $recipe\033[0m" >&2
        ./cook.sh "$recipe" fetch
    fi

    if [ ! -d "${COOKBOOK_BUILD}" ]
Jeremy Soller's avatar
Jeremy Soller committed
        echo -e "\033[01;38;5;155mrepo - preparing $recipe\033[0m" >&2
        ./cook.sh "$recipe" prepare
    elif [ ! -d "${COOKBOOK_SYSROOT}" ]
    then
        echo -e "\033[01;38;5;155mrepo - repreparing $recipe\033[0m" >&2
        ./cook.sh "$recipe" unprepare prepare
        TIME_SOURCE="$($FIND "${COOKBOOK_SOURCE}" -type f -not -path '*/.git*' -printf "%Ts\n" | sort -nr | head -n 1)"
        TIME_BUILD="$($FIND "${COOKBOOK_BUILD}" -type f -not -path '*/.git*' -printf "%Ts\n" | sort -nr | head -n 1)"
Jeremy Soller's avatar
Jeremy Soller committed
        if [ "$TIME_SOURCE" -gt "$TIME_BUILD" ]
        then
            echo -e "\033[01;38;5;155mrepo - repreparing $recipe\033[0m" >&2
            ./cook.sh "$recipe" unprepare prepare
        fi
    fi

Jeremy Soller's avatar
Jeremy Soller committed
    if [ ! -f "${COOKBOOK_STAGE}.pkgar" ]
Jeremy Soller's avatar
Jeremy Soller committed
    then
        echo -e "\033[01;38;5;155mrepo - building $recipe\033[0m" >&2
Jeremy Soller's avatar
Jeremy Soller committed
        ./cook.sh "$recipe" build stage pkg $DEBUG
Jeremy Soller's avatar
Jeremy Soller committed
    else
        TIME_BUILD="$($FIND "${COOKBOOK_BUILD}" -type f -not -path '*/.git*' -printf "%Ts\n" | sort -nr | head -n 1)"
Jeremy Soller's avatar
Jeremy Soller committed
        TIME_STAGE="$($STAT -c "%Y" "${COOKBOOK_STAGE}.pkgar")"
        TIME_RECIPE="$($FIND "${COOKBOOK_RECIPE}"/{recipe.sh,*.patch} -printf '%Ts\n' | sort -nr | head -n 1)"
        if [ "$TIME_BUILD" -gt "$TIME_STAGE" -o "$TIME_RECIPE" -gt "$TIME_STAGE" ]
Jeremy Soller's avatar
Jeremy Soller committed
            echo -e "\033[01;38;5;155mrepo - rebuilding $recipe\033[0m" >&2
Jeremy Soller's avatar
Jeremy Soller committed
            ./cook.sh "$recipe" untar unstage build stage pkg $DEBUG
Jeremy Soller's avatar
Jeremy Soller committed
            echo -e "\033[01;38;5;155mrepo - $recipe up to date\033[0m" >&2
APPSTREAM_SOURCES=()

# Currently, we only support runtime dependencies for recipes in the new TOML
# format. Runtime dependencies include both `[package.dependencies]` and
# [`package.shared_deps`].
# 
# The following adds the package dependencies of the recipes to the repo as
# well.
#
# TODO(?): All of this script can be moved into `cook.rs`.
recipes="$recipes $(target/release/runtime_deps_of $toml_recipes)"

    recipe_path=`target/release/find_recipe $recipe`
    COOKBOOK_RECIPE="$recipe_path"
    TARGET_DIR="${COOKBOOK_RECIPE}/target/${TARGET}"
    COOKBOOK_STAGE="${TARGET_DIR}/stage"

    if [ "${COOKBOOK_STAGE}.pkgar" -nt "$REPO/$recipe.pkgar" ]
Jeremy Soller's avatar
Jeremy Soller committed
    then
        echo -e "\033[01;38;5;155mrepo - publishing $recipe\033[0m" >&2
        cp -v "${COOKBOOK_STAGE}.pkgar" "$REPO/$recipe.pkgar"
Jeremy Soller's avatar
Jeremy Soller committed
        cp -v "${COOKBOOK_STAGE}.toml" "$REPO/$recipe.toml"
Jeremy Soller's avatar
Jeremy Soller committed
    fi

    if [ -e "${COOKBOOK_STAGE}/usr/share/metainfo" ]
    then
        APPSTREAM_SOURCES+=("${COOKBOOK_STAGE}")
    fi
if [ "${APPSTREAM}" == "1" ]
then
    echo -e "\033[01;38;5;155mrepo - generating appstream data\033[0m" >&2

    APPSTREAM_ROOT="$ROOT/build/${TARGET}/appstream"
    APPSTREAM_PKG="$REPO/appstream.pkgar"
    rm -rf "${APPSTREAM_ROOT}" "${APPSTREAM_PKG}"
    mkdir -p "${APPSTREAM_ROOT}"
    if [ -n "${APPSTREAM_SOURCES}" ]
    then
        appstreamcli compose \
            --origin=pkgar \
            --result-root="${APPSTREAM_ROOT}" \
            "${APPSTREAM_SOURCES[@]}"
    fi
    pkgar create \
        --archive "${APPSTREAM_PKG}" \
        --skey "${ROOT}/build/id_ed25519.toml" \
        "${APPSTREAM_ROOT}"
fi

Jeremy Soller's avatar
Jeremy Soller committed
echo -e "\033[01;38;5;155mrepo - generating repo.toml\033[0m" >&2

echo "[packages]" > "$REPO/repo.toml"
for toml in "$REPO/"*".toml"
do
    package="$(basename "$toml" .toml)"
    if [ "$package" != "repo" ]
    then
        version="$(grep version "$toml" | cut -d '=' -f2-)"
        echo "$package =$version" >> "$REPO/repo.toml"
    fi
done