mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Ladislav Michl <oss-lists@triops.cz>
To: ptxdist@pengutronix.de
Subject: [ptxdist] [PATCH 3/6] ptxdist: prepare host tools on demand
Date: Tue, 13 Oct 2026 13:17:39 +0200	[thread overview]
Message-ID: <as4TU-4pebmXMFeo@lenoch> (raw)
In-Reply-To: <as4S9kELLgKY9wdR@lenoch>

From: Ladislav Michl <ladis@triops.cz>

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 <ladis@triops.cz>
---
 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




  parent reply	other threads:[~2026-10-13 11:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13 11:16 [ptxdist] [PATCH 0/6] New BSP from template Ladislav Michl
2026-10-13 11:16 ` [ptxdist] [PATCH 1/6] scripts: add ptxdist_bootstrap.sh with out-of-tree build support Ladislav Michl
2026-10-13 11:17 ` [ptxdist] [PATCH 2/6] ptxdist: introduce PTXDIST_HOSTTOOLS_DIR Ladislav Michl
2026-10-13 11:17 ` Ladislav Michl [this message]
2026-10-13 11:18 ` [ptxdist] [PATCH 4/6] ptxdist: don't depend on bash being /bin/bash Ladislav Michl
2026-10-13 11:18 ` [ptxdist] [PATCH 5/6] configure: use ptxdist_bootstrap.sh to check the host Ladislav Michl
2026-10-13 11:18 ` [ptxdist] [PATCH 6/6] ptxdist: let new project raise from template Ladislav Michl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=as4TU-4pebmXMFeo@lenoch \
    --to=oss-lists@triops.cz \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox