Skip to content

Commit 2743ba5

Browse files
committed
build: symlink resolved CPM deps into the tree for humans
- configure.sh links deps/<name> -> each dep's resolved source and build/<profile>/moxygen -> the moxygen install prefix, read from the configured CMakeCache, so the hash-named cache dirs are findable. - A --moxygen-dir checkout surfaces automatically: CPM_moxygen_SOURCE flows into CPM_PACKAGE_moxygen_SOURCE_DIR. - A real directory at a dep's name (pre-CPM submodule leftover in old checkouts) is warned about, never deleted. Fixes #583.
1 parent 3c0eb99 commit 2743ba5

5 files changed

Lines changed: 40 additions & 0 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ _CPack_Packages/
2424
# moxygen install.
2525
/.scratch/
2626

27+
# Discoverability symlinks to the resolved dependency sources (deps/README.md).
28+
/deps/*
29+
!/deps/README.md
30+
2731
# OS
2832
.DS_Store
2933

BUILD.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ pinned inside moxygen, in its
4444
not here. moqx's [/cmake/dependencies.cmake](/cmake/dependencies.cmake) pins the CPM
4545
ones: moxygen, catapult, reflect-cpp, yaml-cpp.
4646

47+
The resolved dependencies live in a cache outside the repo. After a configure,
48+
`deps/<name>` links to each dependency's source and `build/<profile>/moxygen` to
49+
the moxygen install prefix — see [/deps/README.md](/deps/README.md).
50+
4751
## Build
4852

4953
Three scripts, each taking the profile (`default` | `san` | `tsan`, default

cmake/DepsCache.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
# <root>/cpm CPM's source clones (CPM_SOURCE_CACHE)
44
# <root>/moxygen-<rev>-<plat> extracted prebuilt installs (FetchMoxygenPrebuilt.cmake)
55
#
6+
# scripts/configure.sh symlinks the resolved directories into the tree for
7+
# humans — see deps/README.md.
8+
#
69
# Root precedence: -DMOQX_DEPS_CACHE, $MOQX_DEPS_CACHE, $HOME/.cache/moqx, else a
710
# directory in the build tree (a container with no HOME). Relocating the root
811
# moves both halves; an explicit CPM_SOURCE_CACHE still wins for the clones alone.

deps/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[`scripts/configure.sh`](/scripts/configure.sh) symlinks each CPM dependency's resolved source into this directory.
2+
3+
This directory exists only for discoverability; it is not used during the build.
4+
5+
See [/BUILD.md](/BUILD.md#how-dependencies-work) for how the dependencies are resolved.

scripts/configure.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,30 @@ esac
267267
# profile switch rather than nesting inside the old target.
268268
ln -sfn "$profile/compile_commands.json" build/compile_commands.json
269269

270+
# deps/<name> -> each CPM dep's resolved source
271+
# build/<profile>/moxygen -> the resolved moxygen install prefix
272+
# For convenience only; nothing reads them (see deps/README.md).
273+
# Absolute targets: the sources live outside the repo.
274+
cache="$build_dir/CMakeCache.txt"
275+
# Sweep stale links first; whatever -e still hits is a real dir (e.g. a
276+
# submodule leftover), not safe to delete.
277+
find deps -mindepth 1 -maxdepth 1 -type l -exec rm -f {} +
278+
IFS=';' read -ra cpm_pkgs <<<"$(sed -n 's/^CPM_PACKAGES:INTERNAL=//p' "$cache")"
279+
for pkg in ${cpm_pkgs[@]+"${cpm_pkgs[@]}"}; do
280+
src="$(sed -n "s/^CPM_PACKAGE_${pkg}_SOURCE_DIR:INTERNAL=//p" "$cache")"
281+
[[ -d "$src" ]] || continue
282+
if [[ -e "deps/$pkg" ]]; then
283+
echo "configure.sh: deps/$pkg exists and is not a symlink — leaving it alone" >&2
284+
continue
285+
fi
286+
ln -sfn "$src" "deps/$pkg"
287+
done
288+
# moxygen_DIR is <prefix>/lib/cmake/moxygen in both modes (prebuilt cache
289+
# install and the superbuild's moxygen-install alike).
290+
moxygen_cmake_dir="$(sed -n 's/^moxygen_DIR:PATH=//p' "$cache")"
291+
[[ -n "$moxygen_cmake_dir" ]] \
292+
&& ln -sfn "$(dirname "$(dirname "$(dirname "$moxygen_cmake_dir")")")" "$build_dir/moxygen"
293+
270294
if [[ "$resolved" == "$moxygen" ]]; then
271295
echo "configure.sh: $build_dir configured ($resolved) — compile with: scripts/build.sh $profile"
272296
else

0 commit comments

Comments
 (0)