From: Ladislav Michl <[email protected]> Run ptxdist_bootstrap.sh on first use if PTXdist is neither installed nor configured in-tree. The PTXdist tree itself is never written to.
Concurrent PTXdist runs are serialized using lock file, host tools are prepared again if they were built for another PTXdist tree or a linked host tool vanished. Signed-off-by: Ladislav Michl <[email protected]> --- README | 13 ++++++-- bin/ptxdist | 86 +++++++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 84 insertions(+), 15 deletions(-) diff --git a/README b/README index debf098d8..5774e046a 100644 --- a/README +++ b/README @@ -20,9 +20,16 @@ to install it. When you start using PTXdist, make sure your $PATH environment variable points to <installpath>/bin, because that's where the PTXdist frontend program is being installed to. -For developers who want to work with git versions of PTXdist it is only -necessary to run "./autogen.sh && ./configure && make" and set the PATH -variable to the bin/ directory inside the PTXdist tree. +Installing is optional. PTXdist can be used directly from an unpacked +tarball or a git checkout, without any configure or build step: + + cd <your BSP> + /path/to/ptxdist/bin/ptxdist menuconfig + +On first use, PTXdist checks the host for everything it needs, reports +all missing tools at once, and builds kconfig in .ptxdist/<version>/ +(.ptxdist/git/ for git checkouts) inside the BSP. The PTXdist tree +itself is never written to. Idea ---- diff --git a/bin/ptxdist b/bin/ptxdist index 94c41412f..7b20026bb 100755 --- a/bin/ptxdist +++ b/bin/ptxdist @@ -2131,19 +2131,8 @@ setup_topdir() { ptxdist="$(_realpath "${0}")" && topdir="$(cd "$(dirname "${ptxdist}")"/.. && pwd)" || return - # - # sanity check: is PTXdist already configured? - # - if [ ! -e "${topdir}/.done" ]; then - echo - echo "${PTXDIST_LOG_PROMPT}error: PTXdist in ${topdir} is not built." - echo - exit 1 - fi - PTXDIST="${ptxdist}" PTXDIST_TOPDIR="${topdir}" - PTXDIST_HOSTTOOLS_DIR="${topdir}" PTXDIST_WORKSPACE="$(pwd)" eval PTXDIST_PTXCONFIG_DEFAULT="${PTXDIST_PTXCONFIG_DEFAULT}" @@ -2151,11 +2140,84 @@ setup_topdir() { eval PTXDIST_COLLECTIONCONFIG_DEFAULT="${PTXDIST_COLLECTIONCONFIG_DEFAULT}" eval PTXDIST_TOOLCHAIN_DEFAULT="${PTXDIST_TOOLCHAIN_DEFAULT}" - # ${PTXDIST_HOSTTOOLS_DIR}/bin contains links to sane tools found by configure + setup_hosttools || return + + # ${PTXDIST_HOSTTOOLS_DIR}/bin contains links to sane tools found on the host export PATH="${PTXDIST_HOSTTOOLS_DIR}/bin:${PATH}" } +# +# check that the host tools in ${1} are complete and built for this +# PTXdist, that no linked host tool vanished meanwhile and that the +# sources did not change since, e.g. after 'git pull' +# +_check_hosttools() { + local link + + [ "$(cat "${1}/.done" 2>/dev/null)" = "${PTXDIST_TOPDIR}" ] || return + for link in "${1}/bin/"*; do + [ -e "${link}" ] || return + done + [ -z "$(find "${PTXDIST_TOPDIR}/scripts/kconfig" \ + "${PTXDIST_TOPDIR}/scripts/ptxdist_bootstrap.sh" \ + -newer "${1}/.done" -print -quit)" ] +} + +# +# prepare the host tools (kconfig and links to sane tools) out-of-tree +# unless PTXdist is installed or configured in-tree. +# +# in: PTXDIST_TOPDIR +# PTXDIST_WORKSPACE +# out: PTXDIST_HOSTTOOLS_DIR +# +setup_hosttools() { + local hosttools version lock + + if [ -e "${PTXDIST_TOPDIR}/.done" ]; then + # installed or configured in-tree + PTXDIST_HOSTTOOLS_DIR="${PTXDIST_TOPDIR}" + return + fi + + source "${PTXDIST_TOPDIR}/scripts/ptxdist_version.sh" || return + + # like ptxdistrc: one for all git versions, they change with each commit + version="${PTXDIST_VERSION_FULL}" + if [ -n "${PTXDIST_VERSION_SCM}" ]; then + version=git + fi + + if [ -e "${PTXDIST_WORKSPACE}/selected_ptxconfig" -o \ + -e "${PTXDIST_WORKSPACE}/configs/ptxconfig" ]; then + hosttools="${PTXDIST_WORKSPACE}/.ptxdist/${version}" + else + # not in a BSP, e.g. 'ptxdist setup' + hosttools="${XDG_CACHE_HOME:-${HOME}/.cache}/ptxdist/${version}" + fi + PTXDIST_HOSTTOOLS_DIR="${hosttools}" + + if _check_hosttools "${hosttools}"; then + return + fi + + mkdir -p "$(dirname "${hosttools}")" && + exec {lock}>"${hosttools}.lock" && + flock "${lock}" || return + + # a concurrent PTXdist may have finished first + if ! _check_hosttools "${hosttools}"; then + echo "${PTXDIST_LOG_PROMPT}preparing host tools in '${hosttools}' ..." >&2 + rm -rf "${hosttools}" && + mkdir "${hosttools}" || return + "${BASH}" "${PTXDIST_TOPDIR}/scripts/ptxdist_bootstrap.sh" "${hosttools}" || exit 1 + fi + + exec {lock}>&- +} + + ensure_ptxrc() { local ptxrc tmpptxrc local rc_default="${PTXDIST_TOPDIR}/config/setup/ptxdistrc.default" -- 2.47.3
