From 14bef92feb5cb2750caf5bee79c23f87b5999304 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Sat, 5 Mar 2016 15:15:50 -0500 Subject: [PATCH] Remove pinning of a package to a PACKAGE_TYPE. Previously a particular package could only ever be installed to target or native. Instead, allow any package to be installed to either, with target being the default. Native packages can only ever have native dependencies, but target packages can depend on native ones in order to install tools which they need for their build process. --- .gitignore | 1 + chocpkg/chocpkg | 46 +++++++++++++++++++++++------- chocpkg/modules/check_pkgconfig.sh | 2 +- chocpkg/modules/fetch_download.sh | 4 ++- chocpkg/modules/package_group.sh | 10 +++---- pkgdef/README.md | 9 ------ pkgdef/pkg-config.sh | 1 - 7 files changed, 45 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index a4dacd4..b64943e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ build +build.native install install.native packages diff --git a/chocpkg/chocpkg b/chocpkg/chocpkg index b654955..c50de1b 100755 --- a/chocpkg/chocpkg +++ b/chocpkg/chocpkg @@ -36,12 +36,15 @@ basic_setup() { PATH="$CHOCPKG_ROOT/chocpkg:$PATH" fi + PACKAGES_DIR="$CHOCPKG_ROOT/packages" INSTALL_DIR="$CHOCPKG_ROOT/install" NATIVE_INSTALL_DIR="$CHOCPKG_ROOT/install.native" - PACKAGES_DIR="$CHOCPKG_ROOT/packages" BUILD_DIR="$CHOCPKG_ROOT/build" + NATIVE_BUILD_DIR="$CHOCPKG_ROOT/build.native" - mkdir -p "$INSTALL_DIR" "$NATIVE_INSTALL_DIR" "$PACKAGES_DIR" "$BUILD_DIR" + mkdir -p "$PACKAGES_DIR" \ + "$INSTALL_DIR" "$NATIVE_INSTALL_DIR" \ + "$BUILD_DIR" "$NATIVE_BUILD_DIR" } basic_setup @@ -58,33 +61,55 @@ dependencies() { DEPENDENCIES+=" $*" } +dependencies_for_native() { + for dep in $DEPENDENCIES; do + if [[ "$PACKAGE_TYPE" = native ]] && ! [[ "$dep" =~ native: ]]; then + echo "native:$dep" + else + echo "$dep" + fi + done +} + # Given a package name, find the pkgdef file associated with it, source # the contents of the file and set various variables. configure_for_package() { local package=$1 + PACKAGE_NAME=$package + + # Detect native: prefix and set package type. + if [[ "$package" =~ ^native: ]]; then + PACKAGE_TYPE=native + package=${package/#native:/} + else + PACKAGE_TYPE=target + fi + + # Defaults before loading package file. + PACKAGE_DESCRIPTION="Package $package" + DEPENDENCIES="" + PACKAGE_DIR_NAME=$package + local pkg_file="$CHOCPKG_ROOT/pkgdef/$package.sh" if [ ! -e "$pkg_file" ]; then error_exit "Package file $package.sh not found." fi - # Defaults for package unless overridden: - PACKAGE_NAME=$package - PACKAGE_DIR_NAME=$package - PACKAGE_TYPE=target - PACKAGE_DESCRIPTION="Package $PACKAGE_NAME" - DEPENDENCIES="" . "$pkg_file" - PACKAGE_BUILD_DIR="$BUILD_DIR/$PACKAGE_DIR_NAME" - # We set up build differently depending on the package type: some packages # are for the target we're building for; others are native tools to run on # the build machine as part of the build process. case "$PACKAGE_TYPE" in target) PACKAGE_INSTALL_DIR="$INSTALL_DIR" + PACKAGE_BUILD_DIR="$BUILD_DIR/$PACKAGE_DIR_NAME" ;; native) PACKAGE_INSTALL_DIR="$NATIVE_INSTALL_DIR" + PACKAGE_BUILD_DIR="$NATIVE_BUILD_DIR/$PACKAGE_DIR_NAME" + # When installing a native package, all its dependencies are + # necessarily native as well. + DEPENDENCIES=$(dependencies_for_native) ;; package-group) ;; @@ -197,7 +222,6 @@ cmd_packages() { package_info() { printf "package: %s\n" "$PACKAGE_NAME" printf "description: %s\n" "$PACKAGE_DESCRIPTION" - printf "type: %s\n" "$PACKAGE_TYPE" printf "installed: " if chocpkg installed "$PACKAGE_NAME"; then diff --git a/chocpkg/modules/check_pkgconfig.sh b/chocpkg/modules/check_pkgconfig.sh index 6755eb3..5b02da3 100644 --- a/chocpkg/modules/check_pkgconfig.sh +++ b/chocpkg/modules/check_pkgconfig.sh @@ -4,7 +4,7 @@ check_pkgconfig::init() { # If we're using pkg-config to check, we need to install pkg-config # first. - dependencies pkg-config + dependencies native:pkg-config } # Function that returns true if the package is installed. diff --git a/chocpkg/modules/fetch_download.sh b/chocpkg/modules/fetch_download.sh index d8771c1..34ab0a1 100644 --- a/chocpkg/modules/fetch_download.sh +++ b/chocpkg/modules/fetch_download.sh @@ -26,7 +26,9 @@ extract_package_file() { mkdir -p "$PACKAGE_BUILD_DIR" cd "$PACKAGE_BUILD_DIR" else - cd "$BUILD_DIR" + local parent_dir=$(dirname "$PACKAGE_BUILD_DIR") + echo "cd to $parent_dir">/dev/stderr + cd "$parent_dir" fi (gunzip < "$dlfile" | tar -x) || ( mv "$dlfile" "$dlfile.bad" diff --git a/chocpkg/modules/package_group.sh b/chocpkg/modules/package_group.sh index 5625686..b880622 100644 --- a/chocpkg/modules/package_group.sh +++ b/chocpkg/modules/package_group.sh @@ -1,7 +1,7 @@ package_group::init() { PACKAGE_TYPE=package-group - PKGGRP_PACKAGES="$*" + dependencies "$@" } do_fetch() { @@ -18,20 +18,20 @@ do_build() { # Installing a package group means installing all its packages; we don't # trigger the build step like 'install' usually does (we don't have one). cmd_install() { - for package in $PKGGRP_PACKAGES; do + for package in $DEPENDENCIES; do chocpkg install "$package" done } # Reinstalling a package group means reinstalling *all* its packages. cmd_reinstall() { - for package in $PKGGRP_PACKAGES; do + for package in $DEPENDENCIES; do chocpkg reinstall "$package" done } cmd_dependencies() { - for package in $PKGGRP_PACKAGES; do + for package in $DEPENDENCIES; do echo "$package" chocpkg dependencies "$package" done | sort | uniq @@ -39,7 +39,7 @@ cmd_dependencies() { # Package group is installed if all its packages are installed. cmd_installed() { - for package in $PKGGRP_PACKAGES; do + for package in $DEPENDENCIES; do chocpkg installed "$package" done } diff --git a/pkgdef/README.md b/pkgdef/README.md index 4a9f4a2..feaa16d 100644 --- a/pkgdef/README.md +++ b/pkgdef/README.md @@ -95,15 +95,6 @@ dependencies other-package neato-lib package_group neato-lib dumbo-lib ``` -## Variables - -* `PACKAGE_TYPE`: has a value of either `native` or `target`. The - default is `target`. The variable controls whether the package is - built for the target system when doing cross-compiles, or whether it - is part of the build (native) system and just used to build tools as - part of the build process. The package type determines whether the - result is installed into `install` or `install.native`. - ## Advanced builds Complicated packages can require custom build steps. The following functions diff --git a/pkgdef/pkg-config.sh b/pkgdef/pkg-config.sh index 47c6545..b347162 100644 --- a/pkgdef/pkg-config.sh +++ b/pkgdef/pkg-config.sh @@ -1,4 +1,3 @@ -PACKAGE_TYPE=native description "Development tool for locating installed packages and libraries" check_tool pkg-config fetch_download https://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz