summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Ball <nullspoon@oper.io>2017-06-29 23:44:20 -0600
committerAaron Ball <nullspoon@oper.io>2017-06-29 23:44:20 -0600
commitc7c50b6527999dca23444e97a027d839075c26ce (patch)
treebc9c6048d279f37a0deff784df61b134dc57f6e0
parent712c602b87f41f6f0e33a495ec39a943adcc966b (diff)
downloadportimg-c7c50b6527999dca23444e97a027d839075c26ce.tar.gz
portimg-c7c50b6527999dca23444e97a027d839075c26ce.tar.xz
Refactored pkgmk.sh and libpkg
libpkg: Removed pkg_download_src function. This one is superceeded by the new port_download_src. libpkg: Added pkg_setup_src. This function breaks out the src setup process during the build process away from the source download process. This will enable exclusively source downloads in the future, when the switch is implemented for that. Updated pkgmk.sh to use the new functions, with their new signatures. NOTE: This commit changes behavior of pkgmk. It is now required that the cwd to be the port's directory [that contains the Pkgfile] at runtime, rather than attempting to intelligently figure out what the user meant at runtime. If the cwd does not contain a Pkgfile, the build process is aborted.
-rwxr-xr-xbin/pkgmk.sh63
-rw-r--r--lib/pkg.sh71
2 files changed, 72 insertions, 62 deletions
diff --git a/bin/pkgmk.sh b/bin/pkgmk.sh
index e0f3d4f..3e7e091 100755
--- a/bin/pkgmk.sh
+++ b/bin/pkgmk.sh
@@ -31,33 +31,54 @@ export PORTSDIR=${PORTSDIR:-${BASEDIR}/ports}
export KEEP_BUILD=${KEEP_BUILD:-0}
function main {
- local _pkg=${1:-}
- [[ -z ${_pkg} ]] && lerror "A port name is required." && return 1
-
- local _porttmp # Path to the port build working directory
- local _pkgfile # Path to the port's Pkgfile
-
- _pkgfile="${PORTSDIR}/${_pkg}/Pkgfile"
-
- if [ ! -f ${_pkgfile} ]; then
- lerror "Could not find Pkgfile at ${_pkgfile}."
+ local _porttmp # Path to the port build working directory
+ local _portdir # Path to the port dir that contains the Pkgfile
+
+ local _pkgname # Pkgfile value for 'name'
+ local _pkgsource # Pkgfile value for 'source'
+ local _pkgversion # Pkgfile value for 'version'
+ local _pkgrelease # Pkgfile value for 'release'
+ local _pkgbuildname # Pkgfile composite of name, version, and release
+ local _porttmp # Temporary working directory to build the pkg
+
+ if [ ! -f Pkgfile ]; then
+ lerror "Could not find Pkgfile."
return 1
fi
- source ${_pkgfile}
+ _portdir="$(pwd)"
- # Set all these variables as the same variables will be set later by port
- # files
- _pkgname=${name} && unset 'name'
- _pkgdepends=("${depends[@]}") && unset 'depends[@]'
- _pkgversion=${version} && unset 'version'
- _pkgrelease=${release} && unset 'release'
+ # Include the port Pkgfile
+ source Pkgfile
+
+ # Set all these variables to local versions, to avoid possible overrides,
+ # conflicts, etc. when these are used later on.
+ _pkgname=${name}
+ _pkgsource=("${source[@]}")
+ _pkgversion=${version}
+ _pkgrelease=${release}
_pkgbuildname="${_pkgname}#${_pkgversion}_${_pkgrelease}"
- pkgmk ${_pkg} '_porttmp'
+
+ for _src in ${_pkgsource[@]}; do
+ # Download the package source files
+ port_download_src "_pkgsource[@]"
+ done
+
+
+ # Create the temporary build and packaging location
+ _porttmp=$(mktemp -d /tmp/pkgmk-${_pkgname}.XXXX)
+ mkdir -p ${_porttmp}/{pkg,src}
+
+ # Copy the sources into the build and packaging location
+ for _src in ${_pkgsource[@]}; do
+ pkg_setup_src "./" "${_porttmp}/src" "_pkgsource[@]"
+ done
+
+ pkgmk ${_pkgname} '_pkgsource[@]' "${_porttmp}"
[ $? -gt 0 ] && return 1
- linfo "Generating footprint file for ${_pkg}"
+ linfo "Generating footprint file for ${_pkgname}"
footprint_dir ${_porttmp}/pkg > ${_porttmp}/pkg.footprint
# linfo "Creating deployment tarball from ${_installbase}"
@@ -67,8 +88,8 @@ function main {
xz -v ${_porttmp}/pkg.tar
# # Move the package and footprint to current directory
- mv ${_porttmp}/pkg.tar.xz ${PORTSDIR}/${_pkg}/${_pkgbuildname}.tar.xz
- mv ${_porttmp}/pkg.footprint ${PORTSDIR}/${_pkg}/${_pkgbuildname}.footprint
+ mv -v ${_porttmp}/pkg.tar.xz ${_portdir}/${_pkgbuildname}.tar.xz
+ mv -v ${_porttmp}/pkg.footprint ${_portdir}/${_pkgbuildname}.footprint
# Cleanup if allowed
if [ "${KEEP_BUILD}" = 0 ]; then
diff --git a/lib/pkg.sh b/lib/pkg.sh
index cc11ee0..680ccb6 100644
--- a/lib/pkg.sh
+++ b/lib/pkg.sh
@@ -24,27 +24,32 @@ source ${LIBDIR}/port.sh # Basic port functions
export PORTSDIR=${PORTSDIR:-/usr/ports} # Path to port store
export PORTTMP='' # Path to the port temp dir
-function pkg_download_src {
- local _port=${1:-}
- local _pkgsrc=${2:-}
- shift && shift
- local _src=${@}
+#
+# @param _port_path Path to the port Pkgfile directory
+# @param _port_src_path Path to the port's working src directory for building
+# @param _src Ref to the source array for the given package
+#
+function pkg_setup_src {
+ local _port_path=${1:-}
+ local _port_src_path=${2:-}
+ local _ref_src=${3:-}
+
+ local _file_path
# Download from Pkgfile src spec
for file in ${_src[@]}; do
- if [[ -f ${file} ]]; then
- # If the source file exists locally, just copy from here
- cp -p ${file} ${_pkgsrc}
- else
- if [ -f $(basename ${file}) ]; then
- linfo "Source '${file}' already downloaded"
- else
- linfo "Downloading ${file}"
- download_src ${file} ${_port}
- fi
- linfo "Extracting $(basename ${file}) to ${_pkgsrc}"
- archive_extract ${_port}/$(basename ${file}) ${_pkgsrc}
+ if [ -f "${_port_path}/${file}" ]; then
+ # The referenced source file is a local path, so use that verbatim
+ _file_path="${_port_path}/${file}"
+ elif [ -f "${_port_path}/$(basename ${file})" ]; then
+ # The verbatim referenced source file path does not exist locally, so it
+ # is probably a uri. Get the basename of the path, and try to extract
+ # that.
+ _file_path="${_port_path}/$(basename ${file})"
fi
+ # Extract any local files to the pkg src path
+ linfo "Extracting $(basename ${file}) to ${_port_src_path}"
+ archive_extract "${_file_path}" "${_port_src_path}"
done
}
@@ -53,44 +58,28 @@ function pkg_download_src {
# TODO: Describe this
#
function pkgmk {
- local _port=${1:-}
- local _ref_porttmp=${2:-}
+ local _name=${1:-}
+ local _ref_source=${2:-}
+ local _porttmp=${3:-}
local _retval # Return value variable
- local _tmpdir # Temporary working directory to build the pkg
# NOTE: These are "global", so the Pkgfile can access them
local PKG # Path to the port pkg dir (binary install dest)
local PKGSRC # Path to the port src dir
-
- # Change context to port dir
- cd ${PORTSDIR}/${_port}
-
- # Include the port Pkgfile
- source Pkgfile
# Create the port build and install directory structure
- _tmpdir=$(mktemp -d /tmp/pkgmk-${_port}.XXXX)
- PKGSRC=${_tmpdir}/src
- PKG=${_tmpdir}/pkg
- mkdir -p {${PKGSRC},${PKG}}
-
- # Download the package source files
- pkg_download_src "${PORTSDIR}/${_port}" "${PKGSRC}" "${source[@]}"
+ PKGSRC=${_porttmp}/src
+ PKG=${_porttmp}/pkg
cd ${PKGSRC}
# Call the build process if defined
if [[ $(type -t pkgbuild) == 'function' ]]; then
- linfo "Running ${_port} build process"
+ linfo "Running ${_name} build process"
pkgbuild
- _retval=$?
-
- # Set the pkg temp dir (this is our return value)
- eval "${_ref_porttmp}=${_tmpdir}"
- return ${_retval}
+ return $?
else
- lerror "Port ${_port} has no pkgbuild function. Aborting."
- return 1
+ lerror "Port ${_name} has no pkgbuild function. Aborting."
fi
return 1

Generated by cgit